<!--  -->
<template>
  <div class="m-container">
    <el-page-header
      @back="onCancel"
      :content="title"
    ></el-page-header>
    <div class="m-core">
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
      >
        <!-- <el-form-item prop="organId">
          <el-select
            class="multiple"
            style="width: 180px !important"
            v-model.trim="searchForm.organId"
            filterable
            clearable
            placeholder="请选择分部"
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item prop="chargeType">
          <el-select
            v-model.trim="searchForm.chargeType"
            filterable
            clearable
            placeholder="请选择乐团模式"
          >
            <el-option
              v-for="(item, index) in typeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="subjectId">
          <el-select
            class="multiple"
            style="width: 180px !important"
            v-model.trim="searchForm.subjectId"
            filterable
            clearable
            placeholder="请选择声部"
          >
            <el-option
              v-for="(item, index) in selects.subjects"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="teacherId">
          <remote-search
            :commit="'setTeachers'"
            aria-placeholder="请选择指导老师"
            v-model.trim="searchForm.teacherId"
          />
        </el-form-item>
        <el-form-item prop="remarkType">
          <el-select
            class="multiple"
            style="width: 180px !important"
            v-model.trim="searchForm.remarkType"
            filterable
            clearable
            placeholder="购买套餐"
          >
            <el-option label="2赠1" value="2赠1"></el-option>
            <el-option label="3赠2" value="3赠2"></el-option>
            <el-option label="单月" value="单月"></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>
          <auth  auths='export/countCloudTeacherActiveDetail'></auth>
          <el-button type="primary" @click="onExport">导出</el-button>
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column
            align="center"
            prop="studentId"
            label="学生姓名(编号)"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.username }}({{ scope.row.userId }})</div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="cooperationName"
            label="合作单位"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="musicGroupName"
            label="乐团"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="chargeType"
            label="乐团模式"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="subjectName"
            label="声部"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="currentGradeNum"
            label="年级"
          >
          <template slot-scope="scope">
            <div>
              {{gradeList[scope.row.currentGradeNum]}}
            </div>
          </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="teacherName"
            label="指导老师"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="remark"
            label="购买套餐"
          ></el-table-column>
          <el-table-column align="center" prop="studentId" label="购买金额">
            <template slot-scope="scope">
              <div>
                {{ scope.row.amount | hasMoneyFormat }}
              </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 { classStatus, courseViewTypeList } from "@/utils/searchArray";
import { getType } from "@/api/buildTeam";
import { getCloudTeacherActiveDetail,getGradeList } from "./api";
import { Export } from "@/utils/downLoadFile";
import cleanDeep from "clean-deep";
import qs from "qs";
export default {
  components: { pagination },
  data() {
    return {
      searchForm: {
        search: null,
        chargeType: null,
        remarkType: null,
        subjectId: null,
        teacherId: null,
      },
      courseViewTypeList,
      tableList: [],
      organList: [],
      typeList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      organId: "",
      title:'',
      gradeList:{}
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  async mounted() {
    this.organId = this.$route.query.organId;
    try{
     const res = await getGradeList({id:this.organId})
     this.gradeList = res.data
    }catch(e){
      console.log(e)
    }
    if (this.$route.query.organName) {
      this.title = `${this.$route.query.organName}分部会员活动详情`
    }else{
        this.title = `分部会员活动详情`
    }
    getType({ rows: 1000 }).then((res) => {
      if (res.code == 200) {
        this.typeList = res.data.rows;
      }
    });
    // await this.$store.dispatch("setBranchs");
    await this.$store.dispatch("setSubjects");

    this.init();
  },
  methods: {
    init() {
      this.getList();
    },
    async getList() {
      console.log("organId", this.organId);
      try {
        const res = await getCloudTeacherActiveDetail({
          organIds: this.organId,
          ...this.searchForm,
          page: this.rules.page,
          rows: this.rules.limit,
        });
        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.$nextTick(() => {
        this.search();
      });
    },
    onCancel() {
      this.$router.push("/2021memeberActionManager");
    },
    async onExport() {
      let obj = {
        organIds: this.organId,
          ...this.searchForm,
      };
      await Export(
        this,
        {
          url: "/api-web/export/countCloudTeacherActiveDetail",
          fileName: "2021十一会员活动详情.xls",
          method: "post",
          params: qs.stringify(cleanDeep(obj)),
        },
        "您确定导出会员活动详情列表?"
      );
    },
  },
};
</script>
<style lang='scss' scoped>
</style>
