licp
2024-10-14 ae8b90c76912a7796b7c23c78f1a59bac434457d
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
<template>
  <div class="circuit-parameters">
    <el-divider></el-divider>
    <el-row :gutter="8" style="width: calc(100% - 1px);margin-bottom: 10px;">
      <el-col :span="17">
        <el-row>
          <el-col :span="23" style="display: flex;flex-wrap: wrap;">
            <table border="1" cellpadding="10" style="margin: 4px 10px 10px 0;width: 32%;" v-for="(item,index) in insProductNew" :key="index + 'ppp'" v-show="isMore?true:(index<3?true:false)">
              <tr>
                <td style="text-align: center;background: #F0F1F5;">
                  <el-tooltip effect="dark" :content="item.inspectionItemSubclass" placement="top-start"><span style="display: inline-block;width: 95px;" class="single-line-ellipsis">{{ item.inspectionItemSubclass }}</span>
                  </el-tooltip>
                </td>
                <td>
                  <el-input size="small" placeholder="设备名称" v-model="item.equipName" readonly></el-input>
                </td>
                <td>
                  <el-select v-model="item.equipValue" placeholder="设备编码" size="small"  :disabled="state>1" @focus="methodFocus(item)" @change="m=>handleEquip(m,item)">
                    <el-option
                      v-for="m in item.equipOptions"
                      :key="m.value"
                      :label="m.value"
                      :value="m.value">
                    </el-option>
                  </el-select>
                </td>
              </tr>
            </table>
          </el-col>
          <el-col :span="1" v-show="insProductNew.length>3">
            <el-button icon="el-icon-arrow-down" type="text" @click="isMore=true" v-if="!isMore">更多</el-button>
            <el-button icon="el-icon-arrow-up" type="text" @click="isMore=false" v-if="isMore">收起</el-button>
          </el-col>
        </el-row>
      </el-col>
      <el-col :span="7" v-if="!isLook">
        <div style="display: flex;align-items: center;justify-content: flex-end;" class="btns">
          <el-button type="primary" size="small" @click="addList(allBandList,'频段')" :disabled="state>1" style="margin: 4px;">添加频段</el-button>
          <el-button size="small" @click="deleteList(allBandList.length-1,allBandList,'删除频段')" :disabled="state>1" style="margin: 4px;">删除频段</el-button>
          <el-button type="primary" size="small" @click="addList(angleList)" v-if="!(state>1)&&intermodulationNum>0" style="margin: 4px;">添加角度</el-button>
          <el-button size="small" @click="deleteList(angleList.length-1,angleList)" v-if="!(state>1)&&intermodulationNum>0" style="margin: 4px;">删除角度</el-button>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="5" style="font-size: 18px;font-weight: 700;background: #F0F1F5;padding: 16px 0;box-sizing: border-box;width: 100%;">
      <el-col :span="2">
        <div style="text-align: center;">检验项目</div>
      </el-col>
      <el-col :span="2">
        <div style="text-align: center;">单位</div>
      </el-col>
      <el-col :span="2">
        <div style="text-align: center;">标准要求</div>
      </el-col>
      <el-col :span="16">
        <div style="text-align: center;">检验结果</div>
      </el-col>
      <el-col :span="2">
        <div style="text-align: center;">结论</div>
      </el-col>
    </el-row>
    <div class="circuit-parameters-item" v-for="(h,y) in allBandList" :key="y+'ooo'">
      <div class="circuit-parameters-item-title">
        <span>频段:</span>
        <el-select v-model="h.band" placeholder="请选择" size="small" style="width: 200px;" :disabled="state>1">
          <el-option
            v-for="item in bandList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-button type="primary" size="small" @click="addList(h.projectList,'互调')" style="margin-left: 16px;" v-if="intermodulationNum>0&&!(state>1)">添加互调</el-button>
        <el-button size="small" @click="deleteList(0,h.projectList,'互调')" v-if="intermodulationNum>0&&!(state>1)">删除互调</el-button>
        <el-button type="primary" size="small" @click="save(h,y)" :disabled="state>1" :loading="loading[y]" style="margin-left: 16px;" v-show="!isLook">保 存</el-button>
      </div>
      <el-divider></el-divider>
      <div class="circuit-parameters-item-content">
        <template v-for="(n,j) in h.projectList">
          <!-- 电压驻波比/同极化隔离度/异极化隔离度 -->
          <el-row :gutter="5" style="margin: 12px 0 0;display: flex;align-items: center;" v-if="n.inspectionItemSubclass.includes('驻波比')||n.inspectionItemSubclass.includes('隔离度')">
            <el-col :span="2">
              <div style="text-align: center;">{{ n.inspectionItemSubclass }}</div>
            </el-col>
            <el-col :span="2">
              <div style="text-align: center;">{{ n.unit }}</div>
            </el-col>
            <el-col :span="2">
              <div style="text-align: center;" v-html="n.tell"></div>
            </el-col>
            <el-col :span="16">
              <div class="content" style="text-align: center;width: 100%;overflow-x: auto;">
                <table border="1" cellpadding="10" class="thermal-table">
                  <tr>
                    <td>端口</td>
                    <td v-for="(item,index) in n.portList" :key="index+'aaa'">
                      <div style="display: flex;align-items: center;">
                        <el-input size="small" placeholder="端口" v-model="item.value" :disabled="state>1"></el-input>
                      </div>
                    </td>
                    <td :rowspan="n.angleList.length+1">
                      <el-button icon="el-icon-minus" circle size="mini" type="danger"
                      @click="deleteList(n.portList.length-1,n.portList)" :disabled="state>1" style="margin: 5px;"></el-button>
                      <el-button icon="el-icon-plus" circle size="mini" type="primary" @click="addList(n.portList)" :disabled="state>1" style="margin: 5px;"></el-button>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <span>最差值</span>
                    </td>
                    <td v-for="(m,i) in n.portList" :key="i+'ggg'">
                      <el-input size="small" placeholder="最差值" v-model="n.value[0][i]" v-if="n.value" :disabled="state>1"></el-input>
                    </td>
                  </tr>
                </table>
              </div>
            </el-col>
            <el-col :span="2">
              <div style="text-align: center;" :class="{red:n.result===0,green:n.result===1}">{{ n.result===0?'不合格':(n.result===1?'合格':'待定') }}
              </div>
            </el-col>
          </el-row>
          <!-- 互调 -->
          <el-row :gutter="5" style="margin: 12px 0 0;display: flex;align-items: center;" v-if="n.inspectionItemSubclass.includes('互调')">
            <el-col :span="2">
              <div style="text-align: center;">{{ n.inspectionItemSubclass }}</div>
            </el-col>
            <el-col :span="2">
              <div style="text-align: center;">{{ n.unit }}</div>
            </el-col>
            <el-col :span="2">
              <div style="text-align: center;" v-html="n.tell"></div>
            </el-col>
            <el-col :span="16">
              <div class="content" style="text-align: center;width: 100%;overflow-x: auto;">
                <table border="1" cellpadding="10" class="thermal-table">
                  <tr>
                    <td>频点</td>
                    <td :colspan="n.portList.length+1">
                      <div style="display: flex;align-items: center;">
                        <el-input size="small" placeholder="频点" v-model="n.often" :disabled="state>1" @blur="handlePort(n)"></el-input>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td>端口</td>
                    <td v-for="(item,index) in n.portList" :key="index+'fff'">
                      <div style="display: flex;align-items: center;">
                        <el-input size="small" placeholder="端口" v-model="item.value" :disabled="state>1"></el-input>
                      </div>
                    </td>
                    <td :rowspan="n.angleList.length+1">
                      <el-button icon="el-icon-minus" circle size="mini" type="danger"
                      @click="deleteList(n.portList.length-1,n.portList)" :disabled="state>1" style="margin: 5px;"></el-button>
                      <el-button icon="el-icon-plus" circle size="mini" type="primary" @click="addList(n.portList)" :disabled="state>1" style="margin: 5px;"></el-button>
                    </td>
                  </tr>
                  <tr v-for="(item,index) in n.angleList" :key="index + 'eee'">
                    <td>
                      <el-input size="small" placeholder="角度" v-model="item.value" :disabled="state>1" @blur="handleAngle(item.value,index)"></el-input>
                    </td>
                    <td v-for="(m,i) in n.portList" :key="i+'ggg'">
                      <el-input size="small" placeholder="最差值" v-model="n.value[index][i]" v-if="n.value[index]" :disabled="state>1"></el-input>
                    </td>
                  </tr>
                </table>
              </div>
            </el-col>
            <el-col :span="2">
              <div style="text-align: center;" :class="{red:n.result===0,green:n.result===1}">{{ n.result===0?'不合格':(n.result===1?'合格':'待定') }}
              </div>
            </el-col>
          </el-row>
          <el-divider v-if="j!=h.projectList.length-1"></el-divider>
        </template>
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  props:['insProduct','orderId','sampleId','state','num','isLook','currentNum'],
  data() {
    return {
      value: "",
      bandList:[],
      portList:[
        {
          value:'1',
        },
        {
          value:'2',
        },
        {
          value:'3',
        },
        {
          value:'4',
        },
      ],
      angleList:[
        {
          value:''
        }
      ],
      projectList:[
        {
          inspectionItemSubclass:'电压驻波比',
          unit:'/',
          tell:'≤1.45',
          result:0,
          portList:[],
          angleList:[],
          value:[],//双层数组
        },
        {
          inspectionItemSubclass:'同极化隔离度',
          unit:'dB',
          tell:'≤1.45',
          result:0,
          portList:[],
          angleList:[],
          value:[],//双层数组
        },
        {
          inspectionItemSubclass:'互调',
          often:'',//互调特有字段
          unit:'dB',
          tell:'≤1.45',
          result:0,
          portList:[],
          angleList:[],
          value:[],//双层数组
        },
      ],
      allBandList:[],//频段
      isMore:false,
      insProductNew:[],
      intermodulationNum:0,//互调检验项目的数量
      loading:{}
    };
  },
  watch: {
    // 角度数量变化时,更新所有频段下面的所有项目下的所有端口和角度
    angleList(val) {
      this.allBandList.forEach(item => {
        item.projectList.forEach(m => {
          if(m.angleList.length!==val.length){
            m.angleList = JSON.parse(JSON.stringify(this.angleList))
          }
          if(m.inspectionItemSubclass.includes('互调')){
            for(let i = 0;i<m.angleList.length;i++){
              if(!m.value[i]){
                this.$set(m.value,i, [])
              }
              for(let j=0;j<m.portList.length;j++){
                if(!m.value[i][j]){
                  m.value[i].push('')
                }
              }
            }
          }else{
            for(let j=0;j<m.portList.length;j++){
              if(!m.value[0][j]){
                m.value[0].push('')
              }
            }
          }
        })
      })
    },
    currentNum(val) {
      this.initData()
    }
  },
  mounted() {
    this.getTypeDicts()
    this.initData()
    console.log(2222,this.currentNum)
  },
  methods: {
    // 字典获取数据
    getTypeDicts() {
      this.$axios.post(this.$api.enums.selectEnumByCategory, {
        category: "电路试验波段"
      }).then(res => {
        this.bandList = res.data
      })
    },
    // 初始化数据
    initData(){
      // 处理项目
      this.insProductNew = JSON.parse(JSON.stringify(this.insProduct)).filter(m=>m.inspectionItem.includes('电路试验'))
      this.insProductNew.forEach(async item => {
        // 获取设备列表
        item.equipOptions = await this.getEquipOptions(item)
      })
      if(this.insProductNew[0].insProductResult2&&this.insProductNew[0].insProductResult2.length>0){
        // 已经存在值时,赋值
        let bandList = this.insProductNew[0].insProductResult2.map(m=>m.frequency)
        bandList = Array.from(new Set(bandList))
        this.allBandList = []
        for(let i = 0;i<bandList.length;i++){
          let arr = []
          this.insProductNew.forEach(item => {
            if(item.inspectionItemSubclass.includes('互调')){
              this.intermodulationNum++
            }
            let equipNameList = []
            let equipValueList = []
            item.insProductResult2.forEach(n => {
              if(n.frequency===bandList[i]){
                // 赋值页面设备名称和值
                if(n.equipValue){
                  equipNameList.push(n.equipName)
                  equipValueList.push(n.equipValue)
                }
                // 以下为赋值列表信息
                let portList = []
                let angleList = []
                if(n.port&&n.port.split(',').length>0){
                  n.port.split(',').forEach(m=>{
                    portList.push({value:m})
                  })
                }
                if(n.angle&&n.angle.split(',').length>0){
                  n.angle.split(',').forEach(m=>{
                    angleList.push({value:m})
                  })
                  this.angleList = angleList
                }
                let tell = ''
                if(item.tell.includes(',')){
                  item.tell.split(',').forEach((m,i)=>{
                    tell = tell + m+ (i==item.tell.split(',').length-1?'':'<br/>')
                  })
                }else{
                  tell = item.tell
                }
                let obj = {
                  inspectionItemSubclass: item.inspectionItemSubclass,
                  unit:item.unit,
                  tell:tell,
                  result:n.result,
                  id:item.id,
                  often:n.often,
                  equipName:n.equipName,
                  equipValue:n.equipValue,
                  frequency:n.frequency,
                  sonLaboratory:item.sonLaboratory
                }
                this.$set(obj,'portList', n.port?portList:[])
                this.$set(obj,'angleList', n.angle?angleList:[])
                this.$set(obj,'value', JSON.parse(n.value))
                arr.push(obj)
              }
            })
            if(equipValueList.length>0){
              this.$delete(item,'equipName')
              this.$delete(item,'equipValue')
              this.$set(item,'equipName',equipNameList[equipNameList.length-1])
              this.$set(item,'equipValue',equipValueList[equipValueList.length-1])
            }
          })
          this.$set(this.allBandList,i, {
            band: bandList[i],
            projectList: arr
          })
        }
      }else{
        // 没有值时,初始化页面
        this.insProductNew.forEach(async item => {
          // 是否存在互调检验项目
          if(item.inspectionItemSubclass.includes('互调')){
            this.intermodulationNum++
          }
          // 赋值设备
          item.equipName = ''
          item.equipValue = ''
          // 赋值端口和角度
          item.portList = JSON.parse(JSON.stringify(this.portList))
          item.angleList = JSON.parse(JSON.stringify(this.angleList))
          // 赋值结论
          item.result = ''
          // 赋值最差值
          item.value = []
          if(item.inspectionItemSubclass.includes('互调')){
            for(let i = 0;i<item.angleList.length;i++){
              item.value.push([])
              for(let j=0;j<item.portList.length;j++){
                item.value[i].push('')
              }
            }
          }else{
            item.value.push([])
            for(let j=0;j<item.portList.length;j++){
              item.value[0].push('')
            }
          }
        })
        // 初始化频段
        this.allBandList.push(
          {
            band:'',
            projectList: JSON.parse(JSON.stringify(this.insProductNew))
          }
        )
      }
    },
    // 删除数组
    deleteList(index,list,type){
      if(list.length>1){
        if(type=='互调'){
          let index = null;
          let num = 0;
          list.forEach((m,i)=>{
            if(m.inspectionItemSubclass.includes('互调')){
              index = i;
              num++
            }
          })
          if(num==1){
            this.$message({
              type: 'warning',
              message: '不能删除最后一个互调'
            });
          }else{
            list.splice(index, 1)
          }
        }else if(type=='删除频段'){
          this.$confirm(`是否确定删除 ${list[index].band} 频段数据?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            this.$axios.post(this.$api.insOrderPlan.deleteInsContext, {
              frequency:list[index].band,
              productIds:list[index].projectList.map(m=>m.id),
              num:this.num
            }, {
            headers: {
              'Content-Type': 'application/json'
            },
            noQs:true}).then(res => {
              if (res.code === 201) {
                this.$message.error('删除失败')
                return
              }
              this.$message.success('已删除')
              list.splice(index, 1)
            }).catch(err => {
              console.log(err)
            })
          }).catch(() => {})
        }else{
          list.splice(index, 1)
        }
      }else{
        this.$message({
          type: 'warning',
          message: '不能删除最后一个'
        });
      }
    },
    // 添加数组
    addList(list,type){
      if(type=='互调'){
        let obj = null;
        let index = null;
        list.forEach((m,i)=>{
          if(m.inspectionItemSubclass.includes('互调')){
            obj = JSON.parse(JSON.stringify(m));
            index = i;
          }
        })
        obj.often = ''
        obj.result = ''
        let num0 = obj.value.length
        let num1 = obj.value[0].length
        delete obj.value
        obj.value = []
        for(let i = 0;i<num0;i++){
          obj.value.push([])
          for(let j = 0;j<num1;j++){
            obj.value[i].push('')
          }
        }
        list.splice(index+1, 0, obj)
      }else if(type=='频段'){
        let obj = JSON.parse(JSON.stringify(list[0]));
        obj.band = ''
        obj.projectList.forEach(item=>{
          item.often = ''
          item.result = ''
          item.frequency = ''
          let num0 = item.value.length
          let num1 = item.value[0].length
          delete item.value
          item.value = []
          for(let i = 0;i<num0;i++){
            item.value.push([])
            for(let j = 0;j<num1;j++){
              item.value[i].push('')
            }
          }
        })
        list.push(obj)
      }else{
        let obj = JSON.parse(JSON.stringify(list[0]));
        list.push(obj)
      }
    },
    // 获取设备选项 id:为检验项id
    async getEquipOptions(m) {
      let arr = []
      let res = await this.$axios.post(this.$api.deviceScope.selectDeviceByCategory, {
        inspectionItem: m.inspectionItem,
        inspectionItemSubclass: m.inspectionItemSubclass
      })
      if (res.code === 200 && res.data) {
        arr = res.data.map(m => {
          m.value = m.managementNumber
          m.label = m.deviceName
          return m
        })
      }
      return arr
    },
    // 统一修改角度,如果角度没有带°,则拼接一个
    handleAngle(e,index){
      if(!e){
        return
      }
      let val = e
      if(!val.includes('°')){
        val = val + '°'
      }
      this.allBandList.forEach(item=>{
        item.projectList.forEach(m=>{
          if(m.inspectionItemSubclass.includes('互调')){
            m.angleList.forEach((n,i)=>{
              if(index==i){
                n.value = val
              }
            })
          }
        })
      })
    },
    handlePort(n){
      if(!n.often){
        return
      }
      if(!n.often.includes('MHz')&&!n.often.includes('MHZ')){
        n.often = n.often + 'MHz'
      }
    },
    async methodFocus(item){
      this.$delete(item, 'equipOptions')
      this.$set(item, 'equipOptions', await this.getEquipOptions(item))
    },
    handleEquip(m,item){
      this.$delete(item, 'equipValue')
      this.$set(item, 'equipValue', m)
      this.$delete(item, 'equipName')
      this.$set(item, 'equipName', item.equipOptions.find(m=>m.value==item.equipValue).label)
    },
    save(h,y) {
      let arr = h.projectList.map(item=>{
        if(item.portList&&item.portList.length>0){
          item.value.forEach(m=>{
            m = m.splice(item.portList.length)
          })
        }
        let obj = {
          insProductId:item.id,
          equipValue:this.insProductNew.find(m=>m.id==item.id).equipValue,
          equipName:this.insProductNew.find(m=>m.id==item.id).equipName,
          port:item.portList.map(m=>m.value).join(','),
          angle:item.angleList.map(m=>m.value).join(','),
          value:JSON.stringify(item.value),
          often:item.often
        }
        return obj
      })
      this.$delete(this.loading, y)
      this.$set( this.loading, y, true)
      // this.loading[y] = true
      this.$axios.post(this.$api.insOrderPlan.saveInsContext2, {
        orderId:this.orderId,
        sampleId:this.sampleId,
        sonLaboratory:h.projectList[0].sonLaboratory,
        frequency:h.band,
        insProductResult2s:arr
      }, {
      headers: {
        'Content-Type': 'application/json'
      },
      noQs:true}).then(res => {
        this.$set( this.loading, y, false)
        // this.loading[y] = false
        if (res.code === 201) {
          this.$message.error('保存失败')
          return
        }
        for(let i=0;i<res.data.length;i++){
          h.projectList[i].result = res.data[i]
        }
        this.$message.success('已保存')
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>
 
<style scoped>
.circuit-parameters-item{
  margin-bottom: 10px;
  border: 1px solid #eee;
  padding: 10px;
  box-sizing: border-box;
  border-radius: 8px;
}
.circuit-parameters-item-title{
  display: flex;
  align-items: center;
}
.thermal-table{
  min-width: calc(100% - 10px);
  table-layout: fixed;
}
.thermal-table td,.thermal-table th {
  min-width: 70px;
  text-align: center;
  font-size: 14px;
  word-wrap: break-word;
  white-space: normal;
  padding: 5px;
}
.thermal-table .el-input{
  display: flex;
  align-items: center;
}
.equip{
  display: flex;
  align-items: center;
}
.red{
  color: red;
}
.green{
  color: green;
}
</style>