var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); Page({ data: { orderId: 0, orderInfo: {}, orderGoods: [], aftersale: { pictures: [] }, //columns: ['未上门','服务质量问题','其他'], columns: ['不想要\不喜欢', '7天无理由退款', '搬家/出差', '重复购买', '地址超服务范围', '地址约错', '约不到想要的服务时间', '活动/优惠未享受', '服务质量问题'], contentLength: 0, refundTypes: [], //退款原因 fileList: [] }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 this.setData({ orderId: options.id }); this.getOrderDetail(); this.getRefudnType(); }, getRefudnType() { let that = this; util.request(api.AftersaleRefundType).then(function (res) { if (res.errno === 0) { that.setData({ refundTypes: res.data, columns: res.data.map((obj => obj.name)) }) console.info(that.data.refundTypes) } }); }, getOrderDetail: function () { wx.showLoading({ title: '加载中', }); setTimeout(function () { wx.hideLoading() }, 2000); let that = this; util.request(api.OrderDetail, { orderId: that.data.orderId }).then(function (res) { if (res.errno === 0) { console.log(res.data); that.setData({ orderInfo: res.data.orderInfo, orderGoods: res.data.orderGoods, 'aftersale.orderId': that.data.orderId, 'aftersale.amount': res.data.orderInfo.actualPrice - res.data.orderInfo.freightPrice }); } wx.hideLoading(); }); }, deleteImage(event) { const { fileList = [] } = this.data; fileList.splice(event.detail.index, 1) this.setData({ fileList: fileList }) let urls = []; fileList.forEach(function (e) { urls.push(e.url); }) this.setData({ "aftersale.pictures": urls }) }, afterRead(event) { const { file } = event.detail let that = this const uploadTask = wx.uploadFile({ url: api.StorageUpload, filePath: file.path, name: 'file', success: function (res) { var _res = JSON.parse(res.data); if (_res.errno === 0) { var url = _res.data.url that.data.aftersale.pictures.push(url) const { fileList = [] } = that.data; fileList.push({ ...file, url: url }); that.setData({ fileList: fileList }) } }, fail: function (e) { wx.showModal({ title: '错误', content: '上传失败', showCancel: false }) }, }) }, previewImage: function (e) { wx.previewImage({ current: e.currentTarget.id, // 当前显示图片的http链接 urls: this.data.files // 需要预览的图片http链接列表 }) }, contentInput: function (e) { this.setData({ contentLength: e.detail.cursor, 'aftersale.comment': e.detail.value, }); }, onReasonChange: function (e) { this.setData({ 'aftersale.reason': e.detail, }); }, showTypePicker: function () { this.setData({ showPicker: true, }); }, onCancel: function () { this.setData({ showPicker: false, }); }, onConfirm: function (event) { let name = event.detail.value; let typeId = 0; let vals = this.data.refundTypes.filter(item =>item.name == event.detail.value); typeId = vals[0].id; this.setData({ //'aftersale.type': event.detail.index, //'aftersale.typeDesc': event.detail.value, 'aftersale.type': typeId, 'aftersale.typeDesc': name, showPicker: false, }); }, submit: function () { let that = this; if (that.data.aftersale.type == undefined) { util.showErrorToast('请选择退款类型'); return false; } console.log(that.data.aftersale.reason); if (!that.data.aftersale.reason) { util.showErrorToast('请输入退款原因'); return false; } wx.showLoading({ title: '提交中...', mask: true, success: function () { } }); util.request(api.AftersaleSubmit, that.data.aftersale, 'POST').then(function (res) { wx.hideLoading(); if (res.errno === 0) { wx.showToast({ title: '申请售后成功', icon: 'success', duration: 2000, complete: function () { wx.redirectTo({ url: '/pages/ucenter/aftersaleList/aftersaleList' }); } }); } else { // util.showErrorToast(res.errmsg); wx.showToast({ title: res.errmsg, icon:'none' }) } }); }, onReady: function () { // 页面渲染完成 }, onShow: function () { // 页面显示 }, onHide: function () { // 页面隐藏 }, onUnload: function () { // 页面关闭 } })