| | |
| | | deviceScopeSearch |
| | | } from '@/api/cnas/resourceDemand/device.js' |
| | | import Sortable from "sortablejs"; |
| | | import draftSave from '@/mixins/draftSave' |
| | | |
| | | export default { |
| | | name: "addYearPlanDia", |
| | | // import 引入的组件需要注入到对象中才能使用 |
| | | components: {}, |
| | | mixins: [draftSave], |
| | | data() { |
| | | // 这里存放数据 |
| | | return { |
| | |
| | | calibrationPlanDetailList: [], |
| | | } |
| | | this.calibrationPlanDetailList = [] |
| | | this.$nextTick(() => { |
| | | this.draftRestore('addYearPlanDiaForm', 'form', '', 'applicationForm') |
| | | this.draftRestore('addYearPlanDiaRows', 'calibrationPlanDetailList', '', 'applicationForm') |
| | | }) |
| | | } else { |
| | | this.getRowInfo(row) |
| | | } |
| | |
| | | this.form.planName = res.data.planName |
| | | this.form.planYear = res.data.planYear |
| | | this.form.planId = res.data.planId |
| | | this.$nextTick(() => { |
| | | this.draftRestore('addYearPlanDiaForm', 'form', this.form.planId, 'applicationForm') |
| | | this.draftRestore('addYearPlanDiaRows', 'calibrationPlanDetailList', this.form.planId, 'applicationForm') |
| | | }) |
| | | } |
| | | }).catch(err => { |
| | | this.yearTableLoading = false |
| | |
| | | this.selectionRows = selection |
| | | }, |
| | | changeMachineName() { |
| | | this.selectionRows.map(val => { |
| | | const existingIds = new Set(this.calibrationPlanDetailList.map(item => item.deviceId)) |
| | | let skipped = 0 |
| | | this.selectionRows.forEach(val => { |
| | | if (existingIds.has(val.id)) { |
| | | skipped++ |
| | | return |
| | | } |
| | | // 将 val.nextCalibrationDate 转换为 Date 对象并减去 5 天 |
| | | let nextCalibrationDate = val.nextCalibrationDate ? new Date(val.nextCalibrationDate) : null; |
| | | if (nextCalibrationDate) { |
| | |
| | | verificationUnit: val.calibrationServices, |
| | | deviceAmount: 1 |
| | | }) |
| | | existingIds.add(val.id) |
| | | }) |
| | | if (skipped > 0) { |
| | | this.$message.warning(`已跳过 ${skipped} 台已在计划中的设备`) |
| | | } |
| | | this.addEquipDia = false |
| | | this.rowDrop() |
| | | }, |
| | |
| | | }, |
| | | // 提交新增 |
| | | submitForm() { |
| | | if (!this.form.planName) { |
| | | this.$message.warning('请输入计划名称') |
| | | return |
| | | } |
| | | if (!this.form.planYear) { |
| | | this.$message.warning('请选择年份') |
| | | return |
| | | } |
| | | if (!this.calibrationPlanDetailList.length) { |
| | | this.$message.warning('请添加设备') |
| | | return |
| | | } |
| | | this.form.calibrationPlanDetailList = this.HaveJson(this.calibrationPlanDetailList) |
| | | this.submitFormLoading = true |
| | | if (this.operationType === 'add') { |
| | | addDeviceCalibrationPlan(this.form).then(res => { |
| | | if (res.code == 200) { |
| | | this.$message.success('新增成功') |
| | | this.draftClear('addYearPlanDiaForm') |
| | | this.draftClear('addYearPlanDiaRows') |
| | | this.closeDialog() |
| | | this.$emit('closeDia') |
| | | } |
| | |
| | | } else { |
| | | updateDeviceCalibrationPlan(this.form).then(res => { |
| | | if (res.code == 200) { |
| | | this.$message.success('新增成功') |
| | | this.draftClear('addYearPlanDiaForm') |
| | | this.draftClear('addYearPlanDiaRows') |
| | | this.$message.success('修改成功') |
| | | this.closeDialog() |
| | | this.$emit('closeDia') |
| | | } |
| | |
| | | } |
| | | }, |
| | | closeDialog() { |
| | | this.draftStop('addYearPlanDiaForm') |
| | | this.draftStop('addYearPlanDiaRows') |
| | | this.applicationForm = false |
| | | }, |
| | | // 获取所有设备 |