<template>
  <div class="mall-section-container">
    <div class="mall-content-section">
      <div class="mall-content-title">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '' }"><a href="/report/#/memberSummary">首页</a></el-breadcrumb-item>
          <el-breadcrumb-item>积分商城</el-breadcrumb-item>
          <el-breadcrumb-item>设置</el-breadcrumb-item>
          <el-breadcrumb-item>库存日志</el-breadcrumb-item>
        </el-breadcrumb>
        <h3>
          <span>库存日志</span>
        </h3>
      </div>
      <div class="section">
        <div>
          <div class="operate-top">
            <div class="fl">
              <div class="search-item">
                <el-input v-model="searchValue" placeholder="请输入卡券名称/礼品名称/编码" prefix-icon="el-icon-search" clearable class="w-280" @keyup.enter.native="getSearchList" @clear="getSearchList"> </el-input>
              </div>
              <div class="search-item">
                <el-date-picker v-model="dateValue" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="changeTime"> </el-date-picker>
              </div>
            </div>
          </div>
          <div v-loading="loading">
            <el-table :data="tableDate" style="width: 100%">
              <el-table-column prop="author" label="操作人"> </el-table-column>
              <el-table-column prop="integralMallProName" label="礼品/卡券名称">
                <template slot-scope="scope">
                  <P>{{ scope.row.integralMallProName }}</P>
                  <P>{{ scope.row.integralMallProSku }}</P>
                </template>
              </el-table-column>
              <el-table-column prop="createTime" label="操作时间">
                <template slot-scope="scope">
                  <p>{{ getTime(scope.row.createTime) }}</p>
                  <p>{{ getSeconds(scope.row.createTime) }}</p>
                </template>
              </el-table-column>
              <el-table-column prop="message" label="变更明细">
                <template slot-scope="scope">
                  <p>{{ scope.row.message }}</p>
                </template>
              </el-table-column>
              <template slot="empty">
                <div class="no-data-wrap">
                  <div class="no-data-icon">
                    <img src="../../../static/img/no-data_icon.png" />
                  </div>
                  <p>暂无数据</p>
                </div>
              </template>
            </el-table>
            <div class="pagination-conteiner" v-show="tableDate.length > 0">
              <div class="pagination">
                <el-pagination v-if="total != 0" background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizes" :page-size="pageSize" layout="total, sizes, prev, pager, next" :total="total"> </el-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import qs from 'qs';
import getInputVal from '../../utils/common.js';
import request from '../../service/request.js';
export default {
  data() {
    return {
      getTime: getInputVal.getTime,
      getSeconds: getInputVal.getSeconds,
      getTimeAll: getInputVal.formatDate,
      searchValue: '',
      dateValue: [new Date() - 90 * 24 * 60 * 60 * 1000, new Date().valueOf()],
      currentPage: 1,
      pageSizes: [20, 40, 60, 80],
      pageSize: 20,
      total: 0,
      loading: false,
      startTime: '',
      endTime: '',
      tableDate: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getSearchList() {
      this.currentPage = 1;
      this.getList();
    },
    changeTime() {
      if (this.dateValue) {
        this.startTime = this.dateValue[0] ? this.getTime(this.dateValue[0]) : '';
        this.endTime = this.dateValue[1] ? this.getTime(this.dateValue[1]) : '';
      } else {
        this.startTime = '';
        this.endTime = '';
      }
      this.currentPage = 1;
      this.getList();
    },
    //分页设置每页的数量
    handleSizeChange(size) {
      this.pageSize = size;
      this.getList();
    },
    // 分页设置跳转到第几页
    handleCurrentChange(page) {
      this.currentPage = page;
      this.getList();
    },
    getList() {
      this.startTime = this.dateValue ? this.getTime(this.dateValue[0]) : '';
      this.endTime = this.dateValue ? this.getTime(this.dateValue[1]) : '';
      let params = {
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        search: this.searchValue,
        startTime: this.startTime,
        endTime: this.endTime
      };
      this.loading = true;
      request.get('/api-integral-mall/page-pro-stock-record', { params }).then(res => {
        if (res.data.errorCode === 0) {
          if (res.data.result.result) {
            this.tableDate = res.data.result.result;
            this.total = res.data.result.totalCount;
          } else {
            this.tableDate = [];
            this.total = 0;
          }
          this.loading = false;
        } else {
          this.$message.error(res.data.message);
          this.loading = false;
        }
      });
    }
  },
  components: {}
};
</script>
<style scoped>
.w-280 {
  width: 280px;
}
.section {
  background: #fff;
  margin: 24px;
  padding: 24px;
}
.header-top {
  /* margin: 15px 0 22px 0; */
}
.header-top span {
  width: 130px;
  display: inline-block;
}
</style>
