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 @@ ...@@ -116,7 +116,7 @@
<!-- 添加或修改巡检任务对话框 --> <!-- 添加或修改巡检任务对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <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-form-item label="巡检日期" prop="pollingData">
<el-date-picker <el-date-picker
clearable clearable
...@@ -128,6 +128,17 @@ ...@@ -128,6 +128,17 @@
> >
</el-date-picker> </el-date-picker>
</el-form-item> </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-form-item label="巡检人" prop="inspectionUserId">
<!--远程搜索--> <!--远程搜索-->
<el-select <el-select
...@@ -201,6 +212,7 @@ export default { ...@@ -201,6 +212,7 @@ export default {
// 表单校验 // 表单校验
rules: { rules: {
pollingData: [{ required: true, message: '巡检日期不能为空', trigger: 'blur' }], pollingData: [{ required: true, message: '巡检日期不能为空', trigger: 'blur' }],
pollingEndData: [{ required: true, message: '巡检截止日期不能为空', trigger: 'blur' }],
inspectionUserId: [{ required: true, message: '巡检人不能为空', trigger: 'blur' }], inspectionUserId: [{ required: true, message: '巡检人不能为空', trigger: 'blur' }],
placeId: [{ required: true, message: '巡检地点不能为空', trigger: 'blur' }], placeId: [{ required: true, message: '巡检地点不能为空', trigger: 'blur' }],
}, },
...@@ -297,6 +309,16 @@ export default { ...@@ -297,6 +309,16 @@ export default {
handleAdd() { handleAdd() {
this.reset() this.reset()
this.open = true this.open = true
// 获取巡检地点列表
placeList().then(response => {
this.placeList = response.rows
})
// 获取用户列表
getInspectionUser({
userName: null,
}).then(response => {
this.useroptions = response.rows
})
this.title = '添加巡检任务' this.title = '添加巡检任务'
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
...@@ -317,15 +339,18 @@ export default { ...@@ -317,15 +339,18 @@ export default {
submitForm() { submitForm() {
this.$refs['form'].validate(valid => { this.$refs['form'].validate(valid => {
if (valid) { if (valid) {
this.form.inspectionUserId = this.form.inspectionUserId.join(',') const formData = { ...this.form }
if (this.form.id != null) { formData.inspectionUserId = Array.isArray(formData.inspectionUserId)
updateTask(this.form).then(response => { ? formData.inspectionUserId.join(',')
: formData.inspectionUserId
if (formData.id != null) {
updateTask(formData).then(response => {
this.$modal.msgSuccess('修改成功') this.$modal.msgSuccess('修改成功')
this.open = false this.open = false
this.getList() this.getList()
}) })
} else { } else {
addTask(this.form).then(response => { addTask(formData).then(response => {
this.$modal.msgSuccess('新增成功') this.$modal.msgSuccess('新增成功')
this.open = false this.open = false
this.getList() this.getList()
......
...@@ -78,12 +78,23 @@ ...@@ -78,12 +78,23 @@
<el-form-item label="设备编号" prop="deviceNo"> <el-form-item label="设备编号" prop="deviceNo">
<el-input v-model="form.deviceNo" placeholder="自动获取设备编号" disabled></el-input> <el-input v-model="form.deviceNo" placeholder="自动获取设备编号" disabled></el-input>
</el-form-item> </el-form-item>
<el-form-item label="巡检截止日期" prop="pollingData"> <el-form-item label="巡检日期" prop="pollingData">
<el-date-picker <el-date-picker
clearable clearable
v-model="form.pollingData" v-model="form.pollingData"
type="date" type="date"
value-format="yyyy-MM-dd" 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="请选择巡检截止日期" placeholder="请选择巡检截止日期"
:picker-options="pickerOptions" :picker-options="pickerOptions"
></el-date-picker> ></el-date-picker>
...@@ -149,7 +160,6 @@ export default { ...@@ -149,7 +160,6 @@ export default {
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
pollingData: null,
inspectionUserId: null, inspectionUserId: null,
deviceId: null, deviceId: null,
taskState: null, taskState: null,
...@@ -166,6 +176,7 @@ export default { ...@@ -166,6 +176,7 @@ export default {
{ label: '待巡检', value: 0 }, { label: '待巡检', value: 0 },
{ label: '巡检中', value: 1 }, { label: '巡检中', value: 1 },
{ label: '已完成', value: 2 }, { label: '已完成', value: 2 },
{ label: '未巡检', value: 3 },
], ],
// 表单参数 // 表单参数
form: {}, form: {},
...@@ -174,6 +185,13 @@ export default { ...@@ -174,6 +185,13 @@ export default {
// 表单校验 // 表单校验
rules: { rules: {
pollingData: [ pollingData: [
{
required: true,
message: '巡检日期不能为空',
trigger: 'blur',
},
],
pollingEndData: [
{ {
required: true, required: true,
message: '巡检截止日期不能为空', message: '巡检截止日期不能为空',
...@@ -228,6 +246,18 @@ export default { ...@@ -228,6 +246,18 @@ export default {
created() { created() {
this.getList() 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: { methods: {
// 远程搜索 // 远程搜索
remoteMethod(queryString) { remoteMethod(queryString) {
...@@ -275,7 +305,7 @@ export default { ...@@ -275,7 +305,7 @@ export default {
// 处理并返回数据 // 处理并返回数据
return this.handleTree(response.data, 'deptId') return this.handleTree(response.data, 'deptId')
}) })
.catch(error => { .catch(() => {
return [] // 返回空数组,避免 Promise.all 失败 return [] // 返回空数组,避免 Promise.all 失败
}) })
) )
...@@ -324,11 +354,11 @@ export default { ...@@ -324,11 +354,11 @@ export default {
this.form = { this.form = {
id: null, id: null,
pollingData: null, pollingData: null,
pollingEndData: null,
inspectionUserId: null, inspectionUserId: null,
deviceId: null, deviceId: null,
taskState: null, taskState: null,
createBy: null, createBy: null,
createTime: null,
updateBy: null, updateBy: null,
updateTime: null, updateTime: null,
remark: null, remark: null,
...@@ -354,6 +384,8 @@ export default { ...@@ -354,6 +384,8 @@ export default {
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset() this.reset()
// this.form.pollingData = this.parseTime(new Date(), '{y}-{m}-{d}')
this.form.pollingData = ''
this.open = true this.open = true
this.title = '添加巡检任务' this.title = '添加巡检任务'
}, },
...@@ -361,15 +393,18 @@ export default { ...@@ -361,15 +393,18 @@ export default {
submitForm() { submitForm() {
this.$refs['form'].validate(valid => { this.$refs['form'].validate(valid => {
if (valid) { if (valid) {
this.form.inspectionUserId = this.form.inspectionUserId.join(',') const formData = { ...this.form }
if (this.form.id != null) { formData.inspectionUserId = Array.isArray(formData.inspectionUserId)
updateTask(this.form).then(response => { ? formData.inspectionUserId.join(',')
: formData.inspectionUserId
if (formData.id != null) {
updateTask(formData).then(() => {
this.$modal.msgSuccess('修改成功') this.$modal.msgSuccess('修改成功')
this.open = false this.open = false
this.getList() this.getList()
}) })
} else { } else {
addTask(this.form).then(response => { addTask(formData).then(() => {
this.$modal.msgSuccess('新增成功') this.$modal.msgSuccess('新增成功')
this.open = false this.open = false
this.getList() this.getList()
......
...@@ -59,22 +59,10 @@ ...@@ -59,22 +59,10 @@
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button size="mini" type="text" @click="handleUpdate(scope.row)" v-if="scope.row.orderStates == 0"
size="mini"
type="text"
@click="handleUpdate(scope.row)"
v-hasPermi="['workOrder:workOrder:edit']"
v-if="scope.row.orderStates == 0"
>派单</el-button >派单</el-button
> >
<el-button <el-button size="mini" type="text" @click="handleView(scope.row)" v-if="false">查看</el-button>
size="mini"
type="text"
@click="handleView(scope.row)"
v-hasPermi="['workOrder:workOrder:view']"
v-if="false"
>查看</el-button
>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
...@@ -160,6 +148,42 @@ ...@@ -160,6 +148,42 @@
<el-button @click="cancel"> </el-button> <el-button @click="cancel"> </el-button>
</div> </div>
</el-dialog> </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> </div>
</template> </template>
...@@ -232,6 +256,7 @@ export default { ...@@ -232,6 +256,7 @@ export default {
deviceTypeList: [], deviceTypeList: [],
deviceNameList: [], deviceNameList: [],
deptOptions: [], deptOptions: [],
assignDeptOptions: [],
userList: [], userList: [],
// 表单参数 // 表单参数
form: {}, form: {},
...@@ -247,6 +272,19 @@ export default { ...@@ -247,6 +272,19 @@ export default {
deviceType: [{ required: true, message: '设备类型不能为空', trigger: 'blur' }], deviceType: [{ required: true, message: '设备类型不能为空', trigger: 'blur' }],
deviceName: [{ 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() { created() {
...@@ -289,32 +327,29 @@ export default { ...@@ -289,32 +327,29 @@ export default {
this.form.maintainDeptId = null this.form.maintainDeptId = null
}, },
// 根据设备类型id获取部门列表 // 根据设备类型id获取部门列表
getDeviceTypeDept(val) { getDeviceTypeDept(val, target = 'form') {
// 清空部门 const targetKey = target === 'assign' ? 'assignDeptOptions' : 'deptOptions'
this.deptOptions = [] this[targetKey] = []
const typeDeptIds = this.deviceTypeList.find(item => item.id === val).typeDeptIds const typeItem = this.deviceTypeList.find(item => item.id === val)
// 如果有关联的部门ID,则进行查询 if (!typeItem || !typeItem.typeDeptIds || !typeItem.typeDeptIds.length) {
if (typeDeptIds && typeDeptIds.length > 0) { return Promise.resolve()
// 创建所有 listDept 请求的 Promise 数组 }
const deptPromises = typeDeptIds.map(deptId => const deptPromises = typeItem.typeDeptIds.map(deptId =>
listDept({ deptId: deptId }) listDept({ deptId: deptId })
.then(response => { .then(response => {
// 处理并返回数据
return this.handleTree(response.data, 'deptId') return this.handleTree(response.data, 'deptId')
}) })
.catch(error => { .catch(() => {
return [] // 返回空数组,避免 Promise.all 失败 return []
}) })
) )
//等待所有请求完成 return Promise.all(deptPromises)
Promise.all(deptPromises)
.then(deptData => { .then(deptData => {
this.deptOptions = deptData.flat() this[targetKey] = deptData.flat()
}) })
.catch(error => { .catch(error => {
console.error('获取部门数据失败:', error) console.error('获取部门数据失败:', error)
}) })
}
}, },
// 取消按钮 // 取消按钮
cancel() { cancel() {
...@@ -370,9 +405,9 @@ export default { ...@@ -370,9 +405,9 @@ export default {
}, },
/** 派单 */ /** 派单 */
handleUpdate(row) { handleUpdate(row) {
// 判断如果没有maintainUserId,则使用当前登录用户的ID
if (!row.maintainUserId) { if (!row.maintainUserId) {
row.maintainUserId = this.getUserId this.openAssignDialog(row)
return
} }
updateWorkOrder(row).then(response => { updateWorkOrder(row).then(response => {
this.$modal.msgSuccess('派单成功') this.$modal.msgSuccess('派单成功')
...@@ -415,6 +450,107 @@ export default { ...@@ -415,6 +450,107 @@ export default {
this.userList = response.rows 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) { getDeviceNo(val) {
this.form._deviceName = val this.form._deviceName = val
this.form.deviceName = val.deviceName this.form.deviceName = val.deviceName
...@@ -428,6 +564,7 @@ export default { ...@@ -428,6 +564,7 @@ export default {
if (this.form._deviceName) { if (this.form._deviceName) {
delete this.form._deviceName delete this.form._deviceName
} }
this.form.inspectionUserId = this.getUserId
addWorkOrder(this.form).then(response => { addWorkOrder(this.form).then(response => {
this.$modal.msgSuccess('新增成功') this.$modal.msgSuccess('新增成功')
this.open = false 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