展杰
2023-11-20 f0afdc84ddfb0798cdcb1ba5ff5b1ee92ed833d4
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
<template>
    <view>
        <u-form :model="form" ref="uForm">
            <u-form-item label="唯一编码" prop="eqNo">
                <u-input v-model="form.eqNo" @blur="getSpotItem" />
            </u-form-item>
            <u-form-item label="设备名称" prop="eqName">
                <u-input v-model="form.eqName" />
            </u-form-item>
            <u-form-item label="设备型号" prop="eqMode">
                <u-input v-model="form.eqMode" :disabled=true />
            </u-form-item>
            <u-form-item label="使用部门" prop="department">
                <u-input v-model="form.department" :disabled=true />
            </u-form-item>
            <u-form-item label="放置地点" prop="place">
                <u-input v-model="form.place" :disabled=true />
            </u-form-item>
            <u-form-item label="保养工单" prop="planNo" borderBottom @click="groupShow = true" required>
                <u--input v-model="form.planNo" disabled disabledColor="#fff" suffixIcon="arrow-down"
                    placeholder="请保养工单" border="none"></u--input>
                <u-picker :show="groupShow" :columns="jtList" keyName="label" @confirm="groupConfim"
                    @cancel="groupShow=false"></u-picker>
            </u-form-item>
            <u-form-item label="保养人" prop="planBy">
                <u-input v-model="form.planBy" :disabled=true />
            </u-form-item>
 
            <u-form-item label="计划保养时间" prop="planDate">
                <view class="sss" @click="show = true">
                    <input type="text" v-model="form.planDate" />
                    <u-datetime-picker ref="datetimePicker" :formatter="formatter" :show="show" mode="date"
                        @confirm="confirm" @cancel="close"></u-datetime-picker>
                </view>
            </u-form-item>
            <u-form-item label="备注" prop="remark">
                <u-input v-model="form.remark" />
            </u-form-item>
            <u-form-item label="是否合格">
                <u-radio-group v-model="form.finalResult">
                    <u-radio v-for="(item, index) in radioList" :key="index" :name="item.name"
                        :disabled="item.disabled">
                        {{ item.name }}
                    </u-radio>
                </u-radio-group>
            </u-form-item>
        </u-form>
        <u-button style="background-color: #9294FF;" @click="submit">提交</u-button>
 
        <u-list @scrolltolower="scrolltolower">
            <u-list-item v-for="(item, index) in indexList" :key="index">
                <u-form style="border: 2px solid #000;margin: 5px 0px;">
                    <u-form-item label="唯一编码">
                        <u-input v-model="item.eqNo" :disabled=true />
                    </u-form-item>
                    <u-form-item label="检查内容">
                        <u-input v-model="item.eqMain" :disabled=true />
                    </u-form-item>
                    <u-form-item label="是否合格">
                        <u-radio-group v-model="item.eqEnd">
                            <u-radio v-for="(item, index) in radioList" :key="index" :name="item.name"
                                :disabled="item.disabled">
                                {{ item.name }}
                            </u-radio>
                        </u-radio-group>
                    </u-form-item>
                </u-form>
            </u-list-item>
        </u-list>
    </view>
</template>
 
<script>
    import {
        getEqSpotCheckItem,
        getEq,
        getEqSpotList,
        getSpotItemResult,
        save
    } from '../../api/spotCheck'
 
    export default {
        data() {
            return {
                form: {
                    eqNo: '',
                    eqName: '',
                    eqMode: '',
                    department: '',
                    place: '',
                    planNo: '',
                    planBy: '',
                    planDate: '',
                    remark: '',
                    finalResult: 'OK'
                },
                jtList: [],
                indexList: [],
                rules: {
                    eqNo: [{
                        required: true,
                        message: '请输入唯一编码',
                        // 可以单个或者同时写两个触发验证方式 
                        trigger: ['change', 'blur'],
                    }],
                    planNo: [{
                        required: true,
                        message: '请选择保养工单',
                        // 可以单个或者同时写两个触发验证方式 
                        trigger: ['change', 'blur'],
                    }]
                },
                radioList: [{
                        name: 'OK',
                        disabled: false
                    },
                    {
                        name: 'NG',
                        disabled: false
                    }
                ],
                switchVal: false,
                show: false,
                groupShow: false,
            };
        },
        onLoad() {
            //初始化下拉
        },
        methods: {
            submit() {
                //非空校验,为空时回return;
                if (!this.form.planNo) {
                    uni.showToast({
                        title: '请选择保养工单',
                        icon: 'none',
                        duration: 2000
                    });
                    return;
                }
                if (!this.form.eqNo) {
                    uni.showToast({
                        title: '请输入设备唯一编码',
                        icon: 'none',
                        duration: 2000
                    });
                    return;
                }
                this.form.indexList = this.indexList;
                this.form.submitBy = uni.getStorageSync('userInfo').code;
                this.form.submitDate = this.now();
                console.log(JSON.stringify(this.form));
                save(this.form).then(res => {
                    if(res.result){
                        uni.showToast({
                            title: '保存成功',
                            icon: 'none',
                            duration: 2000
                        });
                        //清空点检单和点检详细信息
                        this.form = {};
                        this.indexList = [];
                    }
                })
            },
            groupConfim(e) {
                //获取选中的值
                // 根据实际需求设置选中的值
                this.form.planNo = e.value[0].label;
                const timeFormat = uni.$u.timeFormat;
                this.form.planDate = timeFormat(e.value[0].date, 'yyyy-mm-dd');
                this.form.planBy = uni.getStorageSync('userInfo').username;
                this.form.remark = e.value[0].remark;
                this.loadmore(this.form.planNo);
                this.groupShow = false
            },
            scrolltolower() {
                //this.loadmore()
            },
            loadmore(planNo) { //获取点检项目并默认合格
                getSpotItemResult(planNo).then(res => {
                    this.indexList = res.data;
                    for(let i=0;i<this.indexList.length;i++){
                        this.indexList[i].eqEnd = 'OK';
                    }
                })
            },
            getSpotItem(event) {  //根据唯一编码查询设备信息
                getEq(event).then(res => {
                    this.form = res.data;
                    this.form.finalResult = 'OK';
                    //再根据唯一编码查询点检单的信息
                    getEqSpotList(event).then(res => {
                        //下拉列表填充值
                        let arr = res.data.map(item => {
                            return {
                                label: item.planNo,
                                id: item.planNo,
                                date: item.planDate,
                                remark: item.remark
                            }
                        });
                        this.jtList = [arr]
                    })
                });
            },
            confirm(e) {  //保养时间选择
                const timeFormat = uni.$u.timeFormat;
                this.form.planDate = timeFormat(e.value, 'yyyy-mm-dd');
                this.show = false;
            },
            close() { //关闭时间选择框
                this.show = false;
            },
            formatter(type, value) {
                if (type === 'year') {
                    return `${value}年`;
                }
                if (type === 'month') {
                    return `${value}月`;
                }
                if (type === 'day') {
                    return `${value}日`;
                }
                return value;
            },
            now() { //获取当前时间格式为yyyy-mm-dd的字符串
                var currentDate = new Date();
                var year = currentDate.getFullYear();
                var month = currentDate.getMonth() + 1; // 注意JavaScript中月份是从0开始的,所以要加1
                var day = currentDate.getDate();
                return year + "-" + month + "-" + day
            }
        },
        // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
        onReady() {
            this.$refs.uForm.setRules(this.rules);
        }
    };
</script>
 
<style scoped>
    .sss {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
 
    }
 
    .sss>view {
        margin-right: 50rpx;
    }
</style>