jiangping
2023-08-21 2837bdd57f72e386bbf9a725e7b3a13e5eb9e930
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
<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 v-show="total > 0">{{total}}{{info.umodel ? info.umodel.name : ''}}</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 formList" :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">
                        <span :style="item.workClothesName ? 'color: #000000;' : ''">
                            <span v-if="!item.attributeType">点击选择工装</span>
                            <span class="black" v-else-if="item.attributeType === Attribute.HH">{{'[' + item.attribute + ']'}}</span>
                            <span class="red" v-else-if="item.attributeType === Attribute.BF">{{'[' + item.attribute + ']'}}</span>
                            <span class="yellow" v-else-if="item.attributeType === Attribute.BL">{{'[' + item.attribute + ']'}}</span>
                            <span class="green" v-else-if="item.attributeType === Attribute.HG">{{'[' + item.attribute + ']'}}</span>
                            <span v-if="item.attributeType" class="black">{{item.workClothesName}}</span>
                        </span>
                        <van-icon name="arrow" color="#999999" />
                    </div>
                </div>
                <div class="tl_list_item">
                    <div class="tl_list_item_label">产出数量({{info.umodel ? info.umodel.name : ''}})</div>
                    <div class="tl_list_item_go">
                        <input type="text" @blur="changeNumber(item.num, index)" 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_copy" @click="copy">复制投料</button>
            <div class="tl_z"></div>
            <button class="tl_footer_submit" v-preventReClick @click="submit">提交</button>
        </div>
    </div>
    <!--  工装器具  -->
    <Tooling :show="gzShow" :classification="true" :attribute="info.type === 2 ? `${Attribute.BF},${Attribute.HG}` : ''" @close="close" @value="getValue" />
</template>
 
<script setup lang="ts">
    import { ref, onMounted, watch } from 'vue'
    import { Toast } from 'vant'
    import { useRoute, useRouter } from "vue-router"
    import {queryById, createProduce, getOrocessRecord} from '@/apis/WorkOrderAPI'
    import { REGULAR } from '@/utils/utils'
    import { Attribute } from '@/enum'
    import VWorkOrderInfo from '@/components/common/WorkOrderInfo.vue'
    import Tooling from '@/components/common/Tooling.vue'
 
    const route = useRoute()
 
    const router = useRouter()
 
    let info: any = ref({})
 
    // 投料索引
    let indexs = ref<number>()
    let total = ref<number>(0)
    let gzShow = ref<boolean>(false)
 
    // 投料信息数组
    let formList: any = ref([
        {
            id: Date.now(),
            toolingTypeId: '',    // 工装类型
            toolingTypeName: '',// 工装类型名称
            workClothesId: '',    // 工装
            workClothesName: '',// 工装名称
            num: route.query.num,              // 数量
            attribute: '',         // 工装属性
            attributeType: ''         // 工装属性类型
        }
    ])
 
    // 复制投料
    const copy = () => {
        getOrocessRecord({
            workorderId: route.query.id,
            type: 0
        }).then(res => {
            if (res.code === 200) {
                if (res.data && res.data.length === 0) {
                    Toast({ message: '暂无投料' })
                    return
                }
                formList.value = []
                res.data.forEach((element: any) => {
                    formList.value.push({
                        id: Date.now(),
                        toolingTypeId: element.amodel.type,    // 工装类型
                        toolingTypeName: element.amodel.categoryId, // 工装类型名称
                        workClothesId: element.amodel.id,    // 工装
                        workClothesName: element.amodel.code, // 工装名称
                        num: element.num,              // 数量
                        attribute: element.smodelCode,         // 工装属性
                        attributeType: element.smodelLabel        // 工装属性类型
                    })
                })
            }
        })
    }
 
    const close = () => {
        gzShow.value = false
    }
 
    // 获取工装数据
    const getValue = (item: any) => {
        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
        gzShow.value = false
    }
 
    // 失去焦点验证整数小数
    const changeNumber = (num: any, index: number): void => {
        if (info.value.umodel.attributeData === 0 && num !== '') {
            if(!REGULAR.positiveInteger.test(num)){
                Toast({ message: '只能输入正整数' })
                formList.value[index].num = ''
            }
        } else if (info.value.umodel.attributeData === 1 && num !== '') {
            if(!REGULAR.number.test(num)){
                Toast({ message: '只能输入正整数或小数(最多四位)' })
                formList.value[index].num = ''
            }
        }
    }
 
    // 打开工装弹框
    const open1 = (index: number): void => {
        indexs.value = index
        gzShow.value = true
    }
 
    // 添加投料信息
    const add = (): void => {
      formList.value.unshift({ id: Date.now(), toolingTypeId: '', toolingTypeName: '', workClothesId: '', workClothesName: '', num: formList.value[formList.value.length - 1].num })
    }
 
    // 删除投料信息
    const dele = (index: number): void => {
      if (formList.value.length === 1) {
        Toast('至少保留一条投料信息')
        return
      }
      formList.value.splice(index, 1)
    }
 
    // 查询工单详情
    const queryByIds = () => {
        queryById(route.query.id).then(res => {
            if (res.code === 200) {
                info.value = res.data
            }
        })
    }
 
    // 提交产出
    const submit = () => {
 
      let isOpen: any = true
 
      formList.value.forEach((item: any) => {
        if (item.toolingTypeId === '' || item.workClothesId === '' || item.num === '') {
          isOpen = false
        }
      })
 
      if (isOpen) {
        let recordList: any = []
        formList.value.forEach((item: any) => {
            recordList.push({ applianceId: item.workClothesId, num: item.num })
        })
        createProduce({
          id: route.query.id,
          recordList: recordList
        }).then(res => {
          if (res.code === 200) {
            Toast.success({
              message: '产出成功',
              duration: 2000,
              forbidClick: true
            })
            setTimeout(() => [
              router.go(-1)
            ], 2000)
          }
        })
      } else {
        Toast({
          message: '请先完善产出信息',
          duration: 2000
        })
      }
    }
 
    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 {
                height: 98px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                /*padding-bottom: 30px;*/
                /*margin-top: 30px;*/
                border-bottom: 1px solid #E5E5E5;
                &:first-child {
                    margin-top: 0 !important;
                }
                &:last-child {
                    padding-bottom: 0 !important;
                    border: none !important;
                }
                .tl_list_item_label {
                    font-size: 30px;
                    font-weight: 400;
                    color: #222222;
                    flex-shrink: 0;
                }
                .tl_list_item_go {
                    flex: 1;
                    display: flex;
                    align-items: center;
                    justify-content: flex-end;
                    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;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .tl_z {
                width: 20px;
            }
            .tl_footer_copy {
                flex: 1;
                height: 88px;
                background: #FFFFFF;
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 30px;
                font-weight: 500;
                color: $nav-color;
                border: none !important;
                box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08);
            }
            .tl_footer_submit {
                flex: 1;
                height: 88px;
                background: $nav-color;
                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;
                border: none;
            }
        }
    }
</style>