Commit f76e4a21 authored by sxl's avatar sxl 💬

fix:巡检多选bug修正

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