<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-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="memberCardName" />
      <el-table-column label="联系方式" align="center" prop="tel" />
      <el-table-column label="剩余积分" align="center" prop="bpoints" />
      <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)"
            v-hasPermi="['member:member:edit']"
          >查看</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"
    />
    <BloggerDraw ref="formRef" />
  </div>
</template>

<script>
import { listMember, getMember, delMember, addMember, updateMember } from "@/api/member/member";
import { changeUserStatus } from "@/api/system/user";
import BloggerDraw from "@/views/member/blogger/form/bloggerDraw.vue"
export default {
  name: "Blogger",
  dicts: ['dl_identity_type'],
  components:{
    BloggerDraw
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员表格数据
      memberList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userType: '02',
        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;
      });
    },
    /**冻结解冻*/
    update(userId,status){
      changeUserStatus(userId,status).then(response => {
        this.$modal.msgSuccess("处理成功");
        this.open = false;
        this.getList();
      });
    },

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


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

  }
};
</script>
