<template>
  <div class="salesStatistics" 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="querychange" style="margin-right: 10px;" v-model="msg.PlatformType"
          size="small" placeholder="请选择">
          <el-option label="全部平台" :value="0"></el-option>
          <el-option v-for="(item,index) in options" :key="index" :label="item.Name" :value="item.Id">
          </el-option>
        </el-select>
        <el-select class="w100" @change="querychange" style="margin-right: 10px;" size="small" v-model="msg.OrderType"
          placeholder="请选择">
          <el-option label="全部订单" :value="0"></el-option>
          <el-option v-for="(item,index) in options2" :key="index" :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="DateValue" type="daterange"
            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
            @change="querychange" 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 class="table-area">
      <div class="el-card is-never-shadow">
        <div class="el-card__header">
          <div>
            <span>总成交</span>
          </div>
        </div>
        <div class="el-card__body">
          <div class="num-info">
            <div class="num-info-item">
              <div>{{Totaldata.OrderNum!=null ?Totaldata.OrderNum:0 }}</div>
              <div class="info-item-name">付款订单数/个</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata.GoodsNum!=null ?Totaldata.GoodsNum:0 }}</div>
              <div class="info-item-name">付款件数/件</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata.PayMemerNum!=null ?Totaldata.PayMemerNum:0 }}</div>
              <div class="info-item-name">付款人次/人</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata.MemberNum!=null ?Totaldata.MemberNum:0 }}</div>
              <div class="info-item-name">付款人数/人</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata.PayMoney!=null ?Totaldata.PayMoney:0 }}</div>
              <div class="info-item-name">付款金额/元</div>
            </div>
          </div>
        </div>
      </div>
      <div class="el-card is-never-shadow">
        <div class="el-card__header">
          <div>
            <span>今日实时成交</span>
          </div>
        </div>
        <div class="el-card__body">
          <div class="num-info">
            <div class="num-info-item">
              <div>{{Totaldata2.OrderNum!=null ?Totaldata2.OrderNum:0 }}</div>
              <div class="info-item-name">付款订单数/个</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata2.GoodsNum!=null ?Totaldata2.GoodsNum:0 }}</div>
              <div class="info-item-name">付款件数/件</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata2.PayMemerNum!=null ?Totaldata2.PayMemerNum:0 }}</div>
              <div class="info-item-name">付款人数/人</div>
            </div>
            <div class="num-info-item">
              <div>{{Totaldata2.PayMoney!=null ?Totaldata2.PayMoney:0 }}</div>
              <div class="info-item-name">付款金额/元</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="table-area" style="display:none;">
      <div class="el-card is-never-shadow">
        <div class="el-card__header">
          <div>
            <span>活跃人数</span>
          </div>
        </div>
        <div class="el-card__body">
          <div class="num-info">
            <div class="num-info-item">
              <div>
                {{loginData.LoginTotal}}
              </div>
              <div class="info-item-name">总人数</div>
            </div>
            <div class="num-info-item">
              <div>
                {{loginData.LoginEmployee}}
              </div>
              <div class="info-item-name">内部员工</div>
            </div>
            <div class="num-info-item">
              <div>
                {{loginData.LoginLeader}}
              </div>
              <div class="info-item-name">领队导游</div>
            </div>
          </div>
        </div>
      </div>
      <div class="el-card is-never-shadow">
        <div class="el-card__header">
          <div>
            <span>下单人数</span>
          </div>
        </div>
        <div class="el-card__body">
          <div class="num-info">
            <div class="num-info-item">
              <div>
                {{orderData.OrderTotal}}
              </div>
              <div class="info-item-name">总下单人数</div>
            </div>
            <div class="num-info-item">
              <div>
                {{orderData.OrderEmployee}}
              </div>
              <div class="info-item-name">内部员工人数</div>
            </div>
            <div class="num-info-item">
              <div>
                {{orderData.OrderLeader}}
              </div>
              <div class="info-item-name">领队导游人数</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div style="padding: 20px;background: #fff;margin-top: 10px">
      <el-tabs v-model="msg.OrderStatus" @tab-click="handleClick2">
        <el-tab-pane v-for="(item,index) of tabsList" :key="index" :label="item.Name" :name="item.ID"></el-tab-pane>
      </el-tabs>
      <el-table v-loading="Listloading" :data="tableData" header-cell-class-name="headClass" style="width: 100%;">
        <el-table-column prop="CreateDate" label="日期" min-width="2">
        </el-table-column>
        <el-table-column prop="PayMemerNum" label="付款人数" min-width="2">
        </el-table-column>
        <el-table-column prop="OrderNum" label="付款订单数" min-width="2">
        </el-table-column>
        <el-table-column prop="PayMoney" label="付款金额" min-width="2">
        </el-table-column>
        <el-table-column prop="GoodsNum" label="付款件数" min-width="2">
        </el-table-column>
        <el-table-column prop="RepurchaseNum" v-if="msg.OrderStatus!=4&&msg.OrderStatus!=5" label="复购人数" min-width="2">
        </el-table-column>
        <el-table-column prop="LoginEmpActive" v-if="msg.OrderStatus==0" label="内部员工活跃人数" min-width="2">
        </el-table-column>
        <el-table-column prop="LoginLeaderActive" v-if="msg.OrderStatus==0" label="领队导游活跃人数" min-width="2">
        </el-table-column>
        <el-table-column prop="OrderEmpActive" v-if="msg.OrderStatus==0" label="内部员工下单人数" min-width="2">
        </el-table-column>
        <el-table-column prop="OrderLeaderActice" v-if="msg.OrderStatus==0" label="领队导游下单人数" min-width="2">
        </el-table-column>
      </el-table>
      <el-pagination style="text-align:right" background @current-change="handleCurrentChange" :page-size="msg.pageSize"
        :current-page.sync="msg.pageIndex" layout="prev, pager, next" :total="count">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    name: "salesStatistics",
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 20,
          PlatformType: 0,
          StartDate: '',
          EndDate: '',
          OrderStatus: 0,
          OrderType: 0,
        },
        Listloading: false,
        tabsList: [{
            Name: "全部",
            ID: "0"
          },
          {
            Name: "未完成订单",
            ID: "1"
          },
          {
            Name: "已完成订单",
            ID: "2"
          },
          {
            Name: "已取消订单",
            ID: "3"
          },
          {
            Name: "售后中订单",
            ID: "4"
          },
          {
            Name: "已完成售后订单",
            ID: "5"
          },
        ],
        options: [],
        options2: [],
        Coupon: 0,
        tableData: [],
        count: 0,
        DateValue: '',
        activeName: '',
        loading: false,
        Totaldata: {
          OrderNum: "0",
          GoodsNum: "0",
          PayMemerNum: "0",
          PayMoney: "0",
        },
        Totaldata2: {
          OrderNum: "0",
          GoodsNum: "0",
          PayMemerNum: "0",
          PayMoney: "0",
        },
        loginData: {},
        orderData: {},
      }
    },
    created() {

    },
    methods: {
      getplat() {
        this.apipost("/api/User/GetMemberUserSourceEnumList", {}, res => {
          if (res.data.resultCode == 1) {
            this.options = res.data.data;
          }
        })
      },
      getOrderTypeEnumEnumList() {
        this.apipost("/api/Order/GetOrderTypeEnumEnumList", {}, res => {
          if (res.data.resultCode == 1) {
            this.options2 = res.data.data;
          }
        })
      },
      //7日和30日切换
      handleClick(tab, event) {
        if (tab.name == 'first') {
          this.fun_date(7)
        } else if (tab.name == 'second') {
          this.fun_date(30)
        }
        this.querychange(tab.name);
      },
      //查询添加改变
      querychange(name) {
        if (name && name != '') {
          this.activeName = name
        } else {
          this.activeName = ''
        }
        this.msg.pageIndex = 1
        if (this.DateValue != '' && this.DateValue != null) {
          this.msg.StartDate = this.DateValue[0];
          this.msg.EndDate = this.DateValue[1];
        } else {
          this.msg.StartDate = '';
          this.msg.EndDate = '';
        }
        this.getIntegraStatisticslList();
        this.getTodayStatics();
        this.getDataList(true)
      },
      //订单列表统计分页切换
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getDataList();
      },
      //获取订单分页列表
      getDataList(show = false) {
        if (show == true) {
          this.Listloading = true;
        }
        this.apipost("/api/Statistics/GetSellPageList", this.msg, res => {
          this.Listloading = false
          if (res.data.resultCode == 1) {
            this.tableData = res.data.data.pageData;
            this.count = res.data.data.count;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //获取订单统计
      getIntegraStatisticslList() {
        this.loading = true;
        let Totalmsg = {
          PlatformType: this.msg.PlatformType,
          StartDate: this.msg.StartDate,
          EndDate: this.msg.EndDate,
          OrderType: this.msg.OrderType,
        }
        this.apipost("/api/Statistics/GetSellOrder", Totalmsg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.Totaldata = res.data.data;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //获取今日实时成交
      getTodayStatics() {
        let Totalmsg2 = {
          PlatformType: this.msg.PlatformType,
          StartDate: this.msg.StartDate,
          EndDate: this.msg.EndDate,
          OrderType: this.msg.OrderType,
        }
        var day1 = new Date();
        day1.setTime(day1.getTime());
        var s1 = day1.getFullYear() + "-" + (day1.getMonth() + 1) + "-" + day1.getDate();
        Totalmsg2.StartDate = s1
        Totalmsg2.EndDate = s1
        this.apipost("/api/Statistics/GetSellOrder", Totalmsg2, res => {
          if (res.data.resultCode == 1) {
            this.Totaldata2 = res.data.data;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      Export() {
        let msg = {
          PlatformType: this.msg.PlatformType,
          StartDate: this.msg.StartDate,
          EndDate: this.msg.EndDate,
          OrderType: this.msg.OrderType,
        }
        msg = JSON.parse(JSON.stringify(msg));
        this.GetLocalFile(
          "/api/Statistics/GetSellExcel",
          msg,
          "销售统计.xls"
        );
      },
      empty() {
        this.msg.PlatformType = 0;
        this.msg.OrderType = 0;
        this.msg.StartDate = '';
        this.msg.EndDate = '';
        this.msg.pageIndex = 1
        this.DateValue = '';
        this.activeName = '';
        this.querychange();
      },
      //订单状态切换
      handleClick2() {
        this.msg.pageIndex = 1;
        this.getDataList(true)
      },
      //计算日期
      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.DateValue = data;
      },
    },
    mounted() {
      this.getplat();
      this.getOrderTypeEnumEnumList()
      this.querychange()
    }
  }

</script>

<style>
  .salesStatistics .el-card__header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #fff;
  }

  .salesStatistics .el-button--small {
    padding: 9px 15px;
  }

  .salesStatistics .content .searchInput {
    border: 1px solid #DCDFE6;
    border-radius: 4px;
  }

  .salesStatistics .content .searchInput .el-input__inner {
    border: none;
    outline: none;
    height: 30px;
    line-height: 30px;
  }

  .salesStatistics .content .searchInput {
    line-height: normal;
    display: inline-table;
    border-collapse: separate;
    border-spacing: 0;
    width: 250px;
    margin-right: 20px;
  }

  .salesStatistics .content {
    background: #fff;
    margin-top: 10px;
    padding: 15px;
    box-sizing: border-box;
  }

  .salesStatistics .el-icon-date {
    line-height: 24px;
  }

  .salesStatistics .el-range-separator {
    line-height: 24px;
  }

  .salesStatistics .zong {
    width: 100%;
    height: 57px;
    padding: 18px 20px;
    border-bottom: 1px solid #EBEEF5;
    background: white;
  }

  .salesStatistics .table-area {
    margin: 10px 0;
    display: flex;
    justify-content: space-between;
  }

  .salesStatistics .table-area .el-card {
    width: 49.5%;
    color: #303133;
  }

  .salesStatistics .el-card {
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    color: #303133;
    -webkit-transition: .3s;
    transition: .3s;
  }

  .salesStatistics .el-card__header {
    padding: 18px 20px;
    border-bottom: 1px solid #EBEEF5;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }

  .salesStatistics .el-card__body {
    padding: 20px;
  }

  .salesStatistics .num-info {
    display: flex;
    width: 100%;
    height: 60px;
    font-size: 24px;
    color: #303133;
    margin: 20px 0;
  }

  .salesStatistics .num-info .num-info-item {
    text-align: center;
    flex-grow: 1;
    border-left: 1px dashed #EFF1F7;
  }

  .salesStatistics .info-item-name {
    font-size: 14px;
    color: #92959B;
  }

</style>
