<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="编号" show-overflow-tooltip />
        <el-table-column prop="LEADER_DEPARTMENT_NAME" label="作业单位" />
        <el-table-column
          prop="LEADER_USER_NAME"
          label="作业指挥负责人"
          show-overflow-tooltip
        />
        <el-table-column label="所在单位负责人" show-overflow-tooltip>
          <template v-slot="{ row }">
            {{ row.CONSTRUCTION_USER_NAME || " 已跳过" }}
          </template>
        </el-table-column>
        <el-table-column label="审核部门负责人" show-overflow-tooltip>
          <template v-slot="{ row }">
            {{ row.AUDIT_USER_NAME || " 已跳过" }}
          </template>
        </el-table-column>
        <el-table-column label="审批部门负责人" show-overflow-toolti>
          <template v-slot="{ row }">
            {{ row.APPROVE_USER_NAME || " 已跳过" }}
          </template>
        </el-table-column>
        <el-table-column
          prop="ACCEPT_USER_NAME"
          label="验收部门负责人"
          show-overflow-tooltip
        />
        <el-table-column label="审核状态">
          <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'
                      ? '/hoisting/job_data/view'
                      : '/hoisting/archive/view',
                  query: { HOISTING_ID: row.HOISTING_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 { getHoistingList } from "@/request/hoisting.js";

const props = defineProps({
  entrance: {
    type: String,
    default: "job_data",
  },
});
const stateList = [
  { ID: "0", NAME: "吊装作业待提交" },
  { ID: "1", NAME: "作业指挥待审核" },
  { ID: "2", NAME: "所在单位待审核" },
  { ID: "3", NAME: "审核部门待审核" },
  { ID: "4", NAME: "审批部门待审核" },
  { ID: "5", NAME: "待验收" },
  { ID: "6", NAME: "验收归档" },
  { ID: "-2", NAME: "作业指挥审核打回" },
  { ID: "-3", NAME: "所在单位审核打回" },
  { ID: "-4", NAME: "审核部门审核打回" },
  { ID: "-5", NAME: "审批部门审核打回" },
  { ID: "-6", NAME: "验收打回" },
];
const router = useRouter();
const listData = useListData(getHoistingList, {
  otherParams: props.entrance === "archive" ? { APPLY_STATUS: "6" } : {},
});
const { list, pagination, searchForm, fnGetData, fnResetPagination } = listData;
const data = reactive({
  flowChartDialog: {
    visible: false,
    info: {},
  },
});
const fnFlowChart = (info) => {
  data.flowChartDialog.visible = true;
  data.flowChartDialog.info = info;
};
</script>

<style scoped></style>
