Commit 88747696 authored by sxl's avatar sxl 💬

feat: 优化巡检项目功能

- 添加设备编号自动获取功能,通过 watch 监听 deviceId 变化
- 新增巡检日期和巡检截止日期字段,完善日期管理
- 添加"未巡检"状态选项,丰富任务状态管理
- 优化表单提交逻辑,处理 inspectionUserId 数组转换
- 移除未使用的 error 参数,清理代码
- 统一日期选择器配置和表单验证规则
Co-Authored-By: 's avatarClaude Sonnet 4.5 <noreply@anthropic.com>
parent 0b95d873
......@@ -116,7 +116,7 @@
<!-- 添加或修改巡检任务对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form ref="form" :model="form" :rules="rules" label-width="110px">
<el-form-item label="巡检日期" prop="pollingData">
<el-date-picker
clearable
......@@ -128,6 +128,17 @@
>
</el-date-picker>
</el-form-item>
<el-form-item label="巡检截止日期" prop="pollingEndData">
<el-date-picker
clearable
v-model="form.pollingEndData"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择巡检截止日期"
:picker-options="pickerOptions"
>
</el-date-picker>
</el-form-item>
<el-form-item label="巡检人" prop="inspectionUserId">
<!--远程搜索-->
<el-select
......@@ -201,6 +212,7 @@ export default {
// 表单校验
rules: {
pollingData: [{ required: true, message: '巡检日期不能为空', trigger: 'blur' }],
pollingEndData: [{ required: true, message: '巡检截止日期不能为空', trigger: 'blur' }],
inspectionUserId: [{ required: true, message: '巡检人不能为空', trigger: 'blur' }],
placeId: [{ required: true, message: '巡检地点不能为空', trigger: 'blur' }],
},
......@@ -297,6 +309,16 @@ export default {
handleAdd() {
this.reset()
this.open = true
// 获取巡检地点列表
placeList().then(response => {
this.placeList = response.rows
})
// 获取用户列表
getInspectionUser({
userName: null,
}).then(response => {
this.useroptions = response.rows
})
this.title = '添加巡检任务'
},
/** 修改按钮操作 */
......@@ -317,15 +339,18 @@ export default {
submitForm() {
this.$refs['form'].validate(valid => {
if (valid) {
this.form.inspectionUserId = this.form.inspectionUserId.join(',')
if (this.form.id != null) {
updateTask(this.form).then(response => {
const formData = { ...this.form }
formData.inspectionUserId = Array.isArray(formData.inspectionUserId)
? formData.inspectionUserId.join(',')
: formData.inspectionUserId
if (formData.id != null) {
updateTask(formData).then(response => {
this.$modal.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addTask(this.form).then(response => {
addTask(formData).then(response => {
this.$modal.msgSuccess('新增成功')
this.open = false
this.getList()
......
......@@ -78,12 +78,23 @@
<el-form-item label="设备编号" prop="deviceNo">
<el-input v-model="form.deviceNo" placeholder="自动获取设备编号" disabled></el-input>
</el-form-item>
<el-form-item label="巡检截止日期" prop="pollingData">
<el-form-item label="巡检日期" prop="pollingData">
<el-date-picker
clearable
v-model="form.pollingData"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择巡检日期"
:picker-options="pickerOptions"
></el-date-picker>
</el-form-item>
<el-form-item label="巡检截止日期" prop="pollingEndData">
<el-date-picker
clearable
v-model="form.pollingEndData"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择巡检截止日期"
:picker-options="pickerOptions"
></el-date-picker>
......@@ -149,7 +160,6 @@ export default {
queryParams: {
pageNum: 1,
pageSize: 10,
pollingData: null,
inspectionUserId: null,
deviceId: null,
taskState: null,
......@@ -166,6 +176,7 @@ export default {
{ label: '待巡检', value: 0 },
{ label: '巡检中', value: 1 },
{ label: '已完成', value: 2 },
{ label: '未巡检', value: 3 },
],
// 表单参数
form: {},
......@@ -174,6 +185,13 @@ export default {
// 表单校验
rules: {
pollingData: [
{
required: true,
message: '巡检日期不能为空',
trigger: 'blur',
},
],
pollingEndData: [
{
required: true,
message: '巡检截止日期不能为空',
......@@ -228,6 +246,18 @@ export default {
created() {
this.getList()
},
watch: {
'form.deviceId'(newVal) {
if (newVal) {
const device = this.deviceList.find(item => item.id === newVal)
if (device) {
this.form.deviceNo = device.deviceNo
}
} else {
this.form.deviceNo = ''
}
},
},
methods: {
// 远程搜索
remoteMethod(queryString) {
......@@ -275,7 +305,7 @@ export default {
// 处理并返回数据
return this.handleTree(response.data, 'deptId')
})
.catch(error => {
.catch(() => {
return [] // 返回空数组,避免 Promise.all 失败
})
)
......@@ -324,11 +354,11 @@ export default {
this.form = {
id: null,
pollingData: null,
pollingEndData: null,
inspectionUserId: null,
deviceId: null,
taskState: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
......@@ -354,6 +384,8 @@ export default {
/** 新增按钮操作 */
handleAdd() {
this.reset()
// this.form.pollingData = this.parseTime(new Date(), '{y}-{m}-{d}')
this.form.pollingData = ''
this.open = true
this.title = '添加巡检任务'
},
......@@ -361,15 +393,18 @@ export default {
submitForm() {
this.$refs['form'].validate(valid => {
if (valid) {
this.form.inspectionUserId = this.form.inspectionUserId.join(',')
if (this.form.id != null) {
updateTask(this.form).then(response => {
const formData = { ...this.form }
formData.inspectionUserId = Array.isArray(formData.inspectionUserId)
? formData.inspectionUserId.join(',')
: formData.inspectionUserId
if (formData.id != null) {
updateTask(formData).then(() => {
this.$modal.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addTask(this.form).then(response => {
addTask(formData).then(() => {
this.$modal.msgSuccess('新增成功')
this.open = false
this.getList()
......
......@@ -59,22 +59,10 @@
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
@click="handleUpdate(scope.row)"
v-hasPermi="['workOrder:workOrder:edit']"
v-if="scope.row.orderStates == 0"
<el-button size="mini" type="text" @click="handleUpdate(scope.row)" v-if="scope.row.orderStates == 0"
>派单</el-button
>
<el-button
size="mini"
type="text"
@click="handleView(scope.row)"
v-hasPermi="['workOrder:workOrder:view']"
v-if="false"
>查看</el-button
>
<el-button size="mini" type="text" @click="handleView(scope.row)" v-if="false">查看</el-button>
</template>
</el-table-column>
</el-table>
......@@ -160,6 +148,42 @@
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 维修负责人选择对话框 -->
<el-dialog title="选择维修负责人" :visible.sync="assignOpen" width="400px" append-to-body>
<el-form ref="assignFormRef" :model="assignForm" :rules="assignRules" label-width="120px">
<!-- <el-form-item label="设备类型">
<el-input v-model="assignForm.deviceTypeName" disabled placeholder="自动获取设备类型" />
</el-form-item>
<el-form-item label="设备名称">
<el-input v-model="assignForm.deviceName" disabled placeholder="自动获取设备名称" />
</el-form-item> -->
<el-form-item label="部门名称" prop="maintainDeptId">
<treeselect
v-model="assignForm.maintainDeptId"
:options="assignDeptOptions"
:normalizer="normalizer"
placeholder="请选择部门名称"
@select="assignDeptSelect"
disabled
/>
</el-form-item>
<el-form-item label="维修负责人" prop="maintainUserId">
<el-select v-model="assignForm.maintainUserId" placeholder="请选择维修负责人">
<el-option
v-for="item in userList"
:key="item.userId"
:label="item.nickName"
:value="item.userId"
></el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="confirmAssign"> </el-button>
<el-button @click="cancelAssign"> </el-button>
</div>
</el-dialog>
</div>
</template>
......@@ -232,6 +256,7 @@ export default {
deviceTypeList: [],
deviceNameList: [],
deptOptions: [],
assignDeptOptions: [],
userList: [],
// 表单参数
form: {},
......@@ -247,6 +272,19 @@ export default {
deviceType: [{ required: true, message: '设备类型不能为空', trigger: 'blur' }],
deviceName: [{ required: true, message: '设备名称不能为空', trigger: 'blur' }],
},
assignOpen: false,
assignForm: {
deviceType: null,
deviceTypeName: '',
deviceName: '',
maintainDeptId: null,
maintainUserId: null,
},
assignRules: {
maintainDeptId: [{ required: true, message: '部门名称不能为空', trigger: 'change' }],
maintainUserId: [{ required: true, message: '维修负责人不能为空', trigger: 'change' }],
},
currentAssignRow: null,
}
},
created() {
......@@ -289,32 +327,29 @@ export default {
this.form.maintainDeptId = null
},
// 根据设备类型id获取部门列表
getDeviceTypeDept(val) {
// 清空部门
this.deptOptions = []
const typeDeptIds = this.deviceTypeList.find(item => item.id === val).typeDeptIds
// 如果有关联的部门ID,则进行查询
if (typeDeptIds && typeDeptIds.length > 0) {
// 创建所有 listDept 请求的 Promise 数组
const deptPromises = typeDeptIds.map(deptId =>
listDept({ deptId: deptId })
.then(response => {
// 处理并返回数据
return this.handleTree(response.data, 'deptId')
})
.catch(error => {
return [] // 返回空数组,避免 Promise.all 失败
})
)
//等待所有请求完成
Promise.all(deptPromises)
.then(deptData => {
this.deptOptions = deptData.flat()
getDeviceTypeDept(val, target = 'form') {
const targetKey = target === 'assign' ? 'assignDeptOptions' : 'deptOptions'
this[targetKey] = []
const typeItem = this.deviceTypeList.find(item => item.id === val)
if (!typeItem || !typeItem.typeDeptIds || !typeItem.typeDeptIds.length) {
return Promise.resolve()
}
const deptPromises = typeItem.typeDeptIds.map(deptId =>
listDept({ deptId: deptId })
.then(response => {
return this.handleTree(response.data, 'deptId')
})
.catch(error => {
console.error('获取部门数据失败:', error)
.catch(() => {
return []
})
}
)
return Promise.all(deptPromises)
.then(deptData => {
this[targetKey] = deptData.flat()
})
.catch(error => {
console.error('获取部门数据失败:', error)
})
},
// 取消按钮
cancel() {
......@@ -370,9 +405,9 @@ export default {
},
/** 派单 */
handleUpdate(row) {
// 判断如果没有maintainUserId,则使用当前登录用户的ID
if (!row.maintainUserId) {
row.maintainUserId = this.getUserId
this.openAssignDialog(row)
return
}
updateWorkOrder(row).then(response => {
this.$modal.msgSuccess('派单成功')
......@@ -415,6 +450,107 @@ export default {
this.userList = response.rows
})
},
openAssignDialog(row) {
this.currentAssignRow = { ...row }
const setAssignForm = deviceType => {
const deviceTypeItem = this.deviceTypeList.find(item => item.id === deviceType)
this.assignForm = {
deviceType: deviceType || null,
deviceTypeName: deviceTypeItem ? deviceTypeItem.typeName : '',
deviceName: row.deviceName || '',
maintainDeptId: row.maintainDeptId || null,
maintainUserId: null,
}
}
const ensureDeviceType = () => {
if (row.deviceType) {
setAssignForm(row.deviceType)
return Promise.resolve(row.deviceType)
}
if (!row.deviceId) {
setAssignForm(null)
return Promise.resolve(null)
}
return getDevice(row.deviceId).then(res => {
const deviceType = res.data.deviceType
setAssignForm(deviceType)
return deviceType
})
}
ensureDeviceType()
.then(deviceType => {
this.assignOpen = true
if (!deviceType) {
this.assignDeptOptions = []
this.queryParamsUser.deptId = undefined
this.userList = []
return
}
this.getDeviceTypeDept(deviceType, 'assign').then(() => {
if (this.assignForm.maintainDeptId) {
this.queryParamsUser.deptId = this.assignForm.maintainDeptId
this.getUserList()
} else if (this.assignDeptOptions.length === 1) {
const onlyDept = this.assignDeptOptions[0]
this.assignForm.maintainDeptId = onlyDept.deptId
this.queryParamsUser.deptId = onlyDept.deptId
this.getUserList()
} else {
this.queryParamsUser.deptId = undefined
this.userList = []
}
})
})
.catch(() => {
this.assignOpen = true
this.assignDeptOptions = []
this.queryParamsUser.deptId = undefined
this.userList = []
})
},
assignDeptSelect(val) {
this.assignForm.maintainDeptId = val.deptId
this.queryParamsUser.deptId = val.deptId
this.assignForm.maintainUserId = null
this.getUserList()
},
confirmAssign() {
this.$refs['assignFormRef'].validate(valid => {
if (!valid) {
return
}
const payload = {
...this.currentAssignRow,
maintainDeptId: this.assignForm.maintainDeptId,
maintainUserId: this.assignForm.maintainUserId,
}
updateWorkOrder(payload).then(() => {
this.$modal.msgSuccess('派单成功')
this.assignOpen = false
this.currentAssignRow = null
this.resetAssignForm()
this.getList()
})
})
},
cancelAssign() {
this.assignOpen = false
this.resetAssignForm()
this.currentAssignRow = null
},
resetAssignForm() {
this.assignForm = {
deviceType: null,
deviceTypeName: '',
deviceName: '',
maintainDeptId: null,
maintainUserId: null,
}
this.assignDeptOptions = []
this.queryParamsUser.deptId = undefined
},
getDeviceNo(val) {
this.form._deviceName = val
this.form.deviceName = val.deviceName
......@@ -428,6 +564,7 @@ export default {
if (this.form._deviceName) {
delete this.form._deviceName
}
this.form.inspectionUserId = this.getUserId
addWorkOrder(this.form).then(response => {
this.$modal.msgSuccess('新增成功')
this.open = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment