jiangping
2023-08-11 5c98be0b50b8ca78ed05358cbd434193e75dcd8a
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
<template>
  <div class="tl">
    <!--    工单详情信息    -->
    <V-WorkOrderInfo :info="info"></V-WorkOrderInfo>
    <div class="tl_title">
      <div class="tl_title_left">
        <div class="tl_title_left_x"></div>
        <span>投料信息</span>
        <span>{{total == 0 ? '' : total}}{{formList[formList.length - 1].dw ? formList[formList.length - 1].dw : ''}}</span>
      </div>
      <div class="tl_title_right" @click="add">
        <img src="@/assets/icon/gongdan_ic_shoudong@2x.png" alt="" />
        <span>增加投料</span>
      </div>
    </div>
    <van-swipe-cell v-for="(item, index) in materialList" :key="index">
      <div class="tl_list">
        <div class="tl_list_item" @click="open1(index)">
          <div class="tl_list_item_label">选择物料</div>
          <div class="tl_list_item_go" v-if="!item.materialName">
            <span :style="item.materialName ? 'color: #000000;' : ''">
              点击跳转到物料列表
            </span>
            <van-icon name="arrow" color="#999999" />
          </div>
          <div class="tl_list_item_wl" v-else>
            <div class="tl_list_item_wl_top">
              <span>{{ item.materialName }}</span>
              <span>&nbsp;|&nbsp;{{ item.materialCode }}</span>
            </div>
            <div class="tl_list_item_wl_bottom">
              <span class="green" v-if="item.qualityType == 0">合格</span>
              <span class="yellow" v-else-if="item.qualityType == 1">不良</span>
              <span class="red" v-else-if="item.qualityType == 2">报废</span>
              <span>{{ item.procedureName ? `&nbsp;/&nbsp;${item.procedureName}` : '&nbsp;/&nbsp;-' }}</span>
              <span>{{ item.locationName ? `&nbsp;/&nbsp;${item.locationName}` : '&nbsp;/&nbsp;-' }}</span>
              <span>{{ item.batch ? `&nbsp;/&nbsp;${item.batch}` : '&nbsp;/&nbsp;-' }}</span>
            </div>
          </div>
        </div>
        <div class="tl_list_item">
          <div class="tl_list_item_label">投料数量{{ item.unitAttribute }}</div>
          <div class="tl_list_item_go">
            <input type="text" @blur="changeNumber(item.num, index, item.unitAttribute)" v-model="item.num" />
          </div>
        </div>
      </div>
      <template #right>
        <van-button square style="height: 100%;" type="danger" text="删除" @click="dele(index)" />
      </template>
    </van-swipe-cell>
    <div class="tl_zw"></div>
    <div class="tl_footer">
      <button class="tl_footer_submit" v-preventReClick @click="submit">提交</button>
    </div>
  </div>
  <!--  入库物料  -->
  <MaterialT :show="show" :workorderId="String(workorderId)" :deviceId="deviceId" @close="close" @value="getValue" />
  <!--  工装器具  -->
  <!-- <Tooling :show="gzShow" :attribute="info.type === 2 ? `${Attribute.BL}` : `${Attribute.HG},${Attribute.HH}`" :classification="true" @close="close" @value="getValue" /> -->
</template>
 
<script setup lang="ts">
    import { ref, onMounted, watch } from 'vue'
    import { useRoute, useRouter } from "vue-router"
    import { queryById, createMaterial, createMaterialStandard } from '@/apis/WorkOrderAPI'
    import { Toast } from 'vant'
    import { REGULAR } from '@/utils/utils'
    import { Attribute } from '@/enum'
    // import Tooling from '@/components/common/Tooling.vue'
    import VWorkOrderInfo from '@/components/common/WorkOrderInfo.vue'
    // import Material from '@/components/common/Material.vue'
    import MaterialT from '@/components/common/MaterialT.vue'
 
    const route = useRoute()
    const router = useRouter()
 
    // 投料索引
    let indexs = ref<number>()
 
    let info: any = ref({})
    let total = ref<number>(0)
    let workorderId = ref<string>('')
    let deviceId = ref<string>('')
    let gzShow = ref<boolean>(false)
 
    let show = ref<boolean>(false)
 
    // 投料信息
    let materialList: any = ref([
      {
        id: '',
        materialName: '',
        materialCode: '',
        qualityType: '',
        procedureName: '',
        locationName: '',
        batch: '',
        num: '',
        unitAttribute: ''
      }
    ])
 
    // 投料信息数组
    let formList: any = ref([
      {
        id: Date.now(),
        toolingTypeId: '',    // 工装类型
        toolingTypeName: '',// 工装类型名称
        workClothesId: '',    // 工装
        workClothesName: '',// 工装名称
        num: '',              // 数量
        attribute: '',         // 工装属性
        attributeType: '',         // 工装属性类型
        dw: '',         // 物料单位
        unitAttribute: ''
      }
    ])
 
    const gzshow = ref<boolean>(false)
 
    // 获取物料数据
    const getValue = (item: any) => {
      for (let i = 0; i < materialList.value.length; i++) {
        if (item.id === materialList.value[i].id) {
          Toast.fail({ message: '不能重复选择相同物料' })
          return
        }
      }
      materialList.value[indexs.value as number].id = item.id
      materialList.value[indexs.value as number].materialName = item.materialName
      materialList.value[indexs.value as number].num = item.num
      materialList.value[indexs.value as number].batch = item.batch
      materialList.value[indexs.value as number].locationName = item.locationName
      materialList.value[indexs.value as number].materialCode = item.materialCode
      materialList.value[indexs.value as number].procedureName = item.procedureName
      materialList.value[indexs.value as number].qualityType = item.qualityType
      materialList.value[indexs.value as number].unitAttribute = item.unitAttribute
      show.value = false
      // return
      //   if (!item.umodelName) {
      //       Toast.fail({ message: '该工装暂无物料,不能进行投料' })
      //       return
      //   }
      //   formList.value[indexs.value as number].toolingTypeId = item.cmodel1BigName
      //   formList.value[indexs.value as number].toolingTypeName = item.categoryId
      //   formList.value[indexs.value as number].workClothesId = item.id
      //   formList.value[indexs.value as number].workClothesName = item.code
      //   formList.value[indexs.value as number].attribute = item.smodelCode
      //   formList.value[indexs.value as number].attributeType = item.smodelLabel
      //   formList.value[indexs.value as number].dw = item.umodelName
      //   formList.value[indexs.value as number].num = item.num
      //   gzShow.value = false
    }
 
    const close = () => {
        show.value = false
    }
 
    // 失去焦点验证整数小数
    const changeNumber = (num: any, index: number, unitAttribute: number): void => {
      if (unitAttribute === 0 && num !== '') {
        if(!REGULAR.positiveInteger.test(num)){
          Toast({ message: '只能输入正整数' })
          materialList.value[index].num = ''
        }
      } else if (unitAttribute === 1 && num !== '') {
        if(!REGULAR.number.test(num)){
          Toast({ message: '只能输入正整数或小数(最多四位)' })
          materialList.value[index].num = ''
        }
      }
      if (num <= 0) {
        Toast({ message: '投料数量不能小于等于0' })
        materialList.value[index].num = ''
      }
    }
 
    // 打开工装弹框
    const open1 = (index: number): void => {
      indexs.value = index
      show.value = true
    }
 
    // 添加投料信息
    const add = (): void => {
      materialList.value.unshift({
        id: '',
        materialName: '',
        materialCode: '',
        qualityType: '',
        procedureName: '',
        locationName: '',
        batch: '',
        num: '',
        unitAttribute: ''
      })
    }
 
    // 删除投料信息
    const dele = (index: number): void => {
      if (materialList.value.length === 1) {
        Toast('至少保留一条投料信息')
        return
      }
      materialList.value.splice(index, 1)
    }
 
    // 提交手动投料
    const submit = (): void => {
      let isOpen: any = true
      materialList.value.forEach((item: any, index: number) => {
        if (!item.num) {
          Toast({ message: `请先完善第${index + 1}条投料信息`, duration: 2000 })
          isOpen = false
        }
      })
      let total: number = 0
      materialList.value.forEach((item: any, index: number) => {
        if (item.num > 0) {
          total += Number(item.num)
        }
      })
      if (info.value.bomType !== 1 && info.value.hasBom !== 1) {
        if (total > info.value.planNum) {
          Toast.fail({ message: '投料数量不能大于计划数量', duration: 2000 })
          return
        }
      }
      if (isOpen) {
        let recordList: any = []
        materialList.value.forEach((item: any) => {
          recordList.push({ wstockId: item.id, num: item.num })
        })
        createMaterialStandard({
          id: route.query.id,
          recordList: recordList
        }).then(res => {
          if (res.code === 200) {
            Toast.success({ message: '投料成功', duration: 2000, forbidClick: true })
            setTimeout(() => {
              router.go(-1)
            }, 2000)
          }
        })
      }
    }
 
    // 获取详情数据
    const queryByIds = (): void => {
      queryById(route.query.id).then(res => {
        if (res.code === 200) {
          info.value = res.data
          workorderId.value = route.query.id as string
          deviceId.value = res.data.pgmodel.id
        }
      })
    }
 
    // 根据id查询工装
    // const getListByConditions = (id: any): void => {
    //     getListByCondition({
    //         categoryId: id
    //     }).then(res => {
    //         if (res.code === 200) {
    //             console.log(res)
    //         }
    //     })
    // }
 
    watch(() => formList.value, (news) => {
        total.value = 0
        news.forEach((element: any) => {
            total.value = total.value + Number(element.num)
        })
    }, { deep: true })
 
    onMounted(() => {
      queryByIds()
    })
</script>
 
<style lang="scss" scoped>
  .tl {
    width: 100%;
    height: 100%;
    position: absolute;
    background: #F7F7F7;
    .tl_title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 30px;
      .tl_title_left {
        display: flex;
        align-items: center;
        .tl_title_left_x {
          width: 8px;
          height: 30px;
          background: $nav-color;
          border-radius: 2px;
          margin-right: 12px;
        }
        span {
          font-size: 32px;
          font-weight: 500;
          color: #222222;
          &:nth-child(3) {
            font-size: 28px;
            font-weight: 500;
            color: $nav-color;
              margin-left: 10px;
          }
        }
      }
      .tl_title_right {
        display: flex;
        align-items: center;
        img {
          width: 28px;
          height: 28px;
          margin-right: 12px;
        }
        span {
          font-size: 28px;
          font-weight: 400;
          color: $nav-color;
        }
      }
    }
    .tl_list {
      display: flex;
      flex-direction: column;
      background: white;
      padding: 0 30px;
      margin-bottom: 20px;
      .tl_list_item {
        min-height: 98px;
        // padding: 20px 0;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid #E5E5E5;
        &:last-child {
          border: none !important;
        }
        .tl_list_item_label {
          font-size: 30px;
          font-weight: 400;
          color: #222222;
        }
        .tl_list_item_wl {
          display: flex;
          flex-direction: column;
          align-items: end;
          .tl_list_item_wl_top {
            display: flex;
            align-items: center;
            span {
              font-size: 28px;
              color: #222222;
            }
          }
          .tl_list_item_wl_bottom {
            display: flex;
            align-items: center;
            span {
              font-size: 28px;
              color: #222222;
            }
          }
        }
        .tl_list_item_go {
          display: flex;
          align-items: center;
          input {
            text-align: right;
            width: 180px;
            height: 60px;
            border-radius: 8px;
            border: 1PX solid #E5E5E5;
            padding: 0 30px;
            box-sizing: border-box;
            font-size: 28px;
            font-weight: 400;
            color: #333333;
          }
          span {
            font-size: 28px;
            font-weight: 400;
            color: #999999;
            margin-right: 10px;
          }
        }
      }
    }
    .tl_zw {
      height: 160px;
    }
    .tl_footer {
      width: 100%;
      position: fixed;
      bottom: 0;
      left: 0;
      padding: 0 30px 68px 30px;
      box-sizing: border-box;
      .tl_footer_submit {
        width: 690px;
        height: 88px;
        border: none;
        background: #4275FC;
        box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08);
        border-radius: 8px;
        font-size: 30px;
        font-weight: 500;
        color: #FFFFFF;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }
</style>