<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户姓名" prop="likeConsumer">
        <el-input
          v-model="queryParams.likeConsumer"
          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="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
          type="info"
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-form-item>
    </el-form>
    <el-table :data="orderList">
      <af-table-column label="油站名" align="center" prop="stationName" v-if="jiBie==0||jiBie==1"/>
      <af-table-column
        v-if="false"
        label="订单id"
        align="center"
        prop="orderId"
      />
      <af-table-column label="订单号" align="center" prop="orderNo" />
      <af-table-column label="油品名称" align="center" prop="oilName" />
      <af-table-column label="油品价格" align="center" prop="oilPirce" />
      <af-table-column label="加油升数" align="center" prop="orderLiters" />
      <af-table-column label="应付金额" align="center" prop="receivableAmt" />
      <af-table-column label="实付金额" align="center" prop="amt" />
      <af-table-column label="优惠金额" align="center" prop="discountAmt" />
      <af-table-column label="客户姓名" align="center" prop="consumer" />
      <af-table-column label="加油员" align="center" prop="oilPersonnel" />
      <af-table-column label="加油枪号" align="center" prop="oilGun" />
      <af-table-column
        label="支付类型"
        align="center"
        prop="payType"
        width="150px"
        :formatter="payTypeFotmat"
      />
      <af-table-column
        label="油站名称"
        align="center"
        v-if="false"
        prop="stationName"
      />
      <af-table-column
        v-if="false"
        label="用户id(消费者)"
        align="center"
        prop="consumerId"
      />
      <af-table-column
        v-if="false"
        label="油站id"
        align="center"
        prop="stationId"
      />
      <af-table-column
        label="状态"
        width="130px"
        align="center"
        prop="status"
        :formatter="statusFotmat"
      />
      <af-table-column label="支付时间" align="center" prop="payDate">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.payDate, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </af-table-column>
      <af-table-column label="创建时间" align="center" prop="createdDate">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.createdDate, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </af-table-column>
      
    </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";
import { listPrice, getPrice } from "@/api/station/price";

export default {
  name: "Order_Oil",
  data() {
    return {
      //创建订单时间间隔
      dateRangeCreatedDate: [],
      // 总条数
      total: 0,
      // 订单支付表格数据
      orderList: [],
      oilNameOptions: [],
      // 字典
      payTypeOptions: [],
      // 下拉油站
      stationOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oilGun: null,
        oilName: null,
        stationId: null,
        orderType: 1,
        oilPersonnel: null,
        createdDate: null,
        likeConsumer: null,
        orderNo:null
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    //字典
    this.getDicts("pay_type").then((response) => {
      this.payTypeOptions = 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 === "wx") {
        return "微信支付";
      } else if (row.payType === "zfb") {
        return "支付宝支付";
      } else if (row.payType === "xj") {
        return "现金支付";
      } else if (row.payType === "dzk") {
        return "电子卡支付";
      } else if (row.payType === "POS") {
        return "POS机支付";
      } else if (row.payType === "yzf") {
        return "预支付";
      } else if (row.payType === "kbzf") {
        return "卡包支付";
      }
    },
    statusFotmat(row, column) {
      if (row.status === "0") {
        return "未支付";
      } else if (row.status === "1") {
        return "已支付";
      }
    },
    /** 查询订单支付列表 */
    getList() {
      listOrder(
        this.addDateRange(this.queryParams, this.dateRangeCreatedDate)
      ).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
      });
    },
    /** 搜索按钮操作 */
    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>
