<template>
  <div>
    <el-card>
      <headers title="分部数据" @changeOrgan="changeOrgan" />
      <el-button
        type="primary"
        v-permission="'export/organStudentOverView'"
        @click="organDateExport"
        size="mini"
        >导出</el-button
      >
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
          @sort-change="sortChang"
        >
          <el-table-column
            align="center"
            prop="organName"
            label="分部"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="totalStudentNum"
            label="学员总数"
          >
            <template slot="header" slot-scope="slot">
              <div class="titleCell">
                <span>学员总数</span>
                <el-tooltip placement="top" popper-class="mTooltip">
                  <div slot="content">该分部下所有学员</div>
                  <i
                    class="el-icon-question micon el-tooltip"
                    style="
                      font-size: 18px;
                      color: #f56c6c;
                      top: 2px;
                      position: relative;
                    "
                  ></i>
                </el-tooltip>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="cloudStudyLivelyStudentNum"
            label="活跃人数"
          >
            <template slot="header" slot-scope="slot">
              <div class="titleCell">
                <span>活跃人数</span>
                <el-tooltip placement="top" popper-class="mTooltip">
                  <div slot="content">近15天内使用达到5天及以上的用户数</div>
                  <i
                    class="el-icon-question micon el-tooltip"
                    style="
                      font-size: 18px;
                      color: #f56c6c;
                      top: 2px;
                      position: relative;
                    "
                  ></i>
                </el-tooltip>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="cloudStudyUseStudentDuty"
            label="使用比例"
            sortable
          >
            <template slot="header" slot-scope="slot">
              <div class="titleCell">
                <span>使用比例</span>
                <el-tooltip placement="top" popper-class="mTooltip">
                  <div slot="content">云教练使用人数 / 学员总数</div>
                  <i
                    class="el-icon-question micon el-tooltip"
                    style="
                      font-size: 18px;
                      color: #f56c6c;
                      top: 2px;
                      position: relative;
                    "
                  ></i>
                </el-tooltip>
              </div>
            </template>
            <template slot-scope="scope">
              <div>{{ scope.row.cloudStudyUseStudentDuty }}%</div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="vipStudentNum"
            label="付费会员数"
          >
            <template slot="header" slot-scope="slot">
              <div class="titleCell">
                <span>付费会员数</span>
                <el-tooltip placement="top" popper-class="mTooltip">
                  <div slot="content">该分部生效中、待生效付费会员总数</div>
                  <i
                    class="el-icon-question micon el-tooltip"
                    style="
                      font-size: 18px;
                      color: #f56c6c;
                      top: 2px;
                      position: relative;
                    "
                  ></i>
                </el-tooltip>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            sortable="custom"
            align="center"
            prop="vipStudentDuty"
            label="付费会员占比"
          >
            <template slot="header" slot-scope="slot">
              <div class="titleCell">
                <span>付费会员占比</span>
                <el-tooltip placement="top" popper-class="mTooltip">
                  <div slot="content">付费会员数 / 学员总数</div>
                  <i
                    class="el-icon-question micon el-tooltip"
                    style="
                      font-size: 18px;
                      color: #f56c6c;
                      top: 2px;
                      position: relative;
                    "
                  ></i>
                </el-tooltip>
              </div>
            </template>
            <template slot-scope="scope">
              <div>{{ scope.row.vipStudentDuty }}%</div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            sortable
            align="center"
            prop="eVipStudentNum"
            label="试用会员"
          >
            <template slot="header" slot-scope="slot">
              <div class="titleCell">
                <span>试用会员</span>
                <el-tooltip placement="top" popper-class="mTooltip">
                  <div slot="content">
                    有生效中或待生效的付费会员，不统计在内
                  </div>
                  <i
                    class="el-icon-question micon el-tooltip"
                    style="
                      font-size: 18px;
                      color: #f56c6c;
                      top: 2px;
                      position: relative;
                    "
                  ></i>
                </el-tooltip>
              </div>
            </template>
          </el-table-column> -->

          <el-table-column align="center" prop="studentId" label="操作">
            <template slot-scope="scope">
              <div>
                <auth auths="/organDateDetail">
                  <el-button type="text" @click="gotoDetail(scope.row)"
                    >详情</el-button
                  >
                </auth>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :autoScroll="false"
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
      </div>
    </el-card>
  </div>
</template>
<script>
import headers from "./modals/headers.vue";
import pagination from "@/components/Pagination/index";
import { organStudentOverView } from "../api";
import { Export } from "@/utils/downLoadFile";
export default {
  components: {
    headers,
    pagination,
  },
  data() {
    return {
      tableList: [],
      organId: "",
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      searchList: {},
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    async getList() {
      try {
        // const arr = [36,39,41,42,43,44,45,46,47,48,49,50,52,54,55,56]
        const res = await organStudentOverView({
          page: this.rules.page,
          rows: this.rules.limit,
          ...this.searchList,
          organIds: this.organId,
        });
        this.tableList = res.data.rows;
        this.rules.total = res.data.total;
        // console.log(this.tableList)
      } catch (e) {
        console.log(e);
      }
    },
    sortChang(val) {
      const dates = {
        ascending: "ASC",
        descending: "DESC",
      };
      this.searchList = {};
      if (val.prop && val.order) {
        this.searchList[val.prop] = dates[val.order];
      }
      this.rules.page = 1;
      this.getList();
    },
    gotoDetail(row) {
      // 跳转到分部数据详情 row.organId
      this.$router.push({
        name: "organDateDetail",
        params: { organId: row.organId },
      });
    },
    changeOrgan(val) {
      this.organId = val;
      this.rules.page = 1;
      this.getList();
    },
    organDateExport() {
      let params = { ...this.searchList, organIds: this.organId };
      Export(
        this,
        {
          url: "/api-web/export/organStudentOverView",
          fileName: "分部云教练数据.xls",
          method: "post",
          params,
        },
        "您确定导出分部云教练数据列表?"
      );
    },
  },
};
</script>
<style lang="scss" scoped>
/deep/.el-card__body {
  padding-top: 0 !important;
}
.titleCell {
  display: inline-block;
}
.tableWrap {
  margin-top: 20px;
}
</style>
