You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crmeb/admin/src/views/pm/facility/maintenance/plan/index.vue

518 lines
19 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<div class="divBox">
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item label="项目名称">
<el-select v-model="dataForm.projectId" placeholder="请选择项目名称" clearable style="width: 150px;">
<el-option
v-for="project in projectList"
:key="project.id"
:label="project.projectName"
:value="project.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="楼栋名称">
<el-select v-model="dataForm.buildingId" placeholder="请选择楼栋名称" clearable style="width: 150px;">
<el-option
v-for="building in buildingList"
:key="building.id"
:label="building.buildingNo"
:value="building.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="设施名称">
<el-select v-model="dataForm.facilityId" placeholder="请选择设施名称" clearable style="width: 150px;">
<el-option
v-for="facility in facilityList"
:key="facility.id"
:label="facility.facilityName"
:value="facility.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="维保类型">
<el-select v-model="dataForm.maintenanceType" placeholder="请选择维保类型" clearable style="width: 150px;">
<el-option
v-for="(label, value) in dict.type.maintenance_type"
:key="value"
:label="label"
:value="value">
</el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()"></el-button>
<el-button @click="resetForm()"></el-button>
<el-button v-hasPermi="['autogencode:pmfacilitymaintenanceplan:save']" type="primary" @click="addOrUpdateHandle()">新增维护</el-button>
<el-button v-hasPermi="['autogencode:pmfacilitymaintenanceplan:delete']" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
</el-form-item>
</el-form>
<el-table
:data="dataList"
border
v-loading="dataListLoading"
@selection-change="selectionChangeHandle"
:row-key="row => row.id"
style="width: 100%;">
<el-table-column
type="selection"
header-align="center"
align="center"
width="50">
</el-table-column>
<el-table-column
type="expand"
header-align="center"
align="center">
<template slot-scope="scope">
<div class="maintenance-records-container">
<el-form :inline="true" :model="getMaintenanceRecordSearchForm(scope.row.id)" @keyup.enter.native="getMaintenanceRecords(scope.row.id)" style="margin-bottom: 10px;">
<el-form-item label="维保日期">
<el-date-picker
v-model="getMaintenanceRecordSearchForm(scope.row.id).execTimeRange"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
size="small">
</el-date-picker>
</el-form-item>
<el-form-item label="执行人">
<el-input v-model="getMaintenanceRecordSearchForm(scope.row.id).executorName" placeholder="请输入执行人" clearable size="small"></el-input>
</el-form-item>
<el-form-item label="执行部门">
<el-input v-model="getMaintenanceRecordSearchForm(scope.row.id).executorDeptName" placeholder="请输入执行部门" clearable size="small"></el-input>
</el-form-item>
<el-form-item>
<el-button size="small" @click="getMaintenanceRecords(scope.row.id)">查询</el-button>
<el-button size="small" @click="resetMaintenanceRecordSearchForm(scope.row.id)">重置</el-button>
<el-button type="primary" size="small" @click="addMaintenanceRecord(scope.row.id)">新增维保记录</el-button>
</el-form-item>
</el-form>
<el-table :data="getMaintenanceRecordsByPlanId(scope.row.id)" style="width: 100%">
<el-table-column prop="execTime" label="维保日期" width="180"></el-table-column>
<el-table-column prop="executorName" label="执行人" width="120"></el-table-column>
<el-table-column prop="executorDeptName" label="执行部门" width="150"></el-table-column>
<el-table-column prop="content" label="维保内容" width="200"></el-table-column>
<el-table-column prop="consumables" label="耗材使用" width="150"></el-table-column>
<el-table-column prop="costAmount" label="维保费用" width="120">
<template slot-scope="recordScope">
{{ recordScope.row.costAmount || 0 }} 元
</template>
</el-table-column>
<el-table-column prop="status" label="维保状态" width="120">
<template slot-scope="scope">
<dict-tag :options="dict.type.maintenance_status" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column prop="result" label="维保结果" width="150"></el-table-column>
<el-table-column prop="remark" label="备注" width="150"></el-table-column>
<el-table-column label="操作" width="180" fixed="right">
<template slot-scope="recordScope">
<el-button type="text" size="small" @click="editMaintenanceRecord(recordScope.row.id, scope.row.id)">{{ '修改' }}</el-button>
<el-button type="text" size="small" @click="deleteMaintenanceRecord(recordScope.row.id, scope.row.id)" style="color: #f56c6c;">{{ '删除' }}</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
</el-table-column>
<el-table-column
prop="facilityId"
header-align="center"
align="center"
label="设施名称">
<template slot-scope="scope">
{{ getFacilityName(scope.row.facilityId) }}
</template>
</el-table-column>
<el-table-column
prop="buildingId"
header-align="center"
align="center"
label="楼栋名称">
<template slot-scope="scope">
{{ getBuildingName(scope.row.buildingId) }}
</template>
</el-table-column>
<el-table-column
prop="projectId"
header-align="center"
align="center"
label="项目名称">
<template slot-scope="scope">
{{ getProjectName(scope.row.projectId) }}
</template>
</el-table-column>
<el-table-column
prop="maintenanceType"
header-align="center"
align="center"
label="维保类型">
<template slot-scope="scope">
<dict-tag :options="dict.type.maintenance_type" :value="scope.row.maintenanceType" />
</template>
</el-table-column>
<el-table-column
prop="cycleDays"
header-align="center"
align="center"
label="维保周期">
</el-table-column>
<el-table-column
prop="nextExecTime"
header-align="center"
align="center"
label="下次执行时间">
</el-table-column>
<el-table-column
prop="maintenanceContent"
header-align="center"
align="center"
label="维保内容">
</el-table-column>
<el-table-column
prop="executorDept"
header-align="center"
align="center"
label="执行部门">
</el-table-column>
<el-table-column
prop="remark"
header-align="center"
align="center"
label="备注">
</el-table-column>
<el-table-column
fixed="right"
header-align="center"
align="center"
width="180"
label="操作">
<template slot-scope="scope">
<el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ '修改' }}</el-button>
<el-button v-hasPermi="['autogencode:pmfacilitymaintenanceplan:delete']" type="text" size="small" @click="deleteHandle(scope.row.id)" style="color: #f56c6c;">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper">
</el-pagination>
<!-- 表单弹窗, 新增数据和修改数据 -->
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
<!-- 维保记录表单弹窗 -->
<add-or-update-record ref="addOrUpdateRecord" :visible="maintenanceRecordFormVisible" :planId="currentPlanId" @close="maintenanceRecordFormVisible = false" @refreshDataList="saveMaintenanceRecord"></add-or-update-record>
</div>
</template>
<script>
import AddOrUpdate from './pmfacilitymaintenanceplan-add-and-update'
import AddOrUpdateRecord from '../record/pmfacilitymaintenacerecord-add-and-update'
import * as api from '@/api/pmfacilitymaintenanceplan.js'
import * as apiByProject from '@/api/pmproject.js'
import * as apiByBuilding from '@/api/pmbuilding.js'
import * as apiByFacility from '@/api/pmfacility.js'
import * as apiByRecord from '@/api/pmfacilitymaintenacerecord.js'
export default {
dicts: ['maintenance_type','maintenance_status'],
data () {
return {
dataForm: {
facilityId: '',
buildingId: '',
projectId: '',
facilityName: '',
maintenanceType: '',
cycleDays: '',
nextExecTime: '',
maintenanceContent: '',
executorDept: '',
remark: '',
},
dataList: [],
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false,
projectList: [],
buildingList: [],
facilityList: [],
// 维保记录相关
maintenanceRecordsMap: {}, // 存储每个计划的维保记录
maintenanceRecordSearchForms: {}, // 存储每个计划的搜索表单
maintenanceRecordFormVisible: false,
currentPlanId: null
}
},
components: {
AddOrUpdate,
AddOrUpdateRecord
},
activated () {
this.getDataList()
},
mounted() {
// 获取项目、楼栋和设施列表
this.getProjectList()
this.getBuildingList()
this.getFacilityList()
// 确保页面加载时自动查询
this.getDataList()
},
methods: {
// 获取项目列表
getProjectList() {
apiByProject.pmprojectListByAllApi().then(res => {
try {
this.projectList = Array.isArray(res) ? res : (res.list || [])
} catch (processingErr) {
this.projectList = []
}
}).catch(err => {
this.projectList = []
})
},
// 获取楼栋列表
getBuildingList(projectId) {
const params = projectId ? { projectId } : {}
apiByBuilding.pmbuildingListByAllApi(params).then(res => {
try {
this.buildingList = Array.isArray(res) ? res : (res.list || [])
} catch (processingErr) {
this.buildingList = []
}
}).catch(err => {
this.buildingList = []
})
},
// 获取设施列表
getFacilityList() {
apiByFacility.pmfacilityListByAllApi().then(res => {
try {
this.facilityList = Array.isArray(res) ? res : (res.list || [])
} catch (processingErr) {
this.facilityList = []
}
}).catch(err => {
this.facilityList = []
})
},
// 根据ID获取项目名称
getProjectName(projectId) {
const project = this.projectList.find(item => item.id === projectId)
return project ? project.projectName : projectId
},
// 根据ID获取楼栋名称
getBuildingName(buildingId) {
const building = this.buildingList.find(item => item.id === buildingId)
return building ? building.buildingNo : buildingId
},
// 根据ID获取设施名称
getFacilityName(facilityId) {
const facility = this.facilityList.find(item => item.id === facilityId)
return facility ? facility.facilityName : facilityId
},
// 重置表单
resetForm() {
this.dataForm = {
facilityId: '',
buildingId: '',
projectId: '',
facilityName: '',
maintenanceType: '',
cycleDays: '',
nextExecTime: '',
maintenanceContent: '',
executorDept: '',
remark: '',
}
this.getDataList()
},
// 获取数据列表
getDataList () {
this.dataListLoading = true
// 根据后端PmFacilityMaintenancePlanController和PageParamRequest的期望格式构建参数
const params = {
page: this.pageIndex,
limit: this.pageSize
}
// 将查询条件添加到参数中
if (this.dataForm.facilityId) params.facilityId = this.dataForm.facilityId;
if (this.dataForm.buildingId) params.buildingId = this.dataForm.buildingId;
if (this.dataForm.projectId) params.projectId = this.dataForm.projectId;
if (this.dataForm.facilityName) params.facilityName = this.dataForm.facilityName;
if (this.dataForm.maintenanceType) params.maintenanceType = this.dataForm.maintenanceType;
if (this.dataForm.cycleDays) params.cycleDays = this.dataForm.cycleDays;
if (this.dataForm.nextExecTime) params.nextExecTime = this.dataForm.nextExecTime;
if (this.dataForm.maintenanceContent) params.maintenanceContent = this.dataForm.maintenanceContent;
if (this.dataForm.executorDept) params.executorDept = this.dataForm.executorDept;
if (this.dataForm.remark) params.remark = this.dataForm.remark;
api.pmfacilitymaintenanceplanListApi(params).then(res => {
this.dataListLoading = false
this.dataList = res.list || [];
this.totalPage = res.total;
}).catch(e => {
this.dataListLoading = false
})
},
// 每页数
sizeChangeHandle (val) {
this.pageSize = val
this.pageIndex = 1
this.getDataList()
},
// 当前页
currentChangeHandle (val) {
this.pageIndex = val
this.getDataList()
},
// 多选
selectionChangeHandle (val) {
this.dataListSelections = val
},
// 新增 / 修改
addOrUpdateHandle (id) {
this.addOrUpdateVisible = true
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id)
})
},
// 删除处理(支持单个删除和批量删除)
deleteHandle (id) {
let ids = []
let idText = ''
// 如果传入了单个id参数则为单个删除
if (id) {
ids = [id]
idText = id
} else {
// 否则为批量删除
ids = this.dataListSelections.map(item => {
return item.id
})
idText = ids.join(',')
}
this.$confirm(`确定进行删除操作?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 调用批量删除API
api.pmfacilitymaintenanceplanDeleteApi(ids).then(res => {
this.$message.success('删除成功')
this.getDataList()
})
})
},
// 获取维保记录列表
getMaintenanceRecords(planId) {
const params = {
planId: planId
}
// 添加搜索条件
const searchForm = this.getMaintenanceRecordSearchForm(planId)
// 处理日期范围
if (searchForm.execTimeRange && searchForm.execTimeRange.length === 2) {
params.execTimeStart = searchForm.execTimeRange[0]
params.execTimeEnd = searchForm.execTimeRange[1]
}
if (searchForm.executorName) params.executorName = searchForm.executorName
if (searchForm.executorDeptName) params.executorDeptName = searchForm.executorDeptName
apiByRecord.pmfacilitymaintenacerecordListApi(params).then(res => {
if (!this.maintenanceRecordsMap[planId]) {
this.$set(this.maintenanceRecordsMap, planId, [])
}
this.$set(this.maintenanceRecordsMap, planId, res.list || [])
}).catch(e => {
if (!this.maintenanceRecordsMap[planId]) {
this.$set(this.maintenanceRecordsMap, planId, [])
}
this.$set(this.maintenanceRecordsMap, planId, [])
})
},
// 根据计划ID获取维保记录
getMaintenanceRecordsByPlanId(planId) {
if (!this.maintenanceRecordsMap[planId]) {
this.getMaintenanceRecords(planId)
return []
}
return this.maintenanceRecordsMap[planId]
},
// 获取或创建维保记录搜索表单
getMaintenanceRecordSearchForm(planId) {
if (!this.maintenanceRecordSearchForms[planId]) {
this.$set(this.maintenanceRecordSearchForms, planId, {
execTime: '',
executorId: '',
executorDept: ''
})
}
return this.maintenanceRecordSearchForms[planId]
},
// 重置维保记录搜索表单
resetMaintenanceRecordSearchForm(planId) {
this.$set(this.maintenanceRecordSearchForms, planId, {
execTimeRange: [],
executorName: '',
executorDeptName: ''
})
this.getMaintenanceRecords(planId)
},
// 新增维保记录
addMaintenanceRecord(planId) {
this.currentPlanId = planId
this.maintenanceRecordFormVisible = true
if (this.$refs.addOrUpdateRecord) {
this.$refs.addOrUpdateRecord.init(0, planId)
}
},
// 编辑维保记录
editMaintenanceRecord(id, planId) {
this.currentPlanId = planId
this.maintenanceRecordFormVisible = true
if (this.$refs.addOrUpdateRecord) {
this.$refs.addOrUpdateRecord.init(id, planId)
}
},
// 删除维保记录
deleteMaintenanceRecord(id, planId) {
this.$confirm('确定要删除这条维保记录吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
apiByRecord.pmfacilitymaintenacerecordDeleteApi([id]).then(() => {
this.$message.success('删除成功')
this.getMaintenanceRecords(planId)
}).catch(() => {
// this.$message.error('删除失败')
})
}).catch(() => {})
},
// 保存维保记录
saveMaintenanceRecord() {
if (this.currentPlanId) {
this.getMaintenanceRecords(this.currentPlanId)
}
}
}
}
</script>