<template>
|
<ChangeableColumnTable
|
@search="onSearch"
|
:pagination="false"
|
:cols="cols"
|
ref="tableRef"
|
@select-updated="selectUpdated"
|
@select-batch-updated="selectBatchUpdated"
|
>
|
<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>
|
<!-- <div class="flex-div flex-v-center">
|
<el-form-item label="部分扣分">
|
<el-select
|
style="width: 310px"
|
collapse-tags
|
collapse-tags-tooltip
|
v-model="partScoreHeads"
|
multiple
|
placeholder="部分扣分项"
|
clearable
|
filterable
|
@change="onSelectionChange"
|
>
|
<el-option
|
v-for="item in cols.filter((item) => 'children' in item)"
|
:key="item"
|
:label="item.label"
|
:value="item.name"
|
/> </el-select
|
></el-form-item>
|
<el-tooltip placement="bottom-start" effect="light">
|
<template #content>
|
<el-text size="b">选中的条目对应的扣分总和将会显示在表格中的部分扣分列中</el-text><br />
|
</template>
|
<el-icon class="m-l-8 cursor-p" :size="16" color="var(--el-color-warning)"
|
><QuestionFilled
|
/></el-icon>
|
</el-tooltip>
|
</div>-->
|
|
<el-form :inline="true">
|
<CompQuickSet @quick-set="setOptions"></CompQuickSet>
|
</el-form>
|
</template>
|
</ChangeableColumnTable>
|
</template>
|
<script>
|
import ChangeableColumnTable from './components/ChangeableColumnTable.vue';
|
import CompReport from './components/CompReport.vue';
|
import evaluateApi from '@/api/fysp/evaluateApi';
|
import { useCloned } from '@vueuse/core';
|
import dayjs from 'dayjs';
|
import { ElMessage } from 'element-plus';
|
import { useMessageBox, useMessageBoxTip } from '../../../composables/messageBox';
|
export default {
|
components: {
|
ChangeableColumnTable,
|
CompReport,
|
},
|
data() {
|
return {
|
partScoreHeads: [],
|
editRecordSwitch: false,
|
dataReady: false,
|
area: {},
|
formSearch: {
|
locations: {},
|
scenetype: {},
|
time: dayjs().add(-1, 'M').date(1).toDate()
|
},
|
refreshTable: true,
|
cols: [],
|
tableData: []
|
};
|
},
|
methods: {
|
onSelectionChange() {
|
for (const tableItem of this.tableData) {
|
tableItem.partSum = 0;
|
for (const headItem of this.partScoreHeads) {
|
if (headItem in tableItem) {
|
tableItem.partSum += tableItem[headItem];
|
} else {
|
tableItem.partSum = '';
|
}
|
}
|
}
|
},
|
// 指定添加的表头顺序
|
addHead(headObj, index) {
|
this.cols.splice(index, 0, headObj);
|
},
|
async selectBatchUpdated(rows, name) {
|
var promises = [];
|
for (const row of rows) {
|
if (!row.subTaskId || row.subTaskId == null) {
|
for (var attr in row) {
|
if (attr.endsWith('ScoreSelect')) {
|
row[attr] = false;
|
}
|
}
|
continue;
|
}
|
var checkedUpdatedList = [];
|
for (const attr in row) {
|
if (attr.endsWith('ScoreSelect') && Boolean(row[attr])) {
|
var id = attr.split('ScoreSelect')[0];
|
checkedUpdatedList.push(id);
|
}
|
}
|
promises.push(
|
evaluateApi
|
.updateScore({
|
subTaskId: row.subTaskId,
|
itemList: checkedUpdatedList
|
})
|
.then(() => {
|
evaluateApi.fetchItemEvaluation(row.subTaskId).then((res) => {
|
this.updateChangeableData(res.data.details, res.data.score, row.subTaskId);
|
});
|
})
|
);
|
}
|
var reSend = true;
|
while (promises.length !== 0 && reSend) {
|
reSend = false;
|
await Promise.allSettled(promises).then((results) => {
|
results.forEach((result, index) => {
|
if (result.status === 'fulfilled') {
|
} else {
|
// 成功了删掉这个promise
|
promises.splice(index, 1);
|
}
|
});
|
});
|
|
ElMessage({
|
message: '全部成功',
|
type: 'success',
|
plain: true
|
});
|
if (promises.length == 0) {
|
// ElMessage({
|
// message: '全部成功',
|
// type: 'success',
|
// plain: true
|
// });
|
} else {
|
// useMessageBoxTip({
|
// confirmMsg: '是否重试',
|
// confirmTitle: '批量更新失败',
|
// onConfirm: async () => {
|
// reSend = true;
|
// }
|
// });
|
}
|
}
|
},
|
// 选中更改的回调
|
selectUpdated(row) {
|
if (!row.subTaskId || row.subTaskId == null) {
|
for (var attr in row) {
|
if (attr.endsWith('ScoreSelect')) {
|
row[attr] = false;
|
}
|
}
|
return;
|
}
|
var checkedUpdatedList = [];
|
for (const attr in row) {
|
if (attr.endsWith('ScoreSelect') && Boolean(row[attr])) {
|
var id = attr.split('ScoreSelect')[0];
|
checkedUpdatedList.push(id);
|
}
|
}
|
evaluateApi
|
.updateScore({
|
subTaskId: row.subTaskId,
|
itemList: checkedUpdatedList
|
})
|
.then(() => {
|
evaluateApi.fetchItemEvaluation(row.subTaskId).then((res) => {
|
this.updateChangeableData(res.data.details, res.data.score, row.subTaskId);
|
});
|
});
|
},
|
_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
|
};
|
},
|
// 更新一行数据
|
updateChangeableData(data, score, subTaskId) {
|
for (let index = 0; index < this.tableData.length; index++) {
|
const element = this.tableData[index];
|
if (element.subTaskId == subTaskId) {
|
element.resultscorebef = score;
|
this.genChangeableData(data, element);
|
// this.tableData[index] = element;
|
}
|
}
|
},
|
// 生成得分条目的数据
|
genChangeableData(data, tableItem) {
|
for (let index = 0; index < data.length; index++) {
|
const element = data[index];
|
tableItem[`${element.id}Score`] = element.score;
|
if (element.select) {
|
tableItem[`${element.id}ScoreSelect`] = element.select;
|
}
|
var twoLevel = element.subList;
|
|
if (!twoLevel) {
|
continue;
|
}
|
for (let index = 0; index < twoLevel.length; index++) {
|
const threeElement = twoLevel[index];
|
tableItem[`${threeElement.id}Score`] = threeElement.score;
|
if (threeElement.select) {
|
tableItem[`${threeElement.id}ScoreSelect`] = threeElement.select;
|
}
|
var threeLevel = threeElement.subList;
|
if (!threeLevel) {
|
continue;
|
}
|
for (let index = 0; index < threeLevel.length; index++) {
|
const target = threeLevel[index];
|
// 展示当前子规则的分值
|
// tableItem[`${target.id}Score`] = target.maxScore;
|
// 展示当前项的当前得分
|
tableItem[`${target.id}Score`] = target.score;
|
if (target.select) {
|
tableItem[`${target.id}ScoreSelect`] = target.select;
|
}
|
}
|
}
|
}
|
},
|
// 生成得分条目的表头
|
genChangeableHead(data) {
|
// 一级表头
|
for (let i = 0; i < data.length; i++) {
|
const element = data[i];
|
const col = {
|
fixed: false
|
};
|
this.cols.push(col);
|
col.label = element.title;
|
col.name = `${element.id}Score`;
|
|
for (const attr in element) {
|
// 二级表头
|
let children = [];
|
col.children = children;
|
if (attr === 'subList') {
|
for (let j = 0; j < element[attr].length; j++) {
|
const twoElement = element[attr][j];
|
const child = {
|
fixed: false
|
};
|
children.push(child);
|
child.label = twoElement.title;
|
child.name = `${twoElement.id}Score`;
|
|
for (const attr2 in twoElement) {
|
// 三级指标
|
let children2 = [];
|
child.children = children2;
|
if (attr2 === 'subList') {
|
for (let k = 0; k < twoElement[attr2].length; k++) {
|
const threeElement = twoElement[attr2][k];
|
const child2 = {
|
fixed: false
|
};
|
children2.push(child2);
|
child2.label = threeElement.title;
|
child2.name = `${threeElement.id}Score`;
|
if (this.editRecordSwitch) {
|
child2.needSelect = true;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
},
|
// 排名表头
|
genRankHead() {
|
var head = {
|
name: 'rank',
|
label: '总分排名',
|
// fixed: 'left'
|
};
|
this.addHead(head, 0);
|
},
|
// 编号方法
|
makeNumber(array, propName) {
|
if (!(array instanceof Array)) {
|
return;
|
}
|
// var copy = [];
|
// array.forEach((item) => {
|
// copy.push(item);
|
// });
|
|
array.sort((a, b) => b[propName] - a[propName]);
|
// var maxIndex = copy.length;
|
var minIndex = 1;
|
array.forEach((item) => {
|
item.rank = minIndex++;
|
});
|
},
|
// 排名数据
|
genRankData() {
|
this.makeNumber(this.tableData, 'resultscorebef');
|
},
|
// 基本信息表头
|
genTableHeadBaseInfo(data) {
|
var cols = [
|
{
|
name: 'sceneIndex',
|
label: '编号',
|
fixed: false,
|
noncloseable: true
|
},
|
{
|
name: 'createdate',
|
label: '巡查日期',
|
fixed: 'left',
|
},
|
{
|
name: 'scensename',
|
label: '名称',
|
fixed: 'left',
|
},
|
{
|
name: 'resultscorebef',
|
label: '得分',
|
fixed: false
|
},
|
{
|
name: 'districtname',
|
label: '区县',
|
fixed: false
|
},
|
{
|
name: 'townname',
|
label: '街道',
|
fixed: false
|
},
|
{
|
name: 'scenseaddress',
|
label: '地址',
|
fixed: false
|
}
|
];
|
for (var col of cols) {
|
this.cols.push(col);
|
}
|
},
|
// 生成基本数据信息
|
genTableDataBaseInfo(data, tableItem) {
|
try {
|
tableItem.sceneIndex = data.sceneIndex;
|
tableItem.scensename = data.sceneName;
|
tableItem.districtname = data.dname;
|
tableItem.townname = data.tname;
|
if (!data.evaluation) {
|
tableItem.createdate = '';
|
tableItem.resultscorebef = '';
|
tableItem.scenseaddress = '';
|
return;
|
}
|
tableItem.createdate = data.evaluation.createdate
|
? dayjs(data.evaluation.createdate).format('MM-DD')
|
: '';
|
tableItem.resultscorebef = data.evaluation.resultscorebef || 0;
|
tableItem.scenseaddress = data.evaluation.scenseaddress || '';
|
} catch (e) {
|
console.log(e.message, data);
|
}
|
},
|
onSearch(page, func) {
|
this.dataReady = false;
|
this.tableData = [];
|
this.cols = [];
|
const area = this._getParam();
|
var expandHeadOk = false;
|
var baseHeadOk = false;
|
var showExpand = true;
|
evaluateApi
|
.fetchAutoEvaluation(area)
|
.then((res) => {
|
for (const element of res.data) {
|
if (element.subTaskId == null) {
|
showExpand = false;
|
// continue;
|
// console.log('subTask为空');
|
} else {
|
showExpand = true;
|
}
|
var tableItem = {};
|
|
if (!baseHeadOk) {
|
this.genTableHeadBaseInfo(element);
|
baseHeadOk = true;
|
}
|
if (showExpand) {
|
evaluateApi
|
.fetchItemEvaluation(element.subTaskId)
|
.then((res) => {
|
const data = res.data.details;
|
tableItem = {
|
subTaskId: element.subTaskId
|
};
|
this.tableData.push(tableItem);
|
try {
|
if (!expandHeadOk) {
|
this.genChangeableHead(data);
|
expandHeadOk = true;
|
}
|
} catch (e) {
|
console.log('表头准备失败', e.message);
|
}
|
this.genTableDataBaseInfo(element, tableItem);
|
this.genChangeableData(data, tableItem);
|
})
|
.catch((error) => {
|
console.error('Error fetching item evaluation:', error);
|
})
|
.finally(() => {});
|
} else {
|
this.genTableDataBaseInfo(element, tableItem);
|
this.tableData.push(tableItem);
|
}
|
}
|
})
|
.finally(() => {
|
setTimeout(() => {
|
this.dataReady = true;
|
// 生成排名表头
|
this.genRankHead();
|
this.genRankData();
|
func({ data: this.tableData });
|
}, 1000);
|
});
|
},
|
// 初始化调整状态
|
initEditRecord() {
|
if (!Boolean(this.$route.meta.readonly)) {
|
this.editRecordSwitch = true;
|
}
|
},
|
// 初始化
|
init() {
|
this.initEditRecord();
|
},
|
|
setOptions(param) {
|
this.formSearch.locations = param.locations;
|
this.formSearch.scenetype = param.scenetype;
|
this.formSearch.sourceType = param.sourceType;
|
this.$refs.tableRef.onSearch();
|
}
|
},
|
created() {
|
this.init();
|
},
|
mounted() {
|
this.$refs.tableRef.onSearch();
|
}
|
};
|
</script>
|
<style scoped>
|
.flex-div {
|
display: flex;
|
}
|
.flex-v-center {
|
align-items: center;
|
}
|
</style>
|