
<!--  -->
<template>
  <div class="m-container">
    <h2>
      <el-page-header
        @back="onCancel"
        :content="musicGroupName"
      ></el-page-header>
    </h2>
    <div class="m-core">
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
        ref="searchForm"
      >
        <el-form-item prop="search">
          <el-input
            v-model="searchForm.search"
            placeholder="学员姓名/编号/手机号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="isReserve">
          <el-select
            v-model.trim="searchForm.isReserve"
            filterable
            clearable
            placeholder="是否预约"
          >
            <el-option value="1" label="是"></el-option>
            <el-option value="0" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="subjectId">
          <el-select
            v-model.trim="searchForm.subjectId"
            filterable
            clearable
            placeholder="声部"
          >
            <el-option
              v-for="(item, index) in soundList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="gradeFlag">
          <el-select
            v-model.trim="searchForm.gradeFlag"
            filterable
            clearable
            placeholder="是否参加器乐考级"
          >
            <el-option value="1" label="是"></el-option>
            <el-option value="0" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="theoryFlag">
          <el-select
            v-model.trim="searchForm.theoryFlag"
            filterable
            clearable
            placeholder="是否参加乐理考级"
          >
            <el-option value="1" label="是"></el-option>
            <el-option value="0" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="vipFlag">
          <el-select
            v-model.trim="searchForm.vipFlag"
            filterable
            clearable
            placeholder="是否购买VIP"
          >
            <el-option value="1" label="是"></el-option>
            <el-option value="0" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="theoryPriceFlag">
          <el-select
            v-model.trim="searchForm.theoryPriceFlag"
            filterable
            clearable
            placeholder="是否购买乐理课"
          >
            <el-option value="1" label="是"></el-option>
            <el-option value="0" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="primary">搜索</el-button>
          <el-button native-type="reset" type="danger">重置</el-button>
        </el-form-item>
      </save-form>

      <!-- <statistic :col="6" class="statistic" :cols="0">
        <statistic-item>
          <span><count-to :endVal="3000" /></span>
          <span>器乐考级人次</span>
        </statistic-item>
        <statistic-item>
          <span><count-to :endVal="3000" /></span>
          <span>器乐考级人次</span>
        </statistic-item>
        <statistic-item>
          <span><count-to :endVal="3000" /></span>
          <span>器乐考级人次</span>
        </statistic-item>
        <statistic-item>
          <span><count-to :endVal="3000" /></span>
          <span>器乐考级人次</span>
        </statistic-item>
        <statistic-item>
          <span><count-to :endVal="3000" /></span>
          <span>器乐考级人次</span>
        </statistic-item>
        <statistic-item>
          <span><count-to :endVal="3000" /></span>
          <span>器乐考级人次</span>
        </statistic-item>
      </statistic> -->
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column
            align="center"
            prop="username"
            label="学员姓名"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="userId"
            label="学员编号"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="phone"
            label="手机号"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="subjectName"
            label="报考声部"
          ></el-table-column>
          <el-table-column align="center" prop="isReserve" label="是否预约">
            <template slot-scope="scope">
              <div>
                {{ scope.row.isReserve ? "是" : "否" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="studentId" label="器乐报考等级">
            <template slot-scope="scope">
              <div>
                {{ scope.row.gradeLeave ? scope.row.gradeLeave + "级" : "-" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="studentId" label="乐理报考等级">
            <template slot-scope="scope">
              <div>
                {{ scope.row.theoryLevel ? scope.row.theoryLevel + "级" : "-" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="studentId" label="是否购买VIP">
            <template slot-scope="scope">
              <div>
                {{ scope.row.buyVipFlag ? "是" : "否" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="studentId"
            label="是否购买乐理课"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.buyTheoryCourseFlag ? "是" : "否" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="studentId" label="支付金额">
            <template slot-scope="scope">
              <div>
                {{ scope.row.totalAmount | moneyFormat }}
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { getToken } from "@/utils/auth";
import pagination from "@/components/Pagination/index";
import load from "@/utils/loading";
import { getMusicGroupDetail } from "./api";
import { getSubject } from "@/api/buildTeam";
import countTo from "vue-count-to";
export default {
  components: { pagination, "count-to": countTo },

  data() {
    return {
      searchForm: {
        search: null,
        isReserve: null,
        subjectId: null,
        gradeFlag: null,
        vipFlag: null,
        theoryPriceFlag: null,
        theoryFlag: null,
      },

      tableList: [{}],
      soundList: [],
      cooperationList: [],
      musicList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      musicGroupName: "",
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    // 获取分部
    this.$store.dispatch("setBranchs");
    this.init();
  },
  methods: {
    init() {
      this.musicGroupName = this.$route.query.musicGroupName || "对外分部";
      getSubject({}).then((res) => {
        if (res.code == 200) {
          this.soundList = res.data;
        }
      });
      this.getList();
    },
    async getList() {
      try {
        const res = await getMusicGroupDetail({
          page: this.rules.page,
          rows: this.rules.limit,
          ...this.searchForm,
          musicGroupId: this.$route.query.musicGroupId,
          cooperationId:this.$route.query.cooperationOrganId || null,
          organId: this.$route.query.organId || null,
        });
        this.tableList = res.data.rows;
        this.rules.total = res.data.total;
      } catch(e) {
        console.log(e)
      }
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      this.rules = {
        ...this.rules,
        page: 1,
      };
      this.$refs.searchForm.resetFields();
      this.search();
    },
    onCancel() {
      this.$store.dispatch("delVisitedViews", this.$route);
      this.$router.push({
        path: "/childrensDay",
      });
    },
  },
};
</script>
<style lang='scss' scoped>
.statistic {
  .statistic-content > span {
    font-size: 20px !important;
    &:first-child {
      font-size: 24px !important;
      color: rgba(0, 0, 0, 0.85);
      font-weight: bold;
    }
  }
}
</style>
