|
@@ -0,0 +1,667 @@
|
|
|
+<template>
|
|
|
+ <ContentWrap v-loading="formLoading">
|
|
|
+ <el-form
|
|
|
+ ref="formRef"
|
|
|
+ :model="formData"
|
|
|
+ :rules="formRules"
|
|
|
+ v-loading="formLoading"
|
|
|
+ style="margin-right: 4em; margin-left: 0.5em; margin-top: 1em"
|
|
|
+ label-width="130px"
|
|
|
+ >
|
|
|
+ <div class="base-expandable-content">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="8">
|
|
|
+ <el-form-item label="工单名称" prop="name">
|
|
|
+ <el-input type="text" v-model="formData.name" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="8">
|
|
|
+ <el-form-item label="工单编号" prop="orderNumber">
|
|
|
+ <el-input type="text" v-model="formData.orderNumber" disabled/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="8">
|
|
|
+ <el-form-item label="责任人" prop="responsiblePerson">
|
|
|
+ <el-select v-model="formData.responsiblePerson" filterable clearable style="width: 100%">
|
|
|
+ <el-option
|
|
|
+ v-for="item in deptUsers"
|
|
|
+ :key="item.id"
|
|
|
+ :label="item.nickname"
|
|
|
+ :value="item.id"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-form-item label="备注" prop="remark">
|
|
|
+ <el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+ </el-form>
|
|
|
+ </ContentWrap>
|
|
|
+ <ContentWrap>
|
|
|
+ <ContentWrap>
|
|
|
+ <!-- 搜索工作栏 -->
|
|
|
+ <el-form
|
|
|
+ class="-mb-15px"
|
|
|
+ :model="queryParams"
|
|
|
+ ref="queryFormRef"
|
|
|
+ :inline="true"
|
|
|
+ label-width="68px"
|
|
|
+ >
|
|
|
+ <!--
|
|
|
+ <el-form-item>
|
|
|
+ <el-button @click="openForm" type="warning">
|
|
|
+ <Icon icon="ep:plus" class="mr-5px" /> 新增设备</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ -->
|
|
|
+ </el-form>
|
|
|
+ </ContentWrap>
|
|
|
+
|
|
|
+ <!-- 列表 -->
|
|
|
+ <ContentWrap>
|
|
|
+ <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
|
|
+ <el-table-column label="设备编码" align="center" prop="deviceCode" />
|
|
|
+ <el-table-column label="设备名称" align="center" prop="deviceName" />
|
|
|
+ <el-table-column label="累计运行时间(H)" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter"/>
|
|
|
+ <el-table-column label="累计运行公里数(KM)" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter"/>
|
|
|
+ <el-table-column label="BOM节点" align="center" prop="name" />
|
|
|
+ <el-table-column label="运行里程" key="mileageRule" width="80">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-switch
|
|
|
+ v-model="scope.row.mileageRule"
|
|
|
+ :active-value="0"
|
|
|
+ :inactive-value="1"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="运行时间" key="runningTimeRule" width="80">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-switch
|
|
|
+ v-model="scope.row.runningTimeRule"
|
|
|
+ :active-value="0"
|
|
|
+ :inactive-value="1"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="自然日期" key="naturalDateRule" width="80">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-switch
|
|
|
+ v-model="scope.row.naturalDateRule"
|
|
|
+ :active-value="0"
|
|
|
+ :inactive-value="1"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" align="center" min-width="120px">
|
|
|
+ <template #default="scope">
|
|
|
+ <div style="display: flex; justify-content: center; align-items: center; width: 100%">
|
|
|
+ <!-- 新增配置按钮 -->
|
|
|
+ <div style="margin-left: 12px">
|
|
|
+ <el-button
|
|
|
+ link
|
|
|
+ type="primary"
|
|
|
+ @click="openConfigDialog(scope.row)"
|
|
|
+ >
|
|
|
+ 配置
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </ContentWrap>
|
|
|
+ </ContentWrap>
|
|
|
+ <ContentWrap>
|
|
|
+ <el-form>
|
|
|
+ <el-form-item style="float: right">
|
|
|
+ <el-button @click="submitForm" type="primary" :disabled="formLoading">保 存</el-button>
|
|
|
+ <el-button @click="close">取 消</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </ContentWrap>
|
|
|
+ <!-- 新增配置对话框 -->
|
|
|
+ <el-dialog
|
|
|
+ v-model="configDialog.visible"
|
|
|
+ :title="`设备 ${configDialog.current?.deviceCode+'-'+configDialog.current?.name} 保养配置`"
|
|
|
+ width="600px"
|
|
|
+ >
|
|
|
+ <el-form :model="configDialog.form" label-width="200px" :rules="configFormRules" ref="configFormRef">
|
|
|
+ <!-- 里程配置 -->
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.mileageRule === 0"
|
|
|
+ label="上次保养里程数(KM)"
|
|
|
+ prop="lastRunningKilometers"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.lastRunningKilometers"
|
|
|
+ :precision="2"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 推迟公里数 -->
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.mileageRule === 0"
|
|
|
+ label="推迟公里数(KM)"
|
|
|
+ prop="delayKilometers"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.delayKilometers"
|
|
|
+ :precision="2"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 运行时间配置 -->
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.runningTimeRule === 0"
|
|
|
+ label="上次保养运行时间(H)"
|
|
|
+ prop="lastRunningTime"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.lastRunningTime"
|
|
|
+ :precision="1"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 推迟时长 -->
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.runningTimeRule === 0"
|
|
|
+ label="推迟时长(H)"
|
|
|
+ prop="delayDuration"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.delayDuration"
|
|
|
+ :precision="2"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 自然日期配置 -->
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.naturalDateRule === 0"
|
|
|
+ label="上次保养自然日期(D)"
|
|
|
+ prop="lastNaturalDate"
|
|
|
+ >
|
|
|
+ <el-date-picker
|
|
|
+ v-model="configDialog.form.lastNaturalDate"
|
|
|
+ type="date"
|
|
|
+ placeholder="选择日期"
|
|
|
+ format="YYYY-MM-DD"
|
|
|
+ value-format="YYYY-MM-DD"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 推迟自然日期 -->
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.naturalDateRule === 0"
|
|
|
+ label="推迟自然日期(D)"
|
|
|
+ prop="delayNaturalDate"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.delayNaturalDate"
|
|
|
+ :precision="2"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 保养规则周期值 + 提前量 -->
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.mileageRule === 0"
|
|
|
+ label="运行里程周期(KM)"
|
|
|
+ prop="nextRunningKilometers"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.nextRunningKilometers"
|
|
|
+ :precision="2"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.mileageRule === 0"
|
|
|
+ label="运行里程周期-提前量(KM)"
|
|
|
+ prop="kiloCycleLead"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.kiloCycleLead"
|
|
|
+ :precision="2"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.runningTimeRule === 0"
|
|
|
+ label="运行时间周期(H)"
|
|
|
+ prop="nextRunningTime"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.nextRunningTime"
|
|
|
+ :precision="1"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.runningTimeRule === 0"
|
|
|
+ label="运行时间周期-提前量(H)"
|
|
|
+ prop="timePeriodLead"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.timePeriodLead"
|
|
|
+ :precision="1"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.naturalDateRule === 0"
|
|
|
+ label="自然日周期(D)"
|
|
|
+ prop="nextNaturalDate"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.nextNaturalDate"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ v-if="configDialog.current?.naturalDateRule === 0"
|
|
|
+ label="自然日周期-提前量(D)"
|
|
|
+ prop="naturalDatePeriodLead"
|
|
|
+ >
|
|
|
+ <el-input-number
|
|
|
+ v-model="configDialog.form.naturalDatePeriodLead"
|
|
|
+ :min="0"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <el-button @click="configDialog.visible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="saveConfig">保存</el-button>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
+</template>
|
|
|
+<script setup lang="ts">
|
|
|
+import { IotMaintainApi, IotMaintainVO } from '@/api/pms/maintain'
|
|
|
+import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
|
|
|
+import * as UserApi from '@/api/system/user'
|
|
|
+import { useUserStore } from '@/store/modules/user'
|
|
|
+import { ref } from 'vue'
|
|
|
+import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
|
|
|
+import { IotMainWorkOrderBomApi, IotMainWorkOrderBomVO } from '@/api/pms/iotmainworkorderbom'
|
|
|
+import { IotMaintenancePlanApi, IotMaintenancePlanVO } from '@/api/pms/maintenance'
|
|
|
+import { IotMainWorkOrderApi, IotMainWorkOrderVO } from '@/api/pms/iotmainworkorder'
|
|
|
+import { useTagsViewStore } from '@/store/modules/tagsView'
|
|
|
+import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
|
|
|
+import MainPlanDeviceList from "@/views/pms/maintenance/MainPlanDeviceList.vue";
|
|
|
+import * as DeptApi from "@/api/system/dept";
|
|
|
+import {erpPriceTableColumnFormatter} from "@/utils";
|
|
|
+import dayjs from 'dayjs'
|
|
|
+
|
|
|
+/** 保养计划 表单 */
|
|
|
+defineOptions({ name: 'IotMainWorkOrderBom' })
|
|
|
+
|
|
|
+const { t } = useI18n() // 国际化
|
|
|
+const message = useMessage() // 消息弹窗
|
|
|
+const { delView } = useTagsViewStore() // 视图操作
|
|
|
+const { currentRoute, push } = useRouter()
|
|
|
+const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
|
|
|
+const dept = ref() // 当前登录人所属部门对象
|
|
|
+const configFormRef = ref() // 配置弹出框对象
|
|
|
+const dialogTitle = ref('') // 弹窗的标题
|
|
|
+const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
|
|
+const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
|
|
+const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
|
|
|
+// const list = ref<IotMaintenanceBomVO[]>([]) // 设备bom关联列表的数据
|
|
|
+const list = ref<IotMainWorkOrderBomVO[]>([]) // 保养工单bom关联列表的数据
|
|
|
+const deviceIds = ref<number[]>([]) // 已经选择的设备id数组
|
|
|
+const { params, name } = useRoute() // 查询参数
|
|
|
+const id = params.id
|
|
|
+const formData = ref({
|
|
|
+ id: undefined,
|
|
|
+ deptId: undefined,
|
|
|
+ name: '',
|
|
|
+ orderNumber: undefined,
|
|
|
+ responsiblePerson: undefined,
|
|
|
+ remark: undefined,
|
|
|
+ status: undefined,
|
|
|
+})
|
|
|
+const formRules = reactive({
|
|
|
+ name: [{ required: true, message: '工单名称不能为空', trigger: 'blur' }],
|
|
|
+ responsiblePerson: [{ required: true, message: '责任人不能为空', trigger: 'blur' }],
|
|
|
+})
|
|
|
+const formRef = ref() // 表单 Ref
|
|
|
+
|
|
|
+// 新增配置相关状态
|
|
|
+const configDialog = reactive({
|
|
|
+ visible: false,
|
|
|
+ current: null as IotMaintenanceBomVO | null,
|
|
|
+ form: {
|
|
|
+ lastRunningKilometers: 0,
|
|
|
+ delayKilometers: 0,
|
|
|
+ lastRunningTime: 0,
|
|
|
+ delayDuration: 0,
|
|
|
+ lastNaturalDate: '',
|
|
|
+ delayNaturalDate: 0,
|
|
|
+ // 保养规则 周期
|
|
|
+ nextRunningKilometers: 0,
|
|
|
+ nextRunningTime: 0,
|
|
|
+ nextNaturalDate: 0,
|
|
|
+ // 提前量
|
|
|
+ kiloCycleLead: 0,
|
|
|
+ timePeriodLead: 0,
|
|
|
+ naturalDatePeriodLead: 0
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+// 打开配置对话框
|
|
|
+const openConfigDialog = (row: IotMainWorkOrderBomVO) => {
|
|
|
+ configDialog.current = row
|
|
|
+
|
|
|
+ // 处理日期初始化(核心修改)
|
|
|
+ let initialDate = ''
|
|
|
+ if (row.lastNaturalDate) {
|
|
|
+ // 如果已有值:时间戳 -> 日期字符串
|
|
|
+ initialDate = dayjs(row.lastNaturalDate).format('YYYY-MM-DD')
|
|
|
+ } else {
|
|
|
+ // 如果无值:设置默认值避免1970问题
|
|
|
+ initialDate = ''
|
|
|
+ }
|
|
|
+
|
|
|
+ configDialog.form = {
|
|
|
+ lastRunningKilometers: row.lastRunningKilometers || 0,
|
|
|
+ delayKilometers: row.delayKilometers || 0,
|
|
|
+ lastRunningTime: row.lastRunningTime || 0,
|
|
|
+ delayDuration: row.delayDuration || 0,
|
|
|
+ lastNaturalDate: initialDate,
|
|
|
+ delayNaturalDate: row.delayNaturalDate || 0,
|
|
|
+ // 保养规则 周期值
|
|
|
+ nextRunningKilometers: row.nextRunningKilometers || 0,
|
|
|
+ nextRunningTime: row.nextRunningTime || 0,
|
|
|
+ nextNaturalDate: row.nextNaturalDate || 0,
|
|
|
+ // 提前量
|
|
|
+ kiloCycleLead: row.kiloCycleLead || 0,
|
|
|
+ timePeriodLead: row.timePeriodLead || 0,
|
|
|
+ naturalDatePeriodLead: row.naturalDatePeriodLead || 0
|
|
|
+ }
|
|
|
+ configDialog.visible = true
|
|
|
+}
|
|
|
+
|
|
|
+// 保存配置
|
|
|
+const saveConfig = () => {
|
|
|
+ (configFormRef.value as any).validate((valid: boolean) => {
|
|
|
+ if (!valid) return
|
|
|
+ if (!configDialog.current) return
|
|
|
+
|
|
|
+ // 动态校验逻辑
|
|
|
+ const requiredFields = []
|
|
|
+ if (configDialog.current.mileageRule === 0) {
|
|
|
+ requiredFields.push('nextRunningKilometers', 'kiloCycleLead')
|
|
|
+ }
|
|
|
+ if (configDialog.current.runningTimeRule === 0) {
|
|
|
+ requiredFields.push('nextRunningTime', 'timePeriodLead')
|
|
|
+ }
|
|
|
+ if (configDialog.current.naturalDateRule === 0) {
|
|
|
+ requiredFields.push('nextNaturalDate', 'naturalDatePeriodLead')
|
|
|
+ }
|
|
|
+
|
|
|
+ const missingFields = requiredFields.filter(field =>
|
|
|
+ !configDialog.form[field as keyof typeof configDialog.form]
|
|
|
+ )
|
|
|
+
|
|
|
+ if (missingFields.length > 0) {
|
|
|
+ message.error('请填写所有必填项')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 强制校验逻辑
|
|
|
+ if (configDialog.current.naturalDateRule === 0) {
|
|
|
+ if (!configDialog.form.lastNaturalDate) {
|
|
|
+ message.error('必须选择自然日期')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证日期有效性
|
|
|
+ const dateValue = dayjs(configDialog.form.lastNaturalDate)
|
|
|
+ if (!dateValue.isValid()) {
|
|
|
+ message.error('日期格式不正确')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换逻辑(关键修改)
|
|
|
+ const finalDate = configDialog.form.lastNaturalDate
|
|
|
+ ? dayjs(configDialog.form.lastNaturalDate).valueOf()
|
|
|
+ : null // 改为null而不是0
|
|
|
+
|
|
|
+ // 更新当前行的数据
|
|
|
+ Object.assign(configDialog.current, {
|
|
|
+ ...configDialog.form,
|
|
|
+ lastNaturalDate: finalDate
|
|
|
+ })
|
|
|
+ configDialog.visible = false
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const queryParams = reactive({
|
|
|
+ workOrderId: id
|
|
|
+})
|
|
|
+
|
|
|
+const close = () => {
|
|
|
+ delView(unref(currentRoute))
|
|
|
+ push({ name: 'IotMainWorkOrder', params:{}})
|
|
|
+}
|
|
|
+
|
|
|
+/** 提交表单 */
|
|
|
+const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
|
|
+const submitForm = async () => {
|
|
|
+ // 校验表单
|
|
|
+ await formRef.value.validate()
|
|
|
+ // 校验表格数据
|
|
|
+ const isValid = validateTableData()
|
|
|
+ if (!isValid) return
|
|
|
+ // 提交请求
|
|
|
+ formLoading.value = true
|
|
|
+ try {
|
|
|
+ const data = {
|
|
|
+ mainPlan: formData.value,
|
|
|
+ mainPlanBom: list.value
|
|
|
+ }
|
|
|
+ if (formType.value === 'create') {
|
|
|
+ await IotMaintenancePlanApi.createIotMaintenancePlan(data)
|
|
|
+ message.success(t('common.createSuccess'))
|
|
|
+ close()
|
|
|
+ } else {
|
|
|
+ await IotMaintainApi.updateIotMaintain(data)
|
|
|
+ message.success(t('common.updateSuccess'))
|
|
|
+ close()
|
|
|
+ }
|
|
|
+ // 发送操作成功的事件
|
|
|
+ emit('success')
|
|
|
+ } finally {
|
|
|
+ formLoading.value = false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 新增表单校验规则
|
|
|
+const configFormRules = reactive({
|
|
|
+ nextRunningKilometers: [{
|
|
|
+ required: true,
|
|
|
+ message: '里程周期必须填写',
|
|
|
+ trigger: 'blur'
|
|
|
+ }],
|
|
|
+ kiloCycleLead: [{
|
|
|
+ required: true,
|
|
|
+ message: '提前量必须填写',
|
|
|
+ trigger: 'blur'
|
|
|
+ }],
|
|
|
+ nextRunningTime: [{
|
|
|
+ required: true,
|
|
|
+ message: '时间周期必须填写',
|
|
|
+ trigger: 'blur'
|
|
|
+ }],
|
|
|
+ timePeriodLead: [{
|
|
|
+ required: true,
|
|
|
+ message: '提前量必须填写',
|
|
|
+ trigger: 'blur'
|
|
|
+ }],
|
|
|
+ nextNaturalDate: [{
|
|
|
+ required: true,
|
|
|
+ message: '自然日周期必须填写',
|
|
|
+ trigger: 'blur'
|
|
|
+ }],
|
|
|
+ naturalDatePeriodLead: [{
|
|
|
+ required: true,
|
|
|
+ message: '提前量必须填写',
|
|
|
+ trigger: 'blur'
|
|
|
+ }]
|
|
|
+})
|
|
|
+
|
|
|
+/** 校验表格数据 */
|
|
|
+const validateTableData = (): boolean => {
|
|
|
+ let isValid = true
|
|
|
+ const errorMessages: string[] = []
|
|
|
+ const noRulesErrorMessages: string[] = [] // 未设置任何保养项规则 的错误提示信息
|
|
|
+ const noRules: string[] = [] // 行记录中设置了保养规则的记录数量
|
|
|
+ const configErrors: string[] = [] // 保养规则配置弹出框
|
|
|
+ let shouldBreak = false;
|
|
|
+
|
|
|
+ if (list.value.length === 0) {
|
|
|
+ errorMessages.push('请至少添加一条设备保养明细')
|
|
|
+ isValid = false
|
|
|
+ // 直接返回无需后续校验
|
|
|
+ message.error('请至少添加一条设备保养明细')
|
|
|
+ return isValid
|
|
|
+ }
|
|
|
+
|
|
|
+ list.value.forEach((row, index) => {
|
|
|
+ if (shouldBreak) return;
|
|
|
+ const rowNumber = index + 1 // 用户可见的行号从1开始
|
|
|
+ const deviceIdentifier = `${row.deviceCode}-${row.name}` // 设备标识
|
|
|
+ // 校验逻辑
|
|
|
+ const checkConfig = (ruleName: string, ruleValue: number, configField: keyof typeof row) => {
|
|
|
+ if (ruleValue === 0) { // 规则开启
|
|
|
+ if (!row[configField] || row[configField] <= 0) {
|
|
|
+ configErrors.push(`第 ${rowNumber} 行(${deviceIdentifier}):请点击【配置】维护${ruleName}上次保养值`)
|
|
|
+ isValid = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 里程校验逻辑
|
|
|
+ if (row.mileageRule === 0) { // 假设 0 表示开启状态
|
|
|
+ if (!row.nextRunningKilometers || row.nextRunningKilometers <= 0) {
|
|
|
+ errorMessages.push(`第 ${rowNumber} 行:开启里程规则必须填写有效的里程周期`)
|
|
|
+ isValid = false
|
|
|
+ }
|
|
|
+ // 再校验配置值
|
|
|
+ checkConfig('里程', row.mileageRule, 'lastRunningKilometers')
|
|
|
+ } else {
|
|
|
+ noRules.push(`第 ${rowNumber} 行:未设置里程规则`)
|
|
|
+ }
|
|
|
+ // 运行时间校验逻辑
|
|
|
+ if (row.runningTimeRule === 0) {
|
|
|
+ if (!row.nextRunningTime || row.nextRunningTime <= 0) {
|
|
|
+ errorMessages.push(`第 ${rowNumber} 行:开启运行时间规则必须填写有效的时间周期`)
|
|
|
+ isValid = false
|
|
|
+ }
|
|
|
+ checkConfig('运行时间', row.runningTimeRule, 'lastRunningTime')
|
|
|
+ } else {
|
|
|
+ noRules.push(`第 ${rowNumber} 行:未设置运行时间规则`)
|
|
|
+ }
|
|
|
+ // 自然日期校验逻辑
|
|
|
+ if (row.naturalDateRule === 0) {
|
|
|
+ if (!row.nextNaturalDate) {
|
|
|
+ errorMessages.push(`第 ${rowNumber} 行:开启自然日期规则必须填写有效的自然日期周期`)
|
|
|
+ isValid = false
|
|
|
+ }
|
|
|
+ checkConfig('自然日期', row.naturalDateRule, 'lastNaturalDate')
|
|
|
+ } else {
|
|
|
+ noRules.push(`第 ${rowNumber} 行:未设置自然日期规则`)
|
|
|
+ }
|
|
|
+ // 如果选中的一行记录未设置任何保养规则 提示 ‘保养项未设置任何保养规则’
|
|
|
+ if (noRules.length === 3) {
|
|
|
+ isValid = false
|
|
|
+ shouldBreak = true; // 设置标志变量为true,退出循环
|
|
|
+ noRulesErrorMessages.push('保养项至少设置1个保养规则')
|
|
|
+ }
|
|
|
+ noRules.length = 0;
|
|
|
+ })
|
|
|
+ if (errorMessages.length > 0) {
|
|
|
+ message.error('设置保养规则后,请维护对应的周期值')
|
|
|
+ } else if (noRulesErrorMessages.length > 0) {
|
|
|
+ message.error(noRulesErrorMessages.pop())
|
|
|
+ } else if (configErrors.length > 0) {
|
|
|
+ message.error(configErrors.pop())
|
|
|
+ }
|
|
|
+ return isValid
|
|
|
+}
|
|
|
+
|
|
|
+/** 重置表单 */
|
|
|
+const resetForm = () => {
|
|
|
+ formData.value = {
|
|
|
+ id: undefined,
|
|
|
+ deviceId: undefined,
|
|
|
+ status: undefined,
|
|
|
+ description: undefined,
|
|
|
+ pic: undefined,
|
|
|
+ remark: undefined,
|
|
|
+ deviceName: undefined,
|
|
|
+ processInstanceId: undefined,
|
|
|
+ auditStatus: undefined,
|
|
|
+ deptId: undefined
|
|
|
+ }
|
|
|
+ formRef.value?.resetFields()
|
|
|
+}
|
|
|
+onMounted(async () => {
|
|
|
+ console.log('id-'+id)
|
|
|
+ const deptId = useUserStore().getUser.deptId
|
|
|
+ // 查询当前登录人所属部门名称
|
|
|
+ dept.value = await DeptApi.getDept(deptId)
|
|
|
+ // formData.value.name = dept.value.name + ' - 保养计划'
|
|
|
+ deptUsers.value = await UserApi.getDeptUsersByDeptId(deptId)
|
|
|
+ formData.value.deptId = deptId
|
|
|
+ // if (id){
|
|
|
+ try{
|
|
|
+ formType.value = 'update'
|
|
|
+ // const iotMaintain = await IotMaintainApi.getIotMaintain(id);
|
|
|
+ // deviceLabel.value = iotMaintain.deviceName
|
|
|
+ // formData.value = iotMaintain
|
|
|
+ // 查询保养工单 主表数据
|
|
|
+ const workOrder = await IotMainWorkOrderApi.getIotMainWorkOrder(id);
|
|
|
+ formData.value = workOrder
|
|
|
+ // 查询保养工单 明细数据
|
|
|
+ const data = await IotMainWorkOrderBomApi.getWorkOrderBOMs(queryParams);
|
|
|
+ console.log('这是个数组:', data)
|
|
|
+ list.value = []
|
|
|
+ if (Array.isArray(data)) {
|
|
|
+ list.value = data.map(item => ({
|
|
|
+ ...item,
|
|
|
+ // 这里可以添加必要的字段转换(如果有日期等需要格式化的字段)
|
|
|
+ lastNaturalDate: item.lastNaturalDate ? dayjs(item.lastNaturalDate).format('YYYY-MM-DD') : null
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('数据加载失败:', error)
|
|
|
+ message.error('数据加载失败,请重试')
|
|
|
+ }
|
|
|
+ /* } else {
|
|
|
+ formType.value = 'create';
|
|
|
+ const { wsCache } = useCache()
|
|
|
+ const userInfo = wsCache.get(CACHE_KEY.USER)
|
|
|
+ formData.value.responsiblePerson = userInfo.user.id;
|
|
|
+ } */
|
|
|
+})
|
|
|
+
|
|
|
+</script>
|
|
|
+<style scoped>
|
|
|
+.base-expandable-content {
|
|
|
+ overflow: hidden; /* 隐藏溢出的内容 */
|
|
|
+ transition: max-height 0.3s ease; /* 平滑过渡效果 */
|
|
|
+}
|
|
|
+</style>
|