<!-- @format -->

<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="类型" prop="cardType">
        <el-select
          v-model="queryParams.cardType"
          placeholder="请选择类型"
          clearable
        >
          <el-option
            v-for="dict in card_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="chineseName">
        <el-input v-model="queryParams.chineseName" placeholder="请输入申请人">
        </el-input>
      </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-table v-loading="loading" :data="formList">
      <el-table-column
        label="序号"
        width="100"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column
        label="申请人"
        align="center"
        prop="chineseName"
      ></el-table-column>
      <el-table-column label="证件类型" align="center">
        <template #default="scope">
          <dict-tag
            :options="zheng_jian_type"
            :value="scope.row.zhengJianType"
          />
        </template>
      </el-table-column>
      <el-table-column label="证件号" align="center" prop="idNum">
        <template #default="scope">
          <span
            >{{ maskIdNumber(scope.row.idNum, isIdView) }}
            <el-icon
              style="cursor: pointer"
              @click="isIdView = true"
              v-if="!isIdView"
              ><View />
            </el-icon>
            <el-icon style="cursor: pointer" @click="isIdView = false" v-else
              ><Hide
            /></el-icon>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center">
        <template #default="scope">
          <dict-tag :options="card_type" :value="scope.row.cardType" />
        </template>
      </el-table-column>
      <el-table-column label="申请编号" align="center" prop="sehnqingNumber" />

      <el-table-column
        label="申请时间"
        align="center"
        prop="createTime"
        width="180"
      >
      </el-table-column>

      <el-table-column label="状态" align="center">
        <template #default="scope">
          <el-tag type="warning">材料补正</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button type="text" icon="Edit" @click="handleView(scope.row)"
            >查看审批意见</el-button
          >
          <el-button type="text" @click="handleEdit(scope.row)" icon="Edit"
            >编辑</el-button
          >
          <el-button type="text" @click="handleDelete(scope.row)" icon="Edit"
            >删除</el-button
          >
        </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-dialog
      v-model="viewDia"
      title="查看详情"
      width="90%"
      :before-close="
        () => {
          viewDia = false;
        }
      "
    >
      <div style="margin: 20px 0px -30px 83px">
        <img :src="bytgImg" class="bysl" alt="" />
        <div class="title">审核结果：材料补正</div>
        <el-form>
          <el-form-item style="width: 350px" label="审核时间">
            <span>{{ applicationContent.createTime }}</span>
          </el-form-item>
          <el-form-item style="width: 350px" label="审核意见">
            <span>{{ applicationContent.auditOpinion }}</span>
          </el-form-item>
        </el-form>
        <div class="title">基本信息</div>
      </div>
      <AmatterClass
        :materialCalssId="atciveMaterial.id"
        :isDisabled="true"
      ></AmatterClass>
      <div style="margin-left: -61px">
        <div class="subheading">材料信息</div>
        <materialTable
          :materialCalssId="atciveMaterial.id"
          :isDisabled="true"
        ></materialTable>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="viewDia = false">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Form">
import {
  listForm,
  getApplicationState,
} from "@/api/talentApplication/draftBox";
import AmatterClass from "@/components/AmatterClass/index";
import materialTable from "@/components/materialTable/index";
import bytgImg from "@/assets/images/sp-clbz.png";
import { useRouter } from "vue-router";

import useUserStore from "@/store/modules/user.js";

const userStore = useUserStore();
const router = useRouter();
const { proxy } = getCurrentInstance();
const { card_type, zheng_jian_type } = proxy.useDict(
  "card_type",
  "yjrc_type",
  "politics_status",
  "zheng_jian_type"
);

const viewDia = ref(false);
const atciveMaterial = ref({});
const formList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const applicationContent = ref({});
const isIdView = ref(false);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    cardType: null,
    shenqingState: "clbz",
    chineseName: null,
  },
});

const { queryParams } = toRefs(data);

//查看正在审核的详情材料
const handleView = (row) => {
  atciveMaterial.value = row;
  getApplicationState({
    rclkApplicationFormId: row.id,
    shenheType: "clbz",
  }).then((res) => {
    viewDia.value = true;
    applicationContent.value = res.data;
  });
};

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm("是否确认删除选中的数据项？")
    .then(function () {
      return delForm(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}
/** 查询人才绿卡申请列表 */
function getList() {
  loading.value = true;
  listForm({ ...queryParams.value, sehnqingrenId: userStore.id }).then(
    (response) => {
      formList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    }
  );
}

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

const handleEdit = (row) => {
  router.push({
    path: "/materialApplication",
    query: {
      materialCalssId: row.id,
      type: row.cardType,
    },
  });
};
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

getList();
</script>
<style lang="scss" scoped>
.title {
  font-size: 16px;
  background: #ebf8fb;
  color: #0068d7;
  padding: 12px 0 12px 20px;
  margin-bottom: 30px;
  position: relative;
}
.subheading {
  color: #303133;
  font-size: 16px;
  font-weight: 700;
  margin: 0px 0 -37px 158px;
  position: relative;
}
.subheading::after {
  content: " ";
  display: inline-block;
  position: absolute;
  height: 100%;
  left: -9px;
  top: 50%;
  transform: translateY(-58%);
  background: #0e62fe;
  height: 16px;
  width: 3px;
}
.bysl {
  position: absolute;
  right: 10rem;
  z-index: 1;
}
</style>
