<template>
<!--  积分商城订单-->
  <div class="app-containers">
    <div class="top_new">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px">
        <el-form-item label=""  prop="giftName">
          <el-input
            v-model="queryParams.orderNumber"
            placeholder="交易单号"
            clearable
            style="width: 170px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="">
          <el-select v-model="queryParams.status" style="width: 170px" placeholder="兑换状态" clearable>
            <el-option  label="未支付" value="unpaid">未支付</el-option>
            <el-option  label="付款成功" value="paid">付款成功</el-option>
            <el-option  label="付款失败" value="payFail">付款失败</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="giftName">
          <el-input
            v-model="queryParams.mobile"
            placeholder="手机号码"
            clearable
            style="width: 170px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="">
          <el-date-picker
            v-model="beginTime"
            style="width: 170px"
            type="date"
            placeholder="开始日期">
          </el-date-picker>
          至
          <el-date-picker
            v-model="endTime"
            style="width: 170px"
            type="date"
            placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

      </el-form>
      <div style="display: flex; height: 32px">
        <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" @click="exportExcelVip()">导出</el-button>
      </div>

    </div>


    <div class="cont_box_b">
      <div class="cont_box">
        <div class="box2">
          <div style="font-size: 26px;color: #0DC291;font-weight: bold;margin-top: 5px">
            {{ statisticsForm.num || 0 }}
          </div>
          <div class="size-hui">
            <div style="width: 8px;height: 8px;border-radius: 4px;background: #0DC291"></div>
            <div style="font-weight: bold;font-size: 13px;margin-left: 5px">笔数</div>
          </div>
        </div>
        <div class="box2">
          <div style="font-size: 26px;color: #00CAFF;font-weight: bold;margin-top: 5px">
            {{ statisticsForm.exchangeQuantity|| 0 }}
          </div>
          <div class="size-hui">
            <div style="width: 8px;height: 8px;border-radius: 4px;background: #00CAFF"></div>
            <div style="font-weight: bold;font-size: 13px;margin-left: 5px">商品数量</div>
          </div>
        </div>
        <div class="box2">
          <div style="font-size: 26px;color: #F44522;font-weight: bold;margin-top: 5px">
            {{ statisticsForm.integral|| 0 }}
          </div>
          <div class="size-hui">
            <div style="width: 8px;height: 8px;border-radius: 4px;background: #F44522"></div>
            <div style="font-weight: bold;font-size: 13px;margin-left: 5px">积分</div>
          </div>
        </div>
        <div class="box2">
          <div style="font-size: 26px;color: #FA6400;font-weight: bold;margin-top: 5px">
            {{ statisticsForm.amount|| 0 }}
          </div>
          <div class="size-hui">
            <div style="width: 8px;height: 8px;border-radius: 4px;background: #FA6400"></div>
            <div style="font-weight: bold;font-size: 13px;margin-left: 5px">支付总额</div>
          </div>
        </div>
      </div>
      <div class="table-box">
   <el-table ref="tables"
             v-loading="loading"
             :data="dataList"
             :default-sort="defaultSort">
     <el-table-column label="用户手机号" align="center" prop="mobile"/>
     <el-table-column label="订单号" align="center" prop="orderNumber"/>
     <el-table-column label="商品名称" align="center" prop="giftName" />
     <el-table-column label="数量" align="center" prop="exchangeQuantity" />
     <el-table-column label="实付信息" align="center"  >
       <el-table-column label="积分" align="center" prop="integral" width=""/>
       <el-table-column label="支付金额" align="center" prop="amount" width="">
         <template slot-scope="scope">
           {{ scope.row.amount?scope.row.amount:"--" }}
         </template>
       </el-table-column>
     </el-table-column>
     <el-table-column label="支付状态" align="center" prop="status" width="">
       <template slot-scope="scope">
         <el-tag  effect="plain" v-if="scope.row.status =='unpaid'"> 待支付</el-tag>
         <el-tag type="success" effect="plain" v-else-if="scope.row.status =='paid'">支付成功</el-tag>
         <el-tag type="warning" effect="plain" v-else>支付失败</el-tag>
       </template>
     </el-table-column>

     <el-table-column label="创建时间" align="center" prop="createTime" width=""/>
     <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
       <template slot-scope="scope">
         <el-button
           size="mini"
           type="text"
           @click="handleDetail(scope.row)"
         >订单详情</el-button>

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

    <el-dialog title="订单详情" :visible.sync="openDetail" width="500px" append-to-body :close-on-click-modal="false">
      <detail :dataForm = "dataForm"></detail>
    </el-dialog>

  </div>
</template>

<script>
import {getOrderApi,getStatisticsApi } from "@/api/cashier/integralOrder/order";
import Detail  from '@/views/cashier/NewComponents/integralOrder/detail'
import {getDicts} from "@/api/dict/data";
import { exportExcelPointsApi } from '@/api/order/exportExcel'

export default {
  name: "pointsCashier",
  components: { Detail },

  // dicts: ['zhzt'],

  data() {
    return {
      openDetail:false,
      dataForm:{},
      dataList:[],
      zhztList:'',
      queryParams: {
        orderType:1,

        giftName: '',
        status: '',
        mobile: '',
        orderNumber: '',
        page:null,
        pageSize:null
      },
      loading: false,
      dateRange: [],
      beginTime:"",
      endTime:"",
      defaultSort: {prop: 'createTime', order: 'descending'},

      total: 0,

      statisticsForm: {
        num:0,
        exchangeQuantity:0,
        integral:0,
        amount: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.getList();
    this.getStatistics();

  },
  methods: {

    exportExcelVip() {
      let dateRange = []
      if (this.beginTime && this.endTime) {
        dateRange.push(this.beginTime.toLocaleDateString())
        dateRange.push(this.endTime.toLocaleDateString())
      }
      exportExcelPointsApi(this.addDateRange(this.queryParams, dateRange)).then(res => {
        const blob = new Blob([res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
        this.$download.saveAs(blob, '积分商城订单.xLsx')
      })
    },
    getList(){
      this.dateRange = []
      if (this.beginTime && this.endTime) {
        this.dateRange.push(this.beginTime.toLocaleDateString())
        this.dateRange.push(this.endTime.toLocaleDateString())
      }
      getOrderApi(this.addDateRange(this.queryParams, this.dateRange)).then(res=>{
        this.dataList = res.data.records
        this.total = res.data.total

      })
    },
    getStatistics() {
      this.dateRange = []
      if (this.beginTime && this.endTime) {
        this.dateRange.push(this.beginTime.toLocaleDateString())
        this.dateRange.push(this.endTime.toLocaleDateString())
      }
      getStatisticsApi(this.addDateRange(this.queryParams, this.dateRange)).then(res=>{
        this.statisticsForm = res.data
      })
      console.log("123123123",this.statisticsForm)
    },

    // 获取支付方式
    getZhzt() {
      getDicts("zhzt").then(response => {
        this.zhztList = response.data;
      })
    },

    handleUpdate(){},
    handleQuery(){
      this.getList();
      this.getStatistics();

    },
    resetQuery(){
      this.queryParams = {
        giftName: '',
        status: '',
        mobile: '',
        orderNumber: '',
        page:1,
        pageSize:10
      },
      this.dateRange = []
      this.beginTime = ""
      this.endTime = ""
      this.getList()
      this.getStatistics();

    },
    handleDetail(data){
      this.openDetail = true
      this.dataForm = data;
    },
  }
}
</script>

<style scoped>
.app-container {
    width: 100%;
    height: 100%;
    background: #f6f8f9;

}

.icon-img{
  //margin-left: 110px;
  width: 100%;
  height: 20px;
  margin-right: 5px;
  img{
    float: right;
    //width: 100%;
    width: 20px;
    height: 100%;
  }
}
.table-box {
  width: 100%;
  height: 66vh;
  overflow: auto;
}
.box{
  //box-sizing: border-box;
  padding: 5px;
  //background: #f9f9f9;
  margin-right: 20px;
  padding-left: 20px;
  margin-bottom: 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: 15px;
}
.size-hui{
  display: flex;
  align-items: center;
  font-family: Source Han Sans CN, Source Han Sans CN;
  font-weight: 400;
  font-size: 13px;
  color: #888888;
  text-align: left;
  font-style: normal;
  text-transform: none;

}
.size-bole{
  height: 31px;
  font-family: YouSheBiaoTiHei;
  font-weight: 400;
  font-size: 24px;
  color: #555555;
  text-align: left;
  font-style: normal;
  text-transform: none;
}
.font-chinese {
  font-size: 15px;
  font-family:Microsoft YaHei;
  font-weight: bold;
  line-height:1.5
}
.font-number {
  font-size: 20px;
  font-family: PingFang SC,sans-serif;
  font-weight: bold;
  line-height:1.3
  }
.box1{
  padding: 5px;
  margin-right: 20px;
  margin-bottom: 20px;
  padding-left: 20px;
  width: 211px;
  height: 60px;
  background: rgba(255,150,85,0.05);
  border-radius: 6px 6px 6px 6px;

  border: 1px solid #FF9655;
}
.top_new{
  display: flex;
  justify-content: space-between;
  background: #fff;
  width: 98%;
  margin: 0px auto;
  border-radius: 8px;
  box-sizing: border-box;
  padding: 0px 15px;
  border-bottom: 1px solid #eceff1;
  padding-bottom: 0px;

}
.cont_box{
  background: #fff;
  width: 100%;
  box-sizing: border-box;
  padding: 15px;
  display: flex;
  padding-left: 0px;
}
.cont_box_b{
  background: #fff;
  width: 98%;
  margin: 5px auto;
  border-radius: 8px;
  box-sizing: border-box;
  padding: 15px;
  padding-top: 0px;
  min-height: 85vh;
}
.box2 {
  padding: 5px;
  margin-right: 20px;

  padding-left: 20px;
  width: 211px;
  height: 70px;
  border-radius: 6px 6px 6px 6px;
  border: 1px solid #FF9655;
}
</style>
