quanyawei
2024-05-13 74990b437b7b6e6072999d65c37658e51de577b3
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
<template>
  <div>
    <a-modal width="70%" title="大屏页面布局" :maskClosable="false"  :visible="configureFlag"  :footer='versionId === -1? "" : undefined' @cancel="handleCancel" @ok="handleOk">
      <a-tabs :active-key="versionId" tabPosition="left" @change="getSnsor" v-if="versionId !== -1">
        <a-tab-pane v-for="(item, key, index) in versionData" :key="item.id" :tab="item.name" >
          <a-page-header
              style="border: 1px solid rgb(235, 237, 240)"
              title="待选区"
              :sub-title="'('+allWaitSensors.length+')'"
          >
            <a-row type="flex">
              <a-col :span="8" :order="3"  v-for="(item, index) in allWaitSensors" :key="index" style="font-size: 14px; opacity: 0.8; margin-top: 12px">
                {{ item.name }}
                <a-dropdown style="float: right; margin-right:40% " :trigger="['click']">
                  <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                    移到 <a-icon type="down" />
                  </a>
                  <a-menu slot="overlay">
                    <a-menu-item>
                      <a  @click="toDefault(0,item, index)">默认区</a>
                    </a-menu-item>
                    <a-menu-item v-if="coreMonitorItems.length === 6" disabled>
                      <span style="color:lightgrey; ">核心区(已满)</span>
                    </a-menu-item>
                    <a-menu-item v-else>
                      <a  @click="toCore(0,item, index)">核心区</a>
                    </a-menu-item>
                  </a-menu>
                </a-dropdown>
              </a-col>
            </a-row>
            <a-button  style="font-size: 14px; margin-top: 12px; margin-left: 74%" @click="toDefault(1,{}, -1)" v-if="allWaitSensors.length > 0">全部添加到默认区</a-button>
            <p style="width: 100%; height: 60px; line-height: 60px; text-align: center; font-size: 20px ">图表显示 : {{ chartSensorKey.name }}</p>
          </a-page-header>
          <a-page-header
              style="border: 1px solid rgb(235, 237, 240)"
              title="默认区"
              :sub-title="'('+defaultMonitorItems.length+')'"
          >
            <a-list :data-source="defaultMonitorItems" :split="false">
              <a-list-item slot="renderItem" slot-scope="item, index" :key="item.code">
                <a-list-item-meta :description="item.name">
                </a-list-item-meta>
                <a style="margin-right: 16%;width: 40px"  @click="clickUp('defaultMonitorItems',index)"> 上移 </a>
                <a style="margin-right: 16%;width: 40px"  @click="clickDown('defaultMonitorItems', index)"> 下移 </a>
                <a style="margin-right: 16%;width: 80px"  @click="setChart(item)"> 设为图表 </a>
                <a-dropdown style="float: right; margin-right:10% " :trigger="['click']">
                  <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                    移到 <a-icon type="down" />
                  </a>
                  <a-menu slot="overlay">
                    <a-menu-item>
                      <a @click="toWait(0,item, index)">待选区</a>
                    </a-menu-item>
                    <a-menu-item v-if="coreMonitorItems.length === 6" disabled>
                      <span style="color:lightgrey; ">核心区(已满)</span>
                    </a-menu-item>
                    <a-menu-item v-else>
                      <a  @click="toCore(1,item, index)">核心区</a>
                    </a-menu-item>
                  </a-menu>
                </a-dropdown>
              </a-list-item>
            </a-list>
          </a-page-header>
          <a-page-header
              style="border: 1px solid rgb(235, 237, 240)"
              title="核心区"
              :sub-title="'('+coreMonitorItems.length+'/6)'"
          >
            <a-list :data-source="coreMonitorItems" :split="false">
              <a-list-item slot="renderItem" slot-scope="item, index" :key="item.code">
                <a-list-item-meta :description="item.name">
                </a-list-item-meta>
                <a  style="margin-right: 16%;width: 40px" @click="clickUp('coreMonitorItems',index)"> 上移 </a>
                <a style="margin-right: 16%;width: 40px"  @click="clickDown('coreMonitorItems', index)"> 下移 </a>
                <a style="margin-right: 16%;width: 80px"   @click="setChart(item)"> 设为图表 </a>
                <a-dropdown style="float: right; margin-right:10% " :trigger="['click']">
                  <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                    移到 <a-icon type="down" />
                  </a>
                  <a-menu slot="overlay">
                    <a-menu-item>
                      <a  @click="toWait(1,item, index)">待选区</a>
                    </a-menu-item>
                    <a-menu-item>
                      <a  @click="toDefault(2,item, index)">默认区</a>
                    </a-menu-item>
                  </a-menu>
                </a-dropdown>
              </a-list-item>
            </a-list>
          </a-page-header>
          <a-page-header
              style="border: 1px solid rgb(235, 237, 240)"
              title="固定区"
              :sub-title="'(' + fixed +')'"
          >
            <a-checkbox :checked="windFlag" v-if="windDir.code" @change="onChange">
              {{ windDir.name }}
            </a-checkbox>
 
          </a-page-header>
        </a-tab-pane>
      </a-tabs>
      <a-result v-else title="该组织下没有可选型号!">
        <template #icon>
          <a-icon type="smile" theme="twoTone" />
        </template>
      </a-result>
    </a-modal>
  </div>
</template>
 
<script lang="tsx">
import {Component, Emit, Prop, Vue, Watch} from 'vue-property-decorator';
import { get, post } from "@/util/request";
 
@Component({
  components: {
  }
})
export default class ConfigureWeb extends Vue {
 
  // 存放所有型号
  private versionData: any = null
 
  // 存放图表区因子
  private chartSensorKey: any = {}
 
  // 存放核心区因子
  private coreMonitorItems: any[] = []
 
  // 存放默认区区因子
  private defaultMonitorItems: any[] = []
 
  // 存放所有待选区因子
  private allWaitSensors: any = []
 
  // 存放当前选中versionId
  private versionId: any = -1
 
  // 存放固定数量
  private fixed: number = 0
 
  // 判断风向有没有选中
  private windFlag: boolean = false
 
  // 存放固定区风向数据
  private windDir: any = {
  }
 
  @Prop({
    type: Boolean,
    default: false
  })
  private configureFlag!: boolean
 
  @Prop({
    type: Object,
    default: () => {
    }
  })
  private configRecord: any
  // 监听弹框变化
  @Watch('configureFlag', {
    deep: true
  })
  private watchConfigureFlag(newVal: boolean, oldVal: boolean) {
    if (newVal === true) {
      this.coreMonitorItems = []
      this.defaultMonitorItems = []
      this.chartSensorKey = {}
      this.versionId = -1
      this.getAllVersion()
      setTimeout(() => {
        this.getSensorByVersionId()
      },100)
    }
  }
 
 
  // 根据组织id获取所有型号
  private getAllVersion() {
      get('version/queryByOrgId',{
          organizationId: this.configRecord.id
      }).then((res: any) => {
        if (res.data.code === 0) {
           this.versionData = res.data.data.versions
        if (this.versionData) {
          if (this.versionData.length > 0) {
            if (this.versionId === -1) {
              this.versionId = this.versionData[0].id
            }
          }
        }
        }
      })
  }
 
  // 移动到默认区
  private toDefault(flag: number,item: any, index: number) {
    if (flag === 0) {
      let obj = {
        code: item.code,
        name: item.name
      }
      this.allWaitSensors.splice(index,1)
      this.defaultMonitorItems.push(obj)
    } else if (flag == 1) {
      if (this.allWaitSensors.length > 0) {
        for (let i = 0; i < this.allWaitSensors.length; i++) {
          let obj = {
            code: this.allWaitSensors[i].code,
            name: this.allWaitSensors[i].name
          }
          this.defaultMonitorItems.push(obj)
        }
        this.allWaitSensors = []
      }
    } else {
      let obj = {
        code: item.code,
        name: item.name
      }
      this.coreMonitorItems.splice(index,1)
      this.defaultMonitorItems.push(obj)
    }
  }
 
  // 移动到核心区
  private toCore(flag: number,item: any, index: number) {
    if (flag === 0) {
      let obj = {
        code: item.code,
        name: item.name
      }
      if (this.coreMonitorItems.length < 6) {
        this.allWaitSensors.splice(index,1)
        this.coreMonitorItems.push(obj)
      } else {
        this.$message.warning('核心区')
      }
    } else {
      let obj = {
        code: item.code,
        name: item.name
      }
      if (this.coreMonitorItems.length < 6) {
        this.defaultMonitorItems.splice(index,1)
        this.coreMonitorItems.push(obj)
      } else {
        this.$message.warning('核心区')
      }
    }
  }
 
  // 移动到待选区
  private toWait( flag: number,item: any, index: any) {
    if (flag === 0) {
      this.defaultMonitorItems.splice(index,1)
      if (item.code === this.chartSensorKey.code) {
        this.chartSensorKey = {}
      }
      this.allWaitSensors.push(item)
    } else {
      this.coreMonitorItems.splice(index,1)
      if (item.code === this.chartSensorKey.code) {
        this.chartSensorKey = {}
      }
      this.allWaitSensors.push(item)
    }
  }
 
  // 根据型号id获取因子
  private getSensorByVersionId() {
    get("version/queryById", {
                id: this.versionId,
                page: 1,
                size: 1000
        })
        .then((res: any) => {
          if (res.data.code === 0) {
            this.allWaitSensors = res.data.data.versions[0].sensors
            for (let i = 0; i < this.allWaitSensors.length; i++) {
              if (this.allWaitSensors[i].code === "a01008") {
                this.windDir.code = this.allWaitSensors[i].code
                this.windDir.name = this.allWaitSensors[i].name
                this.allWaitSensors.splice(i,1)
                this.fixed = 1
                break
              }
            }
            this.getOtherSensorsData()
          }
        })
        .catch(err => {
          console.log(err);
        });
 
 }
 
 // 风向
  private onChange(e: any) {
    this.windFlag = !this.windFlag
  }
 
 // 获取非待选区数据
  private getOtherSensorsData() {
    // 根据型号以及组织id获取默认区,核心区因子
    get("organizationLayout/getLayoutData", {
                version_id: this.versionId,
                organization_id: this.configRecord.id
        }).then((res: any) => {
          if (res.data.code === 0) {
            let sensors = res.data.data
            if (sensors.length > 0) {
              for (let i = 0; i < sensors.length; i++) {
                if (sensors[i].position === 'chartSensorKey') {
                  let name = ''
                  for (let j = 0; j < this.allWaitSensors.length; j++) {
                    if (sensors[i].sensor_code === this.allWaitSensors[j].code) {
                        name = this.allWaitSensors[j].name
                    }
                  }
                  let obj = {
                    code: sensors[i].sensor_code,
                    name: name
                  }
                  this.chartSensorKey = obj
                } else if (sensors[i].position === 'defaultMonitorItems') {
                  for (let j = 0; j < this.allWaitSensors.length; j++) {
                    let name = ''
                    let code = ''
                    if (sensors[i].sensor_code === this.allWaitSensors[j].code) {
                      name = this.allWaitSensors[j].name
                      code = this.allWaitSensors[j].code
                      let obj = {
                        code: code,
                        name: name
                      }
                      this.defaultMonitorItems.push(obj)
                    }
                  }
                } else if (sensors[i].position === 'coreMonitorItems') {
                  for (let j = 0; j < this.allWaitSensors.length; j++) {
                    let name = ''
                    let code = ''
                    if (sensors[i].sensor_code === this.allWaitSensors[j].code) {
                      name = this.allWaitSensors[j].name
                      code = this.allWaitSensors[j].code
                      let obj = {
                        code: code,
                        name: name
                      }
                      this.coreMonitorItems.push(obj)
                    }
                  }
                } else if (sensors[i].position === 'fixedMonitorItems') {
                  console.log(333);
                  this.windFlag = true
                }
              }
 
              for (let i = 0; i <sensors.length; i++) {
                for (let j = 0; j < this.allWaitSensors.length; j++) {
                  if (sensors[i].sensor_code === this.allWaitSensors[j].code) {
                    this.allWaitSensors.splice(j,1)
                  }
                }
              }
            }
 
          }
 
    })
 
  }
 
  // 设为图表
  private setChart(item: any) {
    this.chartSensorKey = item
  }
 
  //点击上移
 
  private clickUp(str: any,index: any){
    if (str === 'coreMonitorItems') {
      if(index === 0){
        this.$message.warning('该因子已经在第一位')
      }else {
        this.swapArray(this.coreMonitorItems, index-1, index);
      }
    }else {
      if(index === 0){
        this.$message.warning('该因子已经在第一位')
      }else {
        this.swapArray(this.defaultMonitorItems, index-1, index);
      }
    }
  }
//点击下移
  private clickDown(str: any,index: any){
    if (str === 'coreMonitorItems') {
      if(index === this.coreMonitorItems.length - 1){
        this.$message.warning('该因子已经在最后一位')
      }else {
        this.swapArray(this.coreMonitorItems, index, index+1);
      }
    }else {
      if(index === this.defaultMonitorItems.length - 1){
        this.$message.warning('该因子已经在最后一位')
      }else {
        this.swapArray(this.defaultMonitorItems, index, index+1);
      }
    }
  }
//数组元素互换位置
  private swapArray(arr: any, index1: any, index2: any) {
    arr[index1] = arr.splice(index2, 1, arr[index1])[0];
    return arr;
  }
 
 
  // 改变型号
  private getSnsor(id: any) {
    this.versionId = id
    this.coreMonitorItems = []
    this.defaultMonitorItems = []
    this.chartSensorKey = {}
    this.windDir = {}
    this.windFlag = false
    this.fixed = 0
    this.getSensorByVersionId()
  }
 
  // 用于传递flag
  @Emit('turnConfigureFlag')
  private sendConfigureFlag(flag: boolean) {
    return flag
  }
  private handleCancel() {
    this.versionId = -1
    this.sendConfigureFlag(false)
    this.windFlag = false
  }
  private handleOk() {
    const organizationLayouts = []
 
    if (this.chartSensorKey.code) {
      const obj = {
        organizationId: this.configRecord.id, //组织id
        versionId: this.versionId,
        position: 'chartSensorKey',
        positionIndex: 0,
        sensorCode: this.chartSensorKey.code
      }
      organizationLayouts.push(obj)
    }
    if (this.defaultMonitorItems.length > 0) {
      for (let i = 0; i < this.defaultMonitorItems.length; i++) {
        const obj = {
          organizationId: this.configRecord.id, //组织id
          versionId: this.versionId,
          position: 'defaultMonitorItems',
          positionIndex: i,
          sensorCode: this.defaultMonitorItems[i].code
        }
        organizationLayouts.push(obj)
      }
    }
    if (this.coreMonitorItems.length > 0) {
      for (let i = 0; i < this.coreMonitorItems.length; i++) {
        const obj = {
          organizationId: this.configRecord.id, //组织id
          versionId: this.versionId,
          position: 'coreMonitorItems',
          positionIndex: i,
          sensorCode: this.coreMonitorItems[i].code
        }
        organizationLayouts.push(obj)
      }
    }
    if (this.windFlag === true && this.windDir.code) {
      const obj = {
        organizationId: this.configRecord.id, //组织id
        versionId: this.versionId,
        position: 'fixedMonitorItems',
        positionIndex: 0,
        sensorCode: this.windDir.code
      }
      organizationLayouts.push(obj)
    }
    this.windFlag = false
    this.save(organizationLayouts)
    //
  }
 
  // 保存数据
  private save(organizationLayouts: any) {
    post('organizationLayout/setUpLayout',
        {
      organizationId: this.configRecord.id,
      versionId: this.versionId,
      organizationLayouts
    }).then((res: any) => {
      if (res.data.code === 0) {
        this.$message.success(res.data.message)
        setTimeout(() => {
          this.versionId = -1
          this.sendConfigureFlag(false)
        },100)
      }
 
 
    })
  }
}
</script>
 
<style scoped>
.editable-cell {
  position: relative;
}
 
.editable-cell-input-wrapper,
.editable-cell-text-wrapper {
  padding-right: 24px;
}
 
.editable-cell-text-wrapper {
  padding: 5px 24px 5px 5px;
}
 
.editable-cell-icon,
.editable-cell-icon-check {
  position: absolute;
  right: 0;
  width: 20px;
  cursor: pointer;
}
 
.editable-cell-icon {
  line-height: 18px;
  display: none;
}
 
.editable-cell-icon-check {
  line-height: 28px;
}
 
.editable-cell:hover .editable-cell-icon {
  display: inline-block;
}
 
.editable-cell-icon:hover,
.editable-cell-icon-check:hover {
  color: #108ee9;
}
 
.editable-add-btn {
  margin-bottom: 8px;
}
</style>