<template>
  <div class>
    <!-- 头部展示 -->
    <statistic :col="3">
      <statistic-item>
        <span>课程总价</span>
        <span>{{ totalPrice | moneyFormat }}</span>
      </statistic-item>
      <statistic-item>
        <span>实收笔数</span>
        <span>{{ feeDeductionNum }}</span>
      </statistic-item>
      <statistic-item>
        <span>线上课课酬</span>
        <span>{{ onlineClassesUnitPrice | moneyFormat }}</span>
      </statistic-item>
      <statistic-item>
        <span>课酬总额</span>
        <span>{{ totalSalary | moneyFormat }}</span>
      </statistic-item>
      <statistic-item>
        <span>实收总额</span>
        <span>{{ totalFeeDeduction | moneyFormat }}</span>
      </statistic-item>
      <statistic-item>
        <span>线下课课酬</span>
        <span>{{ offlineClassesUnitPrice | moneyFormat }}</span>
      </statistic-item>
    </statistic>
    <!-- 搜索栏 -->
    <save-form :inline="true"
    save-key='vipDetail-fnanceInfo'
             :model="searchForm" @submit='search'>
      <el-form-item label="时间范围">
        <el-date-picker v-model.trim="searchForm.time"
                        style="width:400px;"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="课程开始日期"
                        end-placeholder="课程结束日期"
                        value-format="yyyy-MM-dd"
                        :picker-options="{
        firstDayOfWeek: 1
    }"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button native-type="submit"
                   type="danger">搜索</el-button>
      </el-form-item>
    </save-form>
    <div class="tableWrap">
      <el-table :header-cell-style="{background:'#EDEEF0',color:'#444'}"
                :data="tableList">
        <el-table-column label="课程编号"
                         align="center"
                         prop="courseScheduleId">
        </el-table-column>
        <el-table-column label="上课时间"
                         align="center"
                         prop="classDate">
          <template slot-scope="scope">
            <div>{{ scope.row.classDate | dateForMinFormat }}</div>
          </template>
        </el-table-column>
        <el-table-column label="课时类型"
                         align="center"
                         prop="teachMode">
          <template slot-scope="scope">
            <div>{{ scope.row.teachMode | fitterteachMode }}</div>
          </template>
        </el-table-column>
        <el-table-column label="实收总额"
                         align="center"
                         prop="deductionFee">
          <template slot-scope="scope">
            <div>
              {{scope.row.deductionFee|moneyFormat}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="老师课酬"
                         align="center"
                         prop="actualSalary">

          <template slot-scope="scope">
            <div>
              {{scope.row.actualSalary|moneyFormat}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="结算状态"
                         align="center"
                         prop="isSalary">
          <template slot-scope="scope">
            <div>{{ scope.row.isSalary | fitterisSalary }}</div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <pagination
      save-key='vipDetail-fnanceInfo'
      sync
      :total.sync="rules.total"
                  :page.sync="rules.page"
                  :limit.sync="rules.limit"
                  :page-sizes="rules.page_size"
                  @pagination="getList" />
    </div>
  </div>
</template>
<script>
import pagination from "@/components/Pagination/index";
import { getVipGroupSalarys, getVipGroupDetail } from "@/api/vipSeting";
export default {
  components: { pagination },
  data () {
    return {
      searchForm: {
        time: []
      },
      tableList: [],
      id: "",
      onlineClassesUnitPrice: "",
      totalPrice: "",
      offlineClassesUnitPrice: "",
      totalFeeDeduction: "", // 扣费总额
      feeDeductionNum: "", //扣费笔数
      totalSalary: "", // 课酬总额
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      }
    };
  },
  mounted () {
    this.__init();
  },
  activated () {
    this.__init();
  },
  methods: {
    __init () {
      let id = this.$route.query.id;
      this.id = id;
      this.rules.page = 1
      this.getList();
    },
    search () {
      this.rules.page = 1;
      this.getList();
    },
    getList () {
      if (!this.searchForm.time) {
        this.searchForm.time = [];
      }
      getVipGroupSalarys({
        vipGroupId: this.id,
        organId: null,
        page: this.rules.page,
        rows: this.rules.limit,
        startTime: this.searchForm.time[0] || null,
        endTime: this.searchForm.time[1] || null
      }).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.pageInfo.rows;
          //课程总价 totalPrice
          this.totalPrice = res.data.baseInfo.totalCoursePrice;
          // 扣费总额 totalFeeDeduction
          this.totalFeeDeduction = res.data.baseInfo.totalFeeDeduction;
          //扣费笔数 feeDeductionNum
          this.feeDeductionNum = res.data.baseInfo.feeDeductionNum;
          // 课酬总额 totalSalary
          this.totalSalary = res.data.baseInfo.expectTotalSalary;
          // 线上课课酬
          this.onlineClassesUnitPrice =
            res.data.baseInfo.totalOnlineTeacherSalary;
          // 线下课课酬
          this.offlineClassesUnitPrice =
            res.data.baseInfo.totalOfflineTeacherSalary;
          this.rules.total = res.data.pageInfo.total;
        }
      });
    }
  },
  filters: {
    fitterisSalary (val) {
      let arr = ["未结算", "已结算"];
      return arr[val];
    },
    fitterteachMode (val) {
      if (val == "ONLINE") {
        return "线上课";
      } else if (val == "OFFLINE") {
        return "线下课";
      }
    }
  }
};
</script>
<style lang="scss" scope>
</style>
