edit.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div>
  3. <Toptitle :title="$route.query.type==1?'新增':$route.query.type==2?'编辑':'查看'">
  4. <Button type="primary" style="margin-right:10px;" @click="del_total" v-show="$route.query.type==1">批量删除</Button>
  5. <Upload
  6. v-show="$route.query.type!=3"
  7. style="display:inline-block"
  8. name="your_file"
  9. :show-upload-list="false"
  10. :headers="headers"
  11. :on-error="uploadError"
  12. :on-success="uploadSuccess"
  13. :action="$store.state.ip + '/api/cut_order_alloy_import'"
  14. >
  15. <Button type="primary" style="margin-right:10px;"
  16. >导入</Button
  17. >
  18. </Upload>
  19. <Button style="margin-right:10px;" @click="back">返回</Button>
  20. <Button @click="postData" v-show="$route.query.type!=3">保存</Button>
  21. </Toptitle>
  22. <div style="height:85%;overflow:auto">
  23. <Form :label-width='100' style="display:flex;margin-top:15px;flex-wrap:wrap;border-bottom: 1px solid #F4F4F4; ">
  24. <FormItem label='项目编码:' style="width:250px">
  25. <span v-if="$route.query.type==3">{{searchData.project_code}}</span>
  26. <Input v-else clearable :disabled='true' v-model="searchData.project_code"/>
  27. </FormItem>
  28. <FormItem label='项目名称:' style="width:250px">
  29. <span v-if="$route.query.type==3">{{searchData.project_title}}</span>
  30. <Input v-else clearable :disabled='true' v-model='searchData.project_title'/>
  31. </FormItem>
  32. <FormItem label='项目简称:' style="width:250px">
  33. <span v-if="$route.query.type==3">{{searchData.abbreviation}}</span>
  34. <Input v-else clearable :disabled='true' v-model="searchData.abbreviation"/>
  35. </FormItem>
  36. <FormItem label='下单日期:' style="width:250px" class="red_star">
  37. <span v-if="$route.query.type==3">{{searchData.alloy_time}}</span>
  38. <DatePicker type='date' v-model="searchData.alloy_time" placeholder='年/月/日' v-else></DatePicker>
  39. </FormItem>
  40. </Form>
  41. <div v-show="$route.query.type==3">
  42. <Form :label-width='100' style="display:flex;margin-top:15px;flex-wrap:wrap;">
  43. <FormItem label='图号'>
  44. <Select v-model="formData.url_number" filterable multiple>
  45. <Option v-for="(item,index) in url_number" :key="index" :label="item" :value="item"/>
  46. </Select>
  47. </FormItem>
  48. <FormItem label='名称'>
  49. <Select v-model="formData.title" filterable multiple>
  50. <Option v-for="(item,index) in title" :key="index" :label="item" :value="item"/>
  51. </Select>
  52. </FormItem>
  53. <FormItem>
  54. <Button type="primary" @click="initData(formData)">搜索</Button>
  55. </FormItem>
  56. </Form>
  57. </div>
  58. <Table :data='tableData' :columns='$route.query.type==1?tableColumns_add:tableColumns_edit' border max-height='550' @on-selection-change='choose'>
  59. <template slot="set" slot-scope="{row,index}">
  60. <a @click="del(row,index)">删除</a>
  61. </template>
  62. </Table>
  63. </div>
  64. <Page
  65. v-show="$route.query.type==3"
  66. :page-size-opts="[10, 20, 30, 40, 100, 1000]"
  67. @on-page-size-change="changeSize"
  68. @on-change="changePage"
  69. :current="pageIndex"
  70. show-total
  71. :total="total"
  72. show-sizer
  73. :page-size="pageSize"
  74. style="text-align: center; margin-top: 10px"
  75. />
  76. </div>
  77. </template>
  78. <script>
  79. export default {
  80. data(){
  81. return{
  82. url_number:[],
  83. title:[],
  84. formData:{
  85. url_number:[],
  86. title:[],
  87. },
  88. selectData:[],
  89. id:'',
  90. headers: { Authorization: localStorage.getItem("token") },
  91. tableData:[],
  92. tableColumns_add:[
  93. {align:'center',minWidth:60,type:'selection'},
  94. {title:"序号",align:'center',minWidth:80,type:'index'},
  95. {title:"图号",align:'center',minWidth:80,key:'url_number'},
  96. {title:"名称",align:'center',minWidth:80,key:'title'},
  97. {title:"规格型号",align:'center',minWidth:150,key:'model'},
  98. {title:"单位",align:'center',minWidth:80,key:'unit'},
  99. {title:"数量",align:'center',minWidth:80,key:'num'},
  100. {title:"备注",align:'center',minWidth:150,key:'remark'},
  101. {title:"操作",align:'center',minWidth:80,key:'set',slot:'set'},
  102. ],
  103. tableColumns_edit:[
  104. {title:"序号",align:'center',minWidth:80,type:'index'},
  105. {title:"图号",align:'center',minWidth:80,key:'url_number'},
  106. {title:"名称",align:'center',minWidth:80,key:'title'},
  107. {title:"规格型号",align:'center',minWidth:150,key:'model'},
  108. {title:"单位",align:'center',minWidth:80,key:'unit'},
  109. {title:"数量",align:'center',minWidth:80,key:'num'},
  110. {title:"备注",align:'center',minWidth:150,key:'remark'},
  111. {title:"操作",align:'center',minWidth:80,key:'set',slot:'set'},
  112. ],
  113. pageSize:10,
  114. pageIndex:1,
  115. total:0,
  116. searchData:{
  117. abbreviation:'',
  118. project_title:'',
  119. project_code:'',
  120. alloy_time:''
  121. }
  122. }
  123. },
  124. mounted(){
  125. if(this.$route.query.type!=1){
  126. this.initData();
  127. }
  128. },
  129. methods:{
  130. del_total(){
  131. let indexs = [];
  132. this.selectData.forEach(element => {
  133. indexs.push(element.index);
  134. });
  135. for(let i = 0;i<this.tableData.length;i++){
  136. if(indexs.indexOf(this.tableData[i].index)>=0){
  137. this.tableData.splice(i,1);
  138. i--;
  139. }
  140. }
  141. },
  142. choose(e){
  143. this.selectData = e;
  144. },
  145. postData(){
  146. if(!this.id&&this.$route.query.type==1){
  147. return this.$Message.warning('请先导入!')
  148. }
  149. if(!this.searchData.alloy_time){
  150. return this.$Message.warning('请先选择下单时间!')
  151. }
  152. let time = this.searchData.alloy_time;
  153. time = time?Date.parse(time).toString().slice(0,10):'';
  154. let url =this.$route.query.type==2?'/api/cut_order_alloy_edit':'/api/cut_order_alloy_save'
  155. this.axios.post(url,{alloy_time:time,id:this.$route.query.type==1?this.id:this.$route.query.id,data:this.tableData}).then(res=>{
  156. if(res.code==200){
  157. this.$Message.success(res.msg);
  158. this.back();
  159. }
  160. })
  161. },
  162. del(row,index){
  163. this.tableData.splice(index,1);
  164. },
  165. back(){
  166. this.$router.go(-1)
  167. },
  168. initData(row){
  169. this.axios.post('/api/cut_order_alloy_detail',{...this.$route.query,...row}).then(res=>{
  170. this.url_number = res.data.url_number||[];
  171. this.title = res.data.title||[];
  172. this.tableData = res.data.data.data;
  173. this.searchData.abbreviation = res.data.abbreviation;
  174. this.searchData.project_title=res.data.project_name;
  175. this.searchData.project_code=res.data.project_number;
  176. this.searchData.alloy_time = res.data.alloy_time?this.func.replaceDateNoHMS(res.data.alloy_time):''
  177. console.log(this.searchData.alloy_time);
  178. })
  179. },
  180. uploadSuccess(res) {
  181. if (res.code == 200) {
  182. this.$Message.success(res.msg || "上传成功");
  183. this.searchData.abbreviation = res.data.abbreviation;
  184. this.searchData.project_title = res.data.project_name;
  185. this.searchData.project_code = res.data.project_number;
  186. this.id = res.data.id;
  187. if(this.tableData.length==0){
  188. this.tableData = res.data.data;
  189. }else{
  190. this.copyTable = JSON.parse(JSON.stringify(this.tableData));
  191. let idxs = [];
  192. this.tableData.forEach((v,index)=>{
  193. res.data.data.forEach((m,idx)=>{
  194. if(v.material_id==m.material_id&&v.url_number==m.url_number){
  195. this.copyTable.splice(index,1,m);
  196. idxs.push(idx);
  197. }
  198. })
  199. })
  200. res.data.data.forEach((v,index)=>{
  201. if(idxs.indexOf(index)<0){
  202. this.copyTable.push(v);
  203. }
  204. })
  205. this.tableData = JSON.parse(JSON.stringify(this.copyTable));
  206. }
  207. this.tableData.forEach((v,index)=>{
  208. v.index = index;
  209. })
  210. } else {
  211. this.$Message.warning(res.msg || "上传失败");
  212. }
  213. },
  214. uploadError(err) {
  215. this.$Message.error(err.msg || "上传失败");
  216. },
  217. changeSize(e){
  218. this.pageSize =e;
  219. this.pageIndex = 1;
  220. this.initData(this.formData);
  221. },
  222. changePage(e){
  223. this.pageIndex = e;
  224. this.initData(this.formData);
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. //小红星
  231. /deep/.red_star .ivu-form-item-label:before {
  232. content: '*';
  233. display: inline-block;
  234. margin-right: 4px;
  235. line-height: 1;
  236. font-family: SimSun;
  237. font-size: 14px;
  238. color: #ed4014;
  239. }
  240. </style>