<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="手机号" label-width="60px">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          style="width: 160px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号码">
        <el-input
          v-model="queryParams.cardId"
          placeholder="请输入身份证号码"
          clearable
          style="width: 200px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="40px" label="姓名">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入姓名"
          clearable
          style="width: 140px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="120px" label="是否加入黑名单">
        <el-select
          v-model="queryParams.isBlackList"
          placeholder="是否加入黑名单"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.user_is_black_list"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </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-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" border>
      <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
      <el-table-column label="用户昵称" align="center" prop="name" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="身份证号码" align="center" prop="cardId" />
      <el-table-column label="累计消费" align="center" prop="consumeTotal" />
      <el-table-column label="是否实名" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_certification" :value="scope.row.isAuth"/>
        </template>
      </el-table-column>
      <el-table-column label="是否加入黑名单" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_is_black_list" :value="scope.row.isBlackList"/>
        </template>
      </el-table-column>
      <el-table-column label="注册渠道" align="center" prop="onlineTime" width="160">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_source_type" :value="scope.row.regSource"/>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="createTime" width="160">
        <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"
            @click="openDetails(scope.row)"
            v-hasPermi="['userMr:userMr:details']"
          >详情</el-button>
          <span v-hasPermi="['userMr:userMr:authentication']" style="display: inline-block;">
            <el-button
              size="mini"
              type="text"
              style="margin-left: 10px;"
              v-if="scope.row.isAuth == 1"
              @click="updateAuthStatusEven(scope.row)"
            >取消实名认证</el-button>
          </span>
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['userMr:userMr:blacklist']"
            
            @click="addBlackListEven(scope.row)"
          >{{scope.row.isBlackList == 1?'取消黑名单':'加入黑名单'}}</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"
    />
    <!-- 详情 -->
    <!-- 新增/编辑弹框 -->
    <data-box
      ref="addAndEdit"
      @getList="getList"
    />
  </div>
</template>

<script>

import { pageList, updateAuthStatus, addBlackList } from '@/api/userMr/userMr'
import dataBox from "./dialog/dataBox";
export default {
  name: "UserMr",
  components: { dataBox },
  dicts:['user_source_type','user_is_black_list','user_certification'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: "",

      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined
      },
      visibleStatus: false,
      newObj: {},
      visibleType: '',
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      pageList(this.addDateRange(this.queryParams, this.dateRange))
      .then(response => {
          this.dataList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.$set(this.queryParams, 'realName', '');
      this.$set(this.queryParams, 'cardId', '');
      this.$set(this.queryParams, 'mobile', '');
      this.$set(this.queryParams, 'isBlackList', '')
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    /** 详情按钮操作 */
    openDetails(row, type) {
      this.$refs["addAndEdit"].openDialog("详情", row,3);
    },

    /** 取消实名认证按钮操作 */
    updateAuthStatusEven(row) {
      this.$confirm("取消认证后，用户在小程序端会成为未实名状态，您确定要取消该用户的的认证吗?", '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateAuthStatus({ id: row.id}).then((res) => {
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.getList();
          }
        });
      }).catch(() => {});
    },

    /** 加入黑名单按钮操作 */
    addBlackListEven(row) {
      let str = row.isBlackList == 0 ? "是否将该用户加入黑名单?":'是否将该用户移出黑名单?'
      this.$confirm(str, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        addBlackList({ 
          id: row.id,
          type: row.isBlackList == 0 ? 1:2
        }).then((res) => {
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.getList();
          }
        });
      }).catch(() => {});
    },

    /** 查看按钮操作 */
    seeCenter(obj, type) {
      this.visibleStatus = true
      this.visibleType = type;
      this.newObj = obj;
    }
  }
};
</script>
