jiangping
2023-08-17 6365ab0a976afdd247742c9b3dca15deb3a7a7a1
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
<template>
    <div class="rework">
        <div class="rework_list">
            <div class="rework_list_item">
                <span>当前工厂</span>
                <div class="rework_list_item_right">
                    <span style="color:#000">{{ tempFactoryName }}</span>
                </div>
            </div>
            <div class="rework_list_item">
                <span>出库仓库</span>
                <div class="rework_list_item_right">
                    <span style="color:#000">{{ tempWarhouseName }}</span>
                </div>
            </div>
            <div class="rework_list_item" @click="warehouseShow = true">
                <span>入库仓库</span>
                <div class="rework_list_item_right">
                    <span :class="form.warehouseName ? 'black' : ''">{{form.warehouseName ? form.warehouseName : '请点击选择类型'}}</span>
                    <van-icon name="arrow" size="20" color="#999999" />
                </div>
            </div>
            <div class="rework_list_item">
                <span>报废原因</span>
                <div class="rework_list_item_right">
                    <input type="text" style="text-align:right" v-model="form.reason" placeholder="请输入报废原因" />
                </div>
            </div>
        </div>
        <div class="rework_qd">
            <div class="rework_qd_title">
                <div class="x"></div>
                <span>{{'报废工装清单(' + list.length + ')'}}</span>
            </div>
            <van-swipe-cell v-for="(item, index) in list" :key="index">
                <div class="rework_qd_item">
                    <div class="rework_qd_item_i">
                        <span class="black">{{ item.code }}:</span><span class="black">{{ item.num + item.umodelName }}</span>
                    </div>
                    <div class="rework_qd_item_i">
                        <span>物料信息:</span><span>{{ item.mmodelName + ' | ' + item.mmodelCode }}</span>
                    </div>
                    <div class="rework_qd_item_i">
                        <span>批次号:</span><span>{{ item.batch ?? '-' }}</span>
                    </div>
                    <div class="rework_qd_item_i">
                      <span>生产工序:</span><span>{{ item.pmodelName }}</span>
                    </div>
                </div>
                <template #right>
                    <van-button style="height: 100%;" square type="danger" text="删除" @click="dele(index)" />
                </template>
            </van-swipe-cell>
        </div>
        <div class="rework_zw"></div>
        <div class="rework_footer">
            <div class="rework_footer_add" @click="open">扫码添加工装</div>
            <div style="width: 22px;"></div>
            <button class="rework_footer_submit" @click="onConfirm">提交</button>
        </div>
        <v-ScanCode
            :openCode="openCode"
            :infos="['请扫描工装码']"
            @closePopup="closePopup"
            @onDecode="onDecode">
        </v-ScanCode>
      <Warehouse :show="warehouseShow" :systemDicDataId="'6,7'" @close="close" @value="getValue" />
    </div>
</template>
 
<script setup lang="ts">
  import { onMounted, ref, reactive } from 'vue'
  import { useRoute, useRouter } from "vue-router"
  import { Toast } from 'vant'
  import { getBarcodeContent, getListByCondition, createSingle } from '@/apis/WorkOrderAPI'
  import { QRCodeType } from "@/enum"
  import Warehouse from '@/components/common/Warehouse.vue'
 
 
    const route = useRoute()
    const router = useRouter()
    // 表单数据
    let form = reactive({
        warehouseName: '',
        warehouseId: '',
        reason: ''
    })
 
    // 报废清单
    let list = ref<Array<any>>([])
    let warehouseShow = ref<boolean>(false)
 
    let tempFactoryName = ref<string>()
    let tempFactoryId = ref<string>()
    let tempWarhouseName= ref<string>()
    let tempWarhouseId = ref<string>()
 
    let openCode = ref<boolean>(false)
    // 提交
    const onConfirm = async (value: any) => {
 
         let res = await createSingle({
            type: 3,
            factoryId: tempFactoryId.value,
            tempFactoryName: tempFactoryName.value,
            warehouseOutId: tempWarhouseId.value,
            warehouseId: form.warehouseId,
            content: form.reason,
            applianceIdList: list.value.map((item, index, arr) => { return item.id })
        })
 
        if (res.code === 200) {
          Toast.success({ message: '申请成功,等待审批!', duration: 2000, forbidClick: true })
          setTimeout(() => {
            router.back()
          }, 2000)
        } else {
          Toast.fail({ message: res.message })
        }
    }
 
    // 删除
    const dele = (index: any) => {
      if (list.value.length === 1) {
        Toast('至少保留一条工装信息')
        return
      }
      list.value.splice(index, 1)
    }
    // 关闭扫码框
    const closePopup = (): void => {
        openCode.value = false
    }
    // 扫码回调
    const onDecode = async (data: string[]): Promise<void> => {
        console.log(data)
        openCode.value = false
        let res = await getBarcodeContent({
            barcode: data[0]
        })
        if (res.code === 200) {
            if (res.data.barcodeType === QRCodeType.GZ) {
                // 查看是否已有工装
                for (let i = 0; i < list.value.length; i++) {
                    if (list.value[i].id === res.data.id) {
                        Toast.fail({ message: '不能扫描重复的工装' })
                        return
                    }
                }
                // 获取工装详情
                let lk = await getListByCondition({ id: res.data.id })
                if (lk.code === 200) {
                    if (lk.data[0].qualityType === 2) {
                        console.log(tempFactoryId.value, lk.data[0].pmodelOrgId)
                        console.log(tempWarhouseId.value, lk.data[0].warehouseId)
                        if (tempFactoryId.value === lk.data[0].pmodelOrgId &&  tempWarhouseId.value === lk.data[0].warehouseId) {
                          list.value.push(lk.data[0])
                        } else {
                          Toast.fail({ message: '请扫描相同仓库的工装' })
                        }
                    } else {
                        Toast.fail({ message: '请扫描质量属性为报废的工装', duration: 2000 })
                    }
                }
            } else {
                Toast.fail({ message: '请扫描正确的工装码' })
            }
        }
 
    }
    // 打开扫码
    const open = (): void => {
        openCode.value = true
    }
    // 关闭仓库选择弹框
    const close = (): void => {
      warehouseShow.value = false
    }
    // 选择仓库回调
    const getValue = (item: any): void => {
      console.log(item)
      form.warehouseName = item.name
      form.warehouseId = item.id
      warehouseShow.value = false
    }
 
    const getLKInfo = async (id: string | number): Promise<void> => {
        let res = await getListByCondition({ id })
        if (res.code === 200) {
            if (res.data[0].qualityType === 2) {
                list.value.push(res.data[0])
                tempFactoryName.value = res.data[0].dpmodelName
                tempFactoryId.value = res.data[0].pmodelOrgId
                tempWarhouseName.value = res.data[0].whmodelName
                tempWarhouseId.value = res.data[0].warehouseId
            } else {
                Toast.fail({ message: '请扫描质量属性为报废的工装', duration: 2000 })
            }
        }
    }
  onMounted(() => {
    // 获取工装信息
    getLKInfo(route.query.id as string)
  })
</script>
 
<style lang="scss" scoped>
    .rework {
        width: 100%;
        height: 100%;
        position: absolute;
        .rework_list {
            display: flex;
            flex-direction: column;
            background: white;
            margin-top: 20px;
            .rework_list_item {
                display: flex;
                align-items: center;
                justify-content: space-between;
                height: 98px;
                padding: 0 30px;
                border-bottom: 1PX solid #E5E5E5;
                &:last-child {
                    border: none;
                }
                span {
                    font-size: 30px;
                    font-weight: 400;
                    color: #222222;
                    flex-shrink: 0;
                }
                .rework_list_item_right {
                    display: flex;
                    align-items: center;
                    span {
                        font-size: 28px;
                        font-weight: 400;
                        color: #999999;
                    }
                    .black {
                        color: black !important;
                    }
                    input {
                        width: 230px;
                        font-size: 28px;
                        border: none;
                    }
                    input::-webkit-input-placeholder { /* WebKit browsers */
                        font-size: 28px;
                        font-weight: 400;
                        color: #B2B2B2;
                    }
                }
            }
        }
        .rework_qd {
            margin-top: 40px;
            .rework_qd_title {
                display: flex;
                align-items: center;
                padding: 0 30px 30px 30px;
                span {
                    font-size: 32px;
                    font-weight: 500;
                    color: #222222;
                }
                .x {
                    width: 8px;
                    height: 30px;
                    background: #4275FC;
                    border-radius: 2px;
                    margin-right: 12px;
                }
            }
            .rework_qd_item {
                background: #ffffff;
                padding: 30px;
                display: flex;
                flex-direction: column;
                margin-bottom: 30px;
                &:last-child {
                    margin-bottom: 0 !important;
                }
                .rework_qd_item_i {
                    display: flex;
                    align-items: center;
                    margin-bottom: 30px;
                    &:last-child {
                        margin-bottom: 0!important;
                    }
                    .black {
                        font-size: 30px!important;
                        font-weight: 400!important;
                        color: #222222!important;
                    }
                    span {
                        &:first-child {
                            font-size: 26px;
                            font-weight: 400;
                            color: #666666;
                        }
                        &:last-child {
                            font-size: 26px;
                            font-weight: 400;
                            color: #333333;
                        }
                    }
                }
            }
        }
        .rework_zw {
            height: 168px;
        }
        .rework_footer {
            width: calc(100% - 60px);
            position: fixed;
            bottom: 0;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 30px 68px 30px;
            .rework_footer_add {
                flex: 1;
                height: 88px;
                font-size: 30px;
                font-weight: 500;
                color: $nav-color;
                background: #FFFFFF;
                box-shadow: 0 0 12px 0 rgba(0,0,0,0.0800);
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
            }
            .rework_footer_submit {
                flex: 1;
                height: 88px;
                font-size: 30px;
                font-weight: 500;
                color: #ffffff;
                background: $nav-color;
                box-shadow: 0 0 12px 0 rgba(0,0,0,0.0800);
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                border: none;
            }
        }
    }
</style>