liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
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
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="" prop="meterType" style="float: right">
        <el-select v-model="queryParams.deviceId" size="small"
                   @change="getList">
          <el-option
            v-for="device in settingDeviceList"
            :key="device.id"
            :label="device.meterName"
            :value="device.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
 
    <el-table border v-loading="loading" :data="collectIndexList" @select="handleSelectionChange"
              :header-cell-class-name="hideCheckAll"
              ref="energySettingTable">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编码" align="center" prop="code"/>
      <el-table-column label="名称" align="center" prop="name"/>
      <el-table-column label="单位" align="center" prop="unitId" :formatter="unitIdFormat"/>
    </el-table>
 
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
 
<script>
  import {listCollectIndex} from "@/api/basicsetting/energyindex";
  import {getSettingDevice, getSettingCollectIndex} from '@/api/basicsetting/modelNode'
 
  export default {
    name: "CollectIndexSetting",
    data() {
      return {
        collectIndexList: [],
        selectedCollectIndex: [],
        settingDeviceList: [],
        loading: false,
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          deviceId: undefined,
        },
        // 单位字典
        unitIdOptions: []
      }
    },
    created() {
      this.getDicts("sys_unit").then(response => {
        this.unitIdOptions = response.data;
      });
    },
    methods: {
      init(modelNode) {
        getSettingCollectIndex(modelNode.id).then((response) => {
          this.selectedCollectIndex = response.data;
        }).then(() => {
          getSettingDevice(modelNode.id).then((response) => {
            if (response.code === 200) {
              this.settingDeviceList = response.data;
              if (this.settingDeviceList && this.settingDeviceList.length > 0) {
                this.queryParams.deviceId = this.settingDeviceList[0].id;
              }
            } else {
              this.$message.error(response.msg);
            }
 
            this.getList();
          });
        });
      },
      getList() {
        this.loading = true;
        listCollectIndex(this.queryParams).then(response => {
          this.collectIndexList = response.rows;
          this.total = response.total;
          this.loading = false;
          this.$nextTick(function () {
            this.$refs.energySettingTable.data.forEach(rowData => {
              let exist = this.selectedCollectIndex.filter(
                f => f.indexId === rowData.indexId).length;
              if (exist > 0) {
                this.$refs.energySettingTable.toggleRowSelection(rowData, true);
              }
            });
          });
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection, row) {
        let rowStatus = selection.filter(f => f.indexId === row.indexId).length;
        if (rowStatus > 0) {
          this.selectedCollectIndex.push({
            "indexId": row.indexId,
            "code": row.code,
            "name": row.name
          });
        } else {
          this.selectedCollectIndex = this.selectedCollectIndex.filter(
            f => f.indexId !== row.indexId);
        }
 
        this.$emit('collectIndexConfirmSelect', this.selectedCollectIndex);
      },
      unitIdFormat(row) {
        return this.selectDictLabel(this.unitIdOptions, row.unitId);
      }
    }
  }
</script>
 
<style scoped>
 
</style>