<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="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件类型" prop="documentType">
        <el-select v-model="queryParams.documentType" placeholder="请选择证件类型" clearable>
          <el-option
            v-for="dict in dict.type.tb_document_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="证件号" prop="documentNumber">
        <el-input
          v-model="queryParams.documentNumber"
          placeholder="请输入证件号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="常用邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入常用邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位性质" prop="companyType">
        <el-select v-model="queryParams.companyType" placeholder="请选择单位性质" clearable>
          <el-option
            v-for="dict in dict.type.tb_company_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="职位" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位类型" prop="positionType">
        <el-select v-model="queryParams.positionType" placeholder="请选择职位类型" clearable>
          <el-option
            v-for="dict in dict.type.tb_position_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="省" prop="provinceName">-->
<!--        <el-input-->
<!--          v-model="queryParams.provinceName"-->
<!--          placeholder="请输入省"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="市" prop="cityName">-->
<!--        <el-input-->
<!--          v-model="queryParams.cityName"-->
<!--          placeholder="请输入市"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="区" prop="areaName">-->
<!--        <el-input-->
<!--          v-model="queryParams.areaName"-->
<!--          placeholder="请输入区"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="主要业务" prop="business">
        <el-select v-model="queryParams.business" placeholder="请选择主要业务" clearable>
          <el-option
            v-for="dict in dict.type.tb_business"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="examineStatus">
        <el-select v-model="queryParams.examineStatus" placeholder="请选择审核状态" clearable>
          <el-option
            v-for="dict in dict.type.tb_examine_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="创建时间" prop="createTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.createTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          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:conferenceRegistration: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:conferenceRegistration: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:conferenceRegistration: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:conferenceRegistration:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="conferenceRegistrationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="参会报名主键ID" align="center" prop="conferenceRegistrationId" />-->
<!--      <el-table-column label="用户ID" align="center" prop="memberUserId" />-->
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="证件类型" align="center" prop="documentType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_document_type" :value="scope.row.documentType"/>
        </template>
      </el-table-column>
      <el-table-column label="证件号" align="center" prop="documentNumber" />
      <el-table-column label="常用邮箱" align="center" prop="email" />
      <el-table-column label="单位名称" align="center" prop="companyName" />
      <el-table-column label="单位性质" align="center" prop="companyType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_company_type" :value="scope.row.companyType"/>
        </template>
      </el-table-column>
      <el-table-column label="职位" align="center" prop="position" />
      <el-table-column label="职位类型" align="center" prop="positionType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_position_type" :value="scope.row.positionType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="省ID" align="center" prop="provinceId" />-->
<!--      <el-table-column label="市ID" align="center" prop="cityId" />-->
<!--      <el-table-column label="区" align="center" prop="areaId" />-->
      <el-table-column label="省名" align="center" prop="provinceName" />
      <el-table-column label="市名" align="center" prop="cityName" />
      <el-table-column label="区名" align="center" prop="areaName" />
<!--      <el-table-column label="详细地址" align="center" prop="address" />-->
      <el-table-column label="证件照片" align="center" prop="idPhoto" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.idPhoto" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="主要业务" align="center" prop="business">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_business" :value="scope.row.business"/>
        </template>
      </el-table-column>
      <el-table-column label="参会目的" align="center" prop="objective" />
      <el-table-column label="是否参加过往届大会" align="center" prop="isParticipate">
        <template slot-scope="scope">
          <span v-if="scope.row.isParticipate === 0">否</span>
          <span v-if="scope.row.isParticipate === 1">是</span>
        </template>
      </el-table-column>
      <el-table-column label="是否计划参加下一届大会" align="center" prop="isParticipateNext">
        <template slot-scope="scope">
          <span v-if="scope.row.isParticipateNext === 0">否</span>
          <span v-if="scope.row.isParticipateNext === 1">是</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="类型" align="center" prop="type" />-->
      <el-table-column label="审核状态" align="center" prop="examineStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_examine_status" :value="scope.row.examineStatus"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="审核反馈" align="center" prop="examineFeedback" />-->
<!--      <el-table-column label="排序" align="center" prop="sort" />-->
<!--      <el-table-column label="备注" align="center" prop="remarks" />-->
<!--      <el-table-column label="状态" align="center" prop="status">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.tb_status" :value="scope.row.status"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="150" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100px" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hezhi:conferenceRegistration:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hezhi:conferenceRegistration: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="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
<!--        <el-form-item label="用户ID" prop="memberUserId">-->
<!--          <el-input v-model="form.memberUserId" placeholder="请输入用户ID" />-->
<!--        </el-form-item>-->
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" disabled />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" disabled />
        </el-form-item>
        <el-form-item label="证件类型" prop="documentType">
          <el-input v-model="form.documentType" placeholder="请输入证件类型" disabled />
        </el-form-item>
        <el-form-item label="证件号" prop="documentNumber">
          <el-input v-model="form.documentNumber" placeholder="请输入证件号" disabled />
        </el-form-item>
        <el-form-item label="常用邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入常用邮箱" disabled />
        </el-form-item>
        <el-form-item label="单位名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入单位名称" disabled />
        </el-form-item>
        <el-form-item label="单位性质" prop="companyType">
          <el-input v-model="form.companyType" placeholder="请输入单位性质" disabled />
        </el-form-item>
        <el-form-item label="职位" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位" disabled />
        </el-form-item>
        <el-form-item label="职位类型" prop="positionType">
          <el-input v-model="form.positionType" placeholder="请输入职位类型" disabled />
        </el-form-item>
<!--        <el-form-item label="省ID" prop="provinceId">-->
<!--          <el-input v-model="form.provinceId" placeholder="请输入省ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="市ID" prop="cityId">-->
<!--          <el-input v-model="form.cityId" placeholder="请输入市ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="区" prop="areaId">-->
<!--          <el-input v-model="form.areaId" placeholder="请输入区" />-->
<!--        </el-form-item>-->
        <el-form-item label="省" prop="provinceName">
          <el-input v-model="form.provinceName" placeholder="请输入省名" disabled />
        </el-form-item>
        <el-form-item label="市" prop="cityName">
          <el-input v-model="form.cityName" placeholder="请输入市名" disabled />
        </el-form-item>
        <el-form-item label="区" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入区名" disabled />
        </el-form-item>
        <el-form-item label="证件照片" prop="idPhoto">
          <el-image style="width: 200px; height: 200px" :src="form.idPhoto" disabled :preview-src-list="[form.idPhoto]" />
        </el-form-item>
        <el-form-item label="主要业务" prop="business">
          <el-input v-model="form.business" placeholder="请输入主要业务" disabled />
        </el-form-item>
        <el-form-item label="参会目的" prop="objective">
          <el-input v-model="form.objective" placeholder="请输入参会目的" disabled />
        </el-form-item>
        <el-form-item label="是否参加过往届大会" prop="isParticipate">
          <el-input v-model="form.isParticipate === 0? '否':'是'" placeholder="" disabled />
        </el-form-item>
        <el-form-item label="是否计划参加下一届大会" prop="isParticipateNext">
          <el-input v-model="form.isParticipateNext === 0? '否':'是'" placeholder="" disabled />
        </el-form-item>
        <el-form-item label="审核状态" prop="examineStatus">
          <el-radio-group v-model="form.examineStatus">
            <el-radio
              v-for="dict in dict.type.tb_examine_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </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 { listConferenceRegistration, getConferenceRegistration, delConferenceRegistration, addConferenceRegistration, updateConferenceRegistration } from "@/api/hezhi/conferenceRegistration";

export default {
  name: "ConferenceRegistration",
  props: ["screenConferenceNoticeId"],
  dicts: ['tb_document_type', 'tb_examine_status', 'tb_company_type', 'tb_status', 'tb_business', 'tb_position_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参会报名表格数据
      conferenceRegistrationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberUserId: null,
        name: null,
        phone: null,
        documentType: null,
        documentNumber: null,
        email: null,
        companyName: null,
        companyType: null,
        position: null,
        positionType: null,
        provinceId: null,
        cityId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        address: null,
        idPhoto: null,
        business: null,
        objective: null,
        isParticipate: null,
        isParticipateNext: null,
        type: null,
        examineStatus: null,
        examineFeedback: null,
        sort: null,
        remarks: null,
        status: null,
        createTime: null,
        deleteTime: null,
        deleteBy: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询参会报名列表 */
    getList() {
      this.loading = true;
      if (this.screenConferenceNoticeId != null) {
        this.queryParams.conferenceNoticeId = this.screenConferenceNoticeId;
      }
      listConferenceRegistration(this.queryParams).then(response => {
        this.conferenceRegistrationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        conferenceRegistrationId: null,
        memberUserId: null,
        name: null,
        phone: null,
        documentType: null,
        documentNumber: null,
        email: null,
        companyName: null,
        companyType: null,
        position: null,
        positionType: null,
        provinceId: null,
        cityId: null,
        areaId: null,
        provinceName: null,
        cityName: null,
        areaName: null,
        address: null,
        idPhoto: null,
        business: null,
        objective: null,
        isParticipate: null,
        isParticipateNext: null,
        type: null,
        examineStatus: null,
        examineFeedback: null,
        sort: null,
        remarks: null,
        status: null,
        publicationTime: null,
        publisher: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        deleteTime: null,
        deleteBy: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.conferenceRegistrationId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加参会报名";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const conferenceRegistrationId = row.conferenceRegistrationId || this.ids
      getConferenceRegistration(conferenceRegistrationId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改参会报名";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.conferenceRegistrationId != null) {
            updateConferenceRegistration(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addConferenceRegistration(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const conferenceRegistrationIds = row.conferenceRegistrationId || this.ids;
      this.$modal.confirm('是否确认删除参会报名编号为"' + conferenceRegistrationIds + '"的数据项？').then(function() {
        return delConferenceRegistration(conferenceRegistrationIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hezhi/conferenceRegistration/export', {
        ...this.queryParams
      }, `conferenceRegistration_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
