<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="客户姓名" prop="consumer">
        <el-input
          v-model="queryParams.likeConsumer"
          placeholder="请输入客户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="orderNo">
        <el-input
          v-model="queryParams.likeCustomerPhone"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号" prop="orderNo">
        <el-input
          v-model="queryParams.likeCarNo"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油品名称" prop="oilName">
        <el-select v-model="queryParams.oilName" placeholder="油品名称" clearable size="small">
          <el-option
            v-for="dict in oilNameOptions"
            :key="dict.dictLabel"
            :label="dict.dictLabel"
            :value="dict.dictLabel"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="加油员" prop="oilPersonnel">
        <el-input
          v-model="queryParams.oilPersonnel"
          placeholder="请输入加油员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油枪" prop="oilGun">
        <el-input
          v-model="queryParams.oilGun"
          placeholder="请输入油枪"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油站名称" prop="stationId">
        <el-select
          v-model="queryParams.stationId"
          placeholder="请选择油站"
          clearable
          size="small"
        >
          <el-option
            v-for="item in stationOptions"
            :key="item.stationId"
            :label="item.stationName"
            :value="item.stationId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createdDate">
        <el-date-picker style="width: 350px"
                        v-model="dateRangeCreatedDate" size="mini" value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetimerange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button icon="el-icon-download" size="mini" @click="handleExport"  v-hasPermi="['station:order:export']">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="orderList" >
      <el-table-column v-if="false" label="订单id" align="center" prop="orderId" />
      <el-table-column label="订单号"  width="200" align="center" prop="orderNo" />
      <el-table-column label="油品名称" align="center" prop="oilName" />
      <el-table-column label="油品价格" align="center" prop="oilPirce" />
      <el-table-column label="加油升数" align="center" prop="orderLiters" />
      <el-table-column label="金额" align="center" prop="amt" />
      <el-table-column label="消费者" width="120" align="center" prop="consumer" />
      <el-table-column label="加油员" width="120" align="center" prop="oilPersonnel" />
      <el-table-column label="加油枪号" align="center" prop="oilGun" />
      <el-table-column label="支付类型" align="center" prop="payType" :formatter="payTypeFotmat"/>
      <el-table-column label="油站名称" width="120" align="center" v-if="false" prop="stationName" />
      <el-table-column v-if="false" label="用户id(消费者)" align="center" prop="consumerId" />
      <el-table-column v-if="false" label="油站id" align="center" prop="stationId" />
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFotmat"/>
      <el-table-column label="支付方式" align="center" prop="payWay" :formatter="payWayFotmat"/>
      <el-table-column label="支付时间" align="center" prop="payDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createdDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单类型" align="center" prop="orderType" v-if="false" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
  import { listOrder, exportOrder } from "@/api/station/order";
  import {stationinfo} from "@/api/station/gun";

  export default {
    name: "Order",
    data() {
      return {
         //创建订单时间间隔
        dateRangeCreatedDate:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单支付表格数据
        orderList: [],
        oilNameOptions: [],
        //字典
        payTypeOptions:[],
        payWayOptions:[],
        payStatusOptions:[],
        //下拉油站
        stationOptions:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderNo: null,
          oilGun: null,
          oilName: null,
          consumerId: null,
          consumer: null,
          amt: null,
          stationId: null,
          status: null,
          orderLiters: null,
          payType: null,
          payWay: null,
          stationName: null,
          payDate: null,
          payMaxDate: null,
          payMinDate: null,
          createdMaxDate: null,
          createdMinDate: null,
          oilPersonnel: null,
          createdDate: null,
          orderType: null,
          likeConsumer: null,
          likeCustomerPhone: null,
          likeCarNo: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
      //字典
      this.getDicts("pay_type").then(response => {
        this.payTypeOptions = response.data;
      });
      this.getDicts("pay_way").then(response => {
        this.payWayOptions = response.data;
      });
      this.getDicts("pay_status").then(response => {
        this.payStatusOptions = response.data;
      });
      stationinfo().then(response => {
        this.stationOptions = response.rows;
      });
      this.getDicts("oil_name").then(response => {
        this.oilNameOptions = response.data;
      });
    },
    methods: {
      payTypeFotmat(row, column){
        if(row.payType === 'sxf'){
          return '随行付'
        }
      },
      payWayFotmat(row, column){
        if(row.payWay === '02'){
          return '公众号'
        }else if(row.payWay === '03'){
          return '小程序'
        }
      },
      //statusFotmat
      statusFotmat(row, column){
        if(row.status === '0'){
          return '未支付'
        }else if(row.status === '1'){
          return '已支付'
        }
      },
      //orderTypeFotmat
      // orderTypeFotmat(row, column){
      //   if(row.orderType === '1'){
      //     return '柴油'
      //   }else if(row.orderType === '2'){
      //     return '汽油'
      //   }
      // },

      /** 查询订单支付列表 */
      getList() {
        this.loading = true;
        listOrder(this.addDateRange(this.queryParams, this.dateRangeCreatedDate)).then(response => {
          this.orderList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      onInstitutionChang(e){
        let obj = {};
        obj = this.stationOptions.find((item)=>{//这里的userList就是上面遍历的数据源
          return item.stationId === e;//筛选出匹配数据
        })
        this.form.stationName=obj.stationName;
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          orderId: null,
          orderNo: null,
          oilGun: null,
          oilName: null,
          consumerId: null,
          consumer: null,
          amt: null,
          stationId: null,
          status: "0",
          orderLiters: null,
          payType: null,
          payWay: null,
          payDate: null,
          oilPersonnel: null,
          createdDate: null,
          orderType: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRangeCreatedDate =[];
        this.resetForm("queryForm");
        this.handleQuery();
      },

      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有订单支付数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
</script>
