zouyu
2023-09-07 db582914c36d92de14098fff2274811a2696114d
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
<template>
    <div>
        <div>
            <div class="content-main">
                <div class="top-bar">
                    <el-form ref="form" :inline="true" :model="searchData">
                        <el-form-item label="委托编号:" class="sermargin">
                            <el-input size="small" v-model="searchData.code" class="input-form" placeholder="请输入">
                            </el-input>
                        </el-form-item>
                        <el-form-item label="样品名称:" class="sermargin">
                            <el-input size="small" v-model="searchData.name" class="input-form" placeholder="请输入">
                            </el-input>
                        </el-form-item>
                        <el-form-item label="委托单位:" style="margin-right: 20px;">
                            <el-select v-model="searchData.department" placeholder="全部" size="small">
                                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" size="small" @click="search">查询</el-button>
                            <el-button type="primary" size="small" plain @click="reset">重置</el-button>
                        </el-form-item>
                    </el-form>
                    <el-form>
                        <el-popover placement="left" width="410" trigger="click">
                            <div class="vue_qr_div">
                                <el-row>
                                    <el-col>
                                        <el-input v-model="view" readonly size="medium" style="width: 250px;margin-right: 10px;"></el-input>
                                        <el-button size="small" type="primary" @click="viewDia=true">生成</el-button>
                                        <el-button size="small" type="primary" @click="copy">复制</el-button>
                                    </el-col>
                                </el-row>
                                <el-row style="margin-top: 10px;">
                                    <el-col v-if="viewId==null">当前链接已过期,请点击生成按钮重新生成</el-col>
                                    <el-col
                                        v-else-if="viewId!=null">当前链接将在{{(parseInt(viewTime2)/60/60)>1?(parseInt(viewTime2)/60/60).toFixed(1)+'小时':Math.round(parseInt(viewTime2)/60)+'分钟'}}后过期</el-col>
                                </el-row>
                            </div>
                            <el-button size="small" slot="reference" class="rightBtn" type="primary" @click="goToaddCommision">新增委托</el-button>
                        </el-popover>
                    </el-form>
                </div>
                <div class="library-table">
                    <div class="table-header">
                        <div class="search-bar">
                            <el-radio-group v-model="radioValue" @change="radioclick">
                                <el-radio-button v-for="item in conditionsOptions" :key="item.value" :label="item.value">
                                    {{ item.label }}
                                </el-radio-button>
                            </el-radio-group>
                        </div>
                        <div class="generateInsp">
                            <el-button @click="addReportBtn" type="primary" size="mini" icon="el-icon-document"
                                style="background-color: rgb(1, 102, 226);">生成报检单</el-button>
                        </div>
                    </div>
                    <div class="table-box">
                        <el-table ref="commisionTable" :max-height="800" :cell-style="{textAlign: 'left'}"
                            :header-cell-style="{border:'0px',background:'#f5f7fa',color:'#606266',boxShadow: 'inset 0 1px 0 #ebeef5',textAlign: 'left'}"
                            :data="commisionTable" @selection-change="handleSelectionChange" style="width: 100%">
                            <el-table-column type="selection" :selectable="checkSelect" min-width="10%" />
                            <el-table-column type="index" label="序号" min-width="10%" />
                            <el-table-column prop="entrust_coding" label="委托编号" min-width="10%" />
                            <el-table-column prop="entrusted" label="委托单位" min-width="12%" />
                            <el-table-column prop="samples_number" label="样品数量" min-width="8%" />
                            <el-table-column prop="sample_name" label="样品名称" min-width="8%" />
                            <el-table-column prop="speName" label="规格型号" min-width="12%" />
                            <el-table-column prop="inspectionTime" label="送样时间" min-width="8%" />
                            <el-table-column prop="completionDeadline" label="完成期限" min-width="8%" />
                            <el-table-column prop="contacts" label="委托编制人" min-width="8%" />
                            <el-table-column prop="inspection_status" label="状态" min-width="8%">
                                <template slot-scope="scope">
                                    <div v-if="scope.row.inspection_status === 2">
                                        <span style="color: green;">已报检</span>
                                    </div>
                                    <div v-else>
                                        <span style="color: red;">未报检</span>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" min-width="8%">
                                <template slot-scope="scope">
                                    <el-button type="text" size="small" @click="handleClick(scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <!-- 分页器 -->
                        <div>
                            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                :current-page="currentPage" :page-sizes="[5, 10, 20]" :page-size="pageSize"
                                layout="total, sizes, prev, pager, next, jumper" :total="total">
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <el-dialog title="链接时长设置" :visible.sync="viewDia" width="30%">
            <div>
                <el-row style="line-height: 46px;">
                    <el-col :span="6" style="font-size: 14px;text-align: right;">时长设置:</el-col>
                    <el-col :span="14" :offset="1">
                        <el-select v-model="viewTime" size="medium">
                            <el-option label="1 天" :value="1"></el-option>
                            <el-option label="2 天" :value="2"></el-option>
                            <el-option label="3 天" :value="3"></el-option>
                            <el-option label="4 天" :value="4"></el-option>
                            <el-option label="5 天" :value="5"></el-option>
                            <el-option label="6 天" :value="6"></el-option>
                            <el-option label="1 周" :value="7"></el-option>
                        </el-select>
                    </el-col>
                </el-row>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="getViewId()">提 交</el-button>
                <el-button @click="viewDia = false">取 消</el-button>
            </span>
        </el-dialog>
        <!-- 隐藏域输入框用来复制 -->
        <input id="copyContext" style="position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;" />
        <el-dialog title="选择日期" :visible.sync="addReportDialog" width="60%">
            <el-form :model="addInspectionForm" :rules="addInspectionFormRules" ref="addInspectionForm">
                <el-form-item label="检验日期" label-width="100px" prop="inspectionDate">
                    <el-date-picker v-model="addInspectionForm.inspectionDate" type="daterange" value-format="yyyy-MM-dd"
                        range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="当前版本" label-width="100px" prop="version">
                    <el-select @change="changeVersionFun" v-model="addInspectionForm.version" placeholder="请选择版本">
                        <el-option v-for="item in chooseVersion" :key="item.value" :label="item.label" :value="item.value" ></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <el-table
                style="width:90%;margin-left:5%" :data="standardLibraryData" row-key="id" border
                default-expand-all :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
                <el-table-column type="index" width="50px" label="序号"></el-table-column>
                <el-table-column label="项目名称" prop="name" sortable></el-table-column>
                <el-table-column prop="unit" label="单位" sortable></el-table-column>
                <el-table-column label="标准值" prop="required" sortable></el-table-column>
                <el-table-column prop="internal" label="内控值" sortable></el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
                <el-button @click="resetForm('addInspectionForm')">取 消</el-button>
                <el-button type="primary" @click="confirmBtn('addInspectionForm')">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
 
<script>
    import {
        getCommisionList,
        getViewUUID,
        selectViewUUID,
        delLink,
        chooseVersion,
        lookProByVer,
        addInspect
    } from '@/api/inspection/commisioninspection'
    export default {
        data() {
            return {
                standardLibraryData:[],
                chooseVersion: [],
                addInspectionForm: {
                    inspectionDate: [],
                    version: null
                },
                addInspectionFormRules: {
                    inspectionDate: [{
                        required: true,
                        message: '请选择日期区间',
                        trigger: 'change'
                    }],
                },
                addReportDialog: false,
                checkData: [],
                form: [],
                searchData: {
                    code: '',
                    name: '',
                    department: ''
                },
                options: [{
                    value: '1',
                    label: '部门1'
                }],
                radioValue: null,
                commisionTable: [{
                    specifications_models: "GGXH-AAAAA",
                    inspectionTime: "2023-08-03",
                    id: 2,
                    samples_number: 0,
                    dateSurvey: "2023-08-03",
                    entrusted: "阿里巴巴",
                    completionDeadline: "2023-08-03",
                    contacts: "小黑",
                    entrust_coding: "SL20230803000003",
                    sample_name: "发动机",
                    inspection_status: 1
                }],
                conditionsOptions: [{
                        label: '全部',
                        value: null
                    },
                    {
                        label: '已报检',
                        value: 2
                    },
                    {
                        label: '未报检',
                        value: 1
                    }
                ],
                currentPage: 1,
                pageSize: 5,
                total: 100,
                showDetail: false,
                day: 1,
                view: null,
                viewId: null,
                viewTime: 1,
                viewTime2: 1,
                viewDia: false
            }
        },
        watch:{
            addReportDialog(newVal){
                if(newVal === false){
                    this.resetForm("addInspectionForm");
                }
            }
        },
        created() {
            this.getCommisionList()
        },
        updated() {
            if (this.$router.currentRoute.name === 'AddCommision') {
                this.showDetail = true
            }
        },
        methods: {
            resetForm(formName) {
                this.addInspectionForm.inspectionDate = [],
                this.$refs[formName].resetFields();
                this.addReportDialog = false
            },
            checkSelect(row) {
                if (row.inspection_status === 2) {
                    return false;
                } else {
                    return true;
                }
            },
            handleSelectionChange(val) {
                if (val.length > 1) {
                    let data = val.pop();
                    this.$refs.commisionTable.clearSelection();
                    this.$refs.commisionTable.toggleRowSelection(data);
                    this.checkData = data;
                }else{
                    this.checkData = val;
                }
            },
            //生成报检单确认按钮
            confirmBtn(formName) {
                this.$refs[formName].validate((valid)=>{
                    if(valid){
                    let dateArr = this.addInspectionForm.inspectionDate;
                    //添加报检单
                    let val = this.checkData[0];
                    let obj = {
                        "endTime": dateArr[1],
                        "mcode":"mcode",
                        "formTime": val.inspectionTime,
                        "id": val.id,
                        "name": val.sample_name,
                        "num": val.samples_number,
                        "specifications": val.speName,
                        "startTime": dateArr[0],
                        "supplier": val.entrusted,
                        "type": 2,
                        // "unit": "mm",
                        "version": this.addInspectionForm.version
                    }
                    this.createReport(obj);
                    this.addReportDialog = false;
                    }
                });
            },
            //生成报检单请求
            async createReport(param) {
                await addInspect(param).then(res =>{
                    this.search();
                    this.$message.success('报检成功')
                    this.$router.push(`/experiment/Viewdetails/${res.data}`)
                }).catch(()=>{
                    this.$message.error('报检失败')
                });
            },
            //生成报检单按钮
            addReportBtn() {
                if (this.checkData.length < 1) {
                    this.$message.error("请选择一条数据!");
                } else {
                    if (this.checkData.length > 1) {
                        this.$message.error("最多选择一条数据!");
                    } else {
                        let mcode = this.checkData[0].entrust_coding;
                        let name = this.checkData[0].sample_name;
                        let specifications = this.checkData[0].speName;
                        let id = this.checkData[0].id;
                        this.getChooseVersionFun(mcode,name,specifications,id);
                        this.addReportDialog = true;
                    }
                }
            },
            changeVersionFun(){
                let mCode = this.checkData[0].entrust_coding;
                let name = this.checkData[0].sample_name;
                let specifications = this.checkData[0].speName;
                let version = this.addInspectionForm.version;
                let id = this.checkData[0].id;
                this.getProByVersion(mCode,name,specifications,version,id);
            },
            //获取版本下的标准库数据
            async getProByVersion(mCode,name,specifications,version,id){
                var vm = this;
                await lookProByVer({
                    id : id,
                    mcode : mCode,
                    name : name,
                    specifications : specifications,
                    version: version
                }).then((res)=>{
                    var data = res.data;
                    for(var i=0;i<data.length;i++){
                        data[i].id = "0" + i;
                    }
                    vm.standardLibraryData = res.data;
                })
            },
            //获取版本列表
            async getChooseVersionFun(mCode,name,specifications,id){
                var vm = this;
                this.chooseVersion = [];
                await chooseVersion({
                id : id,
                name : name,
                specifications : specifications
                }).then((res)=>{
                    vm.getProByVersion(mCode,name,specifications,res.data[0],id);
                    for(let i=0;i<res.data.length;i++){
                        vm.chooseVersion.push({
                        value: res.data[i],
                        label: "V"+res.data[i]
                        });
                    }
                    vm.addInspectionForm.version = res.data[0];
                });
            },
            async getCommisionList() {
                const res = await getCommisionList({
                    pageNo: this.currentPage,
                    pageSize: this.pageSize
                })
                this.commisionTable = res.data.row
                this.total = res.data.total
                // 获取所有的委托单位名称
                const allDepartmentNames = [...new Set(this.commisionTable.map(item => item.entrusted))]
                // 将allDepartmentNames转换为options需要的格式
                this.options = allDepartmentNames.map(name => ({
                    value: name,
                    label: name
                }))
 
            },
            // 查询方法
            async search() {
                // 将搜索条件作为参数传递给getCommisionList方法
                let res
                if (this.radioValue === 0) {
                    res = await getCommisionList({
                        pageNo: this.currentPage,
                        pageSize: this.pageSize,
                        entrustCoding: this.searchData.code,
                        sampleName: this.searchData.name,
                        entrusted: this.searchData.department,
                    })
                } else {
                    res = await getCommisionList({
                        pageNo: this.currentPage,
                        pageSize: this.pageSize,
                        entrustCoding: this.searchData.code,
                        sampleName: this.searchData.name,
                        entrusted: this.searchData.department,
                        inspectionStatus: this.radioValue
                    })
                }
                this.commisionTable = res.data.row
                this.total = res.data.total
            },
            // 重置方法
            reset() {
                // 重置搜索条件
                this.searchData.code = ''
                this.searchData.name = ''
                this.searchData.department = ''
                this.radioValue = 0
                // 重新获取数据
                this.getCommisionList()
            },
            async radioclick() {
                // 处理点击radio的时间
                if (this.radioValue === 0) {
                    const res = await getCommisionList({
                        pageNo: this.currentPage,
                        pageSize: this.pageSize,
                        inspectionStatus: this.radioValue
                    })
                    this.commisionTable = res.data.row
                    this.total = res.data.total
                } else if(this.radioValue === 1) {
                    const res = await getCommisionList({
                        pageNo: this.currentPage,
                        pageSize: this.pageSize,
                        inspectionStatus: this.radioValue
                    })
                    this.commisionTable = res.data.row
                    this.total = res.data.total
                }else{
                    this.getCommisionList();
                }
 
            },
            // 每页条数改变时触发 选择一页显示多少行
            async handleSizeChange(val) {
                this.currentPage = 1
                this.pageSize = val
                if (this.radioValue === 0) {
                    this.getCommisionList()
                } else {
                    const res = await getCommisionList({
                        pageNo: this.currentPage,
                        pageSize: this.pageSize,
                        inspectionStatus: this.radioValue
                    })
                    this.commisionTable = res.data.row
                    this.total = res.data.total
                }
            },
            // 当前页改变时触发 跳转其他页
            async handleCurrentChange(val) {
                this.currentPage = val
                if (this.radioValue === 0) {
                    this.getCommisionList()
                } else {
                    const res = await getCommisionList({
                        pageNo: this.currentPage,
                        pageSize: this.pageSize,
                        inspectionStatus: this.radioValue
                    })
                    this.commisionTable = res.data.row
                    this.total = res.data.total
                }
            },
            goToaddCommision() {
                // this.showDetail = true
                selectViewUUID({
                    day: this.day
                }).then(res => {
                    this.view = `${this.vueIp}/#/addCommision/${res.data.id}`
                    this.viewId = res.data.id
                    this.viewTime2 = res.data.time
                })
            },
            getViewId() {
                getViewUUID({
                    day: this.viewTime == null ? 1 : this.viewTime
                }).then(res => {
                    this.viewId = res.data
                    this.view = `${this.vueIp}/#/addCommision/${res.data.id}`
                    this.viewDia = false
                    this.$message.success('链接已生成,点击复制按钮进行复制')
                })
            },
            copy() {
                document.getElementById('copyContext').value = this.view
                const input = document.querySelector('#copyContext');
                input.select()
                if (document.execCommand('copy')) {
                    this.$message.success('已复制到剪贴板')
                }
            },
            handleClick(row){
                delLink({
                    id: row.id
                }).then(res=>{
                    this.$message.success('删除成功')
                    this.getCommisionList()
                })
            }
        }
    }
</script>
 
<style scoped lang="scss">
    .top-bar {
        margin: -25px -15px;
        background: #fff;
        display: flex;
        justify-content: space-between;
        padding: 24px 24px 0px 24px;
 
        .sermargin {
            margin-right: 60px;
        }
 
        .rightForm {
            display: flex;
            justify-content: space-between;
            /* background-color: #bfa; */
            height: 40px;
            line-height: 40px;
 
            >div {
                padding: 0px 10px;
                padding-bottom: 10px;
                border: 1px solid rgb(8, 156, 230);
                margin-right: 10px;
                /* height: 40px;
        line-height: 40px; */
            }
 
            .rightBtn {
                background-color: rgb(1, 102, 226);
            }
        }
    }
 
    .library-table {
        background-color: #fff;
        flex: 1;
        margin: 0px -15px;
        margin-top: 40px;
        display: flex;
        flex-direction: column;
 
        .table-header {
            padding: 20px;
            display: flex;
            justify-content: space-between;
 
            .el-form-item {
                margin-bottom: 30px !important;
            }
        }
 
        .table-box {
            padding: 0px 20px;
            margin-top: 0px;
            flex: 1;
            background: #fff;
            /* padding: 20px 20px 10px 20px; */
            display: flex;
            flex-direction: column;
 
            .el-table {
                flex: 1;
            }
 
            >div:nth-child(2) {
                display: flex;
                justify-content: end;
                margin: 10px 0;
            }
        }
    }
 
    .rightBtn {
        background-color: rgb(1, 102, 226);
    }
 
    .library-table {
        background-color: #fff;
        flex: 1;
        margin: 0px -15px;
        margin-top: 40px;
        display: flex;
        flex-direction: column;
 
        .table-header {
            padding: 20px;
            display: flex;
            justify-content: space-between;
 
            .el-form-item {
                margin-bottom: 30px !important;
            }
        }
 
        .table-box {
            padding: 0px 20px;
            margin-top: 0px;
            flex: 1;
            background: #fff;
            /* padding: 20px 20px 10px 20px; */
            display: flex;
            flex-direction: column;
 
            .el-table {
                flex: 1;
            }
 
            >div:nth-child(2) {
                display: flex;
                justify-content: end;
                margin: 10px 0;
            }
        }
    }
 
    .vue_qr_div {
        text-align: center;
        color: #0166e2;
    }
</style>