<template>
  <div class="mall-section-container">
    <div class="mall-content-section">
      <div class="mall-content-title" style="border:none">
        <el-breadcrumb separator="/">
          <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>
      <el-tabs v-model="orderStatus" class="bread-content" @tab-click="handleClick">
        <div style="height:24px;background:#f0f2f5;"></div>
        <div>
          <div class="operate-top">
            <div class="fl">
              <div class="search-item">
                <el-date-picker class="date-picker" @change="changeTime" v-model="dateValue" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
              </div>
              <div class="search-item">
                <el-select v-model="changeType" placeholder="配送方式" clearable @change="getList">
                  <el-option label="物流发货" :value="2"></el-option>
                  <el-option label="在线发货（虚拟商品）" :value="3"></el-option>
                </el-select>
              </div>
              <div class="search-item">
                <el-input v-model="searchValue" placeholder="请输入商品名称或货号" prefix-icon="el-icon-search" clearable @keyup.enter.native="handleInputSearch(searchValue)" @clear="handleInputSearch(searchValue)"> </el-input>
              </div>
            </div>
            <div class="fr">
              <el-button plain><i class="iconfont icon-icon_yunxiazai" style="margin-right:5px"></i>导出订单</el-button>
            </div>
          </div>
        </div>
        <el-tab-pane label="全部" name="-1" class="goods-table-content"> </el-tab-pane>
        <el-tab-pane label="待付款" name="11" class="goods-table-content"> </el-tab-pane>
        <el-tab-pane label="已付款" name="3" class="goods-table-content"> </el-tab-pane>

        <div class="goods-list-content">
          <el-table :data="tableData" ref="multipleTable" style="width: 100%" @sort-change="sortChange" v-loading="loading">
            <el-table-column type="selection" width="40"> </el-table-column>
            <el-table-column label="礼品信息" min-width="320px">
              <template slot-scope="scope">
                <div class="gift-info">
                  <img :src="scope.row.giftMainPic" />
                  <div class="info-name">
                    <p class="pro-ellipsis">{{ scope.row.giftName }}<i class="el-icon-edit"></i></p>
                    <p class="category-ellipsis">颜色：黑色 尺码：L</p>
                    <p class="category-ellipsis">规格编码:{{ scope.row.proCode }}</p>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="createTime" label="下单时间" sortable="custom" min-width="120px">
              <template slot-scope="scope">
                <p style="line-height:18px">{{ getTime(scope.row.createTime) }}</p>
                <p style="line-height:18px" class="gray-color">{{ getSeconds(scope.row.createTime) }}</p>
              </template>
            </el-table-column>
            <el-table-column prop="definedCode" label="订单编号" min-width="120px">
              <template slot-scope="scope">
                <p>{{ scope.row.definedCode }}</p>
              </template>
            </el-table-column>
            <el-table-column label="会员">
              <template slot-scope="scope">
                <p>{{ scope.row.memberName }}</p>
                <p>
                  <a :href="windowUrl + '/member/#/wechatmemberDetail?memberId=' + scope.row.memberId" target="_blank">{{ scope.row.cardNum }}</a>
                </p>
              </template>
            </el-table-column>
            <el-table-column prop="complete" label="交易状态">
              <template slot-scope="scope">
                <!-- <p style="line-height:18px" v-if="scope.row.complete === 0"><span class="dm-status--error">未完善</span></p>
                <p style="line-height:18px" v-if="scope.row.complete === 1"><span class="dm-status--success">已完善</span></p> -->
              </template>
            </el-table-column>
            <el-table-column prop="saleNum" label="实付金额"> </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>
        <div class="pagination-conteiner" style="background:#fff;margin:-50px 24px 0 24px">
          <div class="pagination">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageNum" :page-sizes="pageSizes" :page-size="pageSize" layout="total, sizes, prev, pager, next" :total="total"> </el-pagination>
          </div>
        </div>
      </el-tabs>
    </div>
  </div>
</template>

<script>
import qs from 'qs';
import request from '../../service/request.js';
import getInputVal from '../../utils/common.js';

export default {
  data() {
    return {
      getTime: getInputVal.getTime,
      getSeconds: getInputVal.getSeconds,
      getTimeAll: getInputVal.formatDate,
      activeName: '-1',
      currentPage: 1,
      pageSizes: [20, 30, 50],
      pageSize: 20,
      total: 0,
      tableData: [],
      deliverNum: 0,
      searchValue: '',
      changeType: '', //配送方式
      windowUrl: window.location.origin,
      orderStatus: '-1',
      dateValue: [new Date() - 90 * 24 * 60 * 60 * 1000, new Date().valueOf()]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // tab切换
    handleClick(tab) {
      this.orderStatus = tab.name;
      this.getList();
    },
    // 搜索
    handleInputSearch() {
      this.currentPage = 1;
      this.getList();
    },
    // 分页
    handleSizeChange(size) {
      //设置每页条数
      this.pageSize = size;
      this.getList();
    },
    handleCurrentChange(page) {
      //设置跳到第几页
      this.currentPage = page;
      this.getList();
    },
    // 排序
    sortChange(value) {
      this.sortColumn = value.prop;
      if (value.order == 'ascending') {
        this.sortType = 'asc';
      } else if (value.order == 'descending') {
        this.sortType = 'desc';
      }
      this.getList();
    },
    // 时间改变
    changeTime() {
      if (this.dateValue) {
        this.beginTime = this.getTimeAll(this.dateValue[0]);
        this.endTime = this.getTimeAll(this.dateValue[1]);
      } else {
        this.beginTime = '';
        this.endTime = '';
      }
      this.getList();
    },
    //获取列表
    getList() {
      this.beginTime = this.dateValue ? this.getTimeAll(this.dateValue[0]) : '';
      this.endTime = this.dateValue ? this.getTimeAll(this.dateValue[1]) : '';
      let params = {
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        changeType: this.changeType === '' ? '-1' : this.changeType,
        orderStatus: this.orderStatus,
        searchParams: this.searchValue,
        pageType: 1,
        beginTime: this.beginTime,
        endTime: this.endTime,
        sortType: this.sortType
      };
      this.loading = true;
      request.post('/api-integral-mall/page-undeliver', qs.stringify(params)).then(res => {
        if (res.data.errorCode === 0) {
          if (res.data.result.rows) {
            this.tableData = res.data.result.rows;
            this.total = res.data.result.total;
          } else {
            this.tableData = [];
            this.total = 0;
          }
          this.loading = false;
        } else {
          this.$message.error(res.data.message);
        }
      });
    }
  },
  components: {}
};
</script>
<style scoped>
.section {
  background: #fff;
  margin: 24px;
  padding: 24px;
}

.operate-top {
  background: #fff;
  height: 32px;
  background: #fff;
  margin: 0 25px;
  padding: 25px 25px 0 25px;
}
.goods-list-content {
  margin: 0 25px 25px 25px;
  padding: 22px 24px 24px 24px;
  background: #fff;
}
.gift-info img {
  width: 80px;
  height: 80px;
  border-radius: 4px;
  margin-right: 5px;
}
.info-name {
  display: inline-block;
  vertical-align: top;
  width: 75%;
}
.pro-ellipsis {
  color: #303133;
  height: 36px;
  line-height: 18px;
  font-size: 14px;
}
.category-ellipsis {
  color: #909399;
  font-size: 13px;
}
.el-icon-edit {
  margin-left: 5px;
  cursor: pointer;
}
.pagination-conteiner {
  padding: 30px 16px 34px 0;
}
</style>
