吉安感知网项目-前端
shuishen
2026-02-03 89380e6260a75d1d3b94de687ebcc2f50d50659d
applications/drone-command/src/views/basicManage/maintainRecord/FormDiaLog.vue
@@ -2,10 +2,10 @@
 * @Author       : yuan
 * @Date         : 2026-01-20 14:04:02
 * @LastEditors  : yuan
 * @LastEditTime : 2026-01-20 14:19:54
 * @LastEditTime : 2026-01-20 16:38:55
 * @FilePath     : \applications\drone-command\src\views\basicManage\maintainRecord\FormDiaLog.vue
 * @Description  :
 * Copyright 2026 OBKoro1, All Rights Reserved.
 * @Description  :
 * Copyright 2026 OBKoro1, All Rights Reserved.
 * 2026-01-20 14:04:02
-->
<template>
@@ -44,7 +44,7 @@
            </el-col>
            <el-col :span="12">
               <div class="label">维护时间</div>
               <div class="val">{{ list?.[0]?.maintainTime }}</div>
               <div class="val">{{ dayjs(list?.[0]?.maintainTime).format('YYYY-MM-DD') }}</div>
            </el-col>
            <el-col :span="12">
               <div class="label">维护内容</div>
@@ -61,16 +61,20 @@
            <div class="command-table-content">
               <el-table class="command-table" :data="list">
                  <el-table-column type="index" width="60" label="序号" />
                  <el-table-column prop="maintainTime" label="维护时间" />
                  <el-table-column prop="maintainTime" show-overflow-tooltip label="维护时间">
                     <template v-slot="{ row }">
                        {{ dayjs(row.maintainTime).format('YYYY-MM-DD') }}
                     </template>
                  </el-table-column>
                  <el-table-column prop="maintainContent" label="维护内容" />
                  <el-table-column prop="replacePart" label="跟换部件" />
               </el-table>
            </div>
            <div class="command-table-pagination">
               <el-pagination popper-class="command-select-popper"
                  v-model:current-page="searchParams.current" v-model:page-size="searchParams.size"
                  layout="total, prev, pager, next, sizes" :total="total" @change="getList" />
               <el-pagination popper-class="command-select-popper" v-model:current-page="searchParams.current"
                  v-model:page-size="searchParams.size" layout="total, prev, pager, next, sizes" :total="total"
                  @change="getList" />
            </div>
         </div>
      </div>
@@ -98,17 +102,42 @@
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="维护计划时间" prop="planCycleValue">
                  <el-date-picker class="command-date-picker" popper-class="command-date-picker-popper"
                     v-model="formData.planCycleValue" type="date" placeholder="请选择" clearable
                     value-format="YYYY-MM-DD" :format="planCycleDateFormat" :disabled="!formData.planCycleType"
                     :disabled-date="getPlanCycleDisabledDate" :editable="false" />
               <el-form-item label="维护计划时间" prop="planCycleValue" >
                  <el-date-picker
                     v-if="formData.planCycleType === '1'"
                     :disabled="!formData.planCycleType"
                     class="command-date-picker"
                     popper-class="command-date-picker-popper"
                     v-model="formData.planCycleValue"
                     type="date"
                     placeholder="请选择"
                     clearable
                     value-format="YYYY-MM-DD"
                     :format="planCycleDateFormat"
                     :disabled-date="getPlanCycleDisabledDate"
                     :editable="false" />
                  <el-select
                     v-else
                     :disabled="!formData.planCycleType"
                     class="command-select"
                     popper-class="command-select-popper"
                     v-model="formData.planCycleValue"
                     placeholder="请选择"
                     clearable
                  >
                     <el-option
                        v-for="item in planCycleValueOptions"
                        :key="item.value"
                        :label="item.value"
                        :value="item.value"
                     />
                  </el-select>
               </el-form-item>
            </el-col>
         </el-row>
      </el-form>
      <template #footer>
         <el-button color="#2B2B4C" @click="handleCancel">{{ dialogReadonly ? '关闭' : '取消' }}</el-button>
         <el-button v-if="dialogMode != 'view'" color="#2B2B4C" @click="handleCancel">{{ dialogReadonly ? '关闭' : '取消' }}</el-button>
         <el-button color="#284FE3" v-if="!dialogReadonly" type="primary" :loading="submitting"
            :disabled="submitting" @click="handleSubmit">
            保存
@@ -124,6 +153,8 @@
import { ElMessage } from 'element-plus'
import { fieldRules, getDictLabel } from '@ztzf/utils'
import { fwDeviceMaintainRecordPageApi } from '@/views/basicManage/maintainRecord/fwDeviceMaintainRecord'
import { saveOperationLog } from '@ztzf/apis'
import { useRoute } from 'vue-router'
import {
   fwDeviceMaintainPlanDetailApi,
   fwDeviceMaintainPlanSubmitApi,
@@ -139,6 +170,7 @@
dayjs.locale('zh-cn')
const planCycleOptions = inject('planCycleOptions')
const planCycleValueOptions = ref([])
const emit = defineEmits(['success'])
const formRef = ref(null) // 表单实例
@@ -149,6 +181,7 @@
const deviceList = ref([]) // 设备列表
const getPlanCycleLabel = inject('getPlanCycleLabel')
const dictObj = inject('dictObj')
const route = useRoute()
const dialogReadonly = computed(() => dialogMode.value === 'view')
const titleEnum = ref({ edit: '编辑', view: '查看', add: '维护计划' })
@@ -168,19 +201,42 @@
}
// 获取设备列表
function getDeviceList() {
function getDeviceList () {
   return fwDevicePageApi({ current: 1, size: 999 }).then(res => {
      deviceList.value = res?.data?.data?.records ?? []
   })
}
// 关闭弹框
function handleCancel() {
function handleCancel () {
   visible.value = false
}
watch(
   () => formData.value?.planCycleType,
   type => {
      planCycleValueOptions.value = []
      if (!type) return
      if (type === '1') {
         ;[...Array(12)].forEach((item, index) => {
            ;[...Array(31)].forEach((item1, index1) => {
               planCycleValueOptions.value.push({ value: `${index + 1}月${index1 + 1}号` })
            })
         })
      } else if (type === '2') {
         ;[...Array(31)].forEach((item, index) => {
            planCycleValueOptions.value.push({ value: `${index + 1}号` })
         })
      } else if (type === '3') {
         ;['一', '二', '三', '四', '五', '六', '日'].forEach((item, index) => {
            planCycleValueOptions.value.push({ value: `星期${item}` })
         })
      }
   }
)
// 提交新增/编辑
async function handleSubmit() {
async function handleSubmit () {
   const isValid = await formRef.value?.validate().catch(() => false)
   if (!isValid) return
   submitting.value = true
@@ -193,6 +249,12 @@
         )],
      }
      await fwDeviceMaintainPlanSubmitApi(payload)
      const actionText = dialogMode.value === 'add' ? '维护计划-新增' : '维护计划-编辑'
      saveOperationLog({
         requestUri: route.path,
         title: `${route.name || '维护记录管理'}-${actionText}`,
         type: 1
      })
      ElMessage.success(dialogMode.value === 'add' ? '新增成功' : '更新成功')
      visible.value = false
      emit('success')
@@ -202,7 +264,7 @@
}
// 加载详情
async function loadDetail() {
async function loadDetail () {
   if (!formData.value.id) return
   const res = await fwDeviceMaintainPlanDetailApi({ id: formData.value.id })
   const data = res?.data?.data ?? {}
@@ -214,7 +276,7 @@
}
// 关闭后重置
function handleClosed() {
function handleClosed () {
   formData.value = initForm()
}
@@ -226,7 +288,7 @@
const total = ref(0) // 总条数
const loading = ref(true) // 列表加载中
const list = ref([]) // 列表数据
async function getList() {
async function getList () {
   loading.value = true
   try {
      const params = { ...searchParams.value, planId: formData.value.id }
@@ -239,7 +301,7 @@
}
// 打开弹框
async function open({ mode, row } = {}) {
async function open ({ mode, row } = {}) {
   dialogMode.value = mode || 'add'
   visible.value = true
   await getDeviceList()
@@ -252,14 +314,14 @@
   }
}
function toDateString(date) {
function toDateString (date) {
   const year = date.getFullYear()
   const month = String(date.getMonth() + 1).padStart(2, '0')
   const day = String(date.getDate()).padStart(2, '0')
   return `${year}-${month}-${day}`
}
function formatPlanCycleValue(value, type) {
function formatPlanCycleValue (value, type) {
   if (typeof value !== 'string') return value
   if (!value.includes('-')) return value
   const date = new Date(value)
@@ -274,7 +336,7 @@
   return value
}
function normalizePlanCycleValue(value, type) {
function normalizePlanCycleValue (value, type) {
   if (!value) return ''
   const now = new Date()
   if (typeof value !== 'string') return ''
@@ -304,7 +366,7 @@
   return value
}
function getWeekRange(date) {
function getWeekRange (date) {
   const base = new Date(date.getFullYear(), date.getMonth(), date.getDate())
   const day = base.getDay()
   const diff = day === 0 ? -6 : 1 - day
@@ -317,7 +379,7 @@
   return { start, end }
}
function getPlanCycleDisabledDate(date) {
function getPlanCycleDisabledDate (date) {
   const type = formData.value.planCycleType
   if (!type) return false
   const now = new Date()