<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="nickname">
        <el-input v-model="queryParams.nickname" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="性别" prop="avatar">
        <el-input v-model="queryParams.avatar" placeholder="请输入头像" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="成交" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>
      </el-form-item>
      <el-form-item label="认证" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button>搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button>批量导出</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="['member:user:create']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   :loading="exportLoading"
                   v-hasPermi="['member:user:export']">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table :data="list">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="id"/>
      <el-table-column label="用户名称" align="center" prop="nickname"/>
      <el-table-column label="真实姓名" align="center" prop="avatar"/>
      <el-table-column label="手机号" align="center" prop="status"/>
      <el-table-column label="成交" align="center" prop="mobile"/>
      <el-table-column label="认证" align="center" prop="password"/>
      <el-table-column label="状态" align="center" prop="registerIp"/>
      <el-table-column label="身份证审核状态" align="center" prop="loginIp"/>
      <el-table-column label="营业执照审核状态" align="center" prop="loginDate" width="180">
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
      </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="['member:user:update']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['member:user:delete']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
    <!-- 操作日志  -->
    <el-dialog
      title="操作日志"
      :visible.sync="operationShow"
      width="70%">
      <div>
        <el-table>
          <el-table-column label="标题" align="center" prop="id"/>
          <el-table-column label="操作内容" align="center" prop="id"/>
          <el-table-column label="操作人" align="center" prop="id"/>
          <el-table-column label="操作时间" align="center" prop="id"/>
          <el-table-column label="操作ip" align="center" prop="id"/>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="operationShow = false">取 消</el-button>
    <el-button type="primary" @click="operationShow = false">确 定</el-button>
  </span>
    </el-dialog>
<!--保函，证书 -->
    <el-dialog
      title="保函/证书"
      :visible.sync="certificateShow"
      width="50%">
      <div>
       <el-row :gutter="10">
        <el-col :span="6"> <el-upload
          class="upload-demo"
          action="https://jsonplaceholder.typicode.com/posts/"
          multiple
          :limit="3">
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">可上传图片,pdf文档</div>
        </el-upload></el-col>
        <el-col :span="6"><el-button>保存</el-button></el-col>
       </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="certificateShow = false">取 消</el-button>
    <el-button type="primary" @click="certificateShow = false">确 定</el-button>
  </span>
    </el-dialog>
    <el-dialog
      title="认证"
      :visible.sync="attestationShow"
      width="50%">
      <div>
        <div>
          <el-menu class="el-menu-demo" mode="horizontal" :default-active="identitySwitching"  @select="handleSelect">
            <el-menu-item index="1">身份证</el-menu-item>
            <el-menu-item index="2">营业执照</el-menu-item>
          </el-menu>
        </div>
        <div class="authenticationForm" v-if="identitySwitching == 1">
         <el-form label-position="left" label-width="100px">
           <el-form-item label="姓名">
             <el-input style="width: 200px"></el-input>
           </el-form-item>
           <el-form-item label="证件类型">
             <dict-selector :type="DICT_TYPE.CERTIFICATE_TYPE" placeholder="请选择证件类型"></dict-selector>
           </el-form-item>
           <el-form-item label="证件号码">
             <el-input style="width: 200px;"></el-input>
           </el-form-item>
           <el-form-item label="证件正面照">
             <el-row>
               <el-col :span="10">
                 <el-input style="width: 200px;"></el-input>
               </el-col>
               <el-col :span="6">
                 <el-upload>
                   <el-button size="small" type="primary">点击上传</el-button>
                 </el-upload>
               </el-col>
               <el-col :span="6">
                 <el-image></el-image>
               </el-col>
             </el-row>
           </el-form-item>
           <el-form-item label="证件背面照">
             <el-row>
               <el-col :span="10">
                 <el-input style="width: 200px;"></el-input>
               </el-col>
               <el-col :span="6">
                 <el-upload>
                   <el-button size="small" type="primary">点击上传</el-button>
                 </el-upload>
               </el-col>
               <el-col :span="6">
                 <el-image></el-image>
               </el-col>
             </el-row>
           </el-form-item>
           <el-form-item label="审核状态"></el-form-item>
           <el-form-item label="审核时间"></el-form-item>
           <el-form-item label="审核备注"></el-form-item>
         </el-form>
        </div>
        <div class="authenticationForm" v-else>
         <el-form label-position="left" label-width="100px">
           <el-form-item label="企业名称">
             <el-input style="width: 200px"></el-input>
           </el-form-item>
           <el-form-item label="企业法人">
            <el-input style="width: 200px;"></el-input>
           </el-form-item>
           <el-form-item label="证件号码">
             <el-input style="width: 200px;"></el-input>
           </el-form-item>
           <el-form-item label="证件正面照">
             <el-row>
               <el-col :span="10">
                 <el-input style="width: 200px;"></el-input>
               </el-col>
               <el-col :span="6">
                 <el-upload>
                   <el-button size="small" type="primary">点击上传</el-button>
                 </el-upload>
               </el-col>
               <el-col :span="6">
                 <el-image></el-image>
               </el-col>
             </el-row>
           </el-form-item>
           <el-form-item label="证件背面照">
             <el-row>
               <el-col :span="10">
                 <el-input style="width: 200px;"></el-input>
               </el-col>
               <el-col :span="6">
                 <el-upload>
                   <el-button size="small" type="primary">点击上传</el-button>
                 </el-upload>
               </el-col>
               <el-col :span="6">
                 <el-image></el-image>
               </el-col>
             </el-row>
           </el-form-item>
           <el-form-item label="审核状态"></el-form-item>
           <el-form-item label="审核时间"></el-form-item>
           <el-form-item label="审核备注"></el-form-item>
         </el-form>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="certificateShow = false">取 消</el-button>
    <el-button type="primary" @click="certificateShow = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import {createUser, updateUser, deleteUser, getUser, getUserPage, exportUserExcel} from "@/api/member/user";
import {DICT_TYPE} from "@/utils/dict";
export default {
  name: "User",
  components: {},
  data() {
    return {
      identitySwitching:"1",
      DICT_TYPE,
      operationShow: false,//操作日志
      certificateShow: false,//保函证书，
      attestationShow:false,//认证
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeLoginDate: [],
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        nickname: null,
        avatar: null,
        status: null,
        mobile: null,
        password: null,
        registerIp: null,
        loginIp: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        nickname: [{required: true, message: "用户昵称不能为空", trigger: "blur"}],
        avatar: [{required: true, message: "头像不能为空", trigger: "blur"}],
        status: [{required: true, message: "状态不能为空", trigger: "blur"}],
        mobile: [{required: true, message: "手机号不能为空", trigger: "blur"}],
        password: [{required: true, message: "密码不能为空", trigger: "blur"}],
        registerIp: [{required: true, message: "注册 IP不能为空", trigger: "blur"}],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      // 处理查询参数
      let params = {...this.queryParams};
      this.addBeginAndEndTime(params, this.dateRangeLoginDate, 'loginDate');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
      getUserPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        nickname: undefined,
        avatar: undefined,
        status: undefined,
        mobile: undefined,
        password: undefined,
        registerIp: undefined,
        loginIp: undefined,
        loginDate: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeLoginDate = [];
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getUser(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateUser(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createUser(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除用户编号为"' + id + '"的数据项?').then(function () {
        return deleteUser(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeLoginDate, 'loginDate');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行导出
      this.$modal.confirm('是否确认导出所有用户数据项?').then(() => {
        this.exportLoading = true;
        return exportUserExcel(params);
      }).then(response => {
        this.$download.excel(response, '${table.classComment}.xls');
        this.exportLoading = false;
      }).catch(() => {
      });
    },
    handleSelect(val){
      console.log(val)
      this.identitySwitching = val
    }
  }
};
</script>
<style lang="scss" scoped>
  .authenticationForm{
    padding-top: 20px;
  }
</style>
