<template>
  <div class="ticketManage app-container">
    <div class="search">
      <el-date-picker
        size="small"
        v-model="date"
        class="item-width-400"
        type="datetimerange"
        value-format="yyyy-MM-dd HH:mm:ss"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right"
      >
      </el-date-picker>
     
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
    
      <!-- <el-table-column
        align="center"
        label="订单号"
        prop="orderNo"
        show-overflow-tooltip
      >
      </el-table-column> -->
      <el-table-column
        align="center"
        label="商品ID"
        prop="goodsId"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="goodsName"
        align="center"
        label="商品名称"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="商品类型"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
       {{ goodsTypeObj[scope.row.goodsCode]}}
      </template>
      </el-table-column>
     
      <el-table-column
        prop="createTime"
        align="center"
        label="领取时间"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="useTime"
        align="center"
        label="核销时间"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="checkUser"
        align="center"
        label="核销人员"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="checkShop"
        align="center"
        label="核销店铺"
        show-overflow-tooltip
      >
      </el-table-column>
    </el-table>
    <div class="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="query.currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
import { debounce } from "@/utils/index";
import { getCouponLog } from "@/api/order";
export default {
  name: "ticketManage",
  data() {
    return {
      tableData: [],
      query: {
        startTime: "",
        endTime: "",
        currentPage: 1,
        pageSize: 10,
      },
      date:'',
      title: "",
      total: 0,
      goodsTypeObj:{},//商品类型字典
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  watch: {
    query: {
      handler: debounce(function (val) {
        this.getCouponLog();

      }),
      deep: true,
    },
    date(val){
      if(val){
        this.query.startTime = val[0]
        this.query.endTime = val[1]
      }else{
        this.query.startTime = ''
        this.query.endTime = ''
      }
    }
  },
  methods: {
   
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
      this.getCouponLog();
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.getCouponLog();
    },
    getCouponLog() {
      this.loading = true;
      getCouponLog(this.query).then((res) => {
        this.loading = false;
        if (res.state == "Success") {
          this.tableData = res.content.records
          this.total = res.content.total
        }
      });
    },
  },
  created() {
    this.getCouponLog();
    this.goodsTypeObj = JSON.parse(sessionStorage.getItem('goodsTypeObj'))
  },
};
</script>
  
<style lang="scss" scoped>
.ticketManage {
}
</style>
  