<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="维修工单实例节点ID" prop="instanceActivityId">
              <el-input v-model="queryParams.instanceActivityId" placeholder="请输入维修工单实例节点ID" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="故障报修工单ID，关联故障报修工单主键" prop="repairInstanceId">
              <el-input v-model="queryParams.repairInstanceId" placeholder="请输入故障报修工单ID，关联故障报修工单主键" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="流程定义ID,关联wf_definition_config的id" prop="wfDefinitionId">
              <el-input v-model="queryParams.wfDefinitionId" placeholder="请输入流程定义ID,关联wf_definition_config的id" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="工单流程节点ID" prop="wfNodeId">
              <el-input v-model="queryParams.wfNodeId" placeholder="请输入工单流程节点ID" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="故障类型(1外部故障 2内部故障);最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="faultType">
              <el-select v-model="queryParams.faultType" placeholder="请选择故障类型(1外部故障 2内部故障);最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" clearable >
                <el-option v-for="dict in activity_fault_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
            <el-form-item label="故障描述;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="faultDescription">
              <el-input v-model="queryParams.faultDescription" placeholder="请输入故障描述;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="涉及操作，关联数据字典，可以选择多个;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="designOperations">
              <el-input v-model="queryParams.designOperations" placeholder="请输入涉及操作，关联数据字典，可以选择多个;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="设备ID，关联prod_base_machine_info的machine_id" prop="machineId">
              <el-input v-model="queryParams.machineId" placeholder="请输入设备ID，关联prod_base_machine_info的machine_id" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="维修类型" prop="repairType">
              <el-select v-model="queryParams.repairType" placeholder="请选择维修类型" clearable >
                <el-option v-for="dict in fault_repair_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
            <el-form-item label="外协单位，关联dms_base_outsourcing_info的outsourcing_id;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="outsourcingId">
              <el-input v-model="queryParams.outsourcingId" placeholder="请输入外协单位，关联dms_base_outsourcing_info的outsourcing_id;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="处理意见;第一步不显示，从第2个步骤开始显示此字段" prop="processHandleResolution">
              <el-input v-model="queryParams.processHandleResolution" placeholder="请输入处理意见;第一步不显示，从第2个步骤开始显示此字段" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="状态(0已结束 1执行中 2待接取 3已转发）" prop="processHandleStatus">
              <el-select v-model="queryParams.processHandleStatus" placeholder="请选择状态(0已结束 1执行中 2待接取 3已转发）" clearable >
                <el-option v-for="dict in process_handle_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
            <el-form-item label="工单流程步骤顺序" prop="processStepOrder">
              <el-input v-model="queryParams.processStepOrder" placeholder="请输入工单流程步骤顺序" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="执行开始时间" prop="startTime">
              <el-date-picker clearable
                v-model="queryParams.startTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择执行开始时间"
              />
            </el-form-item>
            <el-form-item label="执行结束时间" prop="endTime">
              <el-date-picker clearable
                v-model="queryParams.endTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择执行结束时间"
              />
            </el-form-item>
            <el-form-item label="处理人ID" prop="handleUserId">
              <el-input v-model="queryParams.handleUserId" placeholder="请输入处理人ID" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="处理人" prop="handleBy">
              <el-input v-model="queryParams.handleBy" placeholder="请输入处理人" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="处理时间" prop="handleTime">
              <el-date-picker clearable
                v-model="queryParams.handleTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择处理时间"
              />
            </el-form-item>
            <el-form-item label="转单人用户id或转发协助用户id" prop="transferUserId">
              <el-input v-model="queryParams.transferUserId" placeholder="请输入转单人用户id或转发协助用户id" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="检查后的故障判断" prop="checkedFault">
              <el-input v-model="queryParams.checkedFault" placeholder="请输入检查后的故障判断" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="维修措施" prop="protectedMethod">
              <el-input v-model="queryParams.protectedMethod" placeholder="请输入维修措施" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="维修人" prop="repairer">
              <el-input v-model="queryParams.repairer" placeholder="请输入维修人" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="维修结果" prop="repairConfirm">
              <el-select v-model="queryParams.repairConfirm" placeholder="请选择维修结果" clearable >
                <el-option v-for="dict in fault_repair_confirm" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
            <el-form-item label="确认时间" prop="confirmTime">
              <el-date-picker clearable
                v-model="queryParams.confirmTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择确认时间"
              />
            </el-form-item>
            <el-form-item label="关联更换零部件内容" prop="componentsPartsId">
              <el-input v-model="queryParams.componentsPartsId" placeholder="请输入关联更换零部件内容" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['dms:dmsFaultInstanceActivity:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['dms:dmsFaultInstanceActivity:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['dms:dmsFaultInstanceActivity:remove']">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['dms:dmsFaultInstanceActivity:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" :columns="columns" :search="true" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="dmsFaultInstanceActivityList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="维修工单实例节点ID" align="center" prop="instanceActivityId" v-if="columns[0].visible"/>
        <el-table-column label="故障报修工单ID，关联故障报修工单主键" align="center" prop="repairInstanceId" v-if="columns[2].visible"/>
        <el-table-column label="流程定义ID,关联wf_definition_config的id" align="center" prop="wfDefinitionId" v-if="columns[3].visible"/>
        <el-table-column label="工单流程节点ID" align="center" prop="wfNodeId" v-if="columns[4].visible"/>
        <el-table-column label="故障类型(1外部故障 2内部故障);最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" align="center" prop="faultType" v-if="columns[5].visible">
          <template #default="scope">
            <dict-tag :options="activity_fault_type" :value="scope.row.faultType"/>
          </template>
        </el-table-column>
        <el-table-column label="故障描述;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" align="center" prop="faultDescription" v-if="columns[6].visible"/>
        <el-table-column label="涉及操作，关联数据字典，可以选择多个;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" align="center" prop="designOperations" v-if="columns[7].visible"/>
        <el-table-column label="设备ID，关联prod_base_machine_info的machine_id" align="center" prop="machineId" v-if="columns[8].visible"/>
        <el-table-column label="维修类型" align="center" prop="repairType" v-if="columns[9].visible">
          <template #default="scope">
            <dict-tag :options="fault_repair_type" :value="scope.row.repairType"/>
          </template>
        </el-table-column>
        <el-table-column label="外协单位，关联dms_base_outsourcing_info的outsourcing_id;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" align="center" prop="outsourcingId" v-if="columns[10].visible"/>
        <el-table-column label="处理意见;第一步不显示，从第2个步骤开始显示此字段" align="center" prop="processHandleResolution" v-if="columns[11].visible"/>
        <el-table-column label="备注" align="center" prop="remark" v-if="columns[12].visible"/>
        <el-table-column label="状态(0已结束 1执行中 2待接取 3已转发）" align="center" prop="processHandleStatus" v-if="columns[13].visible">
          <template #default="scope">
            <dict-tag :options="process_handle_status" :value="scope.row.processHandleStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="工单流程步骤顺序" align="center" prop="processStepOrder" v-if="columns[14].visible"/>
        <el-table-column label="执行开始时间" align="center" prop="startTime" width="180" v-if="columns[15].visible">
          <template #default="scope">
            <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="执行结束时间" align="center" prop="endTime" width="180" v-if="columns[16].visible">
          <template #default="scope">
            <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="处理人ID" align="center" prop="handleUserId" v-if="columns[17].visible"/>
        <el-table-column label="处理人" align="center" prop="handleBy" v-if="columns[18].visible"/>
        <el-table-column label="处理时间" align="center" prop="handleTime" width="180" v-if="columns[19].visible">
          <template #default="scope">
            <span>{{ parseTime(scope.row.handleTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="转单人用户id或转发协助用户id" align="center" prop="transferUserId" v-if="columns[20].visible"/>
        <el-table-column label="检查后的故障判断" align="center" prop="checkedFault" v-if="columns[21].visible"/>
        <el-table-column label="维修内容" align="center" prop="repairContent" v-if="columns[22].visible"/>
        <el-table-column label="维修措施" align="center" prop="protectedMethod" v-if="columns[23].visible"/>
        <el-table-column label="维修人" align="center" prop="repairer" v-if="columns[24].visible"/>
        <el-table-column label="维修结果" align="center" prop="repairConfirm" v-if="columns[25].visible">
          <template #default="scope">
            <dict-tag :options="fault_repair_confirm" :value="scope.row.repairConfirm"/>
          </template>
        </el-table-column>
        <el-table-column label="确认时间" align="center" prop="confirmTime" width="180" v-if="columns[26].visible">
          <template #default="scope">
            <span>{{ parseTime(scope.row.confirmTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="关联更换零部件内容" align="center" prop="componentsPartsId" v-if="columns[27].visible"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['dms:dmsFaultInstanceActivity:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['dms:dmsFaultInstanceActivity:remove']"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <!-- 添加或修改故障报修工单实例节点对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
      <el-form ref="dmsFaultInstanceActivityFormRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="维修工单实例节点ID" prop="instanceActivityId">
          <el-input v-model="form.instanceActivityId" placeholder="请输入维修工单实例节点ID" />
        </el-form-item>
        <el-form-item label="故障报修工单ID，关联故障报修工单主键" prop="repairInstanceId">
          <el-input v-model="form.repairInstanceId" placeholder="请输入故障报修工单ID，关联故障报修工单主键" />
        </el-form-item>
        <el-form-item label="流程定义ID,关联wf_definition_config的id" prop="wfDefinitionId">
          <el-input v-model="form.wfDefinitionId" placeholder="请输入流程定义ID,关联wf_definition_config的id" />
        </el-form-item>
        <el-form-item label="工单流程节点ID" prop="wfNodeId">
          <el-input v-model="form.wfNodeId" placeholder="请输入工单流程节点ID" />
        </el-form-item>
        <el-form-item label="故障类型(1外部故障 2内部故障);最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="faultType">
          <el-select v-model="form.faultType" placeholder="请选择故障类型(1外部故障 2内部故障);最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的">
            <el-option
                v-for="dict in activity_fault_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="故障描述;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="faultDescription">
          <el-input v-model="form.faultDescription" placeholder="请输入故障描述;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" />
        </el-form-item>
        <el-form-item label="涉及操作，关联数据字典，可以选择多个;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="designOperations">
          <el-input v-model="form.designOperations" placeholder="请输入涉及操作，关联数据字典，可以选择多个;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" />
        </el-form-item>
        <el-form-item label="设备ID，关联prod_base_machine_info的machine_id" prop="machineId">
          <el-input v-model="form.machineId" placeholder="请输入设备ID，关联prod_base_machine_info的machine_id" />
        </el-form-item>
        <el-form-item label="维修类型" prop="repairType">
          <el-select v-model="form.repairType" placeholder="请选择维修类型">
            <el-option
                v-for="dict in fault_repair_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="外协单位，关联dms_base_outsourcing_info的outsourcing_id;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" prop="outsourcingId">
          <el-input v-model="form.outsourcingId" placeholder="请输入外协单位，关联dms_base_outsourcing_info的outsourcing_id;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的" />
        </el-form-item>
        <el-form-item label="处理意见;第一步不显示，从第2个步骤开始显示此字段" prop="processHandleResolution">
          <el-input v-model="form.processHandleResolution" placeholder="请输入处理意见;第一步不显示，从第2个步骤开始显示此字段" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="状态(0已结束 1执行中 2待接取 3已转发）" prop="processHandleStatus">
          <el-select v-model="form.processHandleStatus" placeholder="请选择状态(0已结束 1执行中 2待接取 3已转发）">
            <el-option
                v-for="dict in process_handle_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工单流程步骤顺序" prop="processStepOrder">
          <el-input v-model="form.processStepOrder" placeholder="请输入工单流程步骤顺序" />
        </el-form-item>
        <el-form-item label="执行开始时间" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择执行开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="执行结束时间" prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择执行结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理人ID" prop="handleUserId">
          <el-input v-model="form.handleUserId" placeholder="请输入处理人ID" />
        </el-form-item>
        <el-form-item label="处理人" prop="handleBy">
          <el-input v-model="form.handleBy" placeholder="请输入处理人" />
        </el-form-item>
        <el-form-item label="处理时间" prop="handleTime">
          <el-date-picker clearable
            v-model="form.handleTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="转单人用户id或转发协助用户id" prop="transferUserId">
          <el-input v-model="form.transferUserId" placeholder="请输入转单人用户id或转发协助用户id" />
        </el-form-item>
        <el-form-item label="检查后的故障判断" prop="checkedFault">
          <el-input v-model="form.checkedFault" placeholder="请输入检查后的故障判断" />
        </el-form-item>
        <el-form-item label="维修内容">
          <editor v-model="form.repairContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="维修措施" prop="protectedMethod">
          <el-input v-model="form.protectedMethod" placeholder="请输入维修措施" />
        </el-form-item>
        <el-form-item label="维修人" prop="repairer">
          <el-input v-model="form.repairer" placeholder="请输入维修人" />
        </el-form-item>
        <el-form-item label="维修结果" prop="repairConfirm">
          <el-select v-model="form.repairConfirm" placeholder="请选择维修结果">
            <el-option
                v-for="dict in fault_repair_confirm"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="确认时间" prop="confirmTime">
          <el-date-picker clearable
            v-model="form.confirmTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择确认时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关联更换零部件内容" prop="componentsPartsId">
          <el-input v-model="form.componentsPartsId" placeholder="请输入关联更换零部件内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="DmsFaultInstanceActivity" lang="ts">
import { listDmsFaultInstanceActivity, getDmsFaultInstanceActivity, delDmsFaultInstanceActivity, addDmsFaultInstanceActivity, updateDmsFaultInstanceActivity } from '@/api/dms/dmsFaultInstanceActivity';
import { DmsFaultInstanceActivityVO, DmsFaultInstanceActivityQuery, DmsFaultInstanceActivityForm } from '@/api/dms/dmsFaultInstanceActivity/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { fault_repair_type, activity_fault_type, fault_repair_confirm, process_handle_status } = toRefs<any>(proxy?.useDict('fault_repair_type', 'activity_fault_type', 'fault_repair_confirm', 'process_handle_status'));

const dmsFaultInstanceActivityList = ref<DmsFaultInstanceActivityVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const dmsFaultInstanceActivityFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

// 列显隐信息
const columns = ref<FieldOption[]>([
        { key: 0, label: `维修工单实例节点ID`, visible: true },
        { key: 1, label: `租户编号`, visible: true },
        { key: 2, label: `故障报修工单ID，关联故障报修工单主键`, visible: true },
        { key: 3, label: `流程定义ID,关联wf_definition_config的id`, visible: true },
        { key: 4, label: `工单流程节点ID`, visible: true },
        { key: 5, label: `故障类型(1外部故障 2内部故障);最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的`, visible: true },
        { key: 6, label: `故障描述;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的`, visible: true },
        { key: 7, label: `涉及操作，关联数据字典，可以选择多个;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的`, visible: true },
        { key: 8, label: `设备ID，关联prod_base_machine_info的machine_id`, visible: true },
        { key: 9, label: `维修类型`, visible: true },
        { key: 10, label: `外协单位，关联dms_base_outsourcing_info的outsourcing_id;最后一步自动复制第1步的，可在第2步修改，修改保存后为第2步的记录，第1步为要求的，第2步为实际的`, visible: true },
        { key: 11, label: `处理意见;第一步不显示，从第2个步骤开始显示此字段`, visible: true },
        { key: 12, label: `备注`, visible: true },
        { key: 13, label: `状态(0已结束 1执行中 2待接取 3已转发）`, visible: true },
        { key: 14, label: `工单流程步骤顺序`, visible: true },
        { key: 15, label: `执行开始时间`, visible: true },
        { key: 16, label: `执行结束时间`, visible: true },
        { key: 17, label: `处理人ID`, visible: true },
        { key: 18, label: `处理人`, visible: true },
        { key: 19, label: `处理时间`, visible: true },
        { key: 20, label: `转单人用户id或转发协助用户id`, visible: true },
        { key: 21, label: `检查后的故障判断`, visible: true },
        { key: 22, label: `维修内容`, visible: true },
        { key: 23, label: `维修措施`, visible: true },
        { key: 24, label: `维修人`, visible: true },
        { key: 25, label: `维修结果`, visible: true },
        { key: 26, label: `确认时间`, visible: true },
        { key: 27, label: `关联更换零部件内容`, visible: true },
        { key: 28, label: `创建部门`, visible: true },
        { key: 29, label: `创建人`, visible: true },
        { key: 30, label: `创建时间`, visible: true },
        { key: 31, label: `更新人`, visible: true },
        { key: 32, label: `更新时间`, visible: true },
]);

const initFormData: DmsFaultInstanceActivityForm = {
  instanceActivityId: undefined,
  repairInstanceId: undefined,
  wfDefinitionId: undefined,
  wfNodeId: undefined,
  faultType: undefined,
  faultDescription: undefined,
  designOperations: undefined,
  machineId: undefined,
  repairType: undefined,
  outsourcingId: undefined,
  processHandleResolution: undefined,
  remark: undefined,
  processHandleStatus: undefined,
  processStepOrder: undefined,
  startTime: undefined,
  endTime: undefined,
  handleUserId: undefined,
  handleBy: undefined,
  handleTime: undefined,
  transferUserId: undefined,
  checkedFault: undefined,
  repairContent: undefined,
  protectedMethod: undefined,
  repairer: undefined,
  repairConfirm: undefined,
  confirmTime: undefined,
  componentsPartsId: undefined,
}
const data = reactive<PageData<DmsFaultInstanceActivityForm, DmsFaultInstanceActivityQuery>>({
  form: {...initFormData},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    instanceActivityId: undefined,
    repairInstanceId: undefined,
    wfDefinitionId: undefined,
    wfNodeId: undefined,
    faultType: undefined,
    faultDescription: undefined,
    designOperations: undefined,
    machineId: undefined,
    repairType: undefined,
    outsourcingId: undefined,
    processHandleResolution: undefined,
    processHandleStatus: undefined,
    processStepOrder: undefined,
    startTime: undefined,
    endTime: undefined,
    handleUserId: undefined,
    handleBy: undefined,
    handleTime: undefined,
    transferUserId: undefined,
    checkedFault: undefined,
    repairContent: undefined,
    protectedMethod: undefined,
    repairer: undefined,
    repairConfirm: undefined,
    confirmTime: undefined,
    componentsPartsId: undefined,
    params: {
    }
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询故障报修工单实例节点列表 */
const getList = async () => {
  loading.value = true;
  const res = await listDmsFaultInstanceActivity(queryParams.value);
  dmsFaultInstanceActivityList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
}

/** 表单重置 */
const reset = () => {
  form.value = {...initFormData};
  dmsFaultInstanceActivityFormRef.value?.resetFields();
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
}

/** 多选框选中数据 */
const handleSelectionChange = (selection: DmsFaultInstanceActivityVO[]) => {
  ids.value = selection.map(item => item.instanceActivityId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = "添加故障报修工单实例节点";
}

/** 修改按钮操作 */
const handleUpdate = async (row?: DmsFaultInstanceActivityVO) => {
  reset();
  const _instanceActivityId = row?.instanceActivityId || ids.value[0]
  const res = await getDmsFaultInstanceActivity(_instanceActivityId);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  dialog.title = "修改故障报修工单实例节点";
}

/** 提交按钮 */
const submitForm = () => {
  dmsFaultInstanceActivityFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.instanceActivityId) {
        await updateDmsFaultInstanceActivity(form.value).finally(() =>  buttonLoading.value = false);
      } else {
        await addDmsFaultInstanceActivity(form.value).finally(() =>  buttonLoading.value = false);
      }
      proxy?.$modal.msgSuccess("操作成功");
      dialog.visible = false;
      await getList();
    }
  });
}

/** 删除按钮操作 */
const handleDelete = async (row?: DmsFaultInstanceActivityVO) => {
  const _instanceActivityIds = row?.instanceActivityId || ids.value;
  await proxy?.$modal.confirm('是否确认删除故障报修工单实例节点编号为"' + _instanceActivityIds + '"的数据项？').finally(() => loading.value = false);
  await delDmsFaultInstanceActivity(_instanceActivityIds);
  proxy?.$modal.msgSuccess("删除成功");
  await getList();
}

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download('dms/dmsFaultInstanceActivity/export', {
    ...queryParams.value
  }, `dmsFaultInstanceActivity_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getList();
});
</script>
