<template>
  <div class="container">
    <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.sex == 0 ? "女" : scope.row.sex == 1 ? "男" : ""
          }}</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.school }}</template>
        </el-table-column>
        <el-table-column label="年级" align="center">
          <template slot-scope="scope">{{ scope.row.grade }}</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.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="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>
    </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>
  </div>
</template>

<script>
import { newAllocate } from "@/api/cso";

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

export default {
  name: "newAllocate",
  data() {
    return {
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      pageSize: null,
      pageNum: null,
      total: null,
      listLoading: true,
      multipleSelection: [],
      formLabelWidth: "120px"
    };
  },
  methods: {
    getData() {
      newAllocate(this.listQuery).then(res => {
        console.log(res, "getData");
        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();
      });
    },
    handleCurrentChange(val) {
      // 翻页
      this.listQuery.pageNum = val;
      this.getNewAddClew();
    },
    handleStuDetail(id) {
      this.$router.push({
        path: "/pms/stuDetail",
        query: {
          id: id
        }
      });
      // console.log(123);
    },
    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 == "allocateTime") {
        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.getData();
      console.log("changeTableSort");
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  },
  mounted() {
    this.getData();
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
}
.handleStuDetail {
  cursor: pointer;
}
</style>
