import {devicePlanDel, devicePlanInfo, devicePlanPage, devicePlanSave} from "@/api/dev/devicePlanApi"; import { devicePlanDetailDel, devicePlanDetailGroupPage, devicePlanDetailAdd, devicePlanDetailPage, devicePlanDetailDelByDeviceCode } from "@/api/dev/devicePlanDetailApi"; import {getLoading} from "@/utils"; import product from "@/views/basic/product/product.vue"; import { devicePlanDetailItemAdd, devicePlanDetailItemByDeviceCodeDel, devicePlanDetailItemDel, devicePlanDetailItemPage } from "@/api/dev/devicePlanDetailItemApi"; import DeviceCheckItemDict from "@/views/dev/deviceCheckItemDict"; import {deviceCheckGenByPlanId} from "@/api/dev/deviceCheckApi"; let query = { page: 1, limit: 10, name: null, chargeDeptCode: null, } let detailQuery = { page: 1, limit: 10, planId: null, } let rowDeltailQuery = { page: 1, limit: 10, planId: null, productId: null, } let itemQuery = { page: 1, limit: 10, planId: null, productId: null, } let planData = { name: null, chargeDeptCode: null, startDate: null, endDate: null, frequency: 1, dateInterval: null, remark: null, } export default { name: "devicePlan", components: {DeviceCheckItemDict, product}, computed: {}, data() { return { clickRow: null, showSearch: true, loading: false, total: .0, list: [], query: {...query}, //计划详情============================================= detailLoading: false, detailQuery: {...detailQuery}, detailList: [], detailTotal: 0, //=================================================== //巡检项目============================================= itemQuery: {...itemQuery}, itemList: [], itemTotal: 0, itemLoading: false, chooseDetailItemFlag: false, chooseDeviceList: [], chooseItemList: [], //=================================================== createActive: 0, createFlag: false, chooseDeviceFlag: false, expandRowKeys: [], dialogExpandRowKeys: [], planData: {...planData}, formRule: { name: [{required: true, message: "计划名称不能为空", trigger: ["change", "blur"]}], chargeDeptCode: [{required: true, message: "负责部门不能为空", trigger: ["change", "blur"]}], dateInterval: [{required: true, message: "计划执行区间不能为空", trigger: ["change", "blur"]}], frequency: [{ required: true, message: "计划执行频率不能为空", trigger: ["change", "blur"] }], }, dateInterval: null, pickerOptions: { disabledDate: time => { let nowDate = new Date().getTime(); let pickDate = new Date(time).getTime(); return (nowDate >= pickDate); }, shortcuts: [{ text: '一个月(30天)', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() + 3600 * 1000 * 24); end.setTime(start.getTime() + 3600 * 1000 * 24 * 30); picker.$emit('pick', [start, end]); } }, { text: '三个月(90天)', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() + 3600 * 1000 * 24); end.setTime(start.getTime() + 3600 * 1000 * 24 * 30 * 3); picker.$emit('pick', [start, end]); } }, { text: '半年(180天)', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() + 3600 * 1000 * 24); end.setTime(start.getTime() + 3600 * 1000 * 24 * 30 * 6); picker.$emit('pick', [start, end]); } }, { text: '一年(365天)', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() + 3600 * 1000 * 24); end.setTime(start.getTime() + 3600 * 1000 * 24 * 365); picker.$emit('pick', [start, end]); } }, { text: '两年(730天)', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() + 3600 * 1000 * 24); end.setTime(start.getTime() + 3600 * 1000 * 24 * 365 * 2); picker.$emit('pick', [start, end]); } }, { text: '三年(1095天)', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() + 3600 * 1000 * 24); end.setTime(start.getTime() + 3600 * 1000 * 24 * 365 * 3); picker.$emit('pick', [start, end]); } }, { text: '五年(1825天)', onClick(picker) { const end = new Date(); const start = new Date(); start.setTime(start.getTime() + 3600 * 1000 * 24); end.setTime(start.getTime() + 3600 * 1000 * 24 * 365 * 5); picker.$emit('pick', [start, end]); } }] }, } }, watch: { planData(v) { if (v.planId != null) { this.$set(v, "dateInterval", [v.startDate, v.endDate]) } }, "planData.dateInterval"(v) { if (v != null && v.length > 0) { this.planData.startDate = v[0] this.planData.endDate = v[1] } }, "$refs.dialogTable"(v) { this.$refs.dialogTable?.doLayout() } }, created() { this.getList() }, methods: { handleExpendRow(row, expandedRows) { if (expandedRows.length == 0) { return } this.$set(row, "detailData", { loading: false, showSearch: true, list: [], total: 0, query: {...rowDeltailQuery, planId: row.planId, productId: row.productId} }) this.getRowDetailList(row.detailData) }, getRowDetailList(data) { data.loading = true devicePlanDetailPage(data.query).then(res => { data.loading = false if (res.code != 20000) { this.$message.error(res.message) return } data.list = res.data.list || [] data.total = res.data.total || 0 }).catch(() => { data.loading = false data.list = [] data.total = 0 }) }, deviceCheckGenFunc(row) { this.$confirm("此操作将会创建一个任务单,是否继续", "提示", { confirmButtonText: "继续", cancelButtonText: "取消" }).then(() => { let load = getLoading(this) deviceCheckGenByPlanId(row.planId).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.$message.success(res.message) this.getList() }).catch(() => { load.close() }) }) }, delplan(row) { this.$confirm("此操作将会永久删除该计划,现有任务不受影响,是否继续", "提示", { confirmButtonText: "继续", cancelButtonText: "取消" }).then(() => { let load = getLoading(this) devicePlanDel(row.planId).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.$message.success(res.message) this.query.page = 1 this.getList() if (this.clickRow && this.clickRow.planId == row.planId) { this.clickRow = null this.detailTotal = 0 this.detailList = [] } }).catch(() => { load.close() }) }) }, openItem(row) { this.itemQuery = { ...itemQuery, planId: row.planId, productId: row.productId, deviceCode: row.deviceCode, title: `${row.deviceCode ? row.deviceCode + '--' : ''}${row.productName}(${row.nameCode})` } this.getDetailItemList() }, getDetailItemList() { this.itemLoading = true devicePlanDetailItemPage(this.itemQuery).then(res => { this.itemLoading = false if (res.code != 20000) { this.$message.error(res.message) return } this.itemList = res.data.list || [] this.itemTotal = res.data.total || 0 }).catch(e => { this.itemList = [] this.itemTotal = 0 this.itemLoading = false }) }, delDetailItem(row) { this.$confirm("此操作将会永久删除该条明细,且将在下一次任务生效,现有任务不受影响,是否继续", "提示", { confirmButtonText: "继续", cancelButtonText: "取消" }).then(() => { let load = getLoading(this) if (!row.deviceCode) { devicePlanDetailItemDel(row.planId, row.productId, row.itemCode).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.$message.success(res.message) this.itemQuery.page = 1 this.getDetailItemList() }).catch(() => { load.close() }) } else { devicePlanDetailItemByDeviceCodeDel(row.planId, row.deviceCode, row.itemCode).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.$message.success(res.message) this.itemQuery.page = 1 this.getDetailItemList() }).catch(() => { load.close() }) } }) }, delDetail(row) { this.$confirm("此操作将会永久删除该条明细,且将在下一次任务生效,现有任务不受影响,是否继续", "提示", { confirmButtonText: "继续", cancelButtonText: "取消" }).then(() => { let load = getLoading(this) if (row.deviceCode) { devicePlanDetailDelByDeviceCode(row.planId, row.deviceCode).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.$message.success(res.message) this.detailQuery.page = 1 this.getDetailList() }).catch(() => { load.close() }) } else { devicePlanDetailDel(row.planId, row.productId).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.$message.success(res.message) this.detailQuery.page = 1 this.getDetailList() }).catch(() => { load.close() }) } }) }, rowClick(row) { this.clickRow = row this.detailQuery = {...detailQuery, planId: row.planId} this.getDetailList() }, getDetailList() { this.detailLoading = true this.expandRowKeys = [] this.dialogExpandRowKeys = [] devicePlanDetailGroupPage(this.detailQuery).then(res => { this.detailLoading = false if (res.code != 20000) { this.$message.error(res.message) return } this.detailList = res.data.list || [] this.detailTotal = res.data.total || 0 }).catch(e => { this.detailList = [] this.detailTotal = 0 this.detailLoading = false }) }, changeActive(isNext, row) { let load = getLoading(this) if (isNext) { if (this.createActive == 0) { this.$refs.saveForm.validate(b => { if (!b) { load.close() return } devicePlanSave(this.planData).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.planData.planId = res.data this.detailQuery = {...detailQuery, planId: this.planData.planId} this.getDetailList() this.createActive += 1 }).catch(e => { load.close() }) }) } else if (this.createActive == 1) { this.openItem(row) load.close() this.createActive += 1 } } else { if (this.createActive == 2) { this.planData = {...this.planData} this.detailQuery = {...detailQuery, planId: this.itemQuery.planId} this.getDetailList() load.close() this.createActive -= 1 } else if (this.createActive == 1) { devicePlanInfo(this.planData.planId).then(res => { load.close() if (res.code != 20000) { this.$message.error(res.message) return } this.planData = {...res.data} this.createActive -= 1 }).catch(e => { load.close() }) } } load.close() }, itemSelectChangFunc(list) { this.chooseItemList = list.map(i => i.code) }, chooseDetailItem() { let loading = getLoading(this) let param = { planId: this.itemQuery.planId, productId: this.itemQuery.productId, deviceCode: this.itemQuery.deviceCode, itemCodes: this.chooseItemList } devicePlanDetailItemAdd(param).then(res => { loading.close() if (res.code != 20000) { this.$message.error(res.message) return } this.chooseItemList = [] this.$message.success(res.message) this.chooseDetailItemFlag = false this.itemQuery.page = 1 this.getDetailItemList() }).catch(e => { loading.close() }) }, deviceSelectChangFunc(list) { this.chooseDeviceList = list.map(i => i.deviceCode) }, chooseDevice() { let loading = getLoading(this) let param = { planId: this.createFlag ? this.planData.planId : this.clickRow.planId, deviceCodes: this.chooseDeviceList } devicePlanDetailAdd(param).then(res => { loading.close() if (res.code != 20000) { this.$message.error(res.message) return } this.chooseDeviceList = [] this.$message.success(res.message) this.chooseDeviceFlag = false this.detailQuery.page = 1 this.getDetailList() }).catch(e => { loading.close() }) }, openCreate(planId, row, createActive) { this.createActive = 0 if (createActive != null) { this.createActive = createActive } if (planId != null) { devicePlanInfo(planId).then(res => { if (res.code != 20000) { this.$message.error(res.message) return } this.planData = {...res.data} this.createFlag = true if (createActive == 1) { this.detailQuery = {...detailQuery, planId: planId} this.getDetailList() } else if (createActive == 2) { this.itemQuery = { ...detailQuery, planId: planId, productId: row.productId, deviceCode: row.deviceCode, title: `${row.deviceCode ? row.deviceCode + '--' : ''}${row.productName}(${row.nameCode})` } this.getDetailItemList() } }) } else { this.planData = {...planData} this.createFlag = true } }, search() { this.query.page = 1 this.getList() }, onReset() { this.query = {...query} this.getList() }, getList() { this.loading = true devicePlanPage(this.query).then(res => { this.loading = false if (res.code != 20000) { this.$message.error(res.message) return } this.list = res.data.list || [] this.total = res.data.total || 0 }).catch(e => { this.loading = false }) } } }