<!-- 收银台订单-->
<template>
  <div style="margin-top: 30px">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>收银台订单统计</span>
      </div>
      <div class="box-gang">
        <div class="box">
          <div class="size-hui">交易金额</div>
          <div class="size-bole">{{ isNaN(orderStatistics.amount) ? '0.00' : parseFloat(orderStatistics.amount).toFixed(2) }}</div>
        </div>
        <div class="box">
          <div class="size-hui">交易笔数</div>
          <div class="size-bole">{{ isNaN(orderStatistics.strokeCount) ? '0.00' : parseFloat(orderStatistics.strokeCount).toFixed(2) }}</div>

        </div>
        <div class="box">
          <div class="size-hui">笔单价</div>
          <div class="size-bole">{{ isNaN(orderStatistics.unitPrice) ? '0.00' : parseFloat(orderStatistics.unitPrice).toFixed(2) }}</div>
        </div>
        <div class="box">
          <div class="size-hui">日均交易金额</div>
          <div class="size-bole">{{ isNaN(orderStatistics.dailyAmount) ? '0.00' : parseFloat(orderStatistics.dailyAmount).toFixed(2) }}</div>

        </div>
        <div class="box">
          <div class="size-hui">日均交易笔数</div>
          <div class="size-bole">{{ isNaN(orderStatistics.strokesPerDay) ? '0.00' : parseFloat(orderStatistics.strokesPerDay).toFixed(2) }}</div>

        </div>
        <div class="box">
          <div class="size-hui">活跃机构数</div>
          <div class="size-bole">{{ isNaN(orderStatistics.inertiaStore) ? '0.00' : parseFloat(orderStatistics.inertiaStore).toFixed(2) }}</div>

        </div>
      </div>
    </el-card>
    <el-card class="box-card">
      <div class="wgang">
        <div>机构流水分析列表</div>
        <div style="display: flex ">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="120px">

            <el-form-item label="交易时间：">
              <!--          <el-date-picker-->
              <!--            v-model="dateRange"-->
              <!--            style="width: 400px"-->
              <!--            size="medium"-->
              <!--            value-format="yyyy-MM-dd"-->
              <!--            type="datetimerange"-->
              <!--            range-separator="至"-->
              <!--            start-placeholder="开始日期"-->
              <!--            end-placeholder="结束日期"-->
              <!--          ></el-date-picker>-->
              <el-date-picker
                v-model="beginTime"
                style="width: 140px"
                type="date"
                placeholder="开始日期">
              </el-date-picker>
              至
              <el-date-picker
                v-model="endTime"
                style="width: 140px"
                type="date"
                placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="机构：" prop="staffId">
              <el-select
                v-model="queryParams.staffId"
                clearable
                placeholder="全部"
              >
                <el-option v-for="item in staffList" :key="item.id" :label="item.realName" :value="item.id">
                  <span style="float: left">{{ item.realName }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.mobile }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
              <el-button type="primary" icon="el-icon-plus" @click = "exportExcelCashier()">导出订单</el-button>

            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="table-box">
        <el-table
          :data="orderList"
          style="width: 100%">
          <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="deptName" align="center" label="门店名称"> </el-table-column>
          <el-table-column prop="addr" align="center" label="门店省市"> </el-table-column>
          <el-table-column prop="amount" align="center" label="交易金额"> </el-table-column>
          <el-table-column prop="strokeCount" align="center" label="交易笔数"> </el-table-column>
          <el-table-column prop="unitPrice" align="center" label="笔单价"> </el-table-column>
          <el-table-column prop="dailyAmount" align="center" label="日均交易金额"> </el-table-column>
          <el-table-column prop="strokesPerDay" align="center" label="日均交易笔数"> </el-table-column>
          <el-table-column prop="parentStoreId" align="center" label="机构编号"> </el-table-column>
          <el-table-column prop="parentStoreName" align="center" label="机构名称"> </el-table-column>
          <el-table-column prop="leaderName" align="center" label="站长"> </el-table-column>
<!--          <el-table-column prop="seekZero" align="center" label="品牌编号"> </el-table-column>-->
<!--          <el-table-column prop="seekZero" 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>

    </el-card>
  </div>
</template>

<script>

import {getInstituionListApi, getRunningWaterByDataApi,exportExcelOilDeptApi} from "@/api/allOrder";

  export default {
    name: "runningWater-oilDepot",
    data(){
      return{
        loading:false,
        // 员工列表
        staffList:[],
        // 日期范围
        dateRange: [],
        beginTime:"",
        endTime:"",
        // 是否为当天时间
        isSysDate:false,
        // 收银台订单列表
        orderList:[],
        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 10,
          beginTime:"",
          endTime:"",
          deptType:"3",

        },
        orderStatistics:{
          numberOfStrokes:'0',
          theTotalAmountOfTheOrder:'0',
          theTotalAmountPaid:'0',
          oilDiscounts:'0',
          theTotalAmountOfOil:'0',
          theTotalAmountOfTheItem:'0',
        },
        total:0,
      }
    },
    created() {
      let start = new Date();
      start.setHours(0)
      start.setMinutes(0)
      start.setSeconds(0)
      start.setMilliseconds(0)
      this.dateRange = [start,new Date()];
      this.beginTime = start
      this.endTime = new Date()
      this.isSysDate = true
      this.getList();

    },
    methods:{

      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
        })
      },

      // 获取列表信息
      getList(val){
        let dateRange = []
        if (this.beginTime && this.endTime) {
          dateRange.push(this.beginTime.toLocaleDateString())
          dateRange.push(this.endTime.toLocaleDateString())
        }
        getInstituionListApi(this.addDateRange(this.queryParams,dateRange)).then( response => {
          this.orderList = response.data.records;
          this.total = response.data.total;
          this.isSysDate = false
        })
        this.getOrderStatistics()
      },

      // 搜索按钮操作
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      // 重置按钮操作
      resetQuery() {
        this.dateRange = [];
        this.queryParams = {
          page: 1,
          pageSize: 10,
        }
        this.beginTime = ""
        this.endTime = ""
        this.handleQuery();
      },
    }
  }
</script>

<style scoped>
  .app-top{
    width: 100%;

    height: 60px;
    box-sizing: border-box;
    padding: 10px;
  }
  .clearfix{
    width: 100%;

  }
  .box-card{
    width: 100%;
    margin-bottom: 15px;
  }
  .box-gang{
    width: 100%;
    display: flex;
    align-items: center;
  }
  .box{
    width: 200px;
    box-sizing: border-box;
    padding: 10px;
    background: #f9f9f9;
    height: 86px;
    margin-right: 10px;
  }
  .size-hui{
    font-size: 14px;
    margin-bottom: 10px;
    margin-top: 10px;
  }
  .size-bole{
    font-weight: bold;
  }
  .wgang{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;

  }
  .table-box{
    width: 100%;
  }
  .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;
  }

</style>
