<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!--      <el-form-item label="用户姓名" prop="userName">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.userName"-->
      <!--          placeholder="请输入用户ID"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态">
          <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreateTime" 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="['hezhi:tbTeacherAuthentication: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="['hezhi:tbTeacherAuthentication: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="['hezhi:tbTeacherAuthentication: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="['hezhi:tbTeacherAuthentication:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tbTeacherAuthenticationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="教师认证ID" align="center" prop="teacherAuthenticationId" />-->
      <!--      <el-table-column label="用户ID" align="center" prop="memberUserId" />-->
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          {{ selectDictLabel(sexOptions, scope.row.sex) }}
        </template>
      </el-table-column>
      <el-table-column label="生日" align="center" prop="birth">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birth, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="身份证正面" align="center" prop="idCardFront">
        <template slot-scope="scope">
          <image-preview :src="scope.row.idCardFront" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="身份证反面" align="center" prop="idCardBack">
        <template slot-scope="scope">
          <image-preview :src="scope.row.idCardBack" :width="50" :height="50" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="毕业证书" align="center" prop="graduationCertificate" width="100">-->
      <!--        <template slot-scope="scope">-->
      <!--          <image-preview :src="scope.row.graduationCertificate" :width="50" :height="50"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="研究成果" align="center" prop="researchFindings" />-->
      <!--      <el-table-column label="荣誉证书" align="center" prop="certificateUrl" width="100">-->
      <!--        <template slot-scope="scope">-->
      <!--          <image-preview :src="scope.row.certificateUrl" :width="50" :height="50"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ selectDictLabel(statusOptions, scope.row.status) }}
        </template>
      </el-table-column>
      <!--      <el-table-column label="驳回原因" align="center" prop="refuseRemark" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <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="['hezhi:tbTeacherAuthentication:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['hezhi:tbTeacherAuthentication: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="750px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio v-for="(item, index) in sexOptions" :key="index" :label="item.value">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="生日" prop="birth">
          <el-date-picker clearable v-model="form.birth" type="date" value-format="yyyy-MM-dd" placeholder="请选择生日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="身份证号" prop="identityCard">
          <el-input v-model="form.identityCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="身份证正面" prop="idCardFront">
          <image-upload v-model="form.idCardFront" />
        </el-form-item>
        <el-form-item label="身份证反面" prop="idCardBack">
          <image-upload v-model="form.idCardBack" />
        </el-form-item>
        <el-form-item label="毕业证书" prop="graduationCertificate">
          <image-upload v-model="form.graduationCertificate" />
        </el-form-item>
        <el-form-item label="研究成果" prop="researchFindings">
          <file-upload v-model="form.researchFindings" />
        </el-form-item>
        <el-form-item label="荣誉证书" prop="certificateUrl">
          <image-upload v-model="form.certificateUrl" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio v-for="(item, index) in statusOptions" :key="index" :label="item.value">{{ item.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="驳回原因" prop="refuseRemark" v-if="form.status === 2">
          <el-input v-model="form.refuseRemark" 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 { listTbTeacherAuthentication, getTbTeacherAuthentication, delTbTeacherAuthentication, addTbTeacherAuthentication, updateTbTeacherAuthentication } from "@/api/hezhi/tbTeacherAuthentication";
import { selectDictLabel } from "../../../utils/ruoyi";

export default {
  name: "TbTeacherAuthentication",
  data() {
    return {
      sexOptions: [
        {
          label: '男',
          value: 0
        },
        {
          label: '女',
          value: 1
        },
      ],
      statusOptions: [
        {
          label: '待审核',
          value: 0
        },
        {
          label: '审核通过',
          value: 1
        },
        {
          label: '审核驳回',
          value: 2
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      names: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 名师认证表格数据
      tbTeacherAuthenticationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 删除标记时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teacherAuthenticationId: null,
        memberUserId: null,
        name: null,
        sex: null,
        birth: null,
        phone: null,
        identityCard: null,
        idCardFront: null,
        idCardBack: null,
        graduationCertificate: null,
        researchFindings: null,
        certificateUrl: null,
        status: null,
        refuseRemark: null,
        createTime: null,
        updateTime: null,
        deleteTime: null,
        createBy: null,
        updateBy: null,
        deleteBy: null,
        delFlag: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        teacherAuthenticationId: [
          { required: true, message: "教师认证ID不能为空", trigger: "blur" }
        ],
        memberUserId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        birth: [
          { required: true, message: "生日不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "电话不能为空", trigger: "blur" }
        ],
        idCardFront: [
          { required: true, message: "身份证正面不能为空", trigger: "blur" }
        ],
        idCardBack: [
          { required: true, message: "身份证反面不能为空", trigger: "blur" }
        ],
        graduationCertificate: [
          { required: true, message: "毕业证书不能为空", trigger: "blur" }
        ],
        researchFindings: [
          { required: true, message: "研究成果不能为空", trigger: "blur" }
        ],
        certificateUrl: [
          { required: true, message: "荣誉证书不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        refuseRemark: [
          { required: true, message: "驳回原因不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        deleteTime: [
          { required: true, message: "删除时间不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "创建者不能为空", trigger: "blur" }
        ],
        updateBy: [
          { required: true, message: "更新者不能为空", trigger: "blur" }
        ],
        deleteBy: [
          { required: true, message: "删除者不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "删除标记不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    selectDictLabel,
    /** 查询名师认证列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listTbTeacherAuthentication(this.queryParams).then(response => {
        this.tbTeacherAuthenticationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        teacherAuthenticationId: null,
        memberUserId: null,
        name: null,
        sex: null,
        birth: null,
        phone: null,
        idCardFront: null,
        idCardBack: null,
        graduationCertificate: null,
        researchFindings: null,
        certificateUrl: null,
        status: null,
        refuseRemark: null,
        createTime: null,
        updateTime: null,
        deleteTime: null,
        createBy: null,
        updateBy: null,
        deleteBy: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.teacherAuthenticationId)
      this.names = selection.map(item => item.name)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加名师认证";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const teacherAuthenticationId = row.teacherAuthenticationId || this.ids
      getTbTeacherAuthentication(teacherAuthenticationId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改名师认证";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.teacherAuthenticationId != null) {
            updateTbTeacherAuthentication(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTbTeacherAuthentication(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const teacherAuthenticationIds = row.teacherAuthenticationId || this.ids;
      //提示名师姓名
      const name = row.name || this.names;
      this.$modal.confirm('是否确认删除名师姓名为"' + name + '"的数据项？').then(function () {
        return delTbTeacherAuthentication(teacherAuthenticationIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hezhi/tbTeacherAuthentication/export', {
        ...this.queryParams
      }, `名师认证导出.xlsx`)
    }
  }
};
</script>
