// pages/writeReturnLogistics/writeReturnLogistics.js var http = require('../../utils/http.js'); Page({ /** * 页面的初始数据 */ data: { // 物流公司选择 deliveryList:[], expressId: 0, //物流公司id loading:false, expressName: '', //物流公司名称 expressNo: '', //物流单号 imgs: [], //图片凭证 mobile: '', //手机号码 refundSn: '', //退款编号名称 shopId: '', //店铺id senderRemarks: '', //备注信息 type:'',//编辑模式 refundDeliveryId:0,//退货id editData:null }, /** * 选择物流公司 */ chooseLogisticsCompany: function (e) { console.log('快递公司',e.detail.value) this.setData({ expressId: e.detail.value }) }, onExpressNoInput:function(e){ this.setData({ expressNo:e.detail.value }); }, onSenderRemarksInput: function (e) { this.setData({ senderRemarks: e.detail.value }); }, /** * 填写&提交物流信息 */ writeLogisticsMsg: function (e) { let that = this if(this.loading) return if (this.data.expressNo.length == 0) { return wx.showToast({ icon: 'none', title: '请填写物流单号', }) } else { var pics = ''; this.data.imgs.forEach(function (item) { // pics += item.path + ','; pics += item.url + ','; }); if (pics != '') { pics = pics.substring(0, pics.length - 1) } wx.showLoading(); this.loading = true let data = { shopId:this.data.shopId, deyId: this.data.deliveryList[this.data.expressId].dvyId, //物流公司id deyName: this.data.deliveryList[this.data.expressId].dvyName, //物流公司名称 deyNu: this.data.expressNo, //物流单号 imgs: pics, //图片凭证 senderMobile: this.data.mobile, //手机号码 refundSn: this.data.refundSn, //退款编号名称 senderRemarks: this.data.senderRemarks, //备注信息 userId:wx.getStorageSync("loginResult").userId } if(this.data.type == 'edit'){ data.refundDeliveryId = this.data.refundDeliveryId } var parmas = { url:this.data.type == 'edit'?"/refund/delivery/update": "/refund/delivery/save", method: this.data.type == 'edit'?"PUT":"POST", data, callBack: (res) => { that.loading = false wx.hideLoading(); if(res.code == 500){ wx.showToast({ title: res.msg||'操作失败', }) }else{ // 物流填写跳转页面 wx.navigateTo({ url: '/pages/DetailsOfRefund/DetailsOfRefund?refundSn=' + this.data.refundSn, }) } } }; http.request(parmas); } }, /** * 上传图片 */ getUploadImg: function (e) { const idx = e.target.dataset.idx console.log(idx); var ths = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['compressed'], sourceType: ['album', 'camera'], success: function (res) { // 图片的本地临时文件路径列表 var tempFilePaths = res.tempFilePaths; wx.showLoading({ mask: true }) var params = { url: "/p/file/upload", filePath: tempFilePaths[0], 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 imgs = ths.data.imgs; imgs.push(img); ths.setData({ imgs: imgs }) } }; http.upload(params); } }) }, /** * 删除图片 */ removeImage: function (e) { // const index = e.target.dataset.index // const idx = e.target.dataset.idx; var idx = e.currentTarget.dataset.idx; var imgs = this.data.imgs; imgs.splice(idx, 1) this.setData({ imgs: imgs }); console.log('删除图片') }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ refundSn: options.refundSn, shopId: options.shopId, type:options.type, }); this.loadDeliveryData(); }, //获取物流公司列表 loadDeliveryData(){ wx.showLoading(); http.request({ url:"/p/delivery/list", method: "get", data: {}, callBack: (res) => { wx.hideLoading(); this.setData({ deliveryList:res }); console.log(res) if(this.data.type == 'edit'){ this.getByRefundSn() } } }); console.log(this.data.deliveryList) }, /** * * 获取退货物流信息 */ getByRefundSn(){ var parmas = { url: `/refund/delivery/getByRefundSn/${this.data.refundSn}`, method: "GET", data: {}, callBack: (r) => { let res = r.data let imgs = [] if(res.imgs){ imgs = res.imgs.split(',').map(i=>{ return {url:i,path:i} }) } let expressId = 0 this.data.deliveryList.forEach((i,d)=>{ if(i.dvyId == res.deyId){ expressId = d } }) this.setData({ expressId, expressNo:res.deyNu, imgs, senderRemarks:res.senderRemarks, refundDeliveryId:res.refundDeliveryId }) } }; http.request(parmas); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })