<!-- @format -->
<!-- @format -->
<!-- @format -->

<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="申请编号" prop="cardNumber">
        <el-input
          v-model="queryParams.cardNumber"
          placeholder="请输入卡片编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="申请人" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </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="listData"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" align="center" type="index" width="100">
        <template #default="scope">
          <span>{{ handleTableIndex(scope.$index, queryParams) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="类型" align="center" prop="cardType">
        <template #default="scope">
          <dict-tag :options="card_type" :value="scope.row.cardType" />
        </template>
      </el-table-column>
      <el-table-column
        label="申请人"
        align="center"
        prop="chineseName"
      ></el-table-column>
      <el-table-column
        label="申请编号"
        align="center"
        prop="sehnqingNumber"
      ></el-table-column>
      <el-table-column label="事项名称" align="center" width="300">
        <template #default="scope">
          <span
            >{{ scope.row.chineseName }}申请的
            <span>
              <dict-tag
                style="display: inline"
                :options="card_type"
                :value="scope.row.cardType"
              />
            </span>
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="申请时间"
        align="center"
        prop="createTime"
      ></el-table-column>
      <el-table-column label="预审意见" align="center"></el-table-column>
      <el-table-column align="center" label="状态">
        <template #default="scope">
          <el-tag>已补正</el-tag>
        </template>
      </el-table-column>
      <el-table-column>
        <template #default="scope">
          <el-button type="text" icon="View">详细</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="List">
import AmatterClass from "@/components/AmatterClass/index";
import materialTable from "@/components/materialTable/index";
import {
  getTodoList,
  sendFlowToUsers,
  returnBcakRclk,
  bysp,
} from "@/api/talentManagement/todoList";
import { ElMessage } from "element-plus";
import { computed, toValue } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const { proxy } = getCurrentInstance();
const {
  zhi_ka_type,
  is_zhuxiao,
  zhi_ka_state,
  card_type,
  yjrc_type,
  politics_status,
  zheng_jian_type,
  sys_user_sex,
} = proxy.useDict(
  "sys_user_sex",
  "zhi_ka_type",
  "is_zhuxiao",
  "zhi_ka_state",
  "card_type",
  "yjrc_type",
  "politics_status",
  "zheng_jian_type"
);

const listData = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const editDia = ref(false);
const activeItem = ref({});
const logoutDia = ref(false);
const ReviewDia = ref(false);
const editFormRef = ref(null);
const activeForm = ref({});
const rclkApplicationFormId = ref(null);
const editState = ref("0");

const data = reactive({
  editForm: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    fkFlow: "001",
    title: "",
  },
  rules: {
    reviewlMsg: [
      {
        required: true,
        message: "受理意见不能为空",
        trigger: "blur",
      },
    ],
  },
});

const { queryParams, editForm, rules } = toRefs(data);

/** 查询人才库列列表 */
function getList() {
  loading.value = true;
  getTodoList(queryParams.value).then((response) => {
    listData.value = response.list;
    total.value = response.total;
    loading.value = false;
  });
}
const handleEdit = (row) => {
  rclkApplicationFormId.value = row.rclkApplicationFormId;

  activeForm.value = row;
  editDia.value = true;
  activeItem.value = row;
};

//提交受理结果
const handleSaveEdit = (formRef) => {
  formRef.validate((vaild) => {
    if (vaild) {
      if (toValue(editState) == 0) {
        sendFlowToUsers({
          rclkId: activeItem.value.rclkApplicationFormId,
          workid: activeItem.value.WorkID,
          reviewlMsg: editForm.value.reviewlMsg,
          optionName: activeItem.value.NodeName + "审核",
        }).then((res) => {
          editDia.value = false;
          ElMessage({
            type: "success",
            message: "提交成功",
          });
          getList();
        });
      } else if (toValue(editState) == 1) {
        returnBcakRclk({
          id: activeItem.value.rclkApplicationFormId,
          returnMsg: editForm.value.reviewlMsg,
        }).then((res) => {
          editDia.value = false;
          ElMessage({
            type: "success",
            message: "提交成功",
          });
          getList();
        });
      } else if (toValue(editState) == 2) {
        bysp({
          id: activeItem.value.rclkApplicationFormId,
          msg: editForm.value.reviewlMsg,
        }).then((res) => {
          editDia.value = false;
          ElMessage({
            type: "success",
            message: "提交成功",
          });
          getList();
        });
      }
    }
  });
};
// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

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

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

//是否超过复核日期
const fuheJiezhiDate = computed(() => {
  return (date) => {
    return new Date().getTime() - new Date(date).getTime();
  };
});

//是否超过英才卡有效日期
const cardYouxiaoDate = computed(() => {
  return (date) => {
    return new Date().getTime() - new Date(date).getTime();
  };
});

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm("是否确认删除选中的数据项？")
    .then(function () {
      return delList(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}

getList();
</script>
<style lang="scss" scoped>
.cardTitle {
  font-size: 26px;
  font-weight: 550;
  text-align: center;
  color: black;
}
.description {
  text-align: right;
  margin-top: 10px;
  margin-right: 200px;
}
::v-deep .el-dialog:not(.is-fullscreen) {
  margin-top: 1vh !important;
}
::v-deep .el-dialog__header {
  margin-top: 0px !important;
}
.title {
  font-size: 16px;
  background: #ebf8fb;
  color: #0068d7;
  margin-bottom: 30px;
  position: relative;
  padding: 10px 10px 10px 0;
}
::v-deep .el-textarea__inner {
  background: transparent;
}
</style>
