<template>
  <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="1200px" append-to-body>
    <el-table v-loading="loading" :data="userList" >
      <el-table-column label="状态" align="center" prop="status">
        <template v-slot="scope">
          <cai-dict-tag :options="userStatusList" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column :label="systemName+'号'" align="center" prop="usercode" />
      <el-table-column label="账户号" align="center" prop="cardAccount" />
      <el-table-column label="账户名称" align="center" prop="cardName" />
      <el-table-column label="昵称" align="center" prop="nickname" />
      <el-table-column label="手机号" align="center" prop="mobile" width="120"/>
      <el-table-column label="头像" align="center" prop="avatar" >
        <template v-slot="scope">
          <image-avatar :src="scope.row.avatar"/>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="gender">
        <template v-slot="scope">
          <cai-dict-tag :options="genderList" :value="scope.row.gender" />
        </template>
      </el-table-column>
      <el-table-column label="主播" align="center" prop="isAnchor">
        <template v-slot="scope">
          <cai-dict-tag :options="isAnchorList" :value="scope.row.isAnchor"/>
        </template>
      </el-table-column>
      <el-table-column label="最后登陆时间" align="center" prop="lastLoginTime" width="150"/>
      <el-table-column label="登陆IP" align="center" prop="lastLoginIp" width="125"/>
      <el-table-column label="注册时间" align="center" prop="regTime" width="150"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
        <template v-slot="scope">
          <el-button
              size="mini"
              type="text"
              @click="handleInfo(scope.row)"
          >详情</el-button>
          <el-button
              size="mini"
              type="text"
              @click="handleUserForbid(scope.row)"
              v-hasPermi="['cai:user:lock']"
          >封禁</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"
    />
    <user-info-dialog v-if="userInfoDialogVisible" ref="userInfoDialog" />
    <user-forbid-dialog v-if="userForbidVisible" ref="userForbid" @refreshDataList="getList" />
  </el-dialog>
</template>

<script>
import {
  authList,
  genderList,
  isAnchorList,
  onlineStatusList,
  userStatusList,
  videoStatusList
} from "@/constant/statusMap";
import UserInfoDialog from "@/views/cai/user/user-info-dialog.vue";
import UserForbidDialog from "@/views/cai/user/user-forbid-dialog.vue";
import {listAccountBlackUser} from "@/api/cai/accountBlack";

export default {
  components: {
    UserForbidDialog,
    UserInfoDialog
  },
  data () {
    return {
      genderList,authList,userStatusList,isAnchorList,videoStatusList,onlineStatusList,
      systemName: process.env.VUE_APP_SYSTEM_HOME,
      userInfoDialogVisible: false,
      userForbidVisible: false,
      open: false,
      title: '',
      loading: false,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cardAccount: undefined,
        cardName: undefined,
      }
    }
  },
  created() {
  },
  methods: {
    init (row) {
      this.title = "账户黑名单命中用户";
      this.open = true;
      this.$nextTick(() => {
        this.queryParams.cardAccount = row.cardAccount;
        this.queryParams.cardName = row.cardName;
        this.getList();
      })
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listAccountBlackUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleInfo(row){
      this.userInfoDialogVisible = true
      this.$nextTick(() => {
        this.$refs.userInfoDialog.init(row.id)
      })
    },
    handleUserForbid(row){
      this.userForbidVisible = true
      this.$nextTick(() => {
        this.$refs.userForbid.init(row.id)
      })
    },
  }
}
</script>
