<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <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="identityType">
          <el-select v-model="queryParams.identityType" placeholder="请选择通告主身份类型" clearable>
            <el-option
              v-for="dict in dict.type.dl_identity_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </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">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="memberList" >
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="身份类型" align="center" prop="identityType">
        <template slot-scope="scope">
          <dict-tag v-if="scope.row.identityType != null" :options="dict.type.dl_identity_type" :value="scope.row.identityType"/>
          <el-tag v-if="scope.row.identityType == null" type="info">未认证</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="会员" align="center" prop="memberCardName" />
      <el-table-column label="联系方式" align="center" prop="tel" />
      <el-table-column label="剩余额度" align="center" prop="tremaining" />
      <el-table-column label="通告数量" align="center" prop="ttotalNum" />
      <el-table-column label="粉丝数量" align="center" prop="tfansNum" />
      <el-table-column label="报名免打扰" align="center" prop="topenDisturb" />
      <el-table-column label="状态" align="center" prop="status">
        <template  slot-scope="scope">
          <el-tag v-if="scope.row.status == 0" type="success">正常</el-tag>
          <el-tag v-if="scope.row.status == 1" type="danger">冻结</el-tag>
        </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="detail(scope.row)"
          >查看</el-button>
          <el-button
            v-if="scope.row.status == 0"
            size="mini"
            type="text"
            @click="update(scope.row.userId,1)"
            v-hasPermi="['member:member:remove']"
          >冻结</el-button>
          <el-button
            v-if="scope.row.status == 1"
            size="mini"
            type="text"
            @click="update(scope.row.userId,0)"
            v-hasPermi="['member:member: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"
    />
    <AnnouncerDraw ref="formRef" />
  </div>
</template>

<script>
import { listMember } from "@/api/member/member";
import AnnouncerDraw from "@/views/member/announcer/form/announcerDraw.vue"
import { changeUserStatus } from "@/api/system/user";
export default {
  name: "Announcer",
  components: {AnnouncerDraw},
  dicts: ['dl_identity_type','dl_user_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员表格数据
      memberList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userType: '01',
        identityType: null,
        nickName:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会员列表 */
    getList() {
      this.loading = true;
      listMember(this.queryParams).then(response => {
        this.memberList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 通告主查看详情 */
    detail(row) {
      this.$refs['formRef'].initDraw(row.id,row.userId)
    },

    update(userId,status){
      changeUserStatus(userId,status).then(response => {
        this.$modal.msgSuccess("处理成功");
        this.open = false;
        this.getList();
      });
    },



  }
};
</script>
