<template>
  <Dialog title="详情" v-model="dialogVisible" width="60%">
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="任务编号" prop="taskNumber">
            <el-input v-model="formData.taskNumber" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="保养类型" prop="maintenanceType">
            <el-select v-model="formData.maintenanceType" placeholder="请选择保养类型" disabled>
              <el-option
                v-for="dict in getIntDictOptions(DICT_TYPE.DEVICE_MAINTENANCE_TASK_TYPE)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="任务状态" prop="taskStatus">
            <el-select v-model="formData.taskStatus" placeholder="请选择任务状态" disabled>
              <el-option
                v-for="dict in getIntDictOptions(DICT_TYPE.DEVICE_MAINTENANCE_TASK_STATUS)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开始时间" prop="planStartTime">
            <el-input v-model="formData.planStartTime" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结束时间" prop="planEndTime">
            <el-input v-model="formData.planEndTime" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="执行时间" prop="actualStartTime">
            <el-input v-model="formData.actualStartTime" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="负责人" prop="responsibleName">
            <el-input v-model="formData.responsibleName" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="协同处理人" prop="collaboratorNames">
            <el-input v-model="formData.collaboratorNames" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="保养说明" prop="maintenanceInstructions">
            <el-input v-model="formData.maintenanceInstructions" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="验收时间" prop="updateTime">
            <el-input v-model="formData.updateTime" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="创建时间" prop="createTime">
            <el-input v-model="formData.createTime" disabled />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import dayjs from 'dayjs'
import { ref } from 'vue'
/** 设备巡检班组 表单 */
defineOptions({ name: 'DetailForm' })

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改

const staffList = ref([]) // 用户列表
const selectedStaff = ref([]) // 选中的用户

const formData = ref({
  id: undefined,
  teamName: undefined,
  teamStaffIds: undefined,
  teamStaffNames: undefined,
  state: undefined,
  sort: undefined
})
const formRules = reactive({})
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (type, row) => {
  dialogVisible.value = true
  formType.value = type
  Object.keys(row).forEach((item) => {
    const arr = ['planStartTime', 'planEndTime', 'actualStartTime', 'updateTime', 'createTime']
    if (arr.includes(item) && row[item]) {
      row[item] = dayjs(row[item]).format('YYYY-M-D HH:mm:ss')
    }
  })
  formData.value = row
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
