Fixiaobai
2023-09-07 5eb1499c02ac96f5d58fabfd17e36103d35a675c
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
<style scoped>
    .plan {
        width: 100%;
    }
 
    .title {
        height: 60px;
        width: calc(100% - 20px);
        background-color: white;
        margin: 5px 10px;
        display: flex;
        align-items: center;
        padding: 0 30px;
    }
 
    .thing {
        margin: 10px;
        padding: 15px;
        background-color: white;
        height: calc(100vh - 18vh);
        overflow-y: auto;
    }
 
    .order_num {
        border-radius: 1rem;
        width: 35px;
        height: 25px;
        text-align: center;
        margin-right: 8px;
    }
</style>
<style>
    .plan .has-gutter tr th {
        background-color: #f5f7fa !important;
        color: #333;
    }
 
    .plan .cell {
        color: #333;
        display: flex;
    }
</style>
 
<template>
    <div class="plan">
        <div class="title">
            <el-form :model="search" :inline="true" label-position="left">
                <el-form-item prop="code" label="申请单编号:" width="200" style="margin: 20px 10px;">
                    <el-input v-model="search.code" size="small" ></el-input>
                </el-form-item>
                <el-form-item prop="date" label="检验时间:" width="200" style="margin: 20px 10px;">
                    <el-date-picker v-model="search.date" type="daterange" range-separator="至" start-placeholder="开始日期"
                        end-placeholder="结束日期" size="small" value-format="yyyy-MM-dd" style="margin-right: 20px;">
                    </el-date-picker>
                </el-form-item>
                <el-form-item prop="testValue" label="检验结果:" width="200" style="margin: 20px 10px;">
                    <el-select v-model="search.testValue" size="small">
                        <el-option label="全部" :value="null"></el-option>
                        <el-option label="合格" :value="1"></el-option>
                        <el-option label="不合格" :value="0"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <el-button size="small" type="primary" @click="selectDataList">查询</el-button>
            <el-button size="small" @click="cleanBtn">重置</el-button>
            <el-checkbox style="margin-left: 10px;" @change="selectDataList" v-model="isLookMe">只看我</el-checkbox>
        </div>
        <div class="thing">
            <el-table :data="tableData" style="width: 100%;" row-key="code" default-expand-all
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}" :key="upIndex">
                <el-table-column type="index" width="50" label="序号">
                </el-table-column>
                <el-table-column prop="code" label="申请单号" width="250px">
                    <template slot-scope="scope">
                        <div style="display: flex;">
                            <div v-if="scope.row.orderNum=='01'" style="color: #3caaff;background-color: #eff5ff;" class="order_num">
                                01
                            </div>
                            <div v-else-if="scope.row.orderNum=='02'" style="color: #57c981;background-color: #f1fbf4;"
                                class="order_num">
                                02</div>
                            <div v-else-if="scope.row.orderNum=='03'" style="color: #dfa8fb;background-color: #faf2ff;"
                                class="order_num">
                                03</div>
                            <div>{{scope.row.code}}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="名称" width="200px">
                </el-table-column>
                <el-table-column prop="unit" label="单位">
                </el-table-column>
                <el-table-column prop="required" label="要求值">
                </el-table-column>
                <el-table-column prop="internal" label="内控值">
                </el-table-column>
                <el-table-column prop="testValue" label="检验值">
                </el-table-column>
                <el-table-column prop="checker" label="执行人">
                </el-table-column>
                <el-table-column prop="instrumentname" label="检验设备">
                </el-table-column>
                <el-table-column prop="testState" label="检验状态" width="100px">
                    <template slot-scope="scope">
                        <el-tag type="success" effect="dark" v-if="scope.row.children!=undefined&&scope.row.testState!=null">已上报</el-tag>
                        <el-tag type="danger" effect="dark" v-else-if="scope.row.children!=undefined&&scope.row.testState==null">未上报</el-tag>
                        <el-tag type="success" v-else-if="scope.row.children==undefined&&scope.row.testState!=null">已检验</el-tag>
                        <el-tag type="danger" v-else-if="scope.row.children==undefined&&scope.row.testState==null">未检验</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="startTime" label="检验开始" width="100px">
                </el-table-column>
                <el-table-column prop="endTime" label="检验结束" width="100px">
                </el-table-column>
                <el-table-column label="操作" width="150">
                    <template slot-scope="scope">
                        <el-button size="mini" :disabled="!isIfReport(scope.row)" type="primary" v-if="scope.row.orderNum == '01'"
                            @click="addReported(scope.row.id)">上报</el-button>
                        <el-button size="mini" type="text" @click="openUpDia(scope.row)"
                            v-if="scope.row.orderNum=='02'&&scope.row.children==undefined&&scope.row.testState==null">分配</el-button>
                        <el-button size="mini" type="text" @click="openUpInsDia(scope.row)"
                            v-if="scope.row.orderNum=='02'&&scope.row.children==undefined&&scope.row.testState==null">检验</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-dialog title="分配设备和人员" :visible.sync="upDia" width="500px" top="30vh">
            <div class="body">
                <el-row style="line-height: 50px;">
                    <el-col :span="4" style="font-size: 14px;text-align: right;">人员:</el-col>
                    <el-col :span="16" :offset="1">
                        <el-select @change="selectChecker" v-model="upData.checker" size="medium" clearable style="width: 100%;">
                            <el-option v-for="(a, ai) in users" :key="ai" :label="a.name" :value="a.id"></el-option>
                        </el-select>
                    </el-col>
                </el-row>
                <el-row style="line-height: 50px;">
                    <el-col :span="4" style="font-size: 14px;text-align: right;">设备:</el-col>
                    <el-col :span="16" :offset="1">
                        <el-cascader v-model="upData.device" :options="devices" size="medium" style="width: 100%;" clearable
                            :props="{label: 'name',value: 'id',emitPath: false}" :show-all-levels="false"></el-cascader>
                    </el-col>
                </el-row>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitUpData">确 定</el-button>
                <el-button @click="upDia = false">取 消</el-button>
            </span>
        </el-dialog>
        <el-dialog title="检验" :visible.sync="upInsDia" width="600px">
            <div class="body" style="max-height: 50vh;overflow-y: auto;">
                <el-row style="line-height: 46px;">
                    <el-col :span="5" style="font-size: 14px;text-align: right;">申请单编码:</el-col>
                    <el-col :span="7">{{upData.insId}}</el-col>
                    <el-col :span="5" style="font-size: 14px;text-align: right;">样品名称:</el-col>
                    <el-col :span="7">{{upData.productName}}</el-col>
                </el-row>
                <el-row style="line-height: 46px;">
                    <el-col :span="5" style="font-size: 14px;text-align: right;">检验项目:</el-col>
                    <el-col :span="7">{{upData.name}}</el-col>
                    <el-col :span="5" style="font-size: 14px;text-align: right;">单位:</el-col>
                    <el-col :span="7">{{upData.unit}}</el-col>
                </el-row>
                <el-row style="line-height: 46px;">
                    <el-col :span="5" style="font-size: 14px;text-align: right;">标准值:</el-col>
                    <el-col :span="7">{{upData.required}}</el-col>
                    <el-col :span="5" style="font-size: 14px;text-align: right;">内控值:</el-col>
                    <el-col :span="7">{{upData.internal}}</el-col>
                </el-row>
                <el-row style="line-height: 46px;">
                    <el-col :span="5" style="font-size: 14px;text-align: right;">检验结果:</el-col>
                    <el-col :span="7">
                        <el-tag type="success" v-if="upData.testState==1">合格</el-tag>
                        <el-tag type="danger" v-else-if="upData.testState==0">不合格</el-tag>
                        <el-tag type="info" v-else>无结果</el-tag>
                    </el-col>
                </el-row>
                <el-row style="line-height: 46px;">
                    <el-col style="text-align: right;"><el-button size="mini" @click="addRes">添加检验值</el-button></el-col>
                </el-row>
                <el-row>
                    <el-col>
                        <el-table :data="upData.testValue" border style="width: 99.9%;" :key="upIndex2">
                            <el-table-column type="index" width="100" label="序号">
                            </el-table-column>
                            <el-table-column label="检验值">
                                <template slot-scope="scope">
                                    <el-input v-model.number="scope.row.number" size="small" clearable placeholder="请输入"
                                        @change="(val)=>scope.row.number = isNaN(val)?null:val">
                                    </el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" width="80">
                                <template slot-scope="scope">
                                    <el-button size="mini" type="text"
                                        @click.native.prevent="deleteRow(scope.$index, upData.testValue)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-col>
                </el-row>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitUpData2">提 交</el-button>
                <el-button @click="upInsDia = false">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>
 
<script>
    import {
        get,
        post,
        wpost,
        postFile
    } from "@/api/util/requestUtil.js"
    export default {
        data() {
            return {
                search: {
                    code: null,
                    date: [],
                    testValue: null,
                },
                tableData: [],
                upDia: false,
                upData: {},
                upIndex: 0,
                upInsDia: false,
                upIndex2: 0,
                users: [],
                devices: [],
                isLookMe: false
            }
        },
        mounted() {
            this.selectDataList()
            this.getUsers()
            this.getDevices()
        },
        methods: {
            selectDataList() {
                var str = {}
                str.code = this.search.code
                str.isLookMe=this.isLookMe
                str.status = this.search.testValue
                try {
                    if (this.search.date.length != 0) {
                        str.beginTime = this.search.date[0]
                        str.endTime = this.search.date[1]
                    }
                } catch (e) {}
                get(this.$url.selectAllPlan, str).then(res => {
                    this.tableData = JSON.parse(JSON.stringify(res.data).replaceAll('pid', 'code').replaceAll('samplename',
                        'name').replaceAll('inspectionStatus', 'testState'))
                    this.tableData.forEach(a => {
                        a.orderNum = '01'
                        if (a.children != undefined) {
                            a.children.forEach(b => {
                                b.orderNum = '02'
                                if (b.testValue == undefined) {
                                    b.testValue = []
                                }
                            })
                        }
                    })
                    this.upIndex++
                })
            },
            isIfReport(row) {
                var count = 0
                if (row.children == undefined) return false
                row.children.forEach(a => {
                    if (a.testState != null && a.testState != undefined) count++
                })
                return row.testState == undefined && count == row
                    .children.length
            },
            openUpDia(row) {
                // console.log(row);
                this.upDia = true
                this.upData = {
                    id: row.code,
                    checker: null,
                    device: null
                }
                this.upData.checker=row.uId
                this.upData.device=row.isuId
            },
            submitUpData() {
                // console.log(this.upData.device);
                // console.log(this.devices);
                // return;
                if (this.upData.checker == null || this.upData.checker == '') {
                    this.$message.error('人员未分配')
                    return
                } else if (this.upData.device == null || this.upData.device == '') {
                    this.$message.error('设备未分配')
                    return
                }
                wpost(this.$url.distribution, {
                    id: this.upData.id,
                    userId: this.upData.checker,
                    instrumentId: this.upData.device
                }).then(res => {
                    this.$message.success('分配成功')
                    this.upDia = false
                    this.selectDataList()
                })
            },
            selectChecker(){
                // console.log(this.upData.checker);
            },
            openUpInsDia(row) {
                this.upInsDia = true
                this.upData = this.HaveJson(row)
                var str = []
                JSON.parse('[' + this.upData.testValue + ']').forEach(a => {
                    str.push({
                        number: a
                    })
                })
                this.upData.testValue = this.HaveJson(str)
                this.tableData.forEach(a => {
                    a.children.forEach(b => {
                        if (b.code == this.upData.code) {
                            this.upData.insId = a.code
                            this.upData.productName = a.name
                        }
                    })
                })
            },
            deleteRow(index, rows) {
                rows.splice(index, 1);
            },
            addRes() {
                this.upData.testValue.push({
                    "number": null
                })
                this.upIndex2++
            },
            getUsers() {
                get(this.$url.choosecheck).then(res => {
                    this.users = res.data
                })
            },
            getDevices() {
                get(this.$url.chooseinstum).then(res => {
                    this.devices = res.data
                })
            },
            addReported(id) {
                wpost(this.$url.reported, {
                    id: id
                }).then(res => {
                    this.$message.success('上报成功')
                    this.selectDataList()
                }).catch(e => {
                    this.$message.error('上报失败')
                })
            },
            submitUpData2() {
                var data = []
                this.upData.testValue.forEach(a => {
                    if (a.number != '' && a.number != null) {
                        data.push(a.number)
                    }
                })
                wpost(this.$url.check, {
                    id: this.upData.code,
                    value: data.toString()
                }).then(res => {
                    this.upInsDia = false
                    this.selectDataList()
                    this.$confirm(
                        `<p style="line-height: 80px">您的项目(${this.upData.name})检验结果为:<span class="${res.data==1?'ins_state_success':'ins_state_error'}">${res.data==1?'合格':'不合格'}</span></p>`,
                        '提交成功', {
                            confirmButtonText: '确定',
                            cancelButtonText: '关闭',
                            dangerouslyUseHTMLString: true,
                            type: `${res.data==1?'success':'error'}`
                        }).then(() => {}).catch(() => {})
                })
            },
            cleanBtn(){
                this.search = {
                    code: null,
                    date: [],
                    testValue: null,
                }
                this.selectDataList()
            }
        }
    }
</script>