Commit f76e4a21 authored by sxl's avatar sxl 💬

fix:巡检多选bug修正

parent 8212b00e
...@@ -2,7 +2,14 @@ ...@@ -2,7 +2,14 @@
<div class="app-container"> <div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="巡检日期" prop="pollingData"> <el-form-item label="巡检日期" prop="pollingData">
<el-date-picker clearable v-model="queryParams.pollingData" type="date" value-format="yyyy-MM-dd" placeholder="请选择巡检日期"> </el-date-picker> <el-date-picker
clearable
v-model="queryParams.pollingData"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择巡检日期"
>
</el-date-picker>
</el-form-item> </el-form-item>
<el-form-item label="巡检人" prop="inspectionUserId"> <el-form-item label="巡检人" prop="inspectionUserId">
<el-select <el-select
...@@ -14,7 +21,13 @@ ...@@ -14,7 +21,13 @@
:remote-method="remoteMethod" :remote-method="remoteMethod"
:loading="loading" :loading="loading"
> >
<el-option v-for="item in useroptions" :key="item.userId" :label="item.userName + '/' + item.nickName" :value="item.userId"> </el-option> <el-option
v-for="item in useroptions"
:key="item.userId"
:label="item.userName + '/' + item.nickName"
:value="item.userId"
>
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="巡检地点" prop="placeId"> <el-form-item label="巡检地点" prop="placeId">
...@@ -30,10 +43,25 @@ ...@@ -30,10 +43,25 @@
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['inspection:task:add']">新增</el-button> <el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['inspection:task:add']"
>新增</el-button
>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['inspection:task:edit']" <el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['inspection:task:edit']"
>修改</el-button >修改</el-button
> >
</el-col> </el-col>
...@@ -58,13 +86,33 @@ ...@@ -58,13 +86,33 @@
<el-table-column label="备注" align="center" prop="remark" /> <el-table-column label="备注" align="center" prop="remark" />
<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 size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['inspection:task:edit']">修改</el-button> <el-button
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['inspection:task:remove']">删除</el-button> size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['inspection:task:edit']"
>修改</el-button
>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['inspection:task:remove']"
>删除</el-button
>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" /> <pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改巡检任务对话框 --> <!-- 添加或修改巡检任务对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
...@@ -86,12 +134,14 @@ ...@@ -86,12 +134,14 @@
v-model="form.inspectionUserId" v-model="form.inspectionUserId"
filterable filterable
remote remote
multiple
reserve-keyword reserve-keyword
placeholder="请输入关键词" placeholder="请输入关键词"
:remote-method="remoteMethod" :remote-method="remoteMethod"
:loading="loading" :loading="loading"
> >
<el-option v-for="item in useroptions" :key="item.userId" :label="item.nickName + '/' + item.nickName" :value="item.userId"> </el-option> <el-option v-for="item in useroptions" :key="item.userId" :label="item.nickName" :value="item.userId">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="巡检地点" prop="placeId"> <el-form-item label="巡检地点" prop="placeId">
...@@ -113,8 +163,8 @@ ...@@ -113,8 +163,8 @@
</template> </template>
<script> <script>
import { listTask, getTask, delTask, addTask, updateTask, getInspectionUser } from '@/api/patrol/placeInspection'; import { listTask, getTask, delTask, addTask, updateTask, getInspectionUser } from '@/api/patrol/placeInspection'
import { listLog as placeList } from '@/api/patrol/patrolLocation'; import { listLog as placeList } from '@/api/patrol/patrolLocation'
export default { export default {
name: 'Task', name: 'Task',
data() { data() {
...@@ -163,25 +213,25 @@ export default { ...@@ -163,25 +213,25 @@ export default {
pickerOptions: { pickerOptions: {
disabledDate(time) { disabledDate(time) {
// 禁用今天之前的日期(含今天零点) // 禁用今天之前的日期(含今天零点)
return time.getTime() < new Date(new Date().toLocaleDateString()).getTime(); return time.getTime() < new Date(new Date().toLocaleDateString()).getTime()
}, },
}, },
}; }
}, },
created() { created() {
this.getList(); this.getList()
}, },
methods: { methods: {
// 远程搜索 // 远程搜索
remoteMethod(queryString) { remoteMethod(queryString) {
this.loading = true; this.loading = true
getInspectionUser({ getInspectionUser({
userName: queryString, userName: queryString,
}).then(response => { }).then(response => {
this.useroptions = response.rows; this.useroptions = response.rows
this.loading = false; this.loading = false
}); })
}, },
//根据设备类型查询设备列表 //根据设备类型查询设备列表
...@@ -189,31 +239,31 @@ export default { ...@@ -189,31 +239,31 @@ export default {
listDevice({ listDevice({
deviceType: this.form.deviceType, deviceType: this.form.deviceType,
}).then(response => { }).then(response => {
this.deviceList = response.rows; this.deviceList = response.rows
}); })
}, },
/** 查询巡检任务列表 */ /** 查询巡检任务列表 */
getList() { getList() {
this.loading = true; this.loading = true
listTask(this.queryParams).then(response => { listTask(this.queryParams).then(response => {
this.taskList = response.rows; this.taskList = response.rows
this.total = response.total; this.total = response.total
this.loading = false; this.loading = false
}); })
// 巡检地点列表 // 巡检地点列表
placeList().then(response => { placeList().then(response => {
this.placeList = response.rows; this.placeList = response.rows
}); })
getInspectionUser({ getInspectionUser({
userName: null, userName: null,
}).then(response => { }).then(response => {
this.useroptions = response.rows; this.useroptions = response.rows
}); })
}, },
// 取消按钮 // 取消按钮
cancel() { cancel() {
this.open = false; this.open = false
this.reset(); this.reset()
}, },
// 表单重置 // 表单重置
reset() { reset() {
...@@ -224,78 +274,80 @@ export default { ...@@ -224,78 +274,80 @@ export default {
placeId: null, placeId: null,
taskState: null, taskState: null,
remark: null, remark: null,
}; }
this.resetForm('form'); this.resetForm('form')
}, },
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1
this.getList(); this.getList()
}, },
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { resetQuery() {
this.resetForm('queryForm'); this.resetForm('queryForm')
this.handleQuery(); this.handleQuery()
}, },
// 多选框选中数据 // 多选框选中数据
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.ids = selection.map(item => item.id); this.ids = selection.map(item => item.id)
this.single = selection.length !== 1; this.single = selection.length !== 1
this.multiple = !selection.length; this.multiple = !selection.length
}, },
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.reset()
this.open = true; this.open = true
this.title = '添加巡检任务'; this.title = '添加巡检任务'
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
handleUpdate(row) { handleUpdate(row) {
this.reset(); this.reset()
const id = row.id || this.ids; const id = row.id || this.ids
getTask(id).then(response => { getTask(id).then(response => {
this.form = { this.form = {
...response.data, ...response.data,
deviceType: Number(response.data.deviceType), deviceType: Number(response.data.deviceType),
}; inspectionUserId: response.data.inspectionUserId.split(',').map(item => Number(item)),
this.open = true; }
this.title = '修改巡检任务'; this.open = true
}); this.title = '修改巡检任务'
})
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
this.$refs['form'].validate(valid => { this.$refs['form'].validate(valid => {
if (valid) { if (valid) {
this.form.inspectionUserId = this.form.inspectionUserId.join(',')
if (this.form.id != null) { if (this.form.id != null) {
updateTask(this.form).then(response => { updateTask(this.form).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(this.form).then(response => {
this.$modal.msgSuccess('新增成功'); this.$modal.msgSuccess('新增成功')
this.open = false; this.open = false
this.getList(); this.getList()
}); })
} }
} }
}); })
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
const ids = row.id || this.ids; const ids = row.id || this.ids
this.$modal this.$modal
.confirm('是否确认删除巡检任务编号为"' + ids + '"的数据项?') .confirm('是否确认删除巡检任务编号为"' + ids + '"的数据项?')
.then(function () { .then(function () {
return delTask(ids); return delTask(ids)
}) })
.then(() => { .then(() => {
this.getList(); this.getList()
this.$modal.msgSuccess('删除成功'); this.$modal.msgSuccess('删除成功')
}) })
.catch(() => {}); .catch(() => {})
}, },
}, },
}; }
</script> </script>
...@@ -7,7 +7,12 @@ ...@@ -7,7 +7,12 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="设备名称" prop="deviceName"> <el-form-item label="设备名称" prop="deviceName">
<el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable @keyup.enter.native="handleQuery" /> <el-input
v-model="queryParams.deviceName"
placeholder="请输入设备名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
...@@ -37,12 +42,25 @@ ...@@ -37,12 +42,25 @@
</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 size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['inspection:task:remove']">删除</el-button> <el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['inspection:task:remove']"
>删除</el-button
>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" /> <pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改巡检任务对话框 --> <!-- 添加或修改巡检任务对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
...@@ -71,11 +89,18 @@ ...@@ -71,11 +89,18 @@
></el-date-picker> ></el-date-picker>
</el-form-item> </el-form-item>
<el-form-item label="部门名称" prop="maintainDeptId"> <el-form-item label="部门名称" prop="maintainDeptId">
<treeselect v-model="form.maintainDeptId" :options="deptOptions" :normalizer="normalizer" placeholder="请选择部门名称" @select="deptSelect" /> <treeselect
v-model="form.maintainDeptId"
:options="deptOptions"
:normalizer="normalizer"
placeholder="请选择部门名称"
@select="deptSelect"
/>
</el-form-item> </el-form-item>
<el-form-item label="巡检人" prop="inspectionUserId"> <el-form-item label="巡检人" prop="inspectionUserId">
<el-select v-model="form.inspectionUserId" placeholder="请选择巡检人"> <el-select v-model="form.inspectionUserId" multiple placeholder="请选择巡检人">
<el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"> </el-option> <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-form> </el-form>
...@@ -88,13 +113,13 @@ ...@@ -88,13 +113,13 @@
</template> </template>
<script> <script>
import { listTask, delTask, addTask, updateTask, getInspectionUser } from '@/api/patrol/patrolProject'; import { listTask, delTask, addTask, updateTask, getInspectionUser } from '@/api/patrol/patrolProject'
import { listDevice as deviceTypeList } from '@/api/device/deviceType'; import { listDevice as deviceTypeList } from '@/api/device/deviceType'
import { listDevice } from '@/api/device/device'; import { listDevice } from '@/api/device/device'
import { listDept } from '@/api/system/dept'; import { listDept } from '@/api/system/dept'
import { listUser } from '@/api/system/user'; import { listUser } from '@/api/system/user'
import Treeselect from '@riophae/vue-treeselect'; import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'; import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default { export default {
components: { components: {
Treeselect, Treeselect,
...@@ -195,52 +220,52 @@ export default { ...@@ -195,52 +220,52 @@ export default {
pickerOptions: { pickerOptions: {
disabledDate(time) { disabledDate(time) {
// 禁用今天之前的日期(含今天零点) // 禁用今天之前的日期(含今天零点)
return time.getTime() < new Date(new Date().toLocaleDateString()).getTime(); return time.getTime() < new Date(new Date().toLocaleDateString()).getTime()
}, },
}, },
}; }
}, },
created() { created() {
this.getList(); this.getList()
}, },
methods: { methods: {
// 远程搜索 // 远程搜索
remoteMethod(queryString) { remoteMethod(queryString) {
this.loading = true; this.loading = true
getInspectionUser({ getInspectionUser({
userName: queryString, userName: queryString,
}).then(response => { }).then(response => {
this.useroptions = response.rows; this.useroptions = response.rows
this.loading = false; this.loading = false
}); })
}, },
/** 转换部门数据结构 */ /** 转换部门数据结构 */
normalizer(node) { normalizer(node) {
if (node.children && !node.children.length) { if (node.children && !node.children.length) {
delete node.children; delete node.children
} }
return { return {
id: node.deptId, id: node.deptId,
label: node.deptName, label: node.deptName,
children: node.children, children: node.children,
}; }
}, },
deptSelect(val) { deptSelect(val) {
this.queryParamsUser.deptId = val.deptId; this.queryParamsUser.deptId = val.deptId
this.form.inspectionUserId = null; this.form.inspectionUserId = null
this.getUserList(); this.getUserList()
}, },
/** 查询用户列表 */ /** 查询用户列表 */
getUserList() { getUserList() {
listUser(this.addDateRange(this.queryParamsUser)).then(response => { listUser(this.addDateRange(this.queryParamsUser)).then(response => {
this.userList = response.rows; this.userList = response.rows
}); })
}, },
//根据设备类型查询设备列表 //根据设备类型查询设备列表
getDeviceList(val) { getDeviceList(val) {
// 清空部门 // 清空部门
this.deptOptions = []; this.deptOptions = []
const typeDeptIds = this.deviceTypeList.find(item => item.id === val).typeDeptIds; const typeDeptIds = this.deviceTypeList.find(item => item.id === val).typeDeptIds
// 如果有关联的部门ID,则进行查询 // 如果有关联的部门ID,则进行查询
if (typeDeptIds && typeDeptIds.length > 0) { if (typeDeptIds && typeDeptIds.length > 0) {
// 创建所有 listDept 请求的 Promise 数组 // 创建所有 listDept 请求的 Promise 数组
...@@ -248,51 +273,51 @@ export default { ...@@ -248,51 +273,51 @@ export default {
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(error => {
return []; // 返回空数组,避免 Promise.all 失败 return [] // 返回空数组,避免 Promise.all 失败
}) })
); )
//等待所有请求完成 //等待所有请求完成
Promise.all(deptPromises) Promise.all(deptPromises)
.then(deptData => { .then(deptData => {
this.deptOptions = deptData.flat(); this.deptOptions = deptData.flat()
}) })
.catch(error => { .catch(error => {
console.error('获取部门数据失败:', error); console.error('获取部门数据失败:', error)
}); })
} }
this.form.deviceId = null; this.form.deviceId = null
this.form.inspectionUserId = null; this.form.inspectionUserId = null
listDevice({ listDevice({
deviceType: this.form.deviceType, deviceType: this.form.deviceType,
}).then(response => { }).then(response => {
this.deviceList = response.rows; this.deviceList = response.rows
}); })
}, },
/** 查询巡检任务列表 */ /** 查询巡检任务列表 */
getList() { getList() {
this.loading = true; this.loading = true
listTask(this.queryParams).then(response => { listTask(this.queryParams).then(response => {
this.taskList = response.rows; this.taskList = response.rows
this.total = response.total; this.total = response.total
this.loading = false; this.loading = false
}); })
// 设备类型列表 // 设备类型列表
deviceTypeList().then(response => { deviceTypeList().then(response => {
this.deviceTypeList = response.rows; this.deviceTypeList = response.rows
}); })
getInspectionUser({ getInspectionUser({
userName: null, userName: null,
}).then(response => { }).then(response => {
this.useroptions = response.rows; this.useroptions = response.rows
}); })
}, },
// 取消按钮 // 取消按钮
cancel() { cancel() {
this.open = false; this.open = false
this.reset(); this.reset()
}, },
// 表单重置 // 表单重置
reset() { reset() {
...@@ -307,64 +332,65 @@ export default { ...@@ -307,64 +332,65 @@ export default {
updateBy: null, updateBy: null,
updateTime: null, updateTime: null,
remark: null, remark: null,
}; }
this.resetForm('form'); this.resetForm('form')
}, },
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1
this.getList(); this.getList()
}, },
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { resetQuery() {
this.resetForm('queryForm'); this.resetForm('queryForm')
this.handleQuery(); this.handleQuery()
}, },
// 多选框选中数据 // 多选框选中数据
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.ids = selection.map(item => item.id); this.ids = selection.map(item => item.id)
this.single = selection.length !== 1; this.single = selection.length !== 1
this.multiple = !selection.length; this.multiple = !selection.length
}, },
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.reset()
this.open = true; this.open = true
this.title = '添加巡检任务'; this.title = '添加巡检任务'
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
this.$refs['form'].validate(valid => { this.$refs['form'].validate(valid => {
if (valid) { if (valid) {
this.form.inspectionUserId = this.form.inspectionUserId.join(',')
if (this.form.id != null) { if (this.form.id != null) {
updateTask(this.form).then(response => { updateTask(this.form).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(this.form).then(response => {
this.$modal.msgSuccess('新增成功'); this.$modal.msgSuccess('新增成功')
this.open = false; this.open = false
this.getList(); this.getList()
}); })
} }
} }
}); })
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
const ids = row.id || this.ids; const ids = row.id || this.ids
this.$modal this.$modal
.confirm('是否确认删除巡检任务编号为"' + ids + '"的数据项?') .confirm('是否确认删除巡检任务编号为"' + ids + '"的数据项?')
.then(function () { .then(function () {
return delTask(ids); return delTask(ids)
}) })
.then(() => { .then(() => {
this.getList(); this.getList()
this.$modal.msgSuccess('删除成功'); this.$modal.msgSuccess('删除成功')
}) })
.catch(() => {}); .catch(() => {})
}, },
/** 导出按钮操作 */ /** 导出按钮操作 */
handleExport() { handleExport() {
...@@ -374,8 +400,8 @@ export default { ...@@ -374,8 +400,8 @@ export default {
...this.queryParams, ...this.queryParams,
}, },
`task_${new Date().getTime()}.xlsx` `task_${new Date().getTime()}.xlsx`
); )
}, },
}, },
}; }
</script> </script>
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
<el-form-item> <el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button> <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button> <el-button icon="Refresh" @click="resetQuery">重置</el-button>
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['device:device:add']">新增</el-button> <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['device:device:add']"
>新增</el-button
>
</el-form-item> </el-form-item>
</el-form> </el-form>
...@@ -57,27 +59,47 @@ ...@@ -57,27 +59,47 @@
</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 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-hasPermi="['workOrder:workOrder:edit']"
v-if="scope.row.orderStates == 0"
>派单</el-button >派单</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-hasPermi="['workOrder:workOrder:view']"
v-if="false"
>查看</el-button
>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="handlePagination" /> <pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="handlePagination"
/>
<!-- 添加工单派遣对话框 --> <!-- 添加工单派遣对话框 -->
<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="120px"> <el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-form-item label="设备类型" prop="deviceType"> <el-form-item label="设备类型" prop="deviceType">
<el-select v-model="form.deviceType" placeholder="请选择设备类型" @change="getDeviceName"> <el-select v-model="form.deviceType" placeholder="请选择设备类型" @change="getDeviceName">
<el-option v-for="item in deviceTypeList" :key="item.id" :label="item.typeName" :value="item.id"> </el-option> <el-option v-for="item in deviceTypeList" :key="item.id" :label="item.typeName" :value="item.id">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="设备名称" prop="deviceName"> <el-form-item label="设备名称" prop="deviceName">
<el-select v-model="form._deviceName" placeholder="请选择设备名称" value-key="id" @change="getDeviceNo"> <el-select v-model="form._deviceName" placeholder="请选择设备名称" value-key="id" @change="getDeviceNo">
<el-option v-for="item in deviceNameList" :key="item.id" :label="item.deviceName" :value="item"> </el-option> <el-option v-for="item in deviceNameList" :key="item.id" :label="item.deviceName" :value="item">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="设备编码" prop="deviceNo"> <el-form-item label="设备编码" prop="deviceNo">
...@@ -88,22 +110,48 @@ ...@@ -88,22 +110,48 @@
<el-input v-model="form.deviceErrorDetail" placeholder="请输入设备故障描述" /> <el-input v-model="form.deviceErrorDetail" placeholder="请输入设备故障描述" />
</el-form-item> </el-form-item>
<el-form-item label="设备故障图片" prop="deviceErrorPhotos"> <el-form-item label="设备故障图片" prop="deviceErrorPhotos">
<FileUploadInspec :value="form.deviceErrorPhotos" @input="fileSuccess" @handleRemove="handleRemove" :fileType="['jpg', 'jpeg', 'png']" /> <FileUploadInspec
:value="form.deviceErrorPhotos"
@input="fileSuccess"
@handleRemove="handleRemove"
:fileType="['jpg', 'jpeg', 'png']"
/>
</el-form-item> </el-form-item>
<el-form-item label="故障日期" prop="erroDate"> <el-form-item label="故障日期" prop="erroDate">
<el-date-picker clearable v-model="form.erroDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择故障日期"> </el-date-picker> <el-date-picker
clearable
v-model="form.erroDate"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择故障日期"
>
</el-date-picker>
</el-form-item> </el-form-item>
<el-form-item label="维修截止日期" prop="maintainEndDate"> <el-form-item label="维修截止日期" prop="maintainEndDate">
<el-date-picker clearable v-model="form.maintainEndDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择维修截止日期"> </el-date-picker> <el-date-picker
clearable
v-model="form.maintainEndDate"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择维修截止日期"
>
</el-date-picker>
</el-form-item> </el-form-item>
<el-form-item label="部门名称" prop="maintainDeptId"> <el-form-item label="部门名称" prop="maintainDeptId">
<treeselect v-model="form.maintainDeptId" :options="deptOptions" :normalizer="normalizer" placeholder="请选择部门名称" @select="deptSelect" /> <treeselect
v-model="form.maintainDeptId"
:options="deptOptions"
:normalizer="normalizer"
placeholder="请选择部门名称"
@select="deptSelect"
/>
</el-form-item> </el-form-item>
<el-form-item label="维修负责人" prop="maintainUserId"> <el-form-item label="维修负责人" prop="maintainUserId">
<el-select v-model="form.maintainUserId" placeholder="请选择维修负责人"> <el-select v-model="form.maintainUserId" placeholder="请选择维修负责人">
<el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"> </el-option> <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-form> </el-form>
...@@ -112,34 +160,18 @@ ...@@ -112,34 +160,18 @@
<el-button @click="cancel"> </el-button> <el-button @click="cancel"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<el-dialog :title="title" :visible.sync="openpd" width="500px" append-to-body>
<el-form ref="formpd" :model="formpd" :rules="rulespd" label-width="120px">
<el-form-item label="部门名称" prop="maintainDeptId">
<treeselect v-model="formpd.maintainDeptId" :options="deptOptions" :normalizer="normalizer" placeholder="请选择部门名称" @select="deptSelect" />
</el-form-item>
<el-form-item label="维修负责人" prop="maintainUserId">
<el-select v-model="formpd.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="submitFormOrder"> </el-button>
<el-button @click="openpd = false"> </el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { listWorkOrder, getWorkOrder, addWorkOrder, updateWorkOrder } from '@/api/repair/repairProject'; import { listWorkOrder, getWorkOrder, addWorkOrder, updateWorkOrder } from '@/api/repair/repairProject'
import { listDevice as listDeviceType } from '@/api/device/deviceType'; import { listDevice as listDeviceType } from '@/api/device/deviceType'
import { listDevice as listDeviceName, getDevice } from '@/api/device/device'; import { listDevice as listDeviceName, getDevice } from '@/api/device/device'
import { listUser } from '@/api/system/user'; import { listUser } from '@/api/system/user'
import { listDept } from '@/api/system/dept'; import { listDept } from '@/api/system/dept'
import Treeselect from '@riophae/vue-treeselect'; import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'; import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import FileUploadInspec from '@/components/FileUploadInspec'; import FileUploadInspec from '@/components/FileUploadInspec'
export default { export default {
name: 'WorkOrder', name: 'WorkOrder',
components: { Treeselect, FileUploadInspec }, components: { Treeselect, FileUploadInspec },
...@@ -163,7 +195,7 @@ export default { ...@@ -163,7 +195,7 @@ export default {
title: '', title: '',
// 是否显示弹出层 // 是否显示弹出层
open: false, open: false,
openpd: false,
// 维修状态 // 维修状态
orderStatesList: [ orderStatesList: [
{ label: '派单中', value: 0 }, { label: '派单中', value: 0 },
...@@ -203,7 +235,6 @@ export default { ...@@ -203,7 +235,6 @@ export default {
userList: [], userList: [],
// 表单参数 // 表单参数
form: {}, form: {},
formpd: {},
// 表单校验 // 表单校验
rules: { rules: {
repairsId: [{ required: true, message: '维修单编号不能为空', trigger: 'blur' }], repairsId: [{ required: true, message: '维修单编号不能为空', trigger: 'blur' }],
...@@ -216,50 +247,52 @@ export default { ...@@ -216,50 +247,52 @@ 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' }],
}, },
rulespd: { }
maintainDeptId: [{ required: true, message: '部门名称不能为空', trigger: 'blur' }],
maintainUserId: [{ required: true, message: '维修负责人不能为空', trigger: 'blur' }],
},
};
}, },
created() { created() {
this.getList(); this.getList()
listDeviceType().then(response => { listDeviceType().then(response => {
this.deviceTypeList = response.rows; this.deviceTypeList = response.rows
}); })
},
computed: {
// 获取当前登录用户ID
getUserId() {
return this.$store.state.user.id
},
}, },
methods: { methods: {
/** 查询工单派遣列表 */ /** 查询工单派遣列表 */
getList() { getList() {
this.loading = true; this.loading = true
listWorkOrder(this.queryParams).then(response => { listWorkOrder(this.queryParams).then(response => {
this.workOrderList = response.rows; this.workOrderList = response.rows
this.total = response.total; this.total = response.total
this.loading = false; this.loading = false
}); })
}, },
/** 处理分页事件 */ /** 处理分页事件 */
handlePagination(data) { handlePagination(data) {
this.queryParams.pageNum = data.page; this.queryParams.pageNum = data.page
this.queryParams.pageSize = data.limit; this.queryParams.pageSize = data.limit
this.getList(); this.getList()
}, },
// 设备名称 // 设备名称
getDeviceName(val) { getDeviceName(val) {
this.form._deviceName = null; this.form._deviceName = null
this.getDeviceTypeDept(val); this.getDeviceTypeDept(val)
listDeviceName({ deviceType: val }).then(response => { listDeviceName({ deviceType: val }).then(response => {
this.deviceNameList = response.rows; this.deviceNameList = response.rows
}); })
this.form.deviceName = null; this.form.deviceName = null
this.form.deviceNo = null; this.form.deviceNo = null
this.form.maintainDeptId = null; this.form.maintainDeptId = null
}, },
// 根据设备类型id获取部门列表 // 根据设备类型id获取部门列表
getDeviceTypeDept(val) { getDeviceTypeDept(val) {
// 清空部门 // 清空部门
this.deptOptions = []; this.deptOptions = []
const typeDeptIds = this.deviceTypeList.find(item => item.id === val).typeDeptIds; const typeDeptIds = this.deviceTypeList.find(item => item.id === val).typeDeptIds
// 如果有关联的部门ID,则进行查询 // 如果有关联的部门ID,则进行查询
if (typeDeptIds && typeDeptIds.length > 0) { if (typeDeptIds && typeDeptIds.length > 0) {
// 创建所有 listDept 请求的 Promise 数组 // 创建所有 listDept 请求的 Promise 数组
...@@ -267,26 +300,26 @@ export default { ...@@ -267,26 +300,26 @@ export default {
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(error => {
return []; // 返回空数组,避免 Promise.all 失败 return [] // 返回空数组,避免 Promise.all 失败
}) })
); )
//等待所有请求完成 //等待所有请求完成
Promise.all(deptPromises) Promise.all(deptPromises)
.then(deptData => { .then(deptData => {
this.deptOptions = deptData.flat(); this.deptOptions = deptData.flat()
}) })
.catch(error => { .catch(error => {
console.error('获取部门数据失败:', error); console.error('获取部门数据失败:', error)
}); })
} }
}, },
// 取消按钮 // 取消按钮
cancel() { cancel() {
this.open = false; this.open = false
this.reset(); this.reset()
}, },
// 表单重置 // 表单重置
reset() { reset() {
...@@ -310,137 +343,108 @@ export default { ...@@ -310,137 +343,108 @@ export default {
updateBy: null, updateBy: null,
updateTime: null, updateTime: null,
remark: null, remark: null,
}; }
this.resetForm('form'); this.resetForm('form')
}, },
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1
this.getList(); this.getList()
}, },
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { resetQuery() {
this.resetForm('queryForm'); this.resetForm('queryForm')
this.handleQuery(); this.handleQuery()
}, },
// 多选框选中数据 // 多选框选中数据
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.ids = selection.map(item => item.id); this.ids = selection.map(item => item.id)
this.single = selection.length !== 1; this.single = selection.length !== 1
this.multiple = !selection.length; this.multiple = !selection.length
}, },
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.reset()
this.open = true; this.open = true
this.title = '添加工单派遣'; this.title = '添加工单派遣'
}, },
/** 派单 */ /** 派单 */
handleUpdate(row) { handleUpdate(row) {
const id = row.id || this.ids; // 判断如果没有maintainUserId,则使用当前登录用户的ID
this.formpd = { if (!row.maintainUserId) {
maintainDeptId: null, row.maintainUserId = this.getUserId
maintainUserId: null,
};
// 维修单详情
getWorkOrder(id).then(response => {
this.form = response.data;
if (!this.form.deviceId) {
this.$modal.msgWarning('该工单没有设备信息,请先确认设备信息');
return;
}
//通过设备详情,获取设备类型id
getDevice(this.form.deviceId).then(res => {
if (res.code === 200) {
if (res.data.deviceType) {
this.getDeviceTypeDept(res.data.deviceType);
this.openpd = true;
this.title = '派遣';
} else {
this.$modal.msgWarning('该设备没有设备类型,请先确认设备信息');
return;
}
} }
}); updateWorkOrder(row).then(response => {
}); this.$modal.msgSuccess('派单成功')
this.getList()
})
}, },
// 查看 // 查看
handleView(row) { handleView(row) {
const id = row.id || this.ids; const id = row.id || this.ids
// listDept().then((response) => { // listDept().then((response) => {
// this.deptOptions = this.handleTree(response.data, 'deptId') // this.deptOptions = this.handleTree(response.data, 'deptId')
// }) // })
getWorkOrder(id).then(response => { getWorkOrder(id).then(response => {
this.form = response.data; this.form = response.data
this.open = true; this.open = true
this.title = '查看'; this.title = '查看'
console.log(this.form); console.log(this.form)
}); })
}, },
/** 转换部门数据结构 */ /** 转换部门数据结构 */
normalizer(node) { normalizer(node) {
if (node.children && !node.children.length) { if (node.children && !node.children.length) {
delete node.children; delete node.children
} }
return { return {
id: node.deptId, id: node.deptId,
label: node.deptName, label: node.deptName,
children: node.children, children: node.children,
}; }
}, },
deptSelect(val) { deptSelect(val) {
this.queryParamsUser.deptId = val.deptId; this.queryParamsUser.deptId = val.deptId
this.form.maintainUserId = null; this.form.maintainUserId = null
this.getUserList(); this.getUserList()
}, },
/** 查询用户列表 */ /** 查询用户列表 */
getUserList() { getUserList() {
listUser(this.addDateRange(this.queryParamsUser)).then(response => { listUser(this.addDateRange(this.queryParamsUser)).then(response => {
this.userList = response.rows; this.userList = response.rows
}); })
}, },
getDeviceNo(val) { getDeviceNo(val) {
this.form._deviceName = val; this.form._deviceName = val
this.form.deviceName = val.deviceName; this.form.deviceName = val.deviceName
this.form.deviceNo = val.deviceNo; this.form.deviceNo = val.deviceNo
this.form.deviceId = val.id; this.form.deviceId = val.id
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
this.$refs['form'].validate(valid => { this.$refs['form'].validate(valid => {
if (valid) { if (valid) {
if (this.form._deviceName) { if (this.form._deviceName) {
delete this.form._deviceName; delete this.form._deviceName
} }
addWorkOrder(this.form).then(response => { addWorkOrder(this.form).then(response => {
this.$modal.msgSuccess('新增成功'); this.$modal.msgSuccess('新增成功')
this.open = false; this.open = false
this.getList(); this.getList()
}); })
}
});
},
// 派单提交
submitFormOrder() {
this.$refs['formpd'].validate(valid => {
if (valid) {
updateWorkOrder({ ...this.form, ...this.formpd }).then(response => {
this.$modal.msgSuccess('派单成功');
this.openpd = false;
this.getList();
});
} }
}); })
}, },
// 文件上传回调 // 文件上传回调
fileSuccess(val) { fileSuccess(val) {
this.form.deviceErrorPhotos = val; this.form.deviceErrorPhotos = val
}, },
// 文件删除 // 文件删除
handleRemove(url) { handleRemove(url) {
this.form.deviceErrorPhotos = url; this.form.deviceErrorPhotos = url
}, },
}, },
}; }
</script> </script>
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