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
<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>
            </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="open(index)">
                    <div class="tl_list_item_label">生产属性</div>
                    <div class="tl_list_item_go">
                        <span :style="item.attributeName ? 'color: #000;' : ''">{{ item.attributeName ? item.attributeName : '请选择'}}</span>
                        <van-icon name="arrow" color="#999999" />
                    </div>
                </div>
                <div class="tl_list_item" v-if="item.type === ''">
                    <div class="tl_list_item_label">属性值</div>
                    <div class="tl_list_item_go">
                        <input type="text" v-model="item.num" placeholder="请输入" />
                    </div>
                </div>
                <div class="tl_list_item" v-else-if="item.type === 0">
                    <div class="tl_list_item_label">属性值</div>
                    <div class="tl_list_item_go">
                        <van-radio-group v-model="item.num" direction="horizontal">
                            <van-radio :name="item1" checked-color="#4275FC" v-for="(item1, i) in item.data" :key="i">{{item1}}</van-radio>
                        </van-radio-group>
                    </div>
                </div>
                <div class="tl_list_item" v-else-if="item.type === 1">
                    <div class="tl_list_item_label">属性值</div>
                    <div class="tl_list_item_go">
                        <van-checkbox-group v-model="item.num" direction="horizontal">
                            <van-checkbox :name="item1" v-for="(item1, i) in item.data" :key="i">{{item1}}</van-checkbox>
                        </van-checkbox-group>
                    </div>
                </div>
                <div class="tl_list_item" v-else-if="item.type === 2">
                    <div class="tl_list_item_label">属性值</div>
                    <div class="tl_list_item_go">
                        <input type="text" v-model="item.num" :placeholder="item.tips" />
                    </div>
                </div>
                <div class="tl_list_item" v-else-if="item.type === 3">
                    <div class="tl_list_item_label">属性值</div>
                    <div class="tl_list_item_go">
                        <input type="text" v-model="item.num" :placeholder="item.tips" />
                    </div>
                </div>
                <div class="tl_list_item" @click="openTimer(index)" v-else-if="item.type === 4">
                    <div class="tl_list_item_label">属性值</div>
                    <div class="tl_list_item_go">
                        <span :style="item.num ? 'color: #000;' : ''">{{item.num ? item.num : item.tips}}</span>
                        <van-icon name="arrow" color="#999999" />
                    </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>
    <!--  选择生产属性  -->
    <van-popup v-model:show="show" position="bottom" round :style="{ height: '50%' }">
        <van-picker
            title="选择生产属性"
            :columns="gzqjData"
            @confirm="gzqjConfirm"
            @cancel="onCancel"
        />
    </van-popup>
    <!--  日期  -->
<!--    <van-calendar v-model:show="timer" :min-date="minDate" :max-date="maxDate" color="#4275FC" @confirm="onConfirm" />-->
    <!--  日期  -->
    <van-popup v-model:show="timer" position="bottom" :style="{ height: '50%' }">
        <van-datetime-picker
            type="datetime"
            title="请选择时间"
            :min-date="minDate"
            :max-date="maxDate"
            @confirm="onConfirm"
            @cancel="cancelData"
        />
    </van-popup>
</template>
 
<script setup lang="ts">
    import { ref, onMounted } from 'vue'
    import { useRoute, useRouter } from "vue-router"
    import { queryById, getJdList, createDJ } from '@/apis/WorkOrderAPI'
    import { Toast } from 'vant'
    import { setTimeO } from '@/utils/utils'
    import VWorkOrderInfo from '@/components/common/WorkOrderInfo.vue'
 
    const route = useRoute()
 
    const router = useRouter()
 
    // 控制日期显示隐藏
    let timer = ref<boolean>(false)
 
    const minDate: Date = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1, new Date().getHours(), new Date().getMinutes())
 
    const maxDate: Date = new Date(new Date().getFullYear() + 1, 12, 30)
 
    // 属性索引
    let indexs: any = ref<number>()
 
    let info: any = ref({})
 
    // 属性信息数组
    let formList: any = ref([
        {
            id: Date.now(),
            attribute: '',       // 属性值
            attributeName: '',   // 属性值名称
            data: '',            // 数据
            type: '',            // 类型
            tips: '',            // 提示子
            num: ''              // 数量
        }
    ])
 
    // 属性数据
    const gzqjData: any = ref([]);
 
    const show = ref<boolean>(false)
 
    // 打开日期插件
    const openTimer = (i: number) => {
        indexs.value = i
        timer.value = true
    }
 
    // 关闭时间弹框
    const cancelData = () => {
        timer.value = false
    }
 
    // 日期确认
    const onConfirm = (value: any) => {
        formList.value.forEach((item: any, index: number) => {
            if (indexs.value === index) {
                item.num = setTimeO(value, '-')
            }
        })
        timer.value = false;
    }
 
    // 打开属性弹框
    const open = (index: number): void => {
        indexs.value = index
        show.value = true
    }
 
    // 属性确认
    const gzqjConfirm = (value: any): void => {
        formList.value.forEach((item: any, index: number) => {
            if (indexs.value === index) {
                item.attribute = value.id
                item.attributeName = value.text
                item.type = value.type
                item.data = value.data
                item.tips = value.tips
                console.log(value)
                item.num = ''
                if (item.type === 1) {
                    item.num = []
                } else if (item.type === 0) {
                    item.num = item.data[0]
                }
                if (value.type === 4) {
                    formList.value[indexs.value].num = setTimeO(new Date(), '-')
                }
            }
        })
        show.value = false
    }
 
    // 关闭弹框
    const onCancel = (): void => {
        show.value = false
    }
 
    // 添加点检信息
    const add = (): void => {
        formList.value.push({ id: Date.now(), attribute: '', attributeName: '', num: '', type: '', data: '', tips: '' })
    }
 
    // 删除点检信息
    const dele = (index: number): void => {
        if (formList.value.length === 1) {
            Toast('至少保留一条点检信息')
            return
        }
        formList.value.splice(index, 1)
    }
 
    // 提交点检
    const submit = (): void => {
        let isOpen: any = true
 
        formList.value.forEach((item: any) => {
            if (item.type === 1) {
                if (item.attribute === '' || item.num.length === 0) {
                    isOpen = false
                }
            } else {
                if (item.attribute === '' || item.num === '') {
                    isOpen = false
                }
            }
        })
 
        if (isOpen) {
            let attrList: any = []
            formList.value.forEach((item: any) => {
                if (item.type === 1) {
                    attrList.push({ val: item.num.join(' '), attrId: item.attribute })
                } else {
                    attrList.push({ val: item.num, attrId: item.attribute })
                }
            })
            createDJ({
                attrList: attrList,
                id: route.query.id
            }).then(res => {
                if (res.code === 200) {
                    Toast.success({
                        message: '创建成功',
                        duration: 2000,
                        forbidClick: true
                    })
                    setTimeout(() => {
                        router.go(-1)
                    }, 2000)
                }
            })
        } else {
            Toast({
                message: '请将信息填写完整',
                duration: 2000
            })
        }
    }
 
    // 获取详情数据
    const queryByIds = (): void => {
        queryById(route.query.id).then(res => {
            if (res.code === 200) {
                info.value = res.data
            }
        })
    }
 
    // 属性值数据
    const getJdLists = () => {
        getJdList({ workOrderID: route.query.id })
            .then(res => {
                if (res.code === 200 && res.data && res.data.length !== 0) {
                    res.data.forEach((item: any) => {
                        gzqjData.value.push({ text: item.name, id: item.id, type: item.type, data: item.remark ? item.remark.split(' ') : '', tips: item.tips })
                    })
                }
            })
    }
 
    onMounted(() => {
        queryByIds()
        getJdLists()
    })
</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;
                }
            }
            .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;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-bottom: 1px solid #E5E5E5;
                &:last-child {
                    border: none;
                }
                .tl_list_item_label {
                    font-size: 30px;
                    font-weight: 400;
                    color: #222222;
                }
                .tl_list_item_go {
                    display: flex;
                    align-items: center;
                    input {
                        text-align: right;
                        width: 450px;
                        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>