123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- Page({
- data: {
- index:'',
- orderId: 0,
- orderInfo: {},
- orderGoods: [],
- aftersale: {
- pictures: [],
- typeDesc:'',
- reason:'',
- amount:''
- },
- reasonActive:{
- id:'',
- name:''
- },
- reasonPopupShow:false,
- reasonList:[],
- columns: ['地址约错', '约不到想要的服务时间','活动/优惠未享受','服务质量问题'],
- contentLength: 0,
- fileList: [],
- imgList:[],
- },
- onLoad: function (options) {
- // 页面初始化 options为页面跳转所带来的参数
- this.setData({
- orderId: options.id
- });
- this.getOrderDetail();
- this.getRefudnType();
- this.getAmount();
- },
- getRefudnType() {
- let that = this;
- util.request(api.AftersaleRefundType).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- reasonList: res.data,
- columns: res.data.map((obj => obj.name))
- })
- console.info(that.data.refundTypes)
- }
- });
- },
- getAmount:function(){
- util.request(api.AftersaleAmount, {
- orderId: this.data.orderId
- }).then(res=> {
- if (res.errno === 0) {
- console.log(res.data);
- this.setData({
-
- 'aftersale.amount': res.data.refundAmount
- });
- }
-
- });
- },
- 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,
- });
- }
-
- 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) {
- console.log(e);
- this.setData({
- 'aftersale.reason': e.detail.value
- });
- },
- onCommentChange: function (e) {
- console.log(e);
- this.setData({
- 'aftersale.comment': e.detail.value
- });
- },
- showTypePicker: function () {
- this.setData({
- showPicker: true
- });
- },
- onCancel: function () {
- this.setData({
- showPicker: false
- });
- },
- bindPickerChange: function (event) {
- console.log(event);
- this.setData({
- 'aftersale.type': event.detail.value,
- 'aftersale.typeDesc': this.data.columns[event.detail.value],
-
- });
- },
- submit: function () {
- let that = this;
- if (that.data.reasonActive.id == '') {
- util.showErrorToast('请选择退款原因');
- return false;
- }
- if (that.data.aftersale.reason == '') {
- util.showErrorToast('请填写补充描述');
- return false;
- }
-
- // let name = that.data.aftersale.typeDesc;
- // let vals = this.data.refundTypes.filter(item =>item.name == name);
- // that.setData({
- // type:vals[0].id
- // })
- // console.log(that.data.aftersale);
- // if (that.data.aftersale.reason == '') {
- // util.showErrorToast('请输入退款原因');
- // return false;
- // }
- wx.showLoading({
- title: '提交中...',
- mask: true,
- success: function () {}
- });
- // this.setData({
- // "aftersale.pictures": this.data.imgList
- // });
- let params={
- orderId:this.data.orderId,
- pictures: this.data.imgList,
- type:this.data.reasonActive.id,
- typeDesc:this.data.reasonActive.name,
- reason:this.data.aftersale.reason,
- amount:this.data.aftersale.amount
- }
- util.request(api.AftersaleSubmit, params, 'POST').then(function (res) {
- wx.hideLoading();
- if (res.errno === 0) {
- wx.showToast({
- title: '申请售后成功',
- icon: 'success',
- duration: 2000,
- complete: function () {
- wx.navigateBack({
- delta: 1
- });
- // wx.redirectTo({
- // url: '/pages/ucenter/aftersaleList/aftersaleList'
- // });
- }
- });
- } else {
- util.showErrorToast(res.errmsg);
- }
- });
- },
- previewImg(e){
- let img=e.currentTarget.dataset.img;
- let imgs=this.data.imgList
- wx.previewImage({
- current:img , // 当前显示图片的http链接
- urls:imgs // 需要预览的图片http链接列表
- })
- },
- delImg(e){
- let imgs=this.data.imgList;
- let index=e.currentTarget.dataset.index;
- imgs.splice(index,1);
- this.setData({
- imgList:imgs
- })
- },
- uploadImg(){
- if(this.data.imgList.length>=3){
- wx.showToast({
- title: '最多上传3张图片',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- let that=this;
- let count= 3-that.data.imgList.length;
- wx.chooseImage({
- count:count,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success: function (res) {
- console.log(res);
- let tempFilePaths=res.tempFilePaths;
-
- wx.showLoading({
- title: '上传中...',
- });
- for(let i=0;i<tempFilePaths.length;i++){
- let imgs=that.data.imgList;
- if(imgs.length>=3){
- that.setData({
- imgList:imgs
- });
- return false;
- }else{
- wx.uploadFile({
- url: api.StorageUpload,
- filePath: tempFilePaths[i],
- name: 'file',
-
- success (res){
- console.log(res);
- let data=JSON.parse(res.data);
- if(data.errno==0){
-
- imgs.push(data.data.url);
- that.setData({
- imgList:imgs
- });
- }else{
- console.log('上传失败')
- }
- }
- })
- }
-
- }
- wx.hideLoading();
- }
- });
- },
- onReady: function () {
- // 页面渲染完成
- },
- onShow: function () {
- // 页面显示
- },
- onHide: function () {
- // 页面隐藏
- },
- onUnload: function () {
- // 页面关闭
- },
- showReason(){
- this.setData({
- reasonPopupShow:true
- })
- },
- onReasonPopupClose(){
- this.setData({
- reasonPopupShow:false
- });
- },
- onReasonClick(){
- //阻止事件冒泡,不要删
- },
- reasonItemSelect(e){
- let reason=e.currentTarget.dataset.reason;
- this.setData({
- reasonActive:reason,
- });
- },
- reasonItemConfirm(){
- if (this.data.reasonActive.id === '') {
- util.showErrorToast("请选择退款原因");
- return false;
- }
- this.setData({
- reasonPopupShow:false
- });
- },
- });
|