<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" @submit.native.prevent>
      <el-form-item label="关键词" prop="keyword">
        <el-input
          style="width:220px"
          v-model="queryParams.keyword"
          placeholder="请输入微信名称/手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </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-button
        size="mini"
        type="primary"
        style="margin-left: 5px"
        :disabled="ids.length === 0"
        @click="handleUpdateBatch"
        v-hasPermi="['users:user:enabledUsers']"
      >批量启用</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table  height="500" border v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="项目" align="center" prop="projectName" />
      <el-table-column label="用户昵称" align="center" prop="nickname" />
      <el-table-column label="用户头像" align="center" prop="avatar">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <el-image :src="scope.row.avatar" style="width: 200px;height: 200px"/>
            <div slot="reference" class="name-wrapper">
              <el-avatar shape="square" size="large" :src="scope.row.avatar"/>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="createTime" width="160px"/>
<!--      <el-table-column label="看课数量" align="center" prop="watchCourseCount" />-->
<!--      <el-table-column label="缺课数量" align="center" prop="missCourseCount" />-->
<!--      <el-table-column label="缺课状态" align="center" prop="missCourseStatus">-->
<!--        <template slot-scope="scope">-->
<!--          <el-tag effect="dark" type="danger"  v-if="scope.row.missCourseStatus === 1">已缺课</el-tag>-->
<!--          <el-tag effect="dark" type="success" v-else>未缺课</el-tag>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="参与营期数量" align="center" prop="partCourseCount" width="100px"/>-->
      <el-table-column label="最后一次看课时间" align="center" prop="lastWatchDate"  width="160px"/>
<!--      <el-table-column label="看课状态" align="center" prop="courseCountStatus">-->
<!--        <template slot-scope="scope">-->
<!--          <el-tag effect="dark" type="success" v-if="scope.row.courseCountStatus === 1">正常</el-tag>-->
<!--          <el-tag effect="dark" type="info"    v-else-if="scope.row.courseCountStatus === 2">停止</el-tag>-->
<!--          <el-tag effect="dark" type="danger"  v-else>未看</el-tag>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="停课天数" align="center" prop="stopWatchDays" />-->
<!--      <el-table-column label="完播时间" align="center" prop="completeWatchDate" width="160px"/>-->
      <el-table-column label="标签名称" align="center" prop="tag" />
      <el-table-column label="所属销售名称" align="center" prop="companyUserNickName" width="120px"/>
      <el-table-column label="是否重粉" align="center" prop="isRepeatFans" width="120px">
        <template slot-scope="scope">
          <el-tag effect="dark" type="success" v-if="scope.row.isRepeatFans === 0">否</el-tag>
          <el-tag effect="dark" type="danger"    v-else-if="scope.row.isRepeatFans === 1">是</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['users:user:darkRoomList']"
            v-if="scope.row.isRepeatFans !== 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"
    />
  </div>
</template>

<script>
import { darkRoomList,enabledUsers } from "@/api/users/user";

export default {
  name: "darkRoom",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户列表数据
      userList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: null,
        status: 2
      },
      selectUser: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询客户列表 */
    getList() {
      this.loading = true;
      darkRoomList(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.selectedUser = selection.map(item => {return {userId: item.userId, projectId: item.projectId}})
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 启用
    handleUpdate(row) {
      enabledUsers([{userId: row.userId, projectId: row.projectId}]).then(response => {
        if (response.code === 200) {
          this.msgSuccess("取消禁用成功");
          this.getList();
        } else {
          this.msgError(response.msg);
        }
      });
    },
    // 启用
    handleUpdateBatch() {
      enabledUsers(this.selectedUser).then(response => {
        if (response.code === 200) {
          this.msgSuccess("取消禁用成功");
          this.getList();
        } else {
          this.msgError(response.msg);
        }
      });
    }
  }
};
</script>
<style scoped>
.app-container {
  height: 87.5vh;
}
</style>
