<!-- 收银台订单-->
<template>
  <div class="container" >

      <div class="wgang">
        <div style="display: flex;align-items: center ">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="120px">
            <el-date-picker
              v-model="queryParams.dataRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form>
        </div>
        <div>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </div>
      </div>
    <div class="wit_box">
      <div class="box-gang">
        <div class="box">
          <el-tooltip class="item" effect="dark" content="订单总金额（元）/笔数" placement="top-start">
            <div class="size-bole">
              {{orderNewStatisticstow.orderMoney?orderNewStatisticstow.orderMoney:0}}/
              {{orderNewStatisticstow.orderNum?orderNewStatisticstow.orderNum:0}}</div>
          </el-tooltip>
          <div class="size-hui">
            <div class="dian" style="background: #0DC291"></div>
            <div class="nei">订单总金额（元）/笔数</div>
          </div>
        </div>
        <div class="box">
          <el-tooltip class="item" effect="dark" content="实收总金额（元）" placement="top-start">
            <div class="size-bole" style="color:#00CAFF;">
              {{orderNewStatisticstow.trueMoney?orderNewStatisticstow.trueMoney:0}}</div>
          </el-tooltip>
          <div class="size-hui">
            <div class="dian" style="background: #00CAFF"></div>
            <div class="nei">实收总金额（元）</div>
          </div>
        </div>
        <div class="box">
          <el-tooltip class="item" effect="dark" content="退款总金额（元）/笔数" placement="top-start">
            <div class="size-bole" style="color:#F44522;" >{{orderNewStatisticstow.backOrderMoney?orderNewStatisticstow.backOrderMoney:0}}/
              {{orderNewStatisticstow.backOrderNum?orderNewStatisticstow.backOrderNum:0}}</div>
          </el-tooltip>

          <div class="size-hui">
            <div class="dian" style="background: #F44522"></div>
            <div class="nei">退款总金额（元）/笔数</div>
          </div>
        </div>
        <div class="box">
          <el-tooltip class="item" effect="dark" content="日均订单金额（元）" placement="top-start">
            <div class="size-bole"  style="color:#FF7E00;" >{{orderNewStatisticstow.dayaverageOrderMoney?orderNewStatisticstow.dayaverageOrderMoney:0}}</div>
          </el-tooltip>
          <div class="size-hui">
            <div class="dian" style="background: #FF7E00"></div>
            <div class="nei">日均订单金额（元）</div>
          </div>
        </div>
      </div>


      <div class="table-box">
        <el-table
          :data="orderNewStatistics"
          border
          style="width: 100%;margin-top: 15px">
          <el-table-column type="index" width="50" align="center" label="序号"/>
<!--          <el-table-column prop="deptId" align="center" label="门店编号"> </el-table-column>-->
          <el-table-column prop="orderType" align="center" label="订单分类"> </el-table-column>
          <el-table-column prop="orderMoney" align="center" label="订单金额"> </el-table-column>
          <el-table-column prop="trueMoney" align="center" label="实收金额"> </el-table-column>
          <el-table-column prop="orderNum" align="center" label="订单笔数"> </el-table-column>
          <el-table-column prop="oneOrderMoney" align="center" label="笔单价">
          </el-table-column>
          <el-table-column prop="dayaverageOrderMoney" align="center" label="日均交易金额">
          </el-table-column>
          <el-table-column prop="dayaverageOrderNum" align="center" label="日订单笔数">

          </el-table-column>
          <el-table-column prop="backOrderMoney" align="center" label="退款金额"> </el-table-column>
          <el-table-column prop="backOrderNum" align="center" label="退款笔数"> </el-table-column>
          <el-table-column prop="leaderName" align="center" label="统计周期">
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-box">
        <el-pagination
          background
          v-show="total>0"
          layout="prev, pager, next"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.pageSize"
          @current-change="getList">
        </el-pagination>
      </div>

    </div>
  </div>
</template>

<script>

import {
  getInstituionListApi,
  getRunningWaterByDataApi,
  exportExcelOilDeptApi,
  getmyDataApi,
  getInstituionListApi2,
  getInstituionListApi6
} from "@/api/allOrder";
import {getInstituionListApi3} from "../../../../api/allOrder";
  export default {
    name: "runningWater-oilDepot",
    data(){
      return{
        loading:false,
        // 员工列表
        staffList:[],
        // 日期范围
        dataRange: [],
        beginTime:"",
        endTime:"",
        // 是否为当天时间
        isSysDate:false,
        // 收银台订单列表
        orderList:[],
        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 10,
          beginTime:"",
          endTime:"",
          deptType:"3",
          dataRange: [],
        },
        orderStatistics:{
          numberOfStrokes:'0',
          theTotalAmountOfTheOrder:'0',
          theTotalAmountPaid:'0',
          oilDiscounts:'0',
          theTotalAmountOfOil:'0',
          theTotalAmountOfTheItem:'0',
        },

        orderNewStatistics:{
          orderType:'',
          orderMoney:"0",
          trueMoney:"0",
          orderNum:"0",
          oneOrderMoney:"0",
          dayaverageOrderMoney:"0",
          dayaverageOrderNum:"0",
          backOrderMoney:"0",
          backOrderNum:"0",
        },

        orderNewStatisticstow:{
          orderType:'',
          orderMoney:"0",
          trueMoney:"0",
          orderNum:"0",
          oneOrderMoney:"0",
          dayaverageOrderMoney:"0",
          dayaverageOrderNum:"0",
          backOrderMoney:"0",
          backOrderNum:"0",
        },
        total:0,
        timeDifference:1,
      }
    },
    async created() {
      let start = new Date();
      start.setHours(0)
      start.setMinutes(0)
      start.setSeconds(0)
      start.setMilliseconds(0)
      let year = start.getFullYear();  // 获取年份
      let month = String(start.getMonth() + 1).padStart(2, '0');  // 获取月份，月份从0开始所以要+1
      let date = String(start.getDate()).padStart(2, '0');  // 获取日期
      this.queryParams.dataRange = [ year+'-'+month+'-'+date, year+'-'+month+'-'+date];
      this.isSysDate = true
      await this.getDeptList();
      this.getList();
      this.getStatisticsAll()

    },
    methods:{
      getDays(){

        this.timeDifferenceMilliseconds = this.endTime - this.beginTime;
        this.timeDifference = timeDifferenceMilliseconds / (1000 * 60 * 60 * 24);
        console.log("timeDifference",this.timeDifference)

      },
      exportExcelCashier() {
        let dateRange = []
        if (this.beginTime && this.endTime) {
          dateRange.push(this.beginTime.toLocaleDateString())
          dateRange.push(this.endTime.toLocaleDateString())
        }
        exportExcelOilDeptApi(this.addDateRange(this.queryParams, dateRange)).then(res=>{
          const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
          this.$download.saveAs(blob,'油站流水订单统计.xLsx')
        })
      },

      getOrderStatistics() {
        let dateRange = []
        if (this.beginTime && this.endTime) {
          dateRange.push(this.beginTime.toLocaleDateString())
          dateRange.push(this.endTime.toLocaleDateString())
        }
        getRunningWaterByDataApi(this.addDateRange(this.queryParams, dateRange)).then(res=>{
          this.orderStatistics = res.data
        })
      },
      async getDeptList() {
        await getmyDataApi(this.addDateRange(this.queryParams)).then( response => {
          this.queryParams.deptId = response.data.deptId;
        })
      },

      // 获取列表信息
       getList(val){
         getInstituionListApi2(this.queryParams).then( response => {
          this.orderNewStatistics = response.data
           console.log(this.orderNewStatistics.orderMoney)
          this.isSysDate = false
        })
        //this.getOrderStatistics()
      },
      // 获取列表信息
      getStatisticsAll(val){
        getInstituionListApi6(this.queryParams).then( response => {
          this.orderNewStatisticstow = response.data
          console.log(this.orderNewStatisticstow.orderMoney)
        })
        //this.getOrderStatistics()
      },
      // 搜索按钮操作
      async handleQuery() {
        this.queryParams.page = 1;
        await this.getDeptList();
        this.getList();
        this.getStatisticsAll();
      },
      // 重置按钮操作

      async resetQuery() {
        this.dateRange = [];
        this.queryParams = {
          page: 1,
          pageSize: 10,
          deptType:"3",

        }
        this.beginTime = ""
        this.endTime = ""
        await this.getDeptList()
        this.handleQuery();
      },
    }
  }
</script>

<style scoped lang="scss">
.container{
  background: #f4f5f9;
  box-sizing: border-box;
  padding-bottom: 8px;
}
  .app-top{
    width: 100%;
    height: 60px;
    box-sizing: border-box;
    padding: 10px;
  }
  .clearfix{
    width: 100%;

  }
  .box-card{
    width: 100%;
    margin-bottom: 15px;
  }
.card-chan{
  width: 98%;
  background: #fff;

  margin: 10px auto;
  box-sizing: border-box;
  padding: 10px;
  margin-bottom: 5px;
  border-radius: 4px;
}

.box-gang{
  width: 100%;
  display: flex;
  align-items: center;
}
.box{
  padding: 5px;
  padding-left: 20px;
  width: 280px;
  height: 60px;
  background:#fff;
  border-radius: 10px;
  border: 1px solid #FF9655;
  margin-right: 15px;
}
  .el-form--inline .el-form-item {
    margin-right: 44px;
    margin-bottom: 0px;
  }
  .size-hui{
    display: flex;
    align-items: center;
    //width: 200px;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 400;
    font-size: 13px;
    color: #888888;
    //line-height: 0px;
    text-align: left;
    font-style: normal;
    text-transform: none;

  }
  .size-bole{
    height: 31px;
    //font-family: YouSheBiaoTiHei;
    font-weight: 600;
    font-size: 24px;
    color: #555555;
    //line-height: 0px;
    text-align: left;
    font-style: normal;
    text-transform: none;
  }
  .wgang{
    width: 99%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px auto;
    box-sizing: border-box;
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 4px;

  }
.table-box{
  width: 100%;
  height: 58vh;
  overflow: auto;
}
.wit_box{
  width: 99%;
  background: #FFFFFF;
  margin: 5px auto;
  box-sizing: border-box;
  padding: 15px;
  border-radius: 4px;
  height: 78vh;
}
  .pagination-box{
    width: 100%;
    margin: 10px auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .top-app-sou{
    width: 20%;
  }
  .tk{
    text-align: center;
    color: grey;
    margin: 10px 0;
  }
  .icon-img{
    //margin-left: 110px;
    width: 100%;
    height: 20px;
    margin-right: 5px;
    img{
      float: right;
      //width: 100%;
      width: 20px;
      height: 100%;
    }
  }
</style>
