<!-- 收银台订单-->
<template>
  <div style="margin-top: 30px">
    <el-card class="box-card">
      <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="deptId">-->
<!--          <el-select-->
<!--            v-model="queryParams.deptId"-->
<!--            clearable-->
<!--            placeholder="全部"-->
<!--          >-->
<!--            <el-option v-for="item in deptList" :key="item.id" :label="item.deptName" :value="item.deptId">-->
<!--            </el-option>-->


<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="支付渠道：" prop="payChannel">
          <el-select
            v-model="queryParams.payChannel"
            clearable
            placeholder="全部"
          >
            <el-option label="小程序" value="applet"/>
            <el-option label="收银台" value="cashier"/>
            <el-option label="POS端" value="POS"/>
          </el-select>
        </el-form-item>
        <el-form-item label="支付方式：" prop="payType">
          <el-select
            v-model="queryParams.payType"
            clearable
            placeholder="全部"
          >
            <el-option label="现金" value="CASH"/>
            <el-option label="微信" value="WECHAT"/>
            <el-option label="支付宝" value="ALIPAY"/>
            <el-option label="余额" value="balance"/>
          </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>
    </el-card>
    <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">{{
              orderStatistics.refBalanceCount }}</div>
        </div>
        <div class="box">
          <div class="size-hui">退款余额</div>
          <div class="size-bole">{{ orderStatistics.refBalance?orderStatistics.refBalance:0 }}</div>
        </div>

      </div>
    </el-card>
    <el-card class="box-card">
      <div class="wgang">
        <div>机构流水分析列表</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="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="storeName" align="center" label="门店"> </el-table-column>
          <el-table-column prop="createBy" align="center" label="收银员"> </el-table-column>
          <el-table-column prop="payChannel" align="center" label="支付渠道"> </el-table-column>
          <el-table-column prop="mchntCd" align="center" label="商户号"> </el-table-column>
          <el-table-column prop="amount" align="center" label="费率"> </el-table-column>
          <el-table-column prop="type" align="center" label="订单来源">
            <template slot-scope="scope">
              <span v-if="scope.row.type=='1'">油品</span>
              <span v-else-if="scope.row.type=='2'">商品</span>
              <span v-else-if="scope.row.type=='3'">储值卡</span>
              <span v-else-if="scope.row.type=='4'">积分</span>
              <span v-else-if="scope.row.type=='5'">囤油卡</span>
              <span v-else-if="scope.row.type=='6'">油品加商品(收银台订单)</span>
              <span v-else-if="scope.row.type=='7'">挂账订单</span>
              <span v-else="">其他</span>
            </template>
          </el-table-column>
<!--          <el-table-column prop="amount" align="center" label="所属模块"> </el-table-column>-->
          <el-table-column prop="payType" align="center" label="支付方式">
            <template slot-scope="scope">
              <span v-if="scope.row.payType=='CASH'">现金</span>
              <span v-else-if="scope.row.payType=='WECHAT'">微信</span>
              <span v-else-if="scope.row.payType=='ALIPAY'">支付宝</span>
              <span v-else="">余额</span>
            </template>
          </el-table-column>

<!--          <el-table-column prop="goodsMoney" align="center" label="订单金额"> </el-table-column>-->
<!--          <el-table-column prop="payMoney" align="center" label="优惠后应付金额"> </el-table-column>-->
          <el-table-column prop="payMoney" align="center" label="退款金额"> </el-table-column>
<!--          <el-table-column prop="payMoney" align="center" label="实收金额"> </el-table-column>-->
          <!--          <el-table-column prop="payAmount" align="center" label="手续费"> </el-table-column>-->
          <el-table-column prop="userName" align="center" label="付款用户"> </el-table-column>
          <el-table-column prop="reasonRefund" 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"
      />

    </el-card>
    <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 {getmyDataApi, getRunningWaterByTissueApi, getTissueByDataApi, getTradingPageApi} from "@/api/allOrder";

  export default {
    name: "reconciliation-ref",
    data(){
      return{
        radio1:"油号选错",
        loading:false,
        dialogVisible:false,
        ordersInfo: {},
        // 员工列表
        deptList:[],
        staffList:[],
        // 日期范围
        dateRange: [],
        beginTime:"",
        endTime:"",
        // 是否为当天时间
        isSysDate:false,
        // 收银台订单列表
        orderList:[],
        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 10,
          beginTime:"",
          endTime:"",
          orderNo:"",
          status:"refund",
          payType:"",
          payChannel:"",
        },
        orderStatistics:{
          refBalance:"0",
          refBalanceCount:"0",
        },
        total: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:{
      getOrdersInfo(data) {
        this.dialogVisible = true;
        this.ordersInfo = data
      },
      exportExcelCashier() {
        let dateRange = []
        if (this.beginTime && this.endTime) {
          dateRange.push(this.beginTime.toLocaleDateString())
          dateRange.push(this.endTime.toLocaleDateString())
        }
        // exportExcelCashierApi(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())
        }
        getTissueByDataApi(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())
        }
        getTradingPageApi(this.addDateRange(this.queryParams,dateRange)).then( response => {
          this.orderList = response.data.records;
          this.total = response.data.total;
          this.isSysDate = false
        })
        this.getOrderStatistics()
      },
      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;
        })
      },
      // 搜索按钮操作
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      // 重置按钮操作
      resetQuery() {
        this.dateRange = [];
        this.queryParams = {
          page: 1,
          pageSize: 10,
        }
        this.beginTime = ""
        this.endTime = ""
        this.status = "refund"

          this.getDeptList()

        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>
