<template>
|
<FYForm
|
ref="formRef"
|
:form-info="formInfo"
|
:rules="rules"
|
:useCancel="true"
|
label-width="120px"
|
submit-name="创建"
|
@submit="submit"
|
@cancel="cancel"
|
>
|
<template #form-item="{ formObj }">
|
<!-- 区县 -->
|
<FYOptionLocation
|
:allOption="false"
|
:level="3"
|
:initValue="false"
|
:checkStrictly="false"
|
v-model:value="formObj._locations"
|
@change="handleLocationChange"
|
></FYOptionLocation>
|
<el-form-item label="任务名称" prop="name">
|
<el-input
|
clearable
|
show-word-limit
|
v-model="formObj.name"
|
placeholder="任务名称"
|
/>
|
</el-form-item>
|
<FYOptionTime
|
label="起止日期"
|
prop="_timeArr"
|
:initValue="false"
|
type="daterange"
|
v-model:value="formObj._timeArr"
|
@change="handleTimeChange"
|
></FYOptionTime>
|
|
<el-form-item v-show="showMore" label="任务类型" prop="_type">
|
<el-select v-model="formObj._type" style="width: 150px">
|
<el-option
|
v-for="s in taskTypeOptions"
|
:key="s.label"
|
:label="s.label"
|
:value="s.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item v-show="showMore" label="任务期限类别" prop="_deadlinetype">
|
<el-select v-model="formObj._deadlinetype" style="width: 150px">
|
<el-option
|
v-for="s in deadlineTypeOptions"
|
:key="s.label"
|
:label="s.label"
|
:value="s.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item v-show="showMore" label="任务层次" prop="levelnum">
|
<el-select v-model="formObj.levelnum" style="width: 150px">
|
<el-option
|
v-for="s in levelOptions"
|
:key="s.label"
|
:label="s.label"
|
:value="s.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item v-show="showMore" label="执行人" prop="_executors">
|
<el-select
|
v-model="formObj._executors"
|
multiple
|
clearable
|
collapse-tags
|
placeholder="选择执行人"
|
:max-collapse-tags="3"
|
style="width: 300px"
|
>
|
<el-option
|
v-for="s in executorOptions"
|
:key="s.value"
|
:label="s.label"
|
:value="s.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-row justify="center">
|
<el-link type="primary" @click="showMore = !showMore">
|
{{ showMore ? '收起' : '更多选项' }}
|
<el-icon v-if="showMore"><ArrowUp /></el-icon>
|
<el-icon v-else><ArrowDown /></el-icon>
|
</el-link>
|
</el-row>
|
</el-form-item>
|
</template>
|
</FYForm>
|
</template>
|
<script setup>
|
import { ref, reactive, watch, onMounted } from 'vue';
|
import domainApi from '@/api/fysp/domainApi';
|
import userApi from '@/api/fysp/userApi';
|
import dayjs from 'dayjs';
|
import taskApi from '@/api/fysp/taskApi';
|
|
const props = defineProps({
|
//数据
|
model: {
|
type: Object,
|
default: () => {
|
return {};
|
}
|
},
|
//是创建或者更新场景,默认更新
|
create: Boolean
|
});
|
|
const emit = defineEmits(['submit', 'cancel']);
|
|
const rules = reactive({
|
name: [
|
{
|
required: true,
|
message: '任务名称不能为空',
|
trigger: 'change'
|
}
|
],
|
_type: [
|
{
|
required: true,
|
message: '任务类型不能为空',
|
trigger: 'change'
|
}
|
],
|
_deadlinetype: [
|
{
|
required: true,
|
message: '任务期限类型不能为空',
|
trigger: 'change'
|
}
|
],
|
levelnum: [
|
{
|
required: true,
|
message: '任务层次不能为空',
|
trigger: 'change'
|
}
|
],
|
// starttime: [
|
// {
|
// required: true,
|
// message: '开始日期不能为空',
|
// trigger: 'change'
|
// }
|
// ],
|
// endtime: [
|
// {
|
// required: true,
|
// message: '结束日期不能为空',
|
// trigger: 'change'
|
// }
|
// ],
|
_timeArr: [
|
{
|
required: true,
|
message: '起止日期不能为空',
|
trigger: 'change'
|
}
|
],
|
_executors: [
|
{
|
required: true,
|
message: '任务执行人不能为空',
|
trigger: 'change'
|
}
|
]
|
});
|
|
const formRef = ref(null);
|
const formInfo = ref({
|
starttime: dayjs().add(1, 'month').startOf('month').toDate(),
|
endtime: dayjs().add(1, 'month').endOf('month').toDate(),
|
_timeArr: [
|
dayjs().add(1, 'month').startOf('month').toDate(),
|
dayjs().add(1, 'month').endOf('month').set('millisecond', 0).toDate()
|
]
|
});
|
// 任务类型选项
|
const taskTypeOptions = ref([]);
|
// 任务期限类别选项
|
const deadlineTypeOptions = ref([]);
|
// 任务层次类别选项
|
const levelOptions = ref([]);
|
// 任务执行人选项
|
const executorOptions = ref([]);
|
const showMore = ref(false);
|
|
function locationText(location) {
|
if (location.pName == (undefined | null)) return '';
|
let res = location.pName;
|
if (location.cName && location.cName != location.pName) {
|
res += location.cName;
|
}
|
if (location.dName && location.dName != location.cName) {
|
res += location.dName;
|
}
|
return res;
|
}
|
|
function handleLocationChange(location) {
|
genTaskName();
|
}
|
|
function handleTimeChange(timeArr) {
|
genTaskName();
|
}
|
|
function genTaskName() {
|
let name = dayjs(formRef.value.formObj._timeArr[0]).format('YYYY年MM月');
|
name += locationText(formRef.value.formObj._locations);
|
name += formRef.value.formObj._type.text;
|
name += '任务';
|
formRef.value.formObj.name = name;
|
}
|
|
/*************************** 数据更新 ************************************/
|
|
function getExecutors(data) {
|
const ids = [];
|
const uNames = [];
|
const rNames = [];
|
executorOptions.value.forEach((e) => {
|
const index = data._executors.indexOf(e.value);
|
if (index != -1) {
|
ids.push(e.data.guid);
|
uNames.push(e.data.acountname);
|
rNames.push(e.data.realname);
|
}
|
});
|
return {
|
id: ids.join('#'),
|
uName: uNames.join('#'),
|
rName: rNames.join('#')
|
};
|
}
|
|
function submit(data, success, fail) {
|
const v = data.value;
|
const executors = getExecutors(v);
|
const task = {
|
levelnum: v.levelnum,
|
name: v.name,
|
typeno: v._type.value,
|
typename: v._type.text,
|
deadlinetype: v._deadlinetype.text,
|
provincecode: v._locations.pCode,
|
provincename: v._locations.pName,
|
citycode: v._locations.cCode,
|
cityname: v._locations.cName,
|
districtcode: v._locations.dCode,
|
districtname: v._locations.dName,
|
starttime: v._timeArr[0],
|
endtime: v._timeArr[1],
|
// fixme 2024.10.16, 后续加入用户系统后,采用当前登录用户信息
|
plannerguid: 'rAR0A4gJdlOZEqZs',
|
plannerusername: 'ccheck',
|
plannerrealname: '整改审核',
|
settime: new Date(),
|
executorguids: executors.id,
|
executorusernames: executors.uName,
|
executorrealnames: executors.rName,
|
t1stverifierguid: 'rAR0A4gJdlOZEqZs',
|
t1stverifierusername: 'ccheck',
|
t1stverifierrealname: '整改审核',
|
t1stverifytime: new Date(),
|
t1stisverify: true,
|
runingstatus: '未执行',
|
extension1: '3',
|
extension2: '0'
|
};
|
// success();
|
// emit('submit', task);
|
taskApi
|
.putTask(task)
|
.then((res) => {
|
success();
|
emit('submit', res.data);
|
})
|
.catch((err) => fail(err));
|
}
|
function cancel() {
|
emit('cancel');
|
}
|
|
/*************************** 数据初始化 ************************************/
|
|
// 各选项的初始化
|
function initOptions() {
|
domainApi.fetchTaskType().then((res) => {
|
taskTypeOptions.value = res.map((v) => {
|
return {
|
label: v.text,
|
value: v
|
};
|
});
|
formInfo.value._type = taskTypeOptions.value[0].value;
|
});
|
domainApi.fetchDeadlineType().then((res) => {
|
deadlineTypeOptions.value = res.map((v) => {
|
return {
|
label: v.text,
|
value: v
|
};
|
});
|
formInfo.value._deadlinetype = deadlineTypeOptions.value[0].value;
|
});
|
domainApi.fetchLevelType().then((res) => {
|
levelOptions.value = res.map((v) => {
|
return {
|
label: v.text,
|
value: v.value
|
};
|
});
|
formInfo.value.levelnum = levelOptions.value[1].value;
|
});
|
userApi.getUserByType(1).then((res) => {
|
executorOptions.value = res.map((v) => {
|
return {
|
label: v.realname,
|
value: v.guid,
|
data: v
|
};
|
});
|
formInfo.value._executors = executorOptions.value.map((v) => v.value);
|
});
|
}
|
|
onMounted(() => {
|
initOptions();
|
});
|
</script>
|
<style scoped></style>
|