<template>
|
<el-form-item :label="label" :prop="prop">
|
<el-select
|
:model-value="formatedValue"
|
@update:model-value="handleChange"
|
:placeholder="label"
|
style="width: 260px"
|
>
|
<el-option
|
v-for="s in filtedBeforeTask"
|
:key="s.value"
|
:label="s.label"
|
:value="s.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</template>
|
|
<script>
|
import taskApi from '@/api/fysp/taskApi';
|
|
export default {
|
props: {
|
label: {
|
type: String,
|
default: '总任务'
|
},
|
// 返回结果
|
value: Object,
|
// 是否默认返回初始选项
|
initValue: {
|
type: Boolean,
|
default: true
|
},
|
// form表单绑定属性名
|
prop: {
|
type: String,
|
default: 'topTaskId'
|
},
|
// 选项筛选条件,筛选某任务之前的相同行政区划内的任务
|
beforeTask: {
|
type: Object,
|
default: () => {
|
return {};
|
}
|
}
|
},
|
emits: ['update:value'],
|
data() {
|
return {
|
selected: {},
|
topTasks: []
|
};
|
},
|
computed: {
|
// 选择框中使用顶层任务id作为选项值
|
formatedValue() {
|
return this.value?.tguid;
|
},
|
// 某任务之前的相同行政区划内的任务
|
filtedBeforeTask() {
|
const filteredTasks = this.topTasks.filter((t) => {
|
return (
|
(!this.beforeTask.provincecode ||
|
this.beforeTask.provincecode == t.data.provincecode) &&
|
(!this.beforeTask.citycode ||
|
this.beforeTask.citycode == t.data.citycode) &&
|
(!this.beforeTask.districtcode ||
|
this.beforeTask.districtcode == t.data.districtcode) &&
|
(!this.beforeTask.starttime ||
|
t.data.starttime < this.beforeTask.starttime)
|
);
|
});
|
if (filteredTasks.length > 0) {
|
this.handleChange(filteredTasks[0]?.value);
|
}
|
return filteredTasks;
|
}
|
},
|
methods: {
|
//获取查询条件
|
getOptions() {
|
taskApi.getTopTask().then((res) => {
|
const list = res.map((r) => {
|
return {
|
value: r.tguid,
|
label: r.name,
|
data: r
|
};
|
});
|
this.topTasks = list;
|
if (this.initValue) {
|
this.handleChange(list[0].value);
|
}
|
});
|
},
|
//查询子任务统计信息
|
handleChange(value) {
|
const task = this.topTasks.find((t) => t.data.tguid == value);
|
const param = task ? task.data : {};
|
|
this.$emit('update:value', param);
|
}
|
},
|
mounted() {
|
this.getOptions();
|
}
|
};
|
</script>
|