<template>
  <div class="container">
    <!-- <h1>xuefuSingleTagPage</h1> -->
    <div class="tagBox">
      <div>{{ tag }}</div>
      <!-- <div>{{ list.length }}人</div> -->
    </div>
    <div class="table-container">
      <el-table
        ref="productTable"
        :data="list"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        v-loading="listLoading"
        border
        @sort-change="changeTableSort"
      >
        <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column>
        <el-table-column label="姓名" align="center">
          <template slot-scope="scope">
            <div
              class="handleStuDetail"
              @click="handleStuDetail(scope.row.userId)"
            >
              {{ scope.row.nameCn }}
            </div>
          </template>
        </el-table-column>

        <el-table-column label="所在学校" align="center">
          <template slot-scope="scope">{{ scope.row.school }}</template>
        </el-table-column>

        <el-table-column label="年级" align="center">
          <template slot-scope="scope">{{
            scope.row.grade == 1
              ? "大一"
              : scope.row.grade == 2
              ? "大二"
              : scope.row.grade == 3
              ? "大三"
              : scope.row.grade == 4
              ? "大四"
              : scope.row.grade == 5
              ? "大五"
              : ""
          }}</template>
        </el-table-column>

        <el-table-column label="报课数量" align="center">
          <template slot-scope="scope">{{ scope.row.courseNum }}</template>
        </el-table-column>

        <!-- <el-table-column label="客户状态" align="center">
          <template slot-scope="scope">{{ scope.row.userStatus }}</template>
        </el-table-column> -->
        <!-- <el-table-column label="渠道" align="center">
          <template slot-scope="scope">
            <div v-show="scope.row.channel == 1">主动推荐引流</div>
            <div v-show="scope.row.channel == 2">客服自主添加</div>
            <div v-show="scope.row.channel == 3">搜索引擎引流</div>
            <div v-show="scope.row.channel == 4">外部资源推荐</div>
            <div v-show="scope.row.channel == 5">自媒体引流</div>
            <div v-show="scope.row.channel == 6">地推活动</div>
          </template>
        </el-table-column> -->

        <!-- <el-table-column label="意向度" align="center">
          <template slot-scope="scope">{{
            scope.row.planStatus == 1
              ? "低"
              : scope.row.planStatus == 2
              ? "中"
              : scope.row.planStatus == 3
              ? "高"
              : ""
          }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="微信号" align="center">
          <template slot-scope="scope">{{ scope.row.wechatNumber }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="最近沟通记录" align="center">
          <template slot-scope="scope">{{ scope.row.context }}</template>
        </el-table-column> -->

        <el-table-column
          label="缴费时间"
          :sortable="'custom'"
          align="center"
          prop="addTime"
        >
          <template slot-scope="scope">{{ scope.row.addTime }}</template>
        </el-table-column>
        <el-table-column
          label="分配时间"
          :sortable="'custom'"
          align="center"
          prop="allocateTime"
        >
          <template slot-scope="scope">{{ scope.row.allocateTime }}</template>
        </el-table-column>

        <!-- <el-table-column
          label="最近沟通时间"
          :sortable="'custom'"
          align="center"
          prop="addTime"
        >
          <template slot-scope="scope">{{ scope.row.addTime }}</template>
        </el-table-column>
        <el-table-column
          label="下次沟通时间"
          :sortable="'custom'"
          align="center"
          prop="nextChatTime"
        >
          <template slot-scope="scope">{{ scope.row.nextChatTime }}</template>
        </el-table-column> -->
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next,jumper"
        :page-size="pageSize"
        :page-sizes="[5, 10, 15]"
        :current-page.sync="pageNum"
        :total="total"
      >
      </el-pagination>
    </div>
    <el-button @click="del" class="delTag" type="danger">删除</el-button>
    <!-- <div v-for="(item, index) in multipleSelection" :key="index">
      {{ item.userId }},,,,,{{ listQuery.tagId }}
    </div> -->
    <!-- <div>{{ delId }}</div> -->
  </div>
</template>

<script>
import { xuefuSingleTag, deleteList } from "@/api/cso";

const defaultListQuery = {
  pageNum: 1,
  pageSize: 10
};

export default {
  name: "xuefuSingleTagPage",
  data() {
    return {
      tag: "",
      num: "",
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      pageSize: null,
      pageNum: null,
      total: null,
      listLoading: true,
      multipleSelection: [],
      delId: []
    };
  },
  methods: {
    getSingleTag() {
      //   console.log(this.tagId);
      xuefuSingleTag(this.listQuery).then(res => {
        this.listLoading = false;

        this.list = res.data.list;
        this.pageNum = res.data.pageNum;
        this.pageSize = res.data.pageSize;
        this.total = res.data.total;
        // console.log(this.list, "this.list");
        this.$forceUpdate();
        // this.$forceUpdate();
        // console.log("this.$forceUpdate()");
      });
    },
    handleSelectionChange(val) {
      this.delId = [];
      this.multipleSelection = val;
      //   let arr = [];
      val.forEach(item => {
        // arr.push(item.userId);
        this.delId.push(item.userId);
        // this.delId = [...new Set(arr)];
      });
    },
    changeTableSort(column) {
      //   console.log("prop", column.prop);
      //   console.log("order", column.order);
      // console.log("column", column);
      if (column.prop == "addTime") {
        this.listQuery.secondSort = null;
        if (column.order == "ascending") {
          this.listQuery.firstSort = 0;
        } else if (column.order == "descending") {
          this.listQuery.firstSort = 1;
        }
      }
      if (column.prop == "nextChatTime") {
        this.listQuery.firstSort = null;
        if (column.order == "ascending") {
          this.listQuery.secondSort = 0;
        } else if (column.order == "descending") {
          this.listQuery.secondSort = 1;
        }
      }
      if (column.order == null) {
        this.listQuery.secondSort = this.listQuery.firstSort = null;
      }
      this.getSingleTag();
      console.log("changeTableSort");
    },
    handleCurrentChange(val) {
      // 翻页
      this.listQuery.pageNum = val;
      this.getSingleTag();
    },
    handleStuDetail(id) {
      // 测试用的
      this.$router.push({
        path: "/pms/stuDetail",
        query: {
          id: id
        }
      });
      // console.log(123);
    },
    del() {
      //   this.$refs[formName].validate(valid => {
      //   if (valid) {
      //     this.$confirm("是否要提交", "提示", {
      //       confirmButtonText: "确定",
      //       cancelButtonText: "取消",
      //       type: "warning"
      //     }).then(() => {
      //       createUser(this.form).then(response => {
      //         this.$message({
      //           type: "success",
      //           message: "提交成功",
      //           duration: 1000
      //         });
      //         // location.reload();
      //       });
      //     });
      //   } else {
      //     console.log("error submit!!");
      //     console.log(valid);
      //     return false;
      //   }
      // });
      if (this.delId.length > 0) {
        this.$confirm("是否要删除", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          deleteList({
            tagId: this.listQuery.tagId * 1,
            userIds: this.delId
          }).then(res => {
            this.$message({
              type: "success",
              message: "删除成功",
              duration: 1000
            });
            this.getSingleTag();
          });
        });
      } else {
        this.$message({
          type: "error",
          message: "无内容",
          duration: 1000
        });
      }
    }
  },
  mounted() {
    this.listQuery.tagId = this.$route.query.tagId;
    // console.log(typeof this.listQuery.tagId, "typeof this.listQuery.tagId");
    this.tag = this.$route.query.tag;
    this.num = this.$route.query.num;
    // console.log(this.listQuery.tagId, "this.listQuery.tagId");
    this.getSingleTag();
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
}
.tagBox {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100px;
  height: 100px;
  background-color: #3498db;
  box-sizing: border-box;
  //   padding: 10px;
  margin: 10px;
  border-radius: 20px;
  box-shadow: 0 0 5px #333;
  transition: 0.5s;
  //   cursor: pointer;
  &:hover {
    transform: scale(1.1);
  }
  div {
    margin: 3px;
  }
}
.delTag {
  margin-top: 20px;
}
</style>
