jiangping
2023-10-24 349bcef9a96391d22522a3409adf5a89e7e70a95
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="设备编码:" prop="code">
        <el-input v-model="form.code" :disabled="form.id" placeholder="可填写,忽略将自动生成" v-trim/>
      </el-form-item>
      <el-form-item label="设备名称:" prop="name">
        <el-input v-model="form.name" placeholder="请输入设备名称" v-trim/>
      </el-form-item>
      <el-form-item label="设备型号:" prop="model">
        <el-input v-model="form.model" placeholder="请输入设备型号" v-trim/>
      </el-form-item>
      <el-form-item label="所属工序:" prop="procedureId">
        <el-select style="width:48%;" v-model="factory" @visible-change="visibleChange" :loading="loading" placeholder="请选择工厂" filterable clearable @change="selectFactory">
          <el-option
            v-for="item in factoreis"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
        <div style="width:4%;display: inline-block;"></div>
        <el-select style="width:48%" v-model="form.procedureId" placeholder="请选择工序" filterable clearable @change="selectProcedure">
          <el-option
            v-for="item in productes"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
          <!-- <el-select v-model="form.procedureId" placeholder="请选择" @change="selectProcedure">
              <el-option
                  v-for="item in productes"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
              </el-option>
          </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="关联货位" prop="updateTime">
          <el-select v-model="form.updateTime" placeholder="请选择">
              <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
          </el-select>
      </el-form-item> -->
      <el-form-item label="设备类型" prop="type">
         <el-select v-model="form.type" placeholder="请选择设备类型" filterable clearable @change="selectType">
            <el-option
              v-for="item in level"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
         </el-select>
      </el-form-item>
      <el-form-item v-if="form.type==1" label="所属设备组:" prop="groupId">
         <el-select v-model="form.groupId" placeholder="请选择设备组" filterable clearable @change="selectGroup">
            <el-option
              v-for="item in diveGroup"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
         </el-select>
      </el-form-item>
      <el-form-item label="关联待生产货位:" prop="produceWarehouseLocationId">
        <el-select style="width:48%;" v-model="produceWarehouse" placeholder="请选择仓库" @visible-change="visibleChange1" :loading="loading" filterable clearable :disabled="canSelect" @change="selectProduceWarehouse">
          <el-option
            v-for="item in warehousesone"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
        <div style="width:4%;display: inline-block;"></div>
        <el-select style="width:48%" v-model="form.produceWarehouseLocationId" filterable clearable :disabled="canSelect" placeholder="请选择">
          <el-option
            v-for="item in produceWarehouseLocation"
            :key="item.id"
            :label="item.unionName"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="关联已完工货位:" prop="finishWarehouseLocationId">
        <el-select style="width:48%;" v-model="finishWarehouse" placeholder="请选择仓库" @visible-change="visibleChange2" :loading="loading" filterable clearable :disabled="canSelect" @change="selectFinishWarehouse">
          <el-option
            v-for="item in warehouses"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
        <div style="width:4%;display: inline-block;"></div>
        <el-select style="width:48%" v-model="form.finishWarehouseLocationId" filterable clearable :disabled="canSelect" placeholder="请选择">
          <el-option
            v-for="item in finishWarehouserLocation"
            :key="item.id"
            :label="item.unionName"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属员工:" prop="userIds">
        <el-select v-model="form.userIds" @visible-change="visibleChange3" :loading="loading" multiple clearable filterable placeholder="请选择" @change="selectUser">
          <el-option
            v-for="(item, index) in user"
            :key="item.id"
            :label="index==0?'全部':(item.name + '-' + item.dmodel.name + '-' + item.phone)"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工位编号:" prop="stationCode">
        <el-input v-model="form.stationCode" placeholder="请输入工位编号" v-trim/>
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { productesGroup } from '@/api/ext/proceduresExt'
import { equipmentGroup } from '@/api/ext/deviceExt'
import { queryWarehouseAllData } from '@/api/ext/warehouseExt'
import { getDepartmentListByConditon } from '@/api/ext/departmentExt'
import { validateSpecialKey } from '@/assets/js/validate'
import { getListByWarehouseId } from '@/api/ext/warehouseLocationExt'
import { companyUserExtAllUser as getUserDevice } from '@/api/ext/companyUserExt'
export default {
  name: 'OperaDeviceExtWindow',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      options: [
        { label: '测试一', value: 'a' },
        { label: '测试二', value: 'w' }
      ],
      loading: false,
      factoreis: [],
      factory: null,
      productes: [],
      diveGroup: [],
      user: [],
      level: [
        //  0设备 1组
        { name: '设备', id: 1 },
        { name: '设备组', id: 0 }
      ],
      // 表单数据
      form: {
        id: null,
        // updateTime: '',
        procedureId: '',
        code: '',
        type: '',
        name: '',
        model: '',
        stationCode: '',
        groupId: null,
        userIds: [],
        produceWarehouseLocationId: null,
        finishWarehouseLocationId: null
      },
      warehouses: [],
      warehousesone: [],
      produceWarehouse: null,
      produceWarehouseLocation: [],
      finishWarehouse: null,
      finishWarehouserLocation: [],
      // 验证规则
      rules: {
        // code: [
        //   { required: true, message: '请输入设备编码', trigger: 'blur' },
        //   { max: 20, message: '输入字数不超过20', trigger: 'blur' },
        //   { validator: validateSpecialKey, trigger: 'blur' }
        // ],
        name: [
          { required: true, message: '请输入设备名称', trigger: 'blur' },
          { max: 20, message: '输入字数不超过20', trigger: 'blur' }
        ],
        model: [
          { required: false, message: '请输入设型号', trigger: 'blur' },
          { max: 20, message: '输入字数不超过20', trigger: 'blur' }
        ],
        procedureId: [{ required: true, message: '请选择工序', trigger: 'change' }],
        type: [{ required: true, message: '请选择设备类型', trigger: 'change' }],
        produceWarehouseLocationId: [{ required: true, message: '请选择待生产货位', trigger: 'change' }],
        finishWarehouseLocationId: [{ required: true, message: '请选择已完工货位', trigger: 'change' }]
      }
    }
  },
  computed: {
    canSelect: {
      get () {
        if (this.form.groupId) {
          return true
        }
        return false
      }
    }
  },
  created () {
    this.config({
      api: '/ext/deviceExt',
      'field.id': 'id'
    })
    // equipmentGroup({})
    //   .then(res => {
    //     this.diveGroup = res
    //   })
    //   .catch(err => {
    //     console.log(err)
    //   })
    this.form.type=1;
  },
  methods: {
    confirm() {
      if (this.form.id == null || this.form.id === '') {
        this.$refs.form.validate((valid) => {
          if (!valid) {
            return
          }
          // 调用新建接口
          this.isWorking = true
          let data = JSON.parse(JSON.stringify(this.form))
          data.userIds = data.userIds.join(',')
          this.api.create(data)
            .then(() => {
              this.visible = false
              this.$tip.apiSuccess('新建成功')
              this.$emit('success')
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking = false
            })
        })
      } else {
        this.$refs.form.validate((valid) => {
          if (!valid) {
            return
          }
          // 调用更新接口
          this.isWorking = true
          let data = JSON.parse(JSON.stringify(this.form))
          data.userIds = data.userIds.join(',')
          this.api.updateById(data)
            .then(() => {
              this.visible = false
              this.$tip.apiSuccess('修改成功')
              this.$emit('success')
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking = false
            })
        })
      }
    },
    selectUser (v) {
      if (v.indexOf('all') != -1) {
        let all = this.user.map(item => item.id)
        this.form.userIds = all.filter(item => item != 'all')
      }
    },
    visibleChange3(e) {
      // if (e) {
      //   this.loading = true
        getUserDevice({ departmentId: this.$store.state.userInfo.curComDepartment.id })
        .then(res => {
          if (res.length > 0) {
            this.user = [{ id: 'all' }, ...res]
          }
          this.loading = false
        })
        .catch(err => {
          console.log(err)
          this.loading = false
        })
      // }
    },
    visibleChange2(e) {
      if (e) {
        this.loading = true
        queryWarehouseAllData({
          useLocation: 1,
          status: 1,
          systemDicDataId: 7,
          rootDepartId: this.$store.state.userInfo.curComDepartment.id
        })
          .then(res => {
            this.warehouses = res
            this.loading = false
          })
          .catch(err => {
            console.log(err)
            this.loading = false
          })
      }
    },
    visibleChange1(e) {
      if (e) {
        this.loading = true
        queryWarehouseAllData({
          useLocation: 1,
          status: 1,
          rootDepartId: this.$store.state.userInfo.curComDepartment.id
        })
          .then(res => {
            this.warehousesone = res
            this.loading = false
          })
          .catch(err => {
            console.log(err)
            this.loading = false
          })
      }
    },
    visibleChange(e) {
      if (e) {
        this.loading = true
        getDepartmentListByConditon({
          type: 1
        })
          .then(res => {
            // console.log(res)
            this.factoreis = res
            this.loading = false
          })
          .catch(err => {
            console.log(err)
            this.loading = false
          })
      }
    },
    open (title, target) {
      this.visibleChange3(true)
      this.visibleChange2(true)
      this.visibleChange1(true)
      this.visibleChange(true)
      this.title = title
      this.visible = true
      this.produceWarehouse = null
      this.finishWarehouse = null
      this.factory = null
      this.productes = []
      this.produceWarehouseLocation = []
      this.finishWarehouserLocation = []
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form[this.configData['field.id']] = null
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          if (key == 'userIds') {
            this.form.userIds = target['userDeviceExtListVOS'].map(item => item.companyUserId)
            console.log(this.form.userIds)
          } else {
            this.form[key] = target[key]
          }
        }
        // console.log(this.form)
        this.produceWarehouse = target.wpmodel.warehouseId
        this.finishWarehouse = target.wfmodel.warehouseId
        this.factory = target.pmodel.orgId
        this.getProcedure(target.pmodel.orgId)
        this.getDevice()
        this.wareHouserAndLocaltion(target.wpmodel.warehouseId, 0)
        this.wareHouserAndLocaltion(target.wfmodel.warehouseId, 1)
      })
    },
    selectFactory (v) {
      this.form.procedureId = null
      this.getProcedure(v)
    },
    getProcedure (v) {
      productesGroup({ orgId: v })
        .then(res => {
          this.productes = res
        })
        .catch(err => {
          console.log(err)
        })
    },
    selectProduceWarehouse (v) {
      this.form.produceWarehouseLocationId = null
      this.wareHouserAndLocaltion(v, 0, '')
    },
    selectFinishWarehouse (v) {
      this.form.finishWarehouseLocationId = null
      this.wareHouserAndLocaltion(v, 1, 7)
    },
    selectProcedure (v) {
      if (this.form.type === 1 && v) {
        this.diveGroup = []
        this.getDevice()
      }
    },
    selectType (v) {
      this.produceWarehouse = null
      this.finishWarehouse = null
      this.form.finishWarehouseLocationId = null
      this.form.produceWarehouseLocationId = null
      this.produceWarehouseLocation = []
      this.finishWarehouserLocation = []
      if (v === 1 && this.form.procedureId) {
        this.getDevice()
      } else {
        this.form.groupId = null
      }
    },
    getDevice () {
      equipmentGroup({
        type: 0,
        procedureId: this.form.procedureId
      })
        .then(res => {
          this.diveGroup = res
        })
        .catch(err => {
          console.log(err)
        })
    },
    selectGroup (v) {
      for (const item of this.diveGroup) {
        if (item.id === v) {
          this.setLocation(item)
          return
        }
      }
    },
    setLocation (group) {
      this.produceWarehouse = group.wpmodel.warehouseId
      this.finishWarehouse = group.wfmodel.warehouseId
      this.form.finishWarehouseLocationId = group.wfmodel.id
      this.form.produceWarehouseLocationId = group.wpmodel.id
      this.wareHouserAndLocaltion(group.wpmodel.warehouseId, 0)
      this.wareHouserAndLocaltion(group.wfmodel.warehouseId, 1)
    },
    /**
     * @param type 0 待产货位 1产出货位
    */
    wareHouserAndLocaltion (v, type, systemDicDataId) {
      getListByWarehouseId(v, 1, systemDicDataId)
        .then(res => {
          // console.log(res)
          if (type === 0) {
            this.produceWarehouseLocation = res
          } else {
            this.finishWarehouserLocation = res
          }
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>