<!--未支付订单-->
<template>
  <div class="app-container">
    <el-card class="box-card">
<!--      <div style="display: flex;">-->
<!--        <div class="top-app-sou">-->
<!--          <el-form :label-position="labelPosition" label-width="40px" :model="formLabelAlign">-->
<!--            <el-form-item label="名称">-->
<!--              <el-input v-model="formLabelAlign.name" placeholder="请输入要搜索的内容"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-form>-->
<!--        </div>-->
<!--        <div style="margin-left: 10px">-->
<!--          <el-button type="primary" icon="el-icon-search">搜索</el-button>-->
<!--        </div>-->
<!--      </div>-->
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
        <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 label="支付类型" prop="payType">-->
<!--          <el-select-->
<!--            v-model="queryParams.payType"-->
<!--            clearable-->
<!--            placeholder="全部"-->
<!--          >-->
<!--            <el-option v-for="item in payList"-->
<!--                       :key="item.id"-->
<!--                       :label="item.dictLabel"-->
<!--                       :value="item.dictValue">-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="手机号">
          <el-input v-model="queryParams.payUser" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item label="油枪号" prop="oilGunNum">
          <el-select
            v-model="queryParams.oilGunNum"
            filterable
            clearable
            placeholder="全部"
          >
            <el-option v-for="item in oilNumList"
                       :key="item.id"
                       :label="item.oilGunNum"
                       :value="item.id">
              <span style="float: left">{{ getName(oilNameList,item.oilName) }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.oilGunNum }}号枪</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单号">
          <el-input v-model="queryParams.orderNo" placeholder="订单号、官方单号检索"></el-input>
        </el-form-item>
<!--        <el-form-item label="交易时间">-->
<!--          <el-date-picker-->
<!--            v-model="dateRange"-->
<!--            style="width: 240px"-->
<!--            size="medium"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            type="daterange"-->
<!--            range-separator="-"-->
<!--            start-placeholder="开始日期"-->
<!--            end-placeholder="结束日期"-->
<!--          ></el-date-picker>-->
<!--        </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-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" v-for="(item,index) in 7" :key="index">
          <div class="size-hui">订单总数</div>
          <div class="size-bole">55</div>
        </div>

      </div>
    </el-card>
    <el-card class="box-card">
      <div class="wgang">
        <div>未支付订单列表</div>
       <div style="display: flex ">
         <el-button type="primary" size="mini" icon="el-icon-plus" @click="exportExcelOilOrder()">导出订单</el-button>
       </div>
      </div>
      <div class="table-box">
        <el-table
          :data="list"
          style="width: 100%">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" class="demo-table-expand" style="margin-left: 20px">
                <el-form-item label="收银员">
                  <span>{{ getRealName(staffList,props.row.staffId) }}</span>
                </el-form-item>
                <el-form-item label="收银员手机号">
                  <span>{{ getMobile(staffList,props.row.staffId) }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column prop="terminal" label="终端" align="center" width="80"></el-table-column>
          <el-table-column prop="oils" label="油品/油枪" align="center">
            <template slot-scope="props">
              <span>{{ getName(oilNameList,props.row.oils) }}/{{ props.row.oilGunNum }}号枪</span>
            </template>
          </el-table-column>
          <el-table-column label="订单信息" align="center">
            <el-table-column prop="orderNo" label="订单号" align="center"> </el-table-column>
            <el-table-column prop="orderAmount" label="交易金额" align="center"> </el-table-column>
          </el-table-column>

          <el-table-column prop="payType" label="付款类型" align="center">
            <template slot-scope="scope">
              <span>{{getPayType(payTypeList,scope.row.payType)}}</span>
            </template>
          </el-table-column>

          <el-table-column prop="payUser" label="付款用户" align="center">
          </el-table-column>

          <el-table-column prop="createTime" label="交易时间" align="center"></el-table-column>

          <el-table-column prop="orderStatus" align="center" label="支付状态">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.orderStatus == 'unpaid'">未支付</el-tag>
              <el-tag type="info" v-else>支付失败</el-tag>
            </template>
          </el-table-column>

<!--          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--            <template slot-scope="scope">-->
<!--              <el-button-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-edit"-->
<!--              >更多操作</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>


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

<script>
  import {listOilOrder} from "@/api/order/oilorder";
  import {getDicts} from "@/api/order/data";
  import {getOilNameList, getOilNumGun} from "@/api/order/oilnumgun";
  import {queryStaffs} from "@/api/order/staff";
  import {exportExcelOilOrderApi} from "@/api/order/exportExcel";

  export default {
    name: "order_Cashier",
    data(){
      return{
        // 查询参数
        queryParams: {
          page: 1,
          pageSize: 10,
          orderStatus:"paid",
        },
        // 总条数
        total:0,
        // 列表信息
        list:[],
        // 支付状态列表
        payList:[],
        // 支付类型列表
        payTypeList:[],
        oilNameList:[],
        // 员工列表
        staffList:[],
        // 油枪列表
        oilNumList:[],
        // 日期范围
        dateRange: [],

        labelPosition: 'right',
        formLabelAlign: {
          name: '',
        },
        // tableData: [{
        //   date: '2016-05-03',
        //   name: '王小狼',
        //   province: '上海',
        //   city: '普陀区',
        //   address: '上海市普陀区金沙江路 1518 弄',
        //   zip: 200333
        // }, {
        //   date: '2016-05-02',
        //   name: '王小虎',
        //   province: '上海',
        //   city: '普陀区',
        //   address: '上海市普陀区金沙江路 1518 弄',
        //   zip: 200333
        // }, {
        //   date: '2016-05-04',
        //   name: '王小虎',
        //   province: '上海',
        //   city: '普陀区',
        //   address: '上海市普陀区金沙江路 1518 弄',
        //   zip: 200333
        // }, {
        //   date: '2016-05-01',
        //   name: '王小虎',
        //   province: '上海',
        //   city: '普陀区',
        //   address: '上海市普陀区金沙江路 1518 弄',
        //   zip: 200333
        // }, {
        //   date: '2016-05-08',
        //   name: '王小虎',
        //   province: '上海',
        //   city: '普陀区',
        //   address: '上海市普陀区金沙江路 1518 弄',
        //   zip: 200333
        // }, {
        //   date: '2016-05-06',
        //   name: '王小虎',
        //   province: '上海',
        //   city: '普陀区',
        //   address: '上海市普陀区金沙江路 1518 弄',
        //   zip: 200333
        // }, {
        //   date: '2016-05-07',
        //   name: '王小虎',
        //   province: '上海',
        //   city: '普陀区',
        //   address: '上海市普陀区金沙江路 1518 弄',
        //   zip: 200333
        // }]
      }
    },
    created() {
      this.getList();
      this.getPayList();
    },
    methods:{
      exportExcelOilOrder() {

        exportExcelOilOrderApi(this.addDateRange(this.queryParams, this.dateRange)).then(res=>{
          const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
          this.$download.saveAs(blob,'未支付订单统计.xLsx')
        })
      },
      // 获取员工姓名
      getRealName(list,val){
        let name = "";
        list.forEach(item => {
          if (item.id == val){
            name = item.realName
          }
        })
        return name;
      },
      // 获取员工手机号
      getMobile(list,val){
        let name = "";
        list.forEach(item => {
          if (item.id == val){
            name = item.mobile
          }
        })
        return name;
      },
      // 获取油号名称
      getName(oilNameList,id){
        let name = ""
        let _this = this;
        if(oilNameList!=null && oilNameList!=""){
          oilNameList.forEach(item => {
            if (item.id == id){
              name = item.oilName;
              _this.oilType = item.oilType;
            }
          })
        }
        return name;
      },
      // 获取付款类型
      getPayType(list,val){
        let name = "";
        list.forEach(item => {
          if (item.dictValue == val){
            name = item.dictLabel
          }
        })
        return name;
      },
      // 获取支付信息列表
      getPayList(){
        getDicts("pay_status").then( response => {
          this.payList = response.data;
        })
        getDicts("payment_type").then( response => {
          this.payTypeList = response.data;
        })
        getOilNameList().then( response => {
          this.oilNameList = response.data;
        })
        getOilNumGun({oilNum : "全部"}).then( response => {
          this.oilNumList = response.data
        })
        queryStaffs().then( response => {
          this.staffList = response.data;
        })
      },
      // 获取列表信息
      getList(val){
        if (val!=undefined){
          this.queryParams.page = val
        }
        listOilOrder(this.addDateRange(this.queryParams, this.dateRange)).then( response => {
          this.list = response.data.records;
          this.total = response.data.total;
        })
      },
      // 搜索按钮操作
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      // 重置按钮操作
      resetQuery() {
        this.dateRange = [];
        this.queryParams = {
          page: 1,
          pageSize: 10,
          orderStatus:"paid",
        }
        // this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  }
</script>

<style scoped>
.app-container{
    width: 100%;
    height: 100%;
    background: #f6f8f9;
  }
  .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%;
  }


</style>
