<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请类型0:普通用户升级为个人测试者；1:普通用户升级为企业测试者；2:企业升级为企业测试者" prop="applyType">
        <el-input
          v-model="queryParams.applyType"
          placeholder="请输入申请类型0:普通用户升级为个人测试者；1:普通用户升级为企业测试者；2:企业升级为企业测试者"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="apply_tpe为1时有值，对应的公司申请资料申请单ID" prop="companyApplyId">
        <el-input
          v-model="queryParams.companyApplyId"
          placeholder="请输入apply_tpe为1时有值，对应的公司申请资料申请单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="真实姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入真实姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入所在城市"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号码" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态：0:unaudit;1:pass;2:unpass;" prop="status">
        <el-input
          v-model="queryParams.status"
          placeholder="请输入状态：0:unaudit;1:pass;2:unpass;"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人" prop="auditorId">
        <el-input
          v-model="queryParams.auditorId"
          placeholder="请输入审核人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间">
        <el-date-picker
          v-model="daterangeAuditTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['tester:TesterApply:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['tester:TesterApply:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['tester:TesterApply:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['tester:TesterApply:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="TesterApplyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申请ID" align="center" prop="applyId" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="申请类型0:普通用户升级为个人测试者；1:普通用户升级为企业测试者；2:企业升级为企业测试者" align="center" prop="applyType" />
      <el-table-column label="apply_tpe为1时有值，对应的公司申请资料申请单ID" align="center" prop="companyApplyId" />
      <el-table-column label="真实姓名" align="center" prop="name" />
      <el-table-column label="所在城市" align="center" prop="city" />
      <el-table-column label="身份证号码" align="center" prop="idNumber" />
      <el-table-column label="测试能力" align="center" prop="testSkills" />
      <el-table-column label="测试项目经历" align="center" prop="testProjects" />
      <el-table-column label="工作经历" align="center" prop="workExperience" />
      <el-table-column label="奖项和证书" align="center" prop="certificate" />
      <el-table-column label="补充说明" align="center" prop="otherInfo" />
      <el-table-column label="状态：0:unaudit;1:pass;2:unpass;" align="center" prop="status" />
      <el-table-column label="审核人" align="center" prop="auditorId" />
      <el-table-column label="审核意见" align="center" prop="auditOpinion" />
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['tester:TesterApply:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tester:TesterApply:remove']"
          >删除</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"
    />

    <!-- 添加或修改测试者认证申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="申请类型0:普通用户升级为个人测试者；1:普通用户升级为企业测试者；2:企业升级为企业测试者" prop="applyType">
          <el-input v-model="form.applyType" placeholder="请输入申请类型0:普通用户升级为个人测试者；1:普通用户升级为企业测试者；2:企业升级为企业测试者" />
        </el-form-item>
        <el-form-item label="apply_tpe为1时有值，对应的公司申请资料申请单ID" prop="companyApplyId">
          <el-input v-model="form.companyApplyId" placeholder="请输入apply_tpe为1时有值，对应的公司申请资料申请单ID" />
        </el-form-item>
        <el-form-item label="真实姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="所在城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入所在城市" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="测试能力" prop="testSkills">
          <el-input v-model="form.testSkills" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="测试项目经历" prop="testProjects">
          <el-input v-model="form.testProjects" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="工作经历" prop="workExperience">
          <el-input v-model="form.workExperience" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="奖项和证书" prop="certificate">
          <el-input v-model="form.certificate" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="补充说明" prop="otherInfo">
          <el-input v-model="form.otherInfo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="状态：0:unaudit;1:pass;2:unpass;" prop="status">
          <el-input v-model="form.status" placeholder="请输入状态：0:unaudit;1:pass;2:unpass;" />
        </el-form-item>
        <el-form-item label="审核人" prop="auditorId">
          <el-input v-model="form.auditorId" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="审核意见" prop="auditOpinion">
          <el-input v-model="form.auditOpinion" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审核时间" prop="auditTime">
          <el-date-picker clearable size="small"
            v-model="form.auditTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { unaudit, getTesterApply, delTesterApply, addTesterApply, changeTAStatus, exportTesterApply } from "@/api/tester/TesterApply";

export default {
  name: "TesterApply",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试者认证申请表格数据
      TesterApplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 审核时间时间范围
      daterangeAuditTime: [],
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 更新时间时间范围
      daterangeUpdateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        applyType: null,
        companyApplyId: null,
        name: null,
        city: null,
        idNumber: null,
        testSkills: null,
        testProjects: null,
        workExperience: null,
        certificate: null,
        otherInfo: null,
        status: null,
        auditorId: null,
        auditOpinion: null,
        auditTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        applyType: [
          { required: true, message: "申请类型0:普通用户升级为个人测试者；1:普通用户升级为企业测试者；2:企业升级为企业测试者不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态：0:unaudit;1:pass;2:unpass;不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询测试者认证申请列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeAuditTime && '' != this.daterangeAuditTime) {
        this.queryParams.params["beginAuditTime"] = this.daterangeAuditTime[0];
        this.queryParams.params["endAuditTime"] = this.daterangeAuditTime[1];
      }
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
        this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0];
        this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1];
      }
      unaudit(this.queryParams).then(response => {
        this.TesterApplyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        applyId: null,
        userId: null,
        applyType: null,
        companyApplyId: null,
        name: null,
        city: null,
        idNumber: null,
        testSkills: null,
        testProjects: null,
        workExperience: null,
        certificate: null,
        otherInfo: null,
        status: null,
        auditorId: null,
        auditOpinion: null,
        auditTime: null,
        createTime: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeAuditTime = [];
      this.daterangeCreateTime = [];
      this.daterangeUpdateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.applyId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加测试者认证申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const applyId = row.applyId || this.ids
      getTesterApply(applyId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改测试者认证申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.applyId != null) {
            changeTAStatus(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTesterApply(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const applyIds = row.applyId || this.ids;
      this.$confirm('是否确认删除测试者认证申请编号为"' + applyIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTesterApply(applyIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有测试者认证申请数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTesterApply(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
