<template>
|
<el-dialog
|
v-model="dialogVisible"
|
title="派发工单"
|
width="40%"
|
:close-on-click-modal="false"
|
@close="handleClose"
|
>
|
<el-form
|
:model="form"
|
:rules="rules"
|
ref="formRef"
|
label-width="100px"
|
@submit.prevent
|
>
|
<el-form-item label="选择部门" prop="department">
|
<el-select
|
v-model="form.department"
|
placeholder="请选择部门"
|
@change="handleDepartmentChange"
|
class="full-width"
|
>
|
<el-option
|
v-for="dept in departments"
|
:key="dept.value"
|
:label="dept.label"
|
:value="dept.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="选择处理人" prop="handler">
|
<el-select
|
filterable
|
v-model="form.handler"
|
placeholder="请选择处理人"
|
:disabled="!form.department"
|
class="full-width"
|
>
|
<el-option
|
v-for="user in availableHandlers"
|
:key="user.id"
|
:label="user.name"
|
:value="user.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-form>
|
|
<template #footer>
|
<el-button @click="handleClose" icon="el-icon-circle-close">取消</el-button>
|
<el-button
|
type="primary"
|
:loading="loading"
|
@click="handleSubmit"
|
icon="el-icon-check"
|
>
|
确认派发
|
</el-button>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script>
|
import { flowEvent } from '@/api/tickets/ticket';
|
|
export default {
|
name: 'DispatchDialog',
|
props: {
|
modelValue: {
|
type: Boolean,
|
default: false
|
},
|
currentDetail: {
|
type: Object,
|
default: () => ({})
|
},
|
departments: {
|
type: Array,
|
default: () => []
|
},
|
departmentUsers: {
|
type: Object,
|
default: () => ({})
|
},
|
algorithms: {
|
type: Array,
|
default: () => []
|
},
|
types: {
|
type: Array,
|
default: () => []
|
}
|
},
|
emits: ['update:modelValue', 'dispatch-success', 'dispatch-error'],
|
data() {
|
return {
|
form: {
|
department: '',
|
handler: ''
|
},
|
rules: {
|
department: [{ required: true, message: '请选择部门', trigger: 'change' }],
|
handler: [{ required: true, message: '请选择处理人', trigger: 'change' }]
|
},
|
loading: false
|
};
|
},
|
computed: {
|
dialogVisible: {
|
get() {
|
return this.modelValue;
|
},
|
set(value) {
|
this.$emit('update:modelValue', value);
|
}
|
},
|
availableHandlers() {
|
return this.form.department ? this.departmentUsers[this.form.department] || [] : [];
|
}
|
},
|
watch: {
|
modelValue(newVal) {
|
if (newVal) {
|
this.resetForm();
|
}
|
}
|
},
|
methods: {
|
resetForm() {
|
this.form = {
|
department: '',
|
handler: ''
|
};
|
if (this.$refs.formRef) {
|
this.$refs.formRef.clearValidate();
|
}
|
},
|
|
handleClose() {
|
this.dialogVisible = false;
|
this.resetForm();
|
},
|
|
handleDepartmentChange(deptId) {
|
this.form.handler = ''; // 清空处理人选择
|
},
|
|
async handleSubmit() {
|
try {
|
const valid = await this.$refs.formRef.validate();
|
if (!valid) return;
|
|
this.loading = true;
|
|
// 验证必填字段
|
if (!this.validateRequiredFields()) {
|
return;
|
}
|
|
const algorithmValue = this.getAlgorithmValue();
|
|
const data = {
|
id: this.currentDetail.id,
|
status: this.currentDetail.status,
|
isPass: 0, // 0 表示通过
|
eventName: this.currentDetail.orderName,
|
eventNum: this.currentDetail.orderNumber,
|
workOrderTypeDictKey: this.currentDetail.type,
|
content: this.currentDetail.content,
|
createDept: this.form.department,
|
updateUser: this.form.handler,
|
aiType: algorithmValue,
|
};
|
|
const response = await flowEvent(data);
|
if (response.data.code === 0) {
|
this.$message.success('工单已成功派发');
|
this.$emit('dispatch-success');
|
this.handleClose();
|
} else {
|
throw new Error(response.data.msg || '派发失败');
|
}
|
} catch (error) {
|
console.error('派发失败:', error);
|
this.$emit('dispatch-error', error);
|
this.$message.error(error.message || '派发失败,请稍后重试');
|
} finally {
|
this.loading = false;
|
}
|
},
|
|
validateRequiredFields() {
|
if (!this.currentDetail.orderName || !this.currentDetail.orderName.trim()) {
|
this.$message.warning('请填写工单名称');
|
return false;
|
}
|
if (!this.currentDetail.type) {
|
this.$message.warning('请选择工单类型');
|
return false;
|
}
|
if (!this.currentDetail.content || !this.currentDetail.content.trim()) {
|
this.$message.warning('请填写工单内容');
|
return false;
|
}
|
return true;
|
},
|
|
getAlgorithmValue() {
|
const isValue = this.algorithms.some(item => item.value === this.currentDetail.aiType);
|
|
if (isValue) {
|
return this.currentDetail.aiType;
|
} else {
|
const matched = this.algorithms.find(
|
item => item.dict_value === this.currentDetail.aiType ||
|
item.label === this.currentDetail.aiType
|
);
|
return matched ? matched.value : null;
|
}
|
}
|
}
|
};
|
</script>
|
|
<style scoped>
|
.full-width {
|
width: 100%;
|
}
|
</style>
|