<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true"  label-width="68px">
      <el-form-item label="会员名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <el-form-item label="油品" prop="cardOilsType">
        <el-select
          v-model="queryParams.cardOilsType"
          placeholder="请选择油品"
          clearable
          size="small"
        >
          <el-option
            v-for="item in oilOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="消费时间" prop="">
        <el-date-picker
          v-model="dateRangeCreatedDate"
          type="daterange"
          unlink-panels
          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 type="warning" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['customer:record:export']" >导出</el-button> -->
      </el-form-item>
    </el-form>
    <el-table  :data="recordList" >
      <el-table-column label="id" align="center" prop="id" v-if="false" />
      <el-table-column label="消费单号" align="center" prop="orderNo" />
      <el-table-column label="微信用户唯一标识" align="center" prop="unionId" v-if="false" />
      <el-table-column label="电子卡号" align="center" prop="customerNo" />
      <el-table-column label="会员名" align="center" prop="customerName" />
      <el-table-column label="油品" align="center" prop="cardOilsType" :formatter="cardOilsTypeFotmat"/>
      <el-table-column label="电子会员卡消费充值类型：+，充值；-，消费；" align="center" prop="usageType" v-if="false" />
      <el-table-column label="电子会员卡充值消费类型：1.微信；2.POS机" align="center" prop="payType" v-if="false"/>
      <el-table-column label="消费金额" align="center" prop="amt" />
      <el-table-column label="余额" align="center" prop="balance"  />
      <el-table-column label="油站ID" align="center" prop="stationId" v-if="false"/>
      <el-table-column label="油站名称" align="center" prop="stationName" />
      <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="createTime" width="150">
        <template slot-scope="scope1">
          <span>{{ parseTime(scope1.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否消费成功：0，未成功；1，成功" align="center" prop="status" 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 { listConsumption, exportConsumption } from "@/api/customer/consumption";

export default {
  name: "Record",
  data() {
    return {
      //创建订单时间间隔
      dateRangeCreatedDate:[],
      // 总条数
      total: 0,
      // 客户电子会员卡充值消费记录表格数据
      recordList: [],
      oilOptions:[],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: null,
        usageType: "-",
        cardOilsType: null,
        status: 1
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("oil").then(response => {
      this.oilOptions = response.data;
    });
  },
  methods: {
    cardOilsTypeFotmat(row, column){
      if(row.cardOilsType === '2'){
        return '柴油'
      }else if(row.cardOilsType === '1'){
        return '汽油'
      }
    },
    /** 查询客户电子会员卡充值消费记录列表 */
    getList() {
      listConsumption(this.addDateRange(this.queryParams, this.dateRangeCreatedDate)).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
      });
    }, 
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有客户电子会员卡充值记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportConsumption(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
