import orderApi from '../../../api/order'; const app = getApp(); Component({ relations:{ "/components/img-uploader":{ type:'child' } }, /** * 组件的属性列表 */ properties: { orderId:{ type:String, value:'' } }, /** * 组件的初始数据 */ data: { imgUploading:false, money:1, reason:'', reasonFocus:false, requestId:'', isShowMarkup:false, }, /** * 组件的方法列表 */ methods: { async apply(){ const urls = await this.imgUploader.getUploadedUrl(); const valid = app.validateForm({ reason:{required:true,autoFocus:true,shake:true}, money:{min:1,shake:true} },this) if(valid.length>0){ return; } if(this.data.requestId){ orderApi.markUp.update({ id:this.data.requestId, reason:this.data.reason, photo_urls:urls, additional_fee_amount:this.data.money }).then(()=>{ this._updateSuccessAction(); }); }else{ orderApi.markUp.add({ orderid:this.currentOrder.orderid, reason:this.data.reason, photo_urls:urls, additional_fee_amount:this.data.money }).then((data)=>{ this._updateSuccessAction(); }) } }, _updateSuccessAction(){ this.triggerEvent('success'); this.setData({ reason:'', money:0, isShowMarkup:false }); this.imgUploader.setUploadedImgs([]); wx.showToast({ title: '保存成功', }) }, show(order){ this.setData({ isShowMarkup:true }) this.currentOrder = order; orderApi.markUp.get(order.orderid).then((data)=>{ let imgs = []; data.photo_urls.map((item)=>{ imgs.push({ serverUrl:item, uploaded:true }); }); this.setData({ reason:data.reason, money:data.additional_fee_amount, requestId:data.id }) this.imgUploader.setUploadedImgs(imgs); }).catch((error)=>{ this.setData({ reason:'', requestId:'', money:0, }); this.imgUploader.setUploadedImgs([]); }).finally(()=>{ wx.nextTick(()=>{ this.setData({ reasonFocus:true }) }) }) } }, lifetimes:{ attached(){ this.imgUploader = this.selectComponent('#imgUploader') } } })