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
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
<style scoped lang="scss">
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }
 
  .el-aside {
    color: #333;
  }
 
  .el-scrollbar .el-scrollbar__wrap {
    overflow-x: hidden;
  }
</style>
<template>
  <div class="app-container" style="padding:0">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row :gutter="20">
          <el-col :span="16">
            <div class="grid-content bg-purple">{{titleName}} —— 设计</div>
          </el-col>
          <el-col :span="7">
            <div class="grid-content bg-purple">
              <el-button type="button" plain @click="addTable">新增表格</el-button>
              <el-button type="primary" @click="submitForm">保 存</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
      <el-container>
        <el-main><!---->
          <div class="demo-input-size">
            <el-form refs="form" :model="form" >
              <template v-for='(config,tableIndex) in configInfos' >
                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item prop="title">
                      <el-input style="border: 0" v-model="config.tableName"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="18">
                    <div class="grid-content bg-purple">
                      <el-button type="button" plain @click="addRow(tableIndex)">增加行</el-button>
                      <el-button type="button" plain @click="addColumn(tableIndex)">增加列</el-button>
                      <el-button type="button" plain @click="deleteTable(tableIndex)">删除表格</el-button>
                    </div>
                  </el-col>
                </el-row>
                <el-table :data="config.tableRow" ref="multipleTable" tooltip-effect="dark" style="width: 100%;margin-bottom: 20px" border @header-click="deleteCol" @cell-dblclick="showPTable2"  :row-class-name="tableRowClassName">
                  <template v-for='(col,columnIndex) in config.tableColumn'>
                    <el-table-column :show-overflow-tooltip="true" :prop="col.item" :label="col.name" :key="col.item" :index="tableIndex" :type="numToStr(columnIndex)" :current-row-key="2">
                      <template scope="scope">
                        <el-input size="mini" v-model="scope.row[col.item]" v-if="columnIndex===0" ></el-input>
                        <el-input size="mini" v-model="scope.row[col.item]" v-if="columnIndex !=0" ref="nav" style="width: 80%"></el-input>
                        <!--<el-button v-if="columnIndex !=0" @click.native.prevent="collectIndexSetting(columnIndex,tableIndex,scope.$index)" style="width: 100px">选择</el-button>-->
                      </template>
                    </el-table-column>
                  </template>
                  <el-table-column fixed="right" label="操作">
                  <template slot-scope="scope">
                    <el-button @click.native.prevent="deleteRow(tableIndex,scope.$index)" size="small"> 移除 </el-button>
                  </template>
                </el-table-column>
                </el-table>
              </template>
            </el-form>
          </div>
        </el-main>
      </el-container>
    </el-card>
    <!--新增列名称-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible" width="300px">
      <el-form :model="forms" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="列名称" prop="column">
              <el-input v-model="forms.column"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitColumn">确 定</el-button>
      </div>
    </el-dialog>
    <el-drawer title="选择采集指标" :visible.sync="collectIndexDialog" direction="rtl"
               size="55%"> <!--@open="showCollectIndexDialog"-->
      <StatisticIndexSetting ref="collectIndexSetting" indexType="COLLECT" @statisticIndexConfirmSelect="collectIndexConfirmSelect"></StatisticIndexSetting>
    </el-drawer>
  </div>
</template>
<script>
  import {listParameters, getParameters, getAllCollectTag, updateParameters} from "@/api/basicSetup/parameters";
  /*import CollectIndexSetting from "../../basicsetting/nodeSetting/collectIndexSetting"*/;
  import {setNodeToIndex} from '@/api/basicsetting/modelNode'
  /*import StatisticIndexSetting from "../../basicsetting/nodeSetting/statisticIndexSetting";*/
  import StatisticIndexSetting from "./standard_statistic";
  export default {
    name: 'basicIndex',
    components: {StatisticIndexSetting},
    data() {
      return {
        // 罩层遮
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // parameters表格数据
        parametersList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        opens: false,
        dialogFormVisible: false,
        collectIndexDialog: false,
        codeOptions: [],
        // 数据展示类型,1-实时数据,2-阶段数据字典
        dataTypeOptions: [],
        // 是否显示报警字典
        showAlarmOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          id: undefined,
          name: undefined,
          code: undefined,
          categoryName: undefined,
          categoryCode: undefined,
          dataType: undefined,
          showAlarm: undefined
        },
        titleName: "",
        // 表单参数
        form: {},
        forms:{},
        i: -1,
        // 表单校验
        rules: {
          id: [{required: true, message: "是否显示报警不能为空", trigger: "blur"}],
          name: [{required: true, message: "标准参数类别名称不能为空", trigger: "blur"}],
        },
        configInfos: [],
        tableInfos:{},
        settingCollectIndexList: [],
        row_number:"",
        table_number:"",
        column_number:"",
        currentNode:"",
      };
    },
    created() {},
    methods: {
      tableRowClassName ({row, rowIndex}) {
       //把每一行的索引放进row
        row.index = rowIndex;
      },
      showPTable2(row, column){
        if(column.type>0){
          let key = column.property;
          this.row_number=row.index;
          this.table_number=column.index
          this.column_number=key
          this.collectIndexDialog = true;
          this.$nextTick(() => {
            this.$refs.collectIndexSetting.init(this.queryParams.id, this.settingCollectIndexList);
          })
 
        }
      },
      collectIndexConfirmSelect(selectedIndex) {
        //this.settingCollectIndexList = selectedIndex[0];
        console.log(selectedIndex)
        this.configInfos[this.table_number].tableRow[this.row_number][this.column_number] = selectedIndex.code;
        /*let indexIds = selectedIndex.indexId
        setNodeToIndex(this.queryParams.id, indexIds, "COLLECT").then((response) => {
          if (response.code !== 200) {
            this.$message.error(response.msg);
          }
        });*/
      },
      getList(data) {
        this.titleName = data.label;
        this.queryParams.id = data.id;
        this.currentNode=data;
        this.loading = true;
        this.configInfos=[];
        listParameters(this.queryParams).then(response => {
          this.parametersList = response.rows;
          if(this.parametersList.length >0){
            if(this.parametersList[0].configInfo =="null" ||this.parametersList[0].configInfo==null ||this.parametersList[0].configInfo==""){
              this.configInfos=[];
            }else{
              this.configInfos=JSON.parse(this.parametersList[0].configInfo);
            }
          }
          this.loading = false;
        });
      },
      // 数据展示类型,1-实时数据,2-阶段数据字典翻译
      dataTypeFormat(row, column) {
        return this.selectDictLabel(this.dataTypeOptions, row.dataType);
      },
      // 是否显示报警字典翻译
      showAlarmFormat(row, column) {
        return this.selectDictLabel(this.showAlarmOptions, row.showAlarm);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.opens = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          name: undefined,
          configInfo: undefined,
          remark: undefined,
          code: undefined,
          dataType: undefined,
          showAlarm: undefined,
          column: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        //this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加标准参数";
      },
      dialogTable() {
        this.reset();
        this.opens = true;
        this.title = "添加指标";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getParameters(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改标准参数";
        });
      },
      /** 保存按钮 */
      submitForm: function () {
        this.form.id=this.queryParams.id;
        this.form.name=this.titleName;
        if (this.form.id != undefined) {
          this.form.configInfo= JSON.stringify(this.configInfos);
          updateParameters(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("保存成功");
              this.getList(this.currentNode);
            } else {
              this.msgError(response.msg);
            }
          });
        }
      },
      //添加表格
      addTable: function () {
        let tableConfig = {
          tableName: '',
          tableRow: [],
          tableColumn: []
        };
        this.configInfos.push(tableConfig);
      },
      addRow: function (tableIndex) {
        let tableInfo = this.configInfos[tableIndex];
        let row = {};
        for (let i = 0; i < tableInfo.tableColumn.length; i++) {
          row[tableInfo.tableColumn[i].item] = '';
        }
        tableInfo.tableRow.push(row);
      },
      deleteRow: function (tableIndex, rowIndex) {
        let tableInfo = this.configInfos[tableIndex];
        tableInfo.tableRow.splice(rowIndex, 1);
      },
      numToStr(num) {
        num = num.toString()
        return num
      },
        deleteCol: function (column) {
        let tableInfo = this.configInfos[column.index];
        let num=column.type;
        tableInfo.tableColumn.splice(num, 1);
      },
      addColumn: function (tableIndex) {
        this.forms = {
          column: undefined,
        };
        this.resetForm("forms");
        this.dialogFormVisible = true;
        this.title = "添加列标题";
        this.tableInfos = this.configInfos[tableIndex];
      },
      submitColumn: function () {
        this.dialogFormVisible = false;
        let tableInfo = this.tableInfos;
        let tableColInfo = {
          name: this.forms.column,
          item: 'colName' + tableInfo.tableColumn.length
          /*name: '车间' + tableInfo.tableColumn.length,
          item: 'colName' + tableInfo.tableColumn.length*/
        };
        tableInfo.tableColumn.push(tableColInfo)
      },
      deleteTable: function (tableIndex) {
        this.configInfos.splice(tableIndex, 1);
      },
    }
  };
</script>