refundGoods.js 3.69 KB
// page/subPackage/pages/refundGoods/refundGoods.js
import { GET } from '../../../../libs/request.js';
import { API_HOST } from '../../../../libs/config';
import { getImageUrlWithWH } from '../../../../utils/util.js';

const REFUND_GETLIST = 'app.refund.getList';
const REFUND_CANCEL = 'app.refund.cancel';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    gift: '../../../../pages/orders/images/zp-lab@2x.png',
    price_gift: '../../../../pages/orders/images/jjg-lab@2x.png',
    page: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRefundGoodsList();
  },

  getRefundGoodsList(page, limit) {
    GET(API_HOST, {
      method: REFUND_GETLIST,
      limit: 10,
      page: 1
    }).then(json => {
      console.log(json);
      if (json && json.code === 200 && json.data) {
        let list = this.handleList(json.data.list);
        this.setData({
          list
        })
      }
      this.setData({
        loading: false
      });
    }).catch(error => {
      this.setData({
        loading: false
      });
    });
  },

  loadRefundGoodsList(page, limit) {
    GET(API_HOST, {
      method: REFUND_GETLIST,
      limit: limit,
      page: page
    }).then(json => {
      console.log(json);
      if (json && json.code === 200 && json.data) {
        let list = this.handleList(json.data.list);
        let old = this.data.list;
        let newList = old.concat(list);
        this.setData({
          list: newList
        })
      }
      this.setData({
        loading: false
      });
    }).catch(error => {
      console.log(error);
      this.setData({
        loading: false
      });
    });
  },

  handleList(list) {
    list = list.filter(item => {
      if (item.refund_type === 1) {
        item.goods.map(good => {
          good.goods_image = getImageUrlWithWH(good.goods_image, 180, 180 * 1.25);
          good.sales_price = Number(good.sales_price).toFixed(2);
        });
        return item;
      }
    });
    return list;
  },

  cancelRefundGoods(e) {
    let that = this;
    wx.showModal({
      content: '确定取消退换货吗?',
      cancelText: '取消',
      confirmText: '确认',
      confirmColor: '#4A4A4A',
      success(res) {
        if (res.confirm) {
          that.getCancelRefundGood(e);
        }
      }
    })
  },

  navgationToRefund(e) {
    let apply_id = e.currentTarget.dataset.id;
    console.log(e.currentTarget);
    wx.navigateTo({
      url: `../refundOrderProgress/refundOrderProgress?apply_id=${apply_id}`,
    })
  },

  getCancelRefundGood(e) {
    GET(API_HOST, {
      method: REFUND_CANCEL,
      id: e.currentTarget.dataset.id
    }).then(json => {
      console.log(json);
      if (json && json.code === 200 && json.data) {
        this.getRefundGoodsList();
      }
    }).catch(error => {
      console.log(error);
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getRefundGoodsList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.loading === true) {
      return;
    }
    let page = this.data.page;
    this.setData({
      loading: true,
      page: page + 1
    });
    this.loadRefundGoodsList(page, 10);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})