charles
2024-07-10 3f24fbc89959ec4aa9f3308e1af453e43d504ac5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<template>
    <el-dialog
            :visible.sync="editConfig.visible"
            :before-close="handleClose"
    >
        <!-- 头 -->
        <div slot="title" class="dialog-header">
            <span>{{editConfig.title}}车间管理</span>
        </div>
        <div class="dialog-view">
            <el-form
                    ref="workshopForm"
                    :model="editConfig.infomitton"
                    :rules="rules"
                    label-position="right"
                    label-width="100px"
                    size="mini"
            >
                <div>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item prop="workshop"  label="车间:" style="width: 100%;">
                                <el-select
                                        :disabled="editConfig.OperationType===3"
                                        v-model="editConfig.infomitton.workshop"
                                        value-key="workshopName" placeholder="请选择车间"
                                        @change="selWorkshop"
                                >
                                    <el-option
                                            v-for="item in workshopList"
                                            :key="item.ID"
                                            :label="item.name"
                                            :value="{workshopNumber:item.number,workshopName:item.name}">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="组别:" style="width: 100%;"
                                          prop="groupNumber"  >
                                <el-input
                                        type="number"
                                        :disabled="editConfig.OperationType===3"
                                        v-model.number="editConfig.infomitton.groupNumber"
                                        :rows="4"
                                        style="resize: none !important;"
                                        placeholder="请输入组别"
                                        @change="changeGroupNumber"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="开始车号:" style="width: 100%;" prop="startCarNumber" >
                                <el-input
                                        type="number"
                                        :disabled="editConfig.OperationType===3"
                                        v-model.number="editConfig.infomitton.startCarNumber"
                                        :rows="4"
                                        style="resize: none !important;"
                                        placeholder="请输入开始车号"
                                        @change="changeStartCarNumber"
                                >
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="结束车号:" style="width: 100%;"  prop="endCarNumber" >
                                <el-input
                                        type="number"
                                        :disabled="editConfig.OperationType===3"
                                        v-model.number="editConfig.infomitton.endCarNumber"
                                        :rows="4"
                                        style="resize: none !important;"
                                        placeholder="请输入结束车号"
                                >
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="标志类型:" style="width: 100%;" >
                                <el-select
                                        @change="changeCarFlag"
                                        :disabled="editConfig.OperationType===3" v-model.number="editConfig.infomitton.carFlag" placeholder="请选择标志类型">
                                    <el-option
                                            v-for="item in carFlagList"
                                            :key="item.value"
                                            :label="item.name"
                                            :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="备注:" style="width: 100%;" >
                                <el-input
                                        :disabled="this.editConfig.OperationType===3"
                                        v-model="editConfig.infomitton.notes"
                                        type="textarea"
                                        :rows="4"
                                        style="resize: none !important;"
                                        placeholder=""
                                >
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </div>
            </el-form>
        </div>
        <div class="dialog-footer">
            <div class="bottom-tabs">
                <div class="tab-pane" style="background:#2a78fb;color: #fff">
                    组别明细列表
                </div>
            </div>
            <div class="list-view">
                <TableCommonView :table-list="tableList"
                                 @selTableCol="selTableCol">
                    <template slot="tableButton">
                        <el-table-column label="开始车号" width="120" align="center">
                            <template slot-scope="scope">
                                {{scope.row.startCarNumber?scope.row.startCarNumber:'--'}}
                            </template>
                        </el-table-column>
                        <el-table-column label="开始标记" width="120" align="center" v-if="editConfig.infomitton.carFlag===1">
                            <template slot-scope="scope">
                                {{scope.row.startCarHalf===1?'左半车':'右半车'}}
                            </template>
                        </el-table-column>
                        <el-table-column label="结束车号" width="120" align="center">
                            <template slot-scope="scope">
                                <el-input type="number" :disabled="scope.row.noEdit" placeholder="请输入" v-model.number="scope.row.endCarNumber" size="small" v-if="editConfig.OperationType!==3"></el-input>
                                <span v-else>{{scope.row.endCarNumber}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="结束标记" v-if="editConfig.infomitton.carFlag===1" width="120" align="center">
                            <template slot-scope="scope">
                                <el-select size="small" :disabled="scope.row.noEdit" v-model="scope.row.endCarHalf" v-if="editConfig.OperationType!==3">
                                    <el-option label="左半车" :value="1">左半车</el-option>
                                    <el-option label="右半车" :value="2">右半车</el-option>
                                </el-select>
                                <span v-else>{{scope.row.endCarNumber}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="备注" width="100" align="center">
                            <template slot-scope="scope">
                                <el-input  placeholder="请输入" v-model="scope.row.notes" size="small" v-if="editConfig.OperationType!==3"></el-input>
                                <span v-else>{{scope.row.notes}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="操作"
                                width="60"
                                align="center"
                                v-if="editConfig.OperationType!==3"
                        >
                            <template slot-scope="scope">
                                <el-button
                                        type="text"
                                        size="small"
                                        @click.stop="handleDelClick(scope, '操作')">删除</el-button>
                            </template>
                        </el-table-column>
                    </template>
                </TableCommonView>
            </div>
            <div style="line-height: 50px" v-if="editConfig.OperationType!==3">
                <el-button type="primary" size="small" @click="addItem">新增</el-button>
                <el-button type="primary" size="small" @click="clearItem">清空</el-button>
            </div>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button
                    type="primary"
                    size="small"
                    @click="saveClick"
                    :disabled="editConfig.OperationType===3">保存</el-button>
            <el-button size="small" @click="handleClose">取消</el-button>
        </div>
    </el-dialog>
</template>
 
<script>
    import {getDict,saveWorkshopManage} from "@/api/systemSetting/workshopManage";
    export default {
        name: "workshopDialog",
        props:{
            editConfig:{
                type:Object,
                default:()=>({
                    visible: false,//弹框是否可见
                    title: "新建",
                    OperationType:1,//1 新建   2 修改   3 查看
                    infomitton: {
                        details:[]//列表数据
                    },//表单数据  + 明细列表数据
                })
            }
        },
        data(){
            return {
                tableList:{},
                showCol: ["开始标记","车间", "组别", "开始车号","开始标记", "结束车号", "结束标记","标志类型", "备注"],
                tableColumn: [
                    { label: "车间", prop: "workshopName" },
                    { label: "组别", prop: "groupNumber" },
                    { label: "标志类型", prop: "carFlag" ,isCallMethod:true,getCallMethod:(value)=>{return value===0?'全车':'半车'}},
                    /*{ label: "开始车号", prop: "startCarNumber" },*/
                    /*{ label: "结束车号", prop: "endCarNumber" },*/
                    /*{ label: "备注", prop: "notes", },*/
                ],
                workshopList:[],
                carFlagList:[
                    {
                        name:'全车',
                        value:0
                    },
                    {
                        name:'半车',
                        value:1
                    }
                ],// 标志类型列表
                rules:{
                    workshop: [
                        { required: true, message: '请选择车间', trigger: 'change' }
                    ],
                    groupNumber: [
                        { required: true, message: '请填写组别', trigger: 'blur' }
                    ],
                    startCarNumber: [
                        { required: true, message: '请填写', trigger: 'blur' }
                    ],
                    endCarNumber: [
                        { required: true, message: '请填写', trigger: 'blur' }
                    ],
                },
                itemModel:{//新增模板
                    startCarHalf:1,
                    endCarHalf:2,
                    workshopName:'',
                    groupNumber:'',
                    startCarNumber:'',
                    endCarNumber:'',
                    carFlag:1,
                    notes:''
                }
            }
        },
        created(){
          this.initData();
        },
        methods:{
            initBottomTableList(list){
                this.tableList.tableInfomation=JSON.parse(JSON.stringify(list));
            },
            clearData(){
                this.tableList.tableInfomation=[{...this.itemModel}];
                this.$refs['workshopForm'].resetFields();
                this.editConfig.visible=false;
            },
            doChangeData(val,fieldName){
                this.tableList.tableInfomation.forEach((item,index)=>{
                    if(fieldName==='workshop'){
                        item.workshopName=val.workshopName;
                        item.workshopNumber=val.workshopNumber;
                    }else if(fieldName==='startCarNumber'){
                        if(index===0){
                            item.startCarNumber=val;
                        }
                    }else{
                        item[fieldName]=val;
                    }
                });
            },
            //选择车间
            selWorkshop(val){
                this.doChangeData(val,'workshop');
            },
            //改变组别
            changeGroupNumber(val){
                this.doChangeData(val,'groupNumber');
            },
            changeStartCarNumber(val){
                this.doChangeData(val,'startCarNumber');
            },
            changeCarFlag(val){
                this.doChangeData(val,'carFlag');
            },
            //关闭模态框
            handleClose(){
                this.clearData();
            },
            //保存
            saveClick(){
                this.$refs['workshopForm'].validate(async (vail)=>{
                    if(vail){
                        const lastObj=this.tableList.tableInfomation[this.tableList.tableInfomation.length-1];
                        if(!lastObj.endCarNumber){
                            this.$message.error('明细结束车号不能为空');
                            return ;
                        }else if(lastObj.endCarNumber<lastObj.startCarNumber){
                            this.$message.error(`明细结束车号${lastObj.endCarNumber},不能小于明细起始车号${lastObj.startCarNumber}`);
                            return;
                        }else if(lastObj.endCarNumber>this.editConfig.infomitton.endCarNumber){
                            this.$message.error(`明细结束车号${lastObj.endCarNumber},不能大于车间总的结束车号${this.editConfig.infomitton.endCarNumber}`);
                            return;
                        }
                        //执行保存操作
                       const params={
                           ...this.editConfig.infomitton,
                           ...this.editConfig.infomitton.workshop,
                           details:[...this.tableList.tableInfomation].map(item=>{
                               item.startCarNumber=parseInt(item.startCarNumber);
                               item.groupNumber=parseInt(item.groupNumber);
                               return item;
                           })
                       };
                       delete params.workshop;
                       const {code}=await saveWorkshopManage(params);
                       if(code===200){
                           this.$message.success(`${this.editConfig.OperationType===1?'添加':'修改'}成功`);
                           window.setTimeout(()=>{
                               this.clearData();
                               this.$emit('refresh');
                           },500);
                       }else{
                           this.$message.error(`${this.editConfig.OperationType===1?'添加':'修改'}失败`);
                       }
                    }else{
                        this.$message.error('请先将表单填写完整');
                    }
                });
            },
            //新增明细
            addItem(){
                this.$refs['workshopForm'].validate((vail)=>{
                   if(vail){
                       const obj={...this.itemModel};
                       if(this.editConfig.infomitton.workshop){
                           obj.workshopName=this.editConfig.infomitton.workshop.workshopName;
                           obj.workshopNumber=this.editConfig.infomitton.workshop.workshopNumber;
                       }
                       if(this.editConfig.infomitton.groupNumber){
                           obj.groupNumber=this.editConfig.infomitton.groupNumber;
                       }
                       //判断上一个元素的结束车号
                       const lastObj=this.tableList.tableInfomation[this.tableList.tableInfomation.length-1];
                       if(!lastObj.endCarNumber){
                           this.$message.error('明细结束车号不能为空');
                           return ;
                       }else if(lastObj.endCarNumber<lastObj.startCarNumber){
                           this.$message.error(`明细结束车号${lastObj.endCarNumber},不能小于明细起始车号${lastObj.startCarNumber}`);
                           return;
                       }else if(lastObj.endCarNumber>this.editConfig.infomitton.endCarNumber){
                           this.$message.error(`明细结束车号${lastObj.endCarNumber},不能大于车间总的结束车号${this.editConfig.infomitton.endCarNumber}`);
                           return;
                       }
                       if(lastObj.endCarHalf===1){//左半车
                           obj.startCarNumber=lastObj.endCarNumber
                           obj.startCarHalf=2;//右半车
                       }else{
                           obj.startCarNumber=lastObj.endCarNumber+1;
                           obj.startCarHalf=1;//左半车
                       }
                       lastObj.noEdit=true;
                       this.$set(this.tableList.tableInfomation,this.tableList.tableInfomation.length-1,{...lastObj});
                       obj.carFlag=this.editConfig.infomitton.carFlag;
                       this.tableList.tableInfomation.push(obj);
                   }else{
                       this.$message.error('请先将表单填写完整');
                   }
                });
 
            },
            setTable() {
                this.tableList = {
                    maxHeight:320,
                    selectIndex: true,
                    tableInfomation: [{...this.itemModel}],
                    allcol: [],
                    showcol: this.showCol,
                    tableColumn: this.setColumnVisible(this.showCol, this.tableColumn)
                }
                this.setTableList(this.tableList)
            },
            selTableCol(val){
                this.showcol = val;
                this.tableList.tableColumn = this.setColumnVisible(val, this.tableColumn)
            },
            setTableList(tableList) {
                tableList.allcol = tableList.tableColumn.filter((ele) => !ele.default).map((ele) => ele.label)
            },
            setColumnVisible(showCol, tableColumn) {
                return tableColumn.map((ele) => {
                    return {
                        ...ele,
                        isShowColumn: showCol.includes(ele.label)
                    }
                })
            },
            initData(){
                this.setTable();
                this.getDictData();
            },
            async getDictData(){
                await getDict({dictType:1}).then((res)=>{
                    if(res&&res.code===200){
                        this.workshopList=res.data
                    }
                })
            },
            // 删除明细
            handleDelClick(scope){
                if(this.tableList.tableInfomation.length>1){
                    let index=scope.$index;
                    this.tableList.tableInfomation.splice(index,1);
                    const lastObj=this.tableList.tableInfomation[index-1];
                    lastObj.noEdit=false;
                    this.$set(this.tableList.tableInfomation,index-1,{...lastObj})
                }else{
                    this.$message.error('组别至少有一条明细');
                }
            },
            // 清空明细,但是保留第一条明细
            clearItem(){
                if(this.tableList.tableInfomation.length>1){
                    this.tableList.tableInfomation.splice(1,this.tableList.tableInfomation.length-1);
                    const lastObj=this.tableList.tableInfomation[0];
                    lastObj.noEdit=false;
                    this.$set(this.tableList.tableInfomation,scope.$index-1,{...lastObj})
                }else{
                    this.$message.error('组别至少有一条明细');
                }
            }
        }
    }
</script>
 
<style scoped lang="scss">
    .dialog-view{
        width: 96%;
    }
    .dialog-footer{
        .bottom-tabs {
            height: 40px;
            line-height: 40px;
            background: white;
            display: flex;
            .tab-pane {
                width: 100px;
                margin-right: 20px;
                font-size: 12px !important;
                text-align: center;
                cursor: pointer;
                background: #2a78fb;
                border-top-left-radius: 20px;
                border-top-right-radius: 20px;
            }
        }
    }
</style>