<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="积分订单号" prop="integralOrderNo">
        <el-input
          v-model="queryParams.integralOrderNo"
          placeholder="请输入积分订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="商品名称" prop="waresName">
        <el-input
          v-model="queryParams.waresName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <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="exchangeTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.exchangeTime"
          type="date"
          value-format="yyyy-MM-dd"
          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-form-item>
    </el-form>
    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column label="积分订单id" align="center" prop="id" v-if="false"/>
      <el-table-column label="订单号" align="center" prop="integralOrderNo" />
      <el-table-column label="商品类型" align="center" prop="waresType" v-if="false"/>
      <el-table-column label="商品名称" align="center" prop="waresName" />
      <el-table-column label="微信唯一标识" align="center" prop="unionId"  v-if="false"/>
      <el-table-column label="会员名称" align="center" prop="customerName" />
      <el-table-column label="手机号" align="center" prop="mobilePhone" />bu
      <el-table-column label="兑换数量" align="center" prop="exchangeNum" />
      <el-table-column label="兑换时间" align="center" prop="exchangeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.exchangeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status" :formatter="statusFormat" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder } from "@/api/integral/order";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 积分消费订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        integralOrderNo: null,
        waresType: null,
        waresName: null,
        unionId: null,
        customerName: null,
        exchangeNum: null,
        exchangeTime: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    statusFormat(row, column){
      if(row.status === '1'){
        return '已兑换'
      }else if(row.status === '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;
      }
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        integralOrderNo: null,
        waresType: null,
        waresName: null,
        unionId: null,
        customerName: null,
        exchangeNum: null,
        exchangeTime: 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
    },
    detail(row){

    }
  }
};
</script>
