<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"
              label-width="130px"
            >
              <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="NAME"
          label="设备管道名称"
          show-overflow-tooltip
        />
        <el-table-column prop="CHECK_NO" label="编号" show-overflow-tooltip />
        <el-table-column prop="APPLY_USER_NAME" label="申请人" width="100" />
        <el-table-column prop="APPLY_DEPARTMENT_NAME" label="申请部门" />
        <el-table-column
          prop="CONSTRUCTION_USER_NAME"
          label="作业负责人"
          show-overflow-tooltip
        />
        <el-table-column
          prop="LEADER_USER_NAME"
          label="所在单位负责人"
          show-overflow-tooltip
        />
        <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'
                      ? '/blind_plate_plugging/job_data/view'
                      : '/blind_plate_plugging/archive/view',
                  query: { BLINDBOARD_ID: row.BLINDBOARD_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 { getBlindPlatePluggingList } from "@/request/blind_plate_plugging.js";

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

<style scoped></style>
