<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="电子会员卡充值消费类型：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:[],
      // 遮罩层
      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: {
    cardOilsTypeFotmat(row, column){
      if(row.cardOilsType === '2'){
        return '柴油'
      }else if(row.cardOilsType === '1'){
        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;
      }
      listConsumption(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 exportConsumption(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
