<!-- @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, scope.row.isIdView) }}
            <el-icon
              style="cursor: pointer"
              @click="scope.row.isIdView = true"
              v-if="!scope.row.isIdView"
              ><View />
            </el-icon>
            <el-icon
              style="cursor: pointer"
              @click="scope.row.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="danger">不予受理</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
          >
        </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="editDia"
      width="85%"
      :before-close="
        () => {
          editDia = false;
        }
      "
    >
      <div v-if="editDia">
        <div class="cardTitle">
          燕赵英才卡（{{ activeForm.FlowName }}）申请表
        </div>
        <div class="description">
          <el-form :inline="true">
            <!-- <el-form-item label="填报：">
              <span>工作单位</span>
            </el-form-item> -->
            <el-form-item label="编号：">
              <span>{{ activeForm.sehnqingNumber }}</span>
            </el-form-item>
          </el-form>
        </div>
      </div>

      <el-form
        style="margin-top: -50px"
        :model="editForm"
        ref="editFormRef"
        :rules="rules"
        label-width="120px"
      >
        <el-form-item label="审批状态">
          <el-radio-group v-model="editState">
            <el-radio-button label="0">受理</el-radio-button>
            <el-radio-button label="1">材料补正</el-radio-button>
            <el-radio-button label="2">不予受理</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item class="title" label="受理意见" prop="reviewlMsg">
          <el-input
            v-model="editForm.reviewlMsg"
            :rows="2"
            placeholder="请输入受理意见"
            type="textarea"
          />
        </el-form-item>
      </el-form>
      <el-tabs type="border-card">
        <el-tab-pane label="基本信息">
          <div style="height: 580px; overflow-y: auto; margin-top: -40px">
            <AmatterClass
              v-model:materialCalssId="rclkApplicationFormId"
              :isTableVisilite="false"
              :isReviewed="true"
            ></AmatterClass>
          </div>
        </el-tab-pane>
        <el-tab-pane label="申请所需材料">
          <materialTable
            :isDisabled="true"
            :isReviewed="true"
            v-model:materialCalssId="rclkApplicationFormId"
          ></materialTable>
        </el-tab-pane>
      </el-tabs>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="editDia = false">取消</el-button>
          <el-button type="primary" @click="handleSaveEdit(editFormRef)">
            确 定
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Form">
import { listForm, getApplicationState } from "@/api/talentManagement/todoList";
import AmatterClass from "@/components/AmatterClass/index";
import materialTable from "@/components/materialTable/index";
import useUserStore from "@/store/modules/user";

const userStore = useUserStore();
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(null);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    cardType: null,
    shenqingState: "bysl",
    chineseName: null,
    sehnqingrenId: userStore.id,
  },
});
const editFormRef = ref(null);
const activeForm = ref({});
const rclkApplicationFormId = ref(null);
const editState = ref("0");

const { queryParams } = toRefs(data);
const isIdView = ref(false);

const handleEdit = (row) => {
  rclkApplicationFormId.value = row.rclkApplicationFormId;
  activeForm.value = row;
  editDia.value = true;
  activeItem.value = row;

  getNextNode({ workid: row.WorkID, flowNo: "001" }).then((res) => {
    editForm.value.NodeID = res[0].NodeID;
    editForm.value.Name = res[0].Name;
  });

  proxy.resetForm("editFormRef");
  editState.value = 0;
};

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

/** 查询人才绿卡申请列表 */
function getList() {
  loading.value = true;
  listForm(queryParams.value).then((response) => {
    formList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

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

/** 重置按钮操作 */
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>
