// pages/refundDetail/refundDetail.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo

wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    showApplyRefundModal: false,
    id: '',
    refundDetail: null,
    refundId : null,
    baseImgUrl: app.globalData.imageUrl,
  },

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const { id } = this.options
    if (id) {
      this.setData({
        id
      }, () => {
        this.getRfDetail(id)
      })
    }
  },
  handelRevokeRefund() {
    const { id } = this.data
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    // const params = {id}
    wxService.post(`/sale/refund/buyer/cancel?id=${id}`).then(res => {
      if (res) {
        const { result, data } = res.data
        if (result == 0) {
          wx.hideLoading()
          wx.showToast({
            title: '撤销退款成功',
            icon: 'none'
          });
          setTimeout(() => {
            wxService.router('/pages/order/order')
          },200)
        }
      }
    })
  },
  //填写物流信息之后回调
  onDeliveryOk(){
    this.getRfDetail(this.data.id);
  },
  getRfDetail(id) {
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    wxService.post(`/sale/refund/buyer/${id}`).then(res => {
      if (res) {
        const { result, data } = res.data
        if (result == 0) {
          wx.hideLoading()
          this.setData({
            refundDetail: data
          })
        }
      }
    })
  },
  copy(e) {
    wx.setClipboardData({
      //准备复制的数据
      data: e.currentTarget.dataset.content,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
          icon: 'none'
        });
      }
    });
  },

  //填写物流信息
  tapWriteLogis() {
    this.setData({
      showApplyRefundModal: true,
      refundId : this.data.id
    })
  }
})