| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636 | // pages/applyRefund/applyRefund.jsvar http = require('../../utils/http.js');var big = require('../../utils/big.min.js');Page({  /**   * 页面的初始数据   */  data: {    refundType: 2,  // 退款类型 1整单  2单个物品    // 货物状态    goodsStateArray: ['未收到货', '已收到货'],    isReceiver: 0, //货物状态(1:已收到货 0:未收到货)    //  退款原因(已收到货)    refundProdReasonArray: ['请选择', '拍错/多拍/不喜欢', '协商一致退款', '商品破损/少件', '商品与描述不符', '卖家发错货', '质量问题', '其他'],    // 退款原因(未收到货)    refundPriReasonArray: ['请选择', '协商一致退款', '拍错/多拍/不喜欢', '商家一直未发货/快递一直未送达', '其他'],    buyerReason: 0, //退款原因    refundItem: {}, //订单项数据    orderItemId: '', //订单项ID(单个物品退款时使用)    orderNumber: '', //订单编号    applyType: 1, //退款方式(1:仅退款 2退款退货)    goodsNum: 1, //退货数量(0或不传值则为全部数量)    // quantity: 1,  //退货数量    refundAmount: 0, //实际退款金额    maxRefundAmount: 0, //最大退款金额    buyerMobile: '', //手机号码(默认当前订单手机号码)    buyerDesc: '', //备注说明    photoFiles: [], //凭证图片列表    actualTotal: 0,  //总额    isLastProd: false,  //是否最后一样商品    prodPrice: 0,  //商品单价    addTransfee: false, //是否可以加运费(仅一件商品)    orderScore: 0, // 整单使用积分    showNumAndCont: '', // 金额、积分、运费的展示(最多可退)    showPriAndScore: '', // 金额、积分、运费的展示(金额+积分)      },  /**   * 金额、积分、运费的展示   *    * refundType: 退款单类型(1:整单退款,2:单个退款)   * applyType: 退款方式(1:仅退款 2退款退货)   * refundAmount: 实际退款金额   * actualTotal: 总额   * orderScore: 使用积分   * refundItem.status == 2 待发货   * refundItem.transfee 运费   * isLastProd:是否最后一个订单项item   */  showNumber: function() {    var refundItem = this.data.refundItem    var refundAmount = this.data.refundAmount    var refundType = this.data.refundType    var actualTotal = this.data.actualTotal    var orderScore = this.data.orderScore    var isLastProd = this.isLastProd    var showNumAndCont = ''    var showPriAndScore = ''    // 待发货    if(refundItem.status == 2) {      // 有金额,无运费,无积分      if(refundAmount > 0 && (!refundItem.transfee || refundItem.transfee == 0) && (!orderScore || orderScore == 0)){        // 单个退 || 整单退        if(refundType == 2 || refundType == 1) {          showNumAndCont = '¥' + refundAmount          showPriAndScore = '¥' + refundAmount        }      }      // 有金额,有运费,无积分      if(actualTotal > 0 && (refundItem.transfee && refundItem.transfee > 0) && (!orderScore || orderScore == 0)) {        if(isLastProd && refundType == 2) {           // 单个退 && 最后一个订单项          showNumAndCont = '¥' + actualTotal + '+运费' + '¥' + refundItem.transfee // 最多可退          showPriAndScore = '¥' + refundAmount // 显示金额+积分        }else { // (单个退 && 不是最后一个订单项) || 整单退          showNumAndCont = '¥' + refundAmount // 最多可退          showPriAndScore = '¥' + refundAmount // 显示金额+积分        }      }      //有金额,有运费,有积分      if(actualTotal > 0 && (refundItem.transfee && refundItem.transfee > 0) && (orderScore || orderScore > 0)) {        if(isLastProd && refundType == 2) {           // 单个退 && 最后一个订单项          showNumAndCont = '¥' + actualTotal + '+运费' + '¥' + refundItem.transfee + '+' + orderScore + '积分' // 最多可退          showPriAndScore = '¥' + refundAmount +  '+' + orderScore + '积分' // 显示金额+积分        }else { // (单个退 && 不是最后一个订单项) || 整单退          showNumAndCont = '¥' + refundAmount + '+' + orderScore + '积分' // 最多可退          showPriAndScore = '¥' + refundAmount +  '+' + orderScore + '积分' // 显示金额+积分        }      }      //无金额,无运费,有积分      if((!refundAmount || refundAmount == 0) && (!refundItem.transfee || refundItem.transfee == 0) && (orderScore && orderScore > 0)) {        // 单个退 || 整单退        if(refundType == 2 || refundType == 1){          showNumAndCont =  orderScore + '积分'          showPriAndScore = orderScore + '积分'        }      }      //无金额,有运费,有积分      if((!refundAmount || refundAmount == 0)&& (refundItem.transfee && refundItem.transfee > 0) && (orderScore && orderScore > 0)) {        // 单个退 || 整单退        if(refundType == 2 || refundType == 1){          showNumAndCont = '运费' + '¥' + refundItem.transfee + '+' + orderScore + '积分'          showPriAndScore = '¥' + refundItem.transfee + '+' + orderScore + '积分'        }      }      console.log('待发货(最多可退):',showNumAndCont)      console.log('待发货(金额+积分):',showPriAndScore)    };    // 非待发货(已发货 || 已完成)任何情况都不退运费    if(refundItem.status != 2) {      // 有金额,无运费,无积分      if(refundAmount > 0 && (!refundItem.transfee || refundItem.transfee == 0) && (!orderScore || orderScore == 0)){        // 单个退 || 整单退        if(refundType == 2 || refundType == 1) {          showNumAndCont= '¥' + refundAmount          showPriAndScore = '¥' + refundAmount        }      }      // 有金额,有运费,无积分      if(refundAmount > 0 && (refundItem.transfee && refundItem.transfee > 0) && (!orderScore || orderScore == 0)) {        // 单个退 || 整单退        if(refundType == 2 || refundType == 1) {          showNumAndCont = '¥' + refundAmount          showPriAndScore = '¥' + refundAmount        }      }      //有金额,有运费,有积分      if(refundAmount > 0 && (refundItem.transfee && refundItem.transfee > 0) && (orderScore || orderScore > 0)) {        // 单个退 || 整单退        if(refundType == 2 || refundType == 1){          showNumAndCont = '¥' + refundAmount + '+' + orderScore + '积分'          showPriAndScore = '¥' + refundAmount + '+' + orderScore + '积分' // 显示金额+积分        }      }      //无金额,无运费,有积分      if((!refundAmount || refundAmount == 0) && (!refundItem.transfee || refundItem.transfee == 0) && (orderScore && orderScore > 0)) {        // 单个退 || 整单退        if(refundType == 2 || refundType == 1){          showNumAndCont =  orderScore + '积分'          showPriAndScore = orderScore + '积分' // 显示金额+积分        }      }      //无金额,有运费,有积分      if((!refundAmount || refundAmount == 0)&& (refundItem.transfee && refundItem.transfee > 0) && (orderScore && orderScore > 0)) {        // 单个退 || 整单退        if(refundType == 2 || refundType == 1){          showNumAndCont = orderScore + '积分'          showPriAndScore = orderScore + '积分' // 显示金额+积分        }      }      console.log('已发货(最多可退):',showNumAndCont)      console.log('已发货(金额+积分):',showPriAndScore)    }    this.setData({      showNumAndCont,      showPriAndScore    })    console.log('最多可退showNumAndCont:',this.data.showNumAndCont)    console.log('金额+积分showPriAndScore:',this.data.showPriAndScore)  },  /**   * 退款原因选择   * refundType:  退款类型 1整单  2单个物品   * refundItem.status: 2待发货   * isReceiver: 货物状态(1:已收到货 0:未收到货)   * applyType:  1仅退款 2退货退款   */  returnReasonList: function() {    if(this.data.applyType == 2) {      this.setData({        isReceiver: 1 // 已收到货      })    }else {      this.setData({        isReceiver: 0 // 已收到货      })    }    console.log('isReceiver货物状态(1:已收到货 0:未收到货)',this.data.isReceiver)  },  /**   * 货物状态picker选择   */  goodsStateArray: function(e) {    console.log('货物状态', e.detail.value)    this.setData({      isReceiver: e.detail.value,      buyerReason: 0    })  },  /**   * 退款原因picker选择   */  refundReasonChange: function(e) {    console.log('退款原因', e.detail.value)    this.setData({      buyerReason: e.detail.value    })  },  /**   * 生命周期函数--监听页面加载   */  onLoad: function(options) {    console.log(options,'----参数');    // 拿到上一页的参数type(判断退款方式)    // console.log('type:',options.type)    if (options.type) {      this.setData({        applyType: options.type  // 1仅退款 2退货退款      })      // console.log(this.data.type)    }    // console.log('refundType:',options.refundType)    this.setData({      refundType: options.refundType  // 退款类型 1整单  2单个物品    })    console.log('refundType(退款类型 1整单  2单个物品)',this.data.refundType)    this.getRefundProdInfo()  //获取退款商品信息  },  /**   * 获取退款商品信息   */  getRefundProdInfo: function() {    let refundType = this.data.refundType  // 退款类型 1整单  2单个物品    //拿到缓存里的订单项数据    var refundItem = wx.getStorageSync("refundItem");    console.log('拿到缓存里的订单项数据refundItem:',refundItem)    this.setData({      refundItem: refundItem,      orderNumber: refundItem.orderNumber,      goodsNum: refundItem.prodCount,      actualTotal: refundItem.actualTotal,  //总额      isLastProd: refundItem.isLastProd,  //是否最后一样商品      addTransfee: refundItem.addTransfee, //只有一件商品可以退运费      orderScore: refundItem.useScore // 单个退积分    })    console.log('单个退orderScore:',this.data.orderScore)    // console.log('platformShareReduce:',this.data.refundItem.platformShareReduce)    // console.log(refundItem.isLastProd)    if(refundType == 1) {  //整单退款      this.setData({        orderItemDtos: refundItem.orderItemDtos, //商品列表        orderScore: refundItem.orderScore,  //整单积分      });      console.log('整单退orderScore:',this.data.orderScore)    }    let actualTotal = this.data.actualTotal  //商品总额(不含运费)    let prodCount = refundItem.prodCount  //商品总数    // console.log('商品总数prodCount',prodCount)    // console.log('商品总额(不含运费)actualTotal',actualTotal)    if(refundType == 2) {  //单个退      // 计算商品单价      if(prodCount > 0) {        var x = new big(actualTotal)        var y = new big(prodCount)        // 保留两位小数        big.DP = 2        // 向下取整        big.RM = 1        let prodPrice = x.div(y).valueOf()  //商品单价        this.setData({          prodPrice        })        // console.log(this.prodPrice)      }    }        this.returnReasonList() // 退款原因选择列表展示    this.refundAmount() //退款金额计算      },  /**   * 退款金额计算   */  refundAmount: function() {    let actualTotal = this.data.actualTotal    // console.log('总额this.data.actualTotal:',this.data.actualTotal)    let refundItem = this.data.refundItem    // console.log('商品item,this.data.refundItem:',this.data.refundItem)    let refundType = this.data.refundType  // 退款类型 1整单  2单个物品        // console.log('refundType退款类型 1整单  2单个物品:',this.data.refundType)    // console.log('addTransfee是否可加运费:',this.addTransfee)    if (refundItem.status == 2) { //待发货状态      if(refundType == 2) {  //单个退,        if(refundItem.isLastProd) {  //如果是最后一个可退运费(actualTotal总额不包含运费)          this.setData({            refundAmount: actualTotal + refundItem.transfee,          });          // console.log('运费:',refundItem.transfee,'+总额:',actualTotal)          // console.log('待发货单个退(最后一个)金额:',this.data.refundAmount)        }else { //否则不退          this.setData({            refundAmount: actualTotal,          });          if(this.addTransfee) { // 如果是只有一个商品,可退运费            this.setData({              refundAmount: actualTotal + refundItem.transfee,            });            // console.log('单个退加运费可退总额:',this.refundAmount)          }          // console.log('运费:',refundItem.transfee,'+总额:',actualTotal)          // console.log('待发货单个退(不是最后一个)金额:',this.data.refundAmount)        }      } else if(refundType == 1) {  //整单退,退实际金额(actualTotal总额包含运费)        this.setData({          refundAmount: actualTotal,        });        // console.log('运费:',refundItem.transfee)        // console.log('待发货整单退金额:',this.data.refundAmount)      }    } else if (refundItem.status != 2) { // 已发货订单(整单退运费(总额包含运费);单个不退运费(总额不包含运费))       this.setData({         refundAmount: actualTotal,       });      //  console.log('运费:',refundItem.transfee)      //  console.log('已发货整单退金额:',this.data.refundAmount)    }    this.showNumber() // 金额、积分、运费的显示  },    /**     * 改变商品数量重新计算价格(数量加减)     */    changePordNum(e) {      var st = e.currentTarget.dataset.st;      let actualTotal = this.data.actualTotal  //商品总额(不含运费)      var prodCount = this.data.refundItem.prodCount  //商品总数      if(st == 0){        var goodsNum = this.data.goodsNum - 1 //展示的商品总数      }else if(st == 1) {        var goodsNum = this.data.goodsNum + 1 //展示的商品总数      }      if(goodsNum < 1) {        wx.showToast({          title: '退货数量不能小于1!',          icon: 'none',        })        return      }      if(goodsNum > prodCount) {        wx.showToast({          title: '退货数量不能大于订单商品数量!',          icon: 'none',        })        return      }      big.DP = 2      // big.RM = 0      this.setData({        goodsNum,        refundAmount: new big(actualTotal).times(goodsNum).div(prodCount).valueOf()      })    },  /**   * 上传图片   */  getUploadImg: function(e) {    var idx = e.target.dataset.idx    // console.log(idx);    var ths = this;    wx.chooseMedia({      count: 1, // 默认9      mediaType: ['image'],      sourceType: ['album', 'camera'],      maxDuration: 30,      success: function(res) {        // 图片的本地临时文件路径列表        var tempFilePaths = res.tempFiles[0].tempFilePath;        wx.showLoading({          mask: true        })        var params = {          url: "/p/file/upload",          filePath: tempFilePaths,          name: 'file',          callBack: function(res2) {            wx.hideLoading();            var img = {};            img.path = JSON.parse(res2).filePath;            img.url = JSON.parse(res2).resourcesUrl + JSON.parse(res2).filePath;            var photoFiles = ths.data.photoFiles;            photoFiles.push(img);            ths.setData({              photoFiles: photoFiles            })          }        };        http.upload(params);      }    })  },  /**   * 删除图片   */  removeImage: function(e) {    var idx = e.currentTarget.dataset.idx;    var photoFiles = this.data.photoFiles;    photoFiles.splice(idx, 1)    this.setData({      photoFiles: photoFiles    });    console.log('删除图片')  },  /**   * 申请退款   */  applyRefund: function () {    var myreg = /^1(3|4|5|6|7|8|9)\d{9}$/;    var pics = '';    this.data.photoFiles.forEach(function (item) {      pics += item.path + ',';    });    if (pics != '') {      pics = pics.substring(0, pics.length - 1)    }    // 检查数据完整性    if (this.data.buyerReason == 0) {      wx.showToast({        icon: 'none',        title: '请选择退款原因',      })    } else if (this.data.actualTotal < 0){      wx.showToast({        icon: 'none',        title: '请填写正确的退款金额',      })    } else if (this.data.buyerMobile.length !== 11 || !myreg.test(this.data.buyerMobile)) {      // console.log(this.data.buyerMobile)      wx.showToast({        icon: 'none',        title: '请填写正确的手机号码',      })    } else if (this.data.buyerDesc.length == 0) {      wx.showToast({        icon: 'none',        title: '请填写退款说明',      })    }else{      console.log('status:',this.data.refundItem.status)      console.log('isLastProd:',this.data.isLastProd)      var  refundReasonArray;      var  refundReasonArray;      if(this.data.isReceiver == 0) { // 未收货        refundReasonArray = this.data.refundPriReasonArray      }else if(this.data.isReceiver == 1) { // 已收货        refundReasonArray = this.data.refundProdReasonArray      }      if(this.data.refundItem.status == 2 && this.data.isLastProd ) {  //待发货(包含运费)并且是最后一件        console.log('待发货并且是最后一件')        console.log(this.data.isLastProd)        wx.showModal({          title: '提示',          content: '本次申请的退款商品是本单最后一件商品,退款金额中包含本单运费,一旦提交申请,本单所有商品的退款申请均不可撤销,是否确认提交',          success: res => {            if (res.confirm) {              console.log('用户点击确定')              wx.showLoading();              var params = {                url: "/p/orderRefund/apply",                method: "POST",                data: {                  orderNumber: this.data.orderNumber, //订单编号                  applyType: this.data.applyType, //退款方式(1:仅退款 2退款退货)                  isReceiver: Number(this.data.isReceiver), //货物状态(1:已收到货 0:未收到货)                  buyerReason: refundReasonArray[this.data.buyerReason], //退款原因                  goodsNum: this.data.goodsNum, //退款数量(0或不传值则为全部数量)                  refundAmount: this.data.refundAmount, //退款金额                  buyerMobile: this.data.buyerMobile, //手机号码(默认当前订单手机号码)                  buyerDesc: this.data.buyerDesc, //备注说明                  photoFiles: pics, //凭证图片列表                  refundType: this.data.refundType, //退款单类型(1:整单退款,2:单个物品退款)                  orderItemId: this.data.refundItem.orderItemId                },                callBack: (res) => {                  wx.hideLoading();                  // 去到我的退款订单页面                  wx.redirectTo({                    url: '/pages/afterSales/afterSales',                  })                }              };              http.request(params);            } else if (res.cancel) {              console.log('用户点击取消')            }          }        })      } else {        console.log('非待发货(包含运费)或者非是最后一件')        console.log(this.data.isLastProd)        wx.showLoading();        var params = {          url: "/p/orderRefund/apply",          method: "POST",          data: {            orderNumber: this.data.orderNumber, //订单编号            applyType: this.data.applyType, //退款方式(1:仅退款 2退款退货)            isReceiver: Number(this.data.isReceiver), //货物状态(1:已收到货 0:未收到货)            buyerReason: refundReasonArray[this.data.buyerReason], //退款原因            goodsNum: this.data.goodsNum, //退款数量(0或不传值则为全部数量)            refundAmount: this.data.refundAmount, //退款金额            buyerMobile: this.data.buyerMobile, //手机号码(默认当前订单手机号码)            buyerDesc: this.data.buyerDesc, //备注说明            photoFiles: pics, //凭证图片列表            refundType: this.data.refundType, //退款单类型(1:整单退款,2:单个物品退款)            orderItemId: this.data.refundItem.orderItemId          },          callBack: (res) => {            wx.hideLoading();            // 去到我的退款订单页面            wx.redirectTo({              url: '/pages/afterSales/afterSales',            })          }        };        http.request(params);      }    }  },  /**   * 修改退款申请   */  alterRefundApply: function(e) {  },  /**   * 将获取到的input内容放进数据里   */  onDescInput: function(e) {    this.setData({      buyerDesc: e.detail.value    });  },  onRefInput: function(e) {    this.setData({      refundAmount: e.detail.value    })  },  onMobileInput: function(e) {    this.setData({      buyerMobile: e.detail.value    })  },  /**   * 退款图片预览   */  refundPicPreView(e) {    var idx = e.currentTarget.dataset.idx    var urls = []    this.data.photoFiles.forEach(el => {      urls.push(el.url)    })    wx.previewImage({      current: urls[idx],      urls: urls    })  },  /**   * 生命周期函数--监听页面初次渲染完成   */  onReady: function() {  },  /**   * 生命周期函数--监听页面显示   */  onShow: function() {  },  /**   * 生命周期函数--监听页面隐藏   */  onHide: function() {  },  /**   * 生命周期函数--监听页面卸载   */  onUnload: function() {  },  /**   * 页面相关事件处理函数--监听用户下拉动作   */  onPullDownRefresh: function() {  },  /**   * 页面上拉触底事件的处理函数   */  onReachBottom: function() {  },  /**   * 用户点击右上角分享   */  onShareAppMessage: function() {  }})
 |