<template>
    <div class="integralBudget"  v-loading="loading">
      <div class="el-card__header">
        <span>积分收支</span>
        <div style="display: flex;flex-direction: row;align-items: center">
          <el-button type="primary" class="el-button--small" @click="Export">导出全部</el-button>
        </div>
      </div>
      <div class="content">
        <div style="display: flex;flex-direction: row;align-items: center">
          <el-select class="w100" @change="getList" style="margin-right: 10px;" v-model="msg.PlatformType" size="small" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id">
            </el-option>
          </el-select>
          <div class="block">
            <el-date-picker
              style="padding: 3px 10px;width: 380px;height: 32px"
              v-model="value"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="change()"
              align="right">
            </el-date-picker>
          </div>
          <el-tabs v-model="activeName" @tab-click="handleClick" style="margin-left: 20px">
            <el-tab-pane label="7日" name="first"></el-tab-pane>
            <el-tab-pane label="30日" name="second"></el-tab-pane>

          </el-tabs>

          <span style="color: #92959B;margin-left: 35px;cursor: pointer;font-size: 15px;" @click="empty">清空筛选</span>

        </div>
      </div>
      <div style="margin: 10px 0;">
        <div class="zong">
          总成交
        </div>
        <div class="zongshow">
          <div class="num-info">
            <div class="num-info-item">
              <div>{{Totaldata.Income!=null ?Totaldata.Income:0 }}</div>
              <div class="info-item-name">积分收入</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata.Expend!=null ?Totaldata.Expend:0 }}</div>
              <div class="info-item-name">积分支出</div>
            </div>
          </div>
        </div>
      </div>

      <div style="padding: 20px;background: #fff;margin-top: 10px">
        <el-table
          :data="tableData"
          header-cell-class-name="headClass"
          style="width: 1698px;"
        >

          <el-table-column
            prop="CreateDate"
            label="日期"
            width="566">
          </el-table-column>
          <el-table-column
            prop="Income"
            label="积分收入"
            width="566">
          </el-table-column>

          <el-table-column
            prop="Expend"
            label="积分支出"
          >
          </el-table-column>
        </el-table>
        <el-pagination style="text-align:right"
            background
            @current-change="handleCurrentChange"
            :page-size="msg.pageSize"
            layout="prev, pager, next"
            :current-page.sync="msg.pageIndex"
            :total="count">
        </el-pagination>
      </div>
    </div>
</template>

<script>
    export default {
        name: "integralBudget",
      data(){
          return{
            msg:{
              pageIndex:1,
              pageSize:15,
              PlatformType:0,
              StartDate:'',
              EndDate:'',
            },
            options:[],
            tableData:[],
            count:0,
            value:'',
            activeName:'',
            loading:false,
            Totaldata:{
              Expend:0,
              Income:0,
            },
          }
      },
      created(){
        this.getplat();
        this.getIntegraStatisticslList()
      },
      methods:{
        getplat(){
          this.apipost("/api/User/GetMemberUserSourceEnumList", {}, res => {
            if(res.data.resultCode==1){
              this.options = res.data.data;
              this.options.unshift({Name: "全部平台", Id: 0})
            }

          })
        },
        change(){
          this.activeName='',
          this.msg.pageIndex=1,
          this.getIntegraStatisticslList()
        },
        getIntegraStatisticslList(){
          this.loading=true;
          if(this.value!='' && this.value!=null){
            this.msg.StartDate = this.value[0];
            this.msg.EndDate = this.value[1];
          }else{
            this.msg.StartDate='';
            this.msg.EndDate = ''
          }
          this.apipost("/api/Integral/GetIntegraStatisticslList", this.msg, res => {
            this.loading=false;
            if(res.data.resultCode==1){
              this.tableData = res.data.data.pageData;
              this.count = res.data.data.count;
            }else {
              this.Info(res.data.message);
            }

          })
          let Totalmsg = {
            PlatformType:this.msg.PlatformType,
            StartDate :this.msg.StartDate ,
            EndDate :this.msg.EndDate,
          }

          this.apipost("/api/Integral/GetTotalIntegral", Totalmsg, res => {
            this.loading=false;
            if(res.data.resultCode==1){
              this.Totaldata = res.data.data;
            }else {
              this.Info(res.data.message);
            }

          })

        },

        handleCurrentChange(val) {
          this.msg.pageIndex = val;
          this.getIntegraStatisticslList();
        },
        Export(){
          let msg = {
            PlatformType:this.msg.PlatformType,
            StartDate :this.msg.StartDate ,
            EndDate :this.msg.EndDate,
          }
          msg = JSON.parse(JSON.stringify(msg));
          this.GetLocalFile(
            "/api/Integral/GetIntegralListToExcel",
            msg,
            "积分收支.xls"
          );
        },
        empty(){
          this.msg.PlatformType=0;
          this.msg.StartDate='';
          this.msg.EndDate='';
          this.msg.pageIndex=1
          this.value='';
          this.activeName='';
          this.getIntegraStatisticslList()
        },
        handleClick(tab, event) {

          if(tab.name=='first'){
            this.fun_date(7)
          }else if(tab.name=='second'){
            this.fun_date(30)
          }
        },
        fun_date(num){
          let that= this
          let date1 = new Date();
          //今天时间
          let time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate()
          let date2 = new Date(date1);
          date2.setDate(date1.getDate() - num);
          //num是正数表示之后的时间，num负数表示之前的时间，0表示今天
          let time2 = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
          let data = []
          data.push(time2)
          data.push(time1)
          that.value = data;
          this.msg.pageIndex=1
          this.getIntegraStatisticslList()

        },
        getList(){
          this.msg.pageIndex=1
          this.getIntegraStatisticslList()
        }
      },
      mounted(){

      }
    }
</script>

<style>
  .integralBudget .el-card__header{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #fff;
  }
  .integralBudget .el-button--small{
    padding: 9px 15px;
  }
  .integralBudget .content .searchInput{
    border: 1px solid #DCDFE6;
    border-radius: 4px;
  }
  .integralBudget .content .searchInput .el-input__inner{
    border:none;outline:none;
    height: 30px;
    line-height: 30px;
  }
  .integralBudget .content .searchInput{
    line-height: normal;
    display: inline-table;
    border-collapse: separate;
    border-spacing: 0;
    width:250px;
    margin-right: 20px;
  }
  .integralBudget .content{
    background: #fff;
    margin-top:10px;
    padding: 15px;
    box-sizing: border-box;
  }
  .integralBudget .el-icon-date{
    line-height: 24px;
  }
  .integralBudget .el-range-separator{
    line-height: 24px;
  }
  .integralBudget .zong{
    width: 100%;
    height: 57px;
    padding: 18px 20px;
    border-bottom: 1px solid #EBEEF5;
    background: white;
  }
  .integralBudget .zongshow{
    padding: 20px;
    background: white;
  }
  .integralBudget .num-info {
    display: flex;
    width: 100%;
    height: 60px;
    font-size: 24px;
    color: #303133;
    margin: 20px 0;
  }
  .integralBudget .num-info .num-info-item {
    text-align: center;
    flex-grow: 1;
  }
  .integralBudget .info-item-name {
    font-size: 14px;
    color: #92959B;
  }
</style>
