<template>
  <div v-loading="loading">
    <div class="heior_box">
      <el-button size="small" type="primary" icon="el-icon-sold-out" @click="showDialog=true">认领</el-button>
      我认领的订单数：{{order_num}}
      <div class="search-box">
        <el-input v-model="searchModel.Channel" size="small" placeholder="请输入销售员"></el-input>
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
        <el-input v-model="searchModel.keyWord" placeholder="请输入产品名称" clearable size="small">
          <el-button slot="append" icon="el-icon-search" @click="get"></el-button>
        </el-input>
      </div>
    </div>
    <el-table
      :data="retData"
      border
      size="medium"
      :height="$getHeight(100)"
      :span-method="mergeSpan"   
      show-summary         
    >
      <el-table-column prop="Channel" label="销售员"></el-table-column>
      <el-table-column prop="ProductName" label="产品"></el-table-column>
      <el-table-column prop="NewBuyCount" label="新开个数"></el-table-column>
      <el-table-column prop="NewBuyAmount" label="新开金额"></el-table-column>
      <el-table-column prop="AgainBuyCount" label="续费个数"></el-table-column>
      <el-table-column prop="AgainBuyAmount" label="续费金额"></el-table-column>
       <el-table-column prop="SellAmount" label="销售金额"></el-table-column>
      <!-- <el-table-column prop="RefundCount" label="退货个数"></el-table-column>
      <el-table-column prop="RefundAmount" label="退货金额"></el-table-column> -->
      <!-- <el-table-column prop="PaymentAmount" label="换货个数"></el-table-column>
      <el-table-column prop="PaymentAmount" label="换货金额"></el-table-column>-->
    </el-table>
    <el-dialog title="认领订单" :visible.sync="showDialog" width="300px">
      <el-form :model="takeModel" ref="inputForm" label-width="80px">
        <el-form-item prop="phone" label="手机号">
          <el-input v-model="takeModel.phone" size="small"></el-input>
        </el-form-item>
        <el-form-item prop="amount" label="订单金额">
          <el-input v-model="takeModel.amount" size="small" type="number"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetForm('inputForm')">取 消</el-button>
        <el-button type="primary" @click="take()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "treeTable",
  components: {},
  data() {
    return {
      loading: false,
      showDialog:false,
      retData:[],
      order_num:0,
      seller:'',
      
      takeModel:{
        phone:'',
        amount:''
      },
      searchModel: {
        PageIndex: 1,
        Channel:'',
        keyWord: "",
        Status: 0,
        PayType: 0,
        Btime: "",
        Etime: ""
      },
       dateRange:[],
      flagMap:{}
    };
  },
  created() {
    this.$store.commit("setCurrentNav","销售管理>>销售员统计分析")
    this.get();
   
  },
  methods: {
    get() {
      this.flagMap={};
      if (this.dateRange && this.dateRange.length == 2) {
        this.searchModel.Btime = this.dateRange[0];
        this.searchModel.Etime = this.dateRange[1];
      }
      this.$api.get("course/v1/order/SellerStatistics", this.searchModel).then(res => {
        this.retData = res.Data;
        this.retData.forEach(item=>{
          var flag=this.flagMap[item.Channel];
          if(!flag){
            this.flagMap[item.Channel]=true;
             var count=this.retData.filter(m=>m.Channel== item.Channel).length;
             item.rSpan=count;
             item.cSpan=1;
          }else{
             item.rSpan=0;
             item.cSpan=0;
          }         
        })
      })
       this.$api.get(this.$api.phpURL + 'order/order/takeOrderNum', this.searchModel).then(res => {
      this.order_num = res.num;
    })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.showDialog = false;    
    },
    take(){
       this.$api.get("course/v1/order/TakeOrder", this.takeModel).then(res => {
        this.resetForm('inputForm')
      });      
    },
    mergeSpan({row, column, rowIndex, columnIndex}){    
      if (columnIndex === 0) {
          console.log(`${row.rSpan}-${row.cSpan}`)
        return {
              rowspan: row.rSpan,
              colspan: row.cSpan
        }       
     }
    }
  }
};
</script>
<style scoped>
.el-table{
overflow:visible !important;
}
</style>
