<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" 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 v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <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="充值金额" align="center" prop="amt" />
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="消费方式" align="center" prop="payType" :formatter="payTypeFotmat"/>
      <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="create_time" 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 { listRecharge, exportRecharge } from "@/api/customer/recharge";

export default {
  name: "Record",
  data() {
    return {
      //创建订单时间间隔
      dateRangeCreatedDate:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户电子会员卡充值消费记录表格数据
      recordList: [],
      oilOptions:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        unionId: null,
        customerNo: null,
        customerName: null,
        usageType: "+",
        payType: null,
        cardOilsType: null,
        amt: null,
        presentAmt: null,
        balance: null,
        stationId: null,
        stationName: null,
        status: 1
      },
      
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("oil").then(response => {
      this.oilOptions = response.data;
    });
  },
  methods: {
    payTypeFotmat(row, column){
      if(row.payType === '1'){
        return '小程序'
      }else if(row.payType === '2'){
        return 'POS'
      }
    },
    cardOilsTypeFotmat(row, column){
      if(row.cardOilsType === '1'){
        return '汽油'
      }else if(row.cardOilsType === '2'){
        return '柴油'
      }
    },
    /** 查询客户电子会员卡充值消费记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.stationId= this.$store.selectDeptId;
      if(this.queryParams.stationId==null || this.queryParams.stationId==""){
        this.queryParams.stationId =this.$store.state.user.deptId;
      }
      listRecharge(this.addDateRange(this.queryParams, this.dateRangeCreatedDate)).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        unionId: null,
        customerNo: null,
        customerName: null,
        usageType: null,
        payType: null,
        cardOilsType: null,
        amt: null,
        presentAmt: null,
        balance: null,
        createTime: null,
        stationId: null,
        stationName: null,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.queryParams.stationId= this.$store.selectDeptId;
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有客户电子会员卡充值记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportRecharge(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
