<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="用户名称" prop="UserName">
        <el-input
          v-model="queryParams.UserName"
          placeholder="请输入用户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="身份证" prop="UserCord">
        <el-input
          v-model="queryParams.UserCord"
          placeholder="请输入身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期次（年）" prop="QiciYear">
        <el-date-picker
          format="yyyy"
          value-format="yyyy"
          v-model="queryParams.QiciYear"
          type="year"
          placeholder="请选择期次（年）"
        >
        </el-date-picker>
        <span style="display: inline-block; margin: 0 10px 0 15px">-</span>
      </el-form-item>
      <el-form-item prop="QiCi">
        <el-input
          v-model="queryParams.QiCi"
          style="width: 150px"
          placeholder="期次"
          type="number"
        ></el-input>
      </el-form-item>
      <el-form-item label="执业单位" prop="UserCord">
        <el-input
          v-model="queryParams.DeptName"
          placeholder="请输入身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="personList">
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ handleTableIndex(scope.$index, queryParams) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="期次" align="center" prop="QiciYear" width="200">
        <template slot-scope="scope">
          <span>{{ scope.row.QiciYear }}年{{ `第${scope.row.QiCi}期` }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="UserName" />
      <el-table-column label="性别" align="center" prop="UserSex" />
      <el-table-column
        label="身份证号"
        align="center"
        prop="UserCord"
        width="200"
      />
      <el-table-column label="培训类别" align="center" prop="" width="150">
        <template>
          <span>监理工程师</span>
        </template>
      </el-table-column>
      <el-table-column
        label="证书编号"
        align="center"
        prop="zgzsh"
        width="200"
      />
      <el-table-column
        label="执业单位"
        align="center"
        prop="DeptName"
        width="230"
      />
      <el-table-column
        label="证书有效期至"
        align="center"
        prop="Yxqz"
        width="200"
      />
      <el-table-column
        label="报名时间"
        align="center"
        prop="AddDate"
        width="150"
      />
      <el-table-column
        label="交费时间"
        align="center"
        prop="FeeShenheTime"
        width="150"
      />

      <el-table-column label="收费设置" align="center" width="150">
        <el-table-column label="状态" align="center" width="150">
          <template slot-scope="scope">
            <el-tag :type="scope.row.FeeFlg == 0 ? 'danger' : 'success'">{{
              scope.row.FeeFlg == 0 ? "未收费" : "已收费"
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="设置" align="center" width="80">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.FeeFlg == 0"
              @click="handleTollChangeState(scope.row)"
              style="margin-left: 10px"
              size="mini"
              type="text"
              >[ 设置 ]</el-button
            >
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            @click="handleDelectPerson(scope.row)"
            size="mini"
            type="text"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listPerson,
  delectPerson,
  changeFeeFlg,
} from "@/api/xiehui/jxjy/onpayment";
import { handleTableIndex } from "@/utils/index";
export default {
  name: "Person",
  data() {
    return {
      //当前选中的考试日期
      activeExam: null,
      examDia: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // VIEW表格数据
      personList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        FeeFlg: 0,
        // orderByColumn: "PersonId",
        // isAsc: "desc",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //删除人员
    handleDelectPerson(row) {
      this.$confirm("是否确定删除该条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then((res) => {
        delectPerson(row.PersonId).then((res) => {
          this.$message({
            type: "success",
            message: "删除成功",
          });
          this.getList();
        });
      });
    },
    //修改收费状态
    handleTollChangeState(row) {
      this.$confirm("您要改变当前收费状态吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then((res) => {
        changeFeeFlg({
          PersonId: row.PersonId,
          FeeFlg: 1,
        }).then((res) => {
          this.$message({
            type: "success",
            message: "修改成功",
          });
          this.getList();
        });
      });
    },

    handleTableIndex,
    /** 查询VIEW列表 */
    getList() {
      this.loading = true;
      listPerson(this.queryParams).then((response) => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/person/export",
        {
          ...this.queryParams,
        },
        `person_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
