<!-- 收银台订单-->
<template>
  <div >
    <div class="card-change-3-search">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="120px">
        <el-form-item label="">
          <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 class="flex-container" style="float: right">
          <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 class="card-change-1-1">
<!--      <div slot="header" class="clearfix">-->
<!--        <span>收银台订单统计</span>-->
<!--      </div>-->
      <div class="box-gang">
        <div class="box">
          <div class="size-bole">{{ sum.sumL.toFixed(2) }}</div>
          <div class="size-hui">
            <div class="nei">总加油升数</div>
            <div class="icon-img">
              <img src="../../../../assets/images/cut/组 4666@2x.png" alt="">
            </div>
          </div>
        </div>
        <div class="box">
          <div class="size-bole">{{ sum.sumOil.toFixed(2) }}</div>
          <div class="size-hui">
            <div class="nei">总加油笔数</div>
            <div class="icon-img">
              <img src="../../../../assets/images/cut/组 4666@2x.png" alt="">
            </div>
          </div>
        </div>
        <div class="box">
          <div class="size-bole">{{ sum.sumPayMoney.toFixed(2) }}</div>
          <div class="size-hui">
            <div class="nei">总实收金额</div>
            <div class="icon-img">
              <img src="../../../../assets/images/cut/组 4666@2x.png" alt="">
            </div>
          </div>
        </div>
        <div class="box">
          <div class="size-bole">{{ sum.sumDis.toFixed(2) }}</div>
          <div class="size-hui">
            <div class="nei">总油惠金额</div>
            <div class="icon-img">
              <img src="../../../../assets/images/cut/组 4666@2x.png" alt="">
            </div>
          </div>
        </div>
<!--        <div class="box">-->
<!--          <div class="size-hui">银联云闪付收款</div>-->
<!--          <div class="size-bole">{{ 0 }}元/{{0}}笔</div>-->
<!--        </div>-->

      </div>
      <div class="table-box" style="margin-top: 20px">
        <el-table
          :data="orderList"
          border
          style="width: 100%">

          <el-table-column type="index" width="50" align="center" label="序号"/>
<!--          <el-table-column prop="payTime" align="center" label="支付时间" width="220"> </el-table-column>-->
<!--          <el-table-column prop="orderNo" align="center" label="订单号" width="220"> </el-table-column>-->
          <el-table-column prop="oilName" align="center" label="油品名称"> </el-table-column>
          <el-table-column prop="sumOilNum" align="center" label="加油升数"> </el-table-column>
          <el-table-column prop="sumCoumnt" align="center" label="加油笔数"> </el-table-column>
          <el-table-column prop="sumOrderAnount" align="center" label="订单金额"> </el-table-column>
          <el-table-column prop="sumDisCount" align="center" label="优惠金额"> </el-table-column>
          <el-table-column prop="sumRefPayAmount" align="center" label="退款金额">
            <template slot-scope="scope">
              <span v-if="scope.row.sumRefPayAmount">{{ scope.row.sumRefPayAmount }}</span>
              <span v-else>--</span>
            </template>
          </el-table-column>
          <el-table-column prop="sumPayAmount" align="center" label="实收金额"> </el-table-column>




<!--          <el-table-column prop="userName" align="center" label="付款用户" > </el-table-column>-->
<!--          <el-table-column prop="content" align="content" label="备注" > </el-table-column>-->
<!--          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--            <template slot-scope="scope">-->
<!--              <el-button style="width: 60px" size="mini"-->
<!--                         @click="getOrdersInfo(scope.row)"-->
<!--                         type="success" plain round>详情</el-button>-->
<!--            </template>-->
<!--          </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>-->

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

    </div>


    <el-dialog
      title="订单信息"
      :visible.sync="dialogVisible">

      <el-descriptions :title="'订单号：'+ordersInfo.orderNo">
        <el-descriptions-item label="门店">{{ordersInfo.storeName}}</el-descriptions-item>
        <el-descriptions-item label="收银员">{{ordersInfo.createBy}}</el-descriptions-item>
        <el-descriptions-item label="支付渠道">{{ordersInfo.payChannel}}</el-descriptions-item>
        <el-descriptions-item label="商户号">{{ordersInfo.mchntCd}}</el-descriptions-item>
        <el-descriptions-item label="费率">{{ordersInfo.amount}}</el-descriptions-item>
        <el-descriptions-item label="订单来源">{{ordersInfo.type}}</el-descriptions-item>
        <el-descriptions-item label="所属模块">{{ordersInfo.amount}}</el-descriptions-item>
        <el-descriptions-item label="支付方式">{{ordersInfo.payType}}</el-descriptions-item>
        <el-descriptions-item label="付款用户">{{ordersInfo.userName}}</el-descriptions-item>
        <el-descriptions-item label="支付状态">{{ordersInfo.status}}</el-descriptions-item>
        <el-descriptions-item label="备注">{{ordersInfo.content}}</el-descriptions-item>
<!--        <el-descriptions-item label="备注">-->
<!--          <el-tag size="small">学校</el-tag>-->
<!--        </el-descriptions-item>-->
      </el-descriptions>

      <el-descriptions class="margin-top" title="金额详情" :column="3" border>
        <el-descriptions-item>
          <template slot="label">
            订单金额
          </template>
          {{ordersInfo.goodsMoney?ordersInfo.goodsMoney:"--"}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            优惠后应付金额
          </template>
          {{ordersInfo.payMoney?ordersInfo.payMoney:"--"}}

        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            退款金额
          </template>
          {{ordersInfo.refMoney?ordersInfo.refMoney:"--"}}

        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            实收金额
          </template>
          {{ordersInfo.payMoney?ordersInfo.payMoney:"--"}}

        </el-descriptions-item>
      </el-descriptions>


    </el-dialog>

  </div>
</template>

<script>

import {
  exportExcelTradingApi, getmyDataApi,
  getRunningWaterByTissueApi,
  getTissueByDataApi,
  getTradingPageApi
} from "@/api/allOrder";
import {getInfoByOilTypeApi} from "@/api/order/oilorder";

  export default {
    name: "buy-oil",
    data(){
      return{
        radio1:"油号选错",
        loading:false,
        dialogVisible:false,
        // 员工列表
        staffList:[],
        ordersInfo:{},
        // 日期范围
        dateRange: [],
        beginTime:"",
        endTime:"",
        // 是否为当天时间
        isSysDate:false,
        // 收银台订单列表
        orderList:[],
        deptList:[],

        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 10,
          beginTime:"",
          endTime:"",
          orderNo:"",
          status:"",
          payType:"",
          payChannel:"",
          deptType:"3",
          storeId:"",
          deptId:"",
        },
        orderStatistics:{
          CASH:"0",
          WECHAT:"0",
          ALIPAY:"0",
          balance:"0",
          CASHCount:"0",
          WECHATCount:"0",
          ALIPAYCount:"0",
          balanceCount:"0",
          refBalance:"0",
          refBalanceCount:"0",
        },
        total:0,

        sum: {
          // 总加油升数
          // 总加油笔数
          // 总实收金额
          // 总油惠金额
          sumL:'0',
          sumOil:'0',
          sumPayMoney:'0',
          sumDis:'0',
        }
      }
    },
    async 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
      await this.getDeptList();

      this.getList();

    },
    methods:{
      async getDeptList() {
        // getRunningWaterByTissueApi(this.addDateRange(this.queryParams)).then( response => {
        //   this.deptList = response.data.records;
        // })
        await getmyDataApi(this.addDateRange(this.queryParams)).then( response => {
          this.queryParams.deptId = response.data.deptId;
        })
      },
      exportExcelCashier() {
        let dateRange = []
        if (this.beginTime && this.endTime) {
          dateRange.push(this.beginTime.toLocaleDateString())
          dateRange.push(this.endTime.toLocaleDateString())
        }
        exportExcelTradingApi(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())
        }
        getInfoByOilTypeApi(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())
        }
        getInfoByOilTypeApi(this.addDateRange(this.queryParams,dateRange)).then(response => {
          this.orderList = response.data;
          // this.total = response.data.total;
          this.isSysDate = false
          this.sum.sumL=0
          this.sum.sumOil = 0
          this.sum.sumPayMoney =0
          this.sum.sumDis =0
          this.orderList.forEach(res=>{
            this.sum.sumL=this.sum.sumL+res.sumOilNum
            this.sum.sumOil = this.sum.sumOil+res.sumCoumnt
            this.sum.sumPayMoney = this.sum.sumPayMoney + res.sumPayAmount
            this.sum.sumDis =this.sum.sumDis + res.sumDisCount
          })
        })
        this.getOrderStatistics()
      },
      getOrdersInfo(data) {
        this.dialogVisible = true;
        this.ordersInfo = data
      },
      // 搜索按钮操作
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      // 重置按钮操作
      resetQuery() {
        this.dateRange = [];
        this.queryParams = {
          page: 1,
          pageSize: 10,
        }
        this.beginTime = ""
        this.endTime = ""
        this.getDeptList()

        this.handleQuery();
      },
    }
  }
</script>

<style scoped lang="scss">
  .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{
    //box-sizing: border-box;
    padding: 5px;
    //background: #f9f9f9;
    margin-right: 20px;
    padding-left: 20px;

    width: 211px;
    height: 60px;
    background: rgba(64,158,255,0.05);
    border-radius: 6px 6px 6px 6px;
    border: 1px solid #fe8c4a;
  }
  .el-form--inline .el-form-item {
    margin-right: 44px;
  }
  .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;
    .nei {
      width: 150px;
    }
  }

  .icon-img{
    //margin-left: 110px;
    width: 100%;
    height: 20px;
    margin-right: 5px;
    img{
      float: right;
      //width: 100%;
      width: 20px;
      height: 100%;
    }
  }
  .size-bole{
    //font-weight: bold;

    //width: 53px;
    height: 31px;
    font-family: YouSheBiaoTiHei;
    font-weight: 400;
    font-size: 24px;
    color: #555555;
    //line-height: 0px;
    text-align: left;
    font-style: normal;
    text-transform: none;
  }
  .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>
