<template>
  <div class="page-body myOrder">
    <div class="row col" style="height: 40px">
      <div class="row col" style="justify-content: space-between;align-items: center;margin-bottom: 10px" >

        <div>
          <template v-if="data&& data.ClassInfo">
            {{data.ClassInfo.ClassName}}
          </template>
        </div>
        <div class="row" style="align-items: center">
          <span>带班老师</span>
          <img :src="data.ClassInfo&&data.ClassInfo.TeacherIcon?data.ClassInfo.TeacherIcon:''" style="width:30px;height: 30px;border-radius: 50%;margin: 0 10px" />
          <span v-if="data&& data.ClassInfo" style="color:#2961FE;font-weight: bold">
            {{data.ClassInfo.TeacherName}}
          </span>
        </div>
      </div>
    </div>
    <div class="page-content">
      <orderlist :dataList="dataList" ref="orderL" :cancelList="CancelList" @success="refreshClassOrder"></orderlist>
    </div>
  </div>
</template>
<script>
  import {
    quertClassOrderList
  } from '../../api/sale/sale';

  import orderlist from '../../components/sale/orderlist'
  export default {
    components: {
      orderlist
    },
    data() {
      return {
        data: {},
        msg: {
          ClassId: 0
        },
        //正常订单
        dataList: [],
        //取消订单
        CancelList: [],
      }
    },
    created() {
      if (this.$route.query.ClassId) {
        this.ClassId = this.$route.query.ClassId
        this.msg.ClassId = this.ClassId;

      }
      this.getList();
    },
    mounted() {

    },
    methods: {
      //获取菜单分页列表
      getList() {
        this.loading = true;
        quertClassOrderList(this.msg).then(res => {

          this.data = res.Data;
          if (this.data && this.data.OrderList && this.data.OrderList.NorList) {
            this.dataList = this.data.OrderList.NorList;
            let OrderIds=[]
            this.dataList.forEach(x=>{
              OrderIds.push(x.OrderId)
            })
            if(OrderIds.length>0){
              OrderIds = OrderIds.join(',')
              // this.getOrderFinanceList(OrderIds,1)
              this.$refs.orderL.getOrderFinanceList(OrderIds,1)

            }

          }
          if (this.data && this.data.OrderList && this.data.OrderList.CancelList) {
            this.CancelList = this.data.OrderList.CancelList;
            let OrderIds=[]
            this.CancelList.forEach(x=>{
              OrderIds.push(x.OrderId)
            })
            if(OrderIds.length>0){
              OrderIds = OrderIds.join(',')
              // this.getOrderFinanceList(OrderIds,2)
              this.$refs.orderL.getOrderFinanceList(OrderIds,2)

            }
          }
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      },
      getOrderFinanceList(msg,type){
        this.apipost('sellorder_post_GetOrderFinanceListForEdu',{OrderIds:msg},res=>{
          if(res.data.resultCode===1){
            this.loading = false;
            let data = res.data.data;
            if(type == 1){
              this.dataList.forEach(x=>{
                data.forEach(j=>{
                  if(x.OrderId == j.OrderId){
                    x.FinanceList = j.FinanceList
                    x.RefundFinanceList = j.RefundFinanceList
                  }
                })
              })
            }else if(type ==2){
              this.CancelList.forEach(x=>{
                data.forEach(j=>{
                  if(x.OrderId == j.OrderId){
                    x.FinanceList = j.FinanceList
                    x.RefundFinanceList = j.RefundFinanceList
                  }
                })
              })
            }
          }else{
            this.loading = false;
            this.$message.error(res.data.message);
          }
        },err=>{})
      },
      //刷新页面
      refreshClassOrder() {
        this.getList();
      }
    }
  }

</script>
<style>

</style>
