Riku
2024-09-28 c18772a3b843e3ca5af5e58d6570860ce1a4aa8f
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
<template>
  <FYTable
    @search="onSearch"
    :pagination="false"
    ref="tableRef"
    @cell-click="cellClick"
    :cell-class-name="cellClassName"
    @table-paste="handlePaste"
    @sort-change="handleSortChange"
  >
    <template #options>
      <!-- 区县 -->
      <FYOptionLocation
        :allOption="false"
        :level="3"
        :checkStrictly="false"
        v-model:value="formSearch.locations"
      ></FYOptionLocation>
      <!-- 场景类型 -->
      <FYOptionScene
        :allOption="false"
        :type="2"
        v-model:value="formSearch.scenetype"
      ></FYOptionScene>
      <!-- 时间 -->
      <FYOptionTime :initValue="false" type="month" v-model:value="formSearch.time"></FYOptionTime>
    </template>
    <template #buttons>
      <!-- <el-button icon="Download" size="default" type="success" @click="download"
        >规范性评估与分析报告</el-button
      > -->
      <CompReport
        :locations="formSearch.locations"
        :scenetype="formSearch.scenetype"
        :time="formSearch.time"
      ></CompReport>
    </template>
 
    <template #options-expand>
      <el-form :inline="true">
        <CompQuickSet @quick-set="setOptions"></CompQuickSet>
      </el-form>
    </template>
 
    <template #table-column="{ size }">
      <el-table-column fixed="left" sortable="custom" prop="sceneIndex" label="编号" width="80">
      </el-table-column>
      <el-table-column prop="sceneName" :show-overflow-tooltip="true" label="名称" width="300">
      </el-table-column>
      <el-table-column
        prop="subTaskTime"
        label="巡查日期"
        width="110"
        sortable="custom"
        :formatter="timeFormat"
      />
      <el-table-column prop="evaluation.resultscorebef" label="得分" width="90" sortable="custom" />
      <el-table-column prop="evaluation.resultscorebef" label="环信码" width="100">
        <template #default="{ row }">
          <span :style="`color: ${toCode(row).color};`">{{ toCode(row).name }}</span>
        </template>
      </el-table-column>
 
      <el-table-column prop="dname" label="区县" width="90" />
      <el-table-column
        prop="tname"
        label="街道"
        width="110"
        :filters="townFilters"
        :filter-method="filterHandler"
      />
      <el-table-column prop="evaluation.scenseaddress" label="地址" />
      <!-- <el-table-column prop="biArea" label="集中区" width="110" />
      <el-table-column prop="biManagementCompany" label="物业" min-width="110"/> -->
      <el-table-column
        v-if="scoreShow"
        fixed="right"
        align="right"
        label="监测数据超标"
        width="160"
      >
        <template #default="{ row }">
          <el-input :size="size" v-model="row.score1" />
        </template>
      </el-table-column>
      <el-table-column
        v-if="scoreShow"
        fixed="right"
        align="right"
        label="监测数据超区月均值"
        width="160"
      >
        <template #default="{ row }">
          <el-input :size="size" v-model="row.score2" />
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="right" label="操作" width="160">
        <template #header>
          <el-button
            v-show="!scoreShow"
            icon="ArrowLeft"
            size="small"
            type="success"
            @click="scoreShow = true"
            >监测数据得分</el-button
          >
          <el-button v-show="scoreShow" size="small" type="primary" @click="updateMultipleScore"
            >上传</el-button
          >
          <el-button v-show="scoreShow" size="small" type="error" @click="scoreShow = false"
            >取消</el-button
          >
        </template>
        <template #default="{ row }">
          <el-button type="primary" size="small" @click="editRow(row)">查看</el-button>
        </template>
      </el-table-column>
    </template>
  </FYTable>
</template>
 
<script>
import dayjs from 'dayjs';
import evaluateApi from '@/api/fysp/evaluateApi';
import { envCreditCode } from '@/constants/index';
import CompReport from './components/CompReport.vue';
import { useTablePaste } from '@/composables/tablePaste';
import { useCloned } from '@vueuse/core';
import { useMessageBoxTip } from '@/composables/messageBox';
 
export default {
  setup() {
    const { cellClick, cellClassName, handlePaste, setTableData, addRefreshEvent, tableData } =
      useTablePaste({
        score1: 8,
        score2: 9
      });
    return { cellClick, cellClassName, handlePaste, setTableData, addRefreshEvent, tableData };
  },
  components: { CompReport },
  data() {
    return {
      formSearch: {
        locations: {},
        scenetype: {},
        time: dayjs().add(-1, 'M').date(1).toDate()
      },
      townFilters: [],
      // 原始数据,用于排序取消后
      orginData: [],
      evaluationRule: undefined,
      evaluationSubRule: undefined,
      //监测数据规则名称
      ruleName: {
        score1: {
          id: undefined,
          name: '监测数据出现单日及以上有效超标'
        },
        score2: {
          id: undefined,
          name: '监测数据月均值超区域月均值20%以上或数据明显异常'
        }
      },
      scoreShow: false
    };
  },
  computed: {
    area() {
      const { locations, scenetype, time } = this.formSearch;
      return {
        provincecode: locations.pCode,
        provincename: locations.pName,
        citycode: locations.cCode,
        cityname: locations.cName,
        districtcode: locations.dCode,
        districtname: locations.dName,
        starttime: dayjs(time).format('YYYY-MM-DD HH:mm:ss'),
        scensetypeid: scenetype.value
      };
    }
  },
  methods: {
    // _getParam() {
    //   const { locations, scenetype, time } = this.formSearch;
    //   return {
    //     provincecode: locations.pCode,
    //     provincename: locations.pName,
    //     citycode: locations.cCode,
    //     cityname: locations.cName,
    //     districtcode: locations.dCode,
    //     districtname: locations.dName,
    //     starttime: dayjs(time).format('YYYY-MM-DD HH:mm:ss'),
    //     scensetypeid: scenetype.value
    //   };
    // },
    editRow(row) {
      this.$router.push(`evalutationEdit/${row.subTaskId}`);
    },
    setOptions(param) {
      this.formSearch.locations = param.locations;
      this.formSearch.scenetype = param.scenetype;
      this.formSearch.sourceType = param.sourceType;
      this.$refs.tableRef.onSearch();
    },
    onSearch(page, func) {
      this.$refs.tableRef.clearSort();
      this.fetchEvaluationRule(this.area).then(() => {
        evaluateApi.fetchAutoEvaluation(this.area).then((res) => {
          if (res.data) {
            this.tableData = res.data;
            this.orginData = useCloned(this.tableData).cloned;
            console.log(this.orginData);
            this.getFilters(res.data);
            if (typeof func === 'function') {
              func({ data: this.tableData });
            }
          }
        });
      });
    },
    fetchEvaluationRule() {
      const param = {
        // 自动评估类型
        taskTypeId: 99,
        ...this.area
      };
      // 获取评估总规则
      return evaluateApi.fetchEvaluationRule(param).then((res) => {
        if (res.data.length > 0) {
          this.evaluationRule = res.data[0];
          // 获取具体子规则
          return evaluateApi.getSubRules(this.evaluationRule.guid).then((res) => {
            this.evaluationSubRule = res.data;
            // 查找可导入得分的规则id
            for (const key in this.ruleName) {
              const value = this.ruleName[key];
              const subrule = this.evaluationSubRule.find((v) => {
                return v.itemname == value.name;
              });
              value.id = subrule.guid;
            }
          });
        }
      });
    },
    // 批量更新监测数据得分
    updateMultipleScore() {
      useMessageBoxTip({
        confirmMsg: '是否上传监测数据得分',
        confirmTitle: '上传监测数据得分',
        onConfirm: () => {
          if (this.evaluationRule) {
            const param = this.tableData.map((v) => {
              const subRule = [];
              for (const key in this.ruleName) {
                const value = this.ruleName[key];
                subRule.push({
                  first: value.id,
                  second: v[key].trim() != ''
                });
              }
              return {
                ...this.area,
                subTaskId: v.subTaskId,
                ruleId: this.evaluationRule.guid,
                subRule
              };
            });
 
            evaluateApi.updateMultipleScore(param);
          }
        }
      });
    },
    // 规范性评估与分析报告后台生成任务
    download() {
      evaluateApi.downloadAutoEvaluation(this.area).then((res) => {
        if (res == false) {
          // 未下载文档,而是开启了文档生成后台任务
          this.$parent;
        }
      });
    },
    // 导出表格为excel格式
    exportExcel() {},
    getFilters(data) {
      const townList = [];
      data.forEach((e) => {
        if (townList.indexOf(e.tname) == -1) {
          townList.push(e.tname);
        }
      });
      this.townFilters = townList.map((v) => {
        return { text: v, value: v };
      });
    },
    toCode(row, column) {
      if (row.evaluation) {
        return envCreditCode(row.evaluation.resultscorebef);
      } else {
        return '';
      }
    },
    timeFormat(row, column) {
      const time = row.subTaskTime;
      if (time) {
        return dayjs(time).format('MM-DD');
      } else {
        return '';
      }
    },
    filterHandler(value, row, column) {
      const property = column['property'];
      return row[property] === value;
    },
    sortScore(a, b) {
      const s1 = a.evaluation ? parseInt(a.evaluation.resultscorebef) : 0;
      const s2 = b.evaluation ? parseInt(b.evaluation.resultscorebef) : 0;
      return s1 - s2;
    },
    handleSortChange({ column, prop, order }) {
      console.log(column, prop, order);
      if (order == null) {
        this.orginData.forEach((e, i) => {
          this.tableData[i] = e;
        });
      } else if (prop == 'evaluation.resultscorebef') {
        this.tableData.sort((a, b) => {
          const s1 = a.evaluation ? parseInt(a.evaluation.resultscorebef) : 0;
          const s2 = b.evaluation ? parseInt(b.evaluation.resultscorebef) : 0;
          if (order == 'ascending') {
            return s1 - s2;
          } else if (order == 'descending') {
            return s2 - s1;
          }
        });
      } else if (prop == 'sceneIndex') {
        this.tableData.sort((a, b) => {
          if (order == 'ascending') {
            if (a.sceneIndex === b.sceneIndex) {
              return a.subTaskTime > b.subTaskTime ? 1 : -1;
            } else {
              return a.sceneIndex - b.sceneIndex;
            }
          } else if (order == 'descending') {
            if (a.sceneIndex === b.sceneIndex) {
              return b.subTaskTime > a.subTaskTime ? 1 : -1;
            } else {
              return b.sceneIndex - a.sceneIndex;
            }
          }
        });
      } else if (prop == 'subTaskTime') {
        this.tableData.sort((a, b) => {
          if (order == 'ascending') {
            return a[prop] > b[prop] ? 1 : -1;
            // return dayjs(a).isAfter(dayjs(b)) ? 1 : -1;
          } else if (order == 'descending') {
            return b[prop] > a[prop] ? 1 : -1;
            // return dayjs(b).isAfter(dayjs(a)) ? 1 : -1;
          }
        });
      }
    }
  },
  mounted() {
    this.addRefreshEvent(this.$refs.tableRef.doLayout);
  }
};
</script>
<style scoped></style>