<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="50px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="编号" prop="KEYWORDS">
              <el-input
                v-model="searchForm.KEYWORDS"
                placeholder="请输入关键字"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="entrance === 'job_data'">
            <el-form-item label="状态" prop="APPLY_STATUS">
              <el-select v-model="searchForm.APPLY_STATUS">
                <el-option
                  v-for="item in stateList"
                  :key="item.ID"
                  :label="item.NAME"
                  :value="item.ID"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPagination">
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        :data="list"
        v-model:pagination="pagination"
        @get-data="fnGetData"
      >
        <el-table-column label="序号" width="70">
          <template v-slot="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="CHECK_NO" label="编号" />
        <el-table-column prop="WORK_LEVEL" label="作业级别" />
        <el-table-column prop="APPLY_USER_NAME" label="申请人" />
        <el-table-column prop="ANALYZE_USER_NAME" label="分析人" />
        <el-table-column prop="CONFIRM_USER_NAME" label="作业负责人" />
        <el-table-column prop="LEADER_USER_NAME" label="所在单位负责人" />
        <el-table-column
          label="安全管理部门负责人"
          show-overflow-tooltip
          width="150"
        >
          <template v-slot="{ row }">
            {{ row.AUDIT_USER_NAME || " 已跳过" }}
          </template>
        </el-table-column>
        <el-table-column label="动火审批人" show-overflow-tooltip>
          <template v-slot="{ row }">
            {{ row.APPROVE_USER_NAME || " 已跳过" }}
          </template>
        </el-table-column>
        <el-table-column prop="MONITOR_USER_NAME" label="动火前在岗班长" />
        <el-table-column prop="ACCEPT_USER_NAME" label="验收部门负责人" />
        <el-table-column label="审核状态" width="170">
          <template v-slot="{ row }">
            {{
              entrance === "job_data"
                ? translationStatus(row.APPLY_STATUS, stateList)
                : "已归档"
            }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template v-slot="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="fnFlowChart(row)"
              v-if="entrance === 'job_data'"
            >
              流程图
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path:
                    props.entrance === 'job_data'
                      ? '/hot_work/job_data/view'
                      : '/hot_work/archive/view',
                  query: { HOTWORK_ID: row.HOTWORK_ID, entrance },
                })
              "
            >
              审批表详情
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
    <flow-chart
      v-model:visible="data.flowChartDialog.visible"
      :info="data.flowChartDialog.info"
    />
  </div>
</template>

<script setup>
import { serialNumber, translationStatus } from "@/assets/js/utils.js";
import { useRouter } from "vue-router";
import useListData from "@/assets/js/useListData.js";
import { reactive } from "vue";
import FlowChart from "./components/flow_chart.vue";
import { getHotWorkList } from "@/request/hot_work.js";

const props = defineProps({
  entrance: {
    type: String,
    default: "job_data",
  },
});
const stateList = [
  { ID: "0", NAME: "动火作业待提交" },
  { ID: "1", NAME: "作业负责人待审核" },
  { ID: "2", NAME: "所在单位待审核" },
  { ID: "4", NAME: "安全管理部门待审核" },
  { ID: "5", NAME: "动火审批人待审核" },
  { ID: "6", NAME: "班长待验票" },
  { ID: "7", NAME: "待验收" },
  { ID: "8", NAME: "验收归档" },
  { ID: "-2", NAME: "作业负责人审核打回" },
  { ID: "-4", NAME: "所在单位审核打回" },
  { ID: "-5", NAME: "安全管理部门审核打回" },
  { ID: "-6", NAME: "动火审批人审核打回" },
  { ID: "-7", NAME: "班长验票打回" },
  { ID: "-8", NAME: "验收打回" },
  { ID: "-99", NAME: "已作废(班长未验票)" },
  { ID: "-98", NAME: "已作废(未进行气体检测)" },
];
const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getHotWorkList, {
    otherParams: props.entrance === "archive" ? { APPLY_STATUS: "8" } : {},
  });
const data = reactive({
  flowChartDialog: {
    visible: false,
    info: {},
  },
});
const fnFlowChart = (info) => {
  data.flowChartDialog.visible = true;
  data.flowChartDialog.info = info;
};
</script>

<style scoped></style>
