diff --git a/api/order.js b/api/order.js index 11f53f2..7f757df 100644 --- a/api/order.js +++ b/api/order.js @@ -26,5 +26,15 @@ export default { pickup:(orderid)=>request.post(`/api/order/${orderid}/deliveryman/pickup`), complete:(orderid,images)=>request.post(`/api/order/${orderid}/deliveryman/complete`,{images:images}), cancel:(orderid,reason)=>request.post(`/api/order/${orderid}/deliveryman/cancel`,{reason}), - check:()=>request.get('/api/order/deliveryman/check_new_order') + check:()=>request.get('/api/order/deliveryman/check_new_order'), + + markUp:{ + status:{ + pending:"PENDING", + accepted:"ACCEPTED" + }, + add:(data)=>request.post('/api/order-additional-fee',data), + get:(orderid)=>request.get(`/api/order-additional-fee/order/${orderid}`,{},{noTips:true}), + update:(data)=>request.put(`/api/order-additional-fee/${data.id}`,data) + } } \ No newline at end of file diff --git a/app.js b/app.js index 7f46d41..b92956f 100644 --- a/app.js +++ b/app.js @@ -59,7 +59,10 @@ App({ for(var key in rules){ ((rules[key] instanceof Array)?rules[key]:[rules[key]]).map((item)=>{ let valid = true; - let value = (page.data[key]||'').trim(); + let value = page.data[key]; + if(typeof value=='string'){ + value = value.trim(); + } //非空 if(item.required){ if(value==''){ @@ -78,6 +81,10 @@ App({ if(value.length>(item.maxLength||Infinity)||value.length{ + this.setData({ + tempImgs:this.data.tempImgs.concat(res.tempFiles) + }); + this.uploadImages(); + } + }); + }, + async uploadImages(){ + let imgIndex = -1; + const file = this.data.tempImgs.find((item,index)=>{ + imgIndex = index; + return !item.uploaded; + }); + if(!file){ + this.setData({ + loading:false + }) + return; + } + this.setData({ + loading:true + }) + let onProgress = (res)=>{ + //进度 + this.setData({ + [`tempImgs[${imgIndex}].progress`]:res.progress + }) + } + //无奈之举,不大范围改动代码的同时,我需要获取到上传任务task,来中断上传操作,不然要出问题task在上传时被附加到了onProgress + this.data.tempImgs[imgIndex].onProgress = onProgress; + let uploadResult = {}; + try { + // uploadResult = await userApi.uploadImg({tempFilePath:'123'},onProgress); + uploadResult = await userApi.uploadImg(file,onProgress); + } catch (error) { + //这里要死循环 + // await this.uploadImages(); + // return; + } + if(uploadResult.url){ + this.setData({ + [`tempImgs[${imgIndex}].uploaded`]:true, + [`tempImgs[${imgIndex}].serverUrl`]:uploadResult.url + }) + await this.uploadImages(); + }else{ + //上传失败 + this.setData({ + loading:false + }) + wx.showToast({ + icon:'error', + title: '上传失败', + }) + return new Error('失败') + } + }, + removeImage(event){ + const index = event.currentTarget.dataset.index; + if(this.data.tempImgs[index].onProgress&&this.data.tempImgs[index].onProgress.task){ + this.data.tempImgs[index].onProgress.task.abort(); + } + console.log('remove',new Date().getTime()); + this.data.tempImgs.splice(index,1); + this.setData({ + tempImgs:this.data.tempImgs + }); + }, + async getUploadedUrl(){ + await this.uploadImages(); + let urls = [],loadAll = true; + this.data.tempImgs.map((item)=>{ + if(!item.uploaded)loadAll = false; + urls.push(item.serverUrl); + }) + if(loadAll){ + return urls + } + throw new Error('图片上传失败'); + }, + setUploadedImgs(imgs){ + this.setData({ + tempImgs:imgs.concat(this.data.tempImgs) + }) + } + }, + lifetimes:{ + attached(){ + console.log('img uploader init'); + } + } +}) \ No newline at end of file diff --git a/components/img-uploader/index.json b/components/img-uploader/index.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/components/img-uploader/index.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/components/img-uploader/index.wxml b/components/img-uploader/index.wxml new file mode 100644 index 0000000..ccff240 --- /dev/null +++ b/components/img-uploader/index.wxml @@ -0,0 +1,14 @@ + +{{uploadedImgs.length}} + + + + + + + + + + 点击拍照 + + \ No newline at end of file diff --git a/components/img-uploader/index.wxss b/components/img-uploader/index.wxss new file mode 100644 index 0000000..8c2be75 --- /dev/null +++ b/components/img-uploader/index.wxss @@ -0,0 +1,58 @@ +.img-area{ + margin-top:60rpx; + display: flex; + flex-wrap: wrap; + gap: 20rpx; + display: flex; + justify-content: flex-end; +} +.img-area .item{ + width: 120rpx;height:120rpx; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + border-radius: 12rpx; + position: relative; +} + +.img-area .item .progress{ + position: absolute; + top:0;left:0; + width:100%; + z-index: 1; +} +.img-area .item .close-area{ + position: absolute; + right:-16rpx;top:-16rpx; + z-index: 2; + padding:5rpx; + display: flex; + align-items: center; +} +.img-area .item .close-area .icon{ + width:28rpx;height:28rpx; +} +.img-area .item.loading::after{ + content: ''; + position: absolute; + width:100%;height:100%; + left:0;top:0; + background-color: rgba(0, 0, 0, 0.3); + z-index: 0; +} +.img-area .item .image{ + width:100%;height:100%; + border-radius: 12rpx; +} + + +.img-area .take-photo{ + font-size: 20rpx; + color: rgba(153, 153, 153, 0.5); + border: 1.2px solid rgba(124, 134, 149, 0.3); +} +.img-area .take-photo .icon{ + width:32rpx;height:32rpx; + margin-bottom:14rpx; +} \ No newline at end of file diff --git a/components/modalView/index.js b/components/modalView/index.js index dc04c14..e7d69ff 100644 --- a/components/modalView/index.js +++ b/components/modalView/index.js @@ -1,7 +1,6 @@ const app = getApp(); Component({ - /** * 组件的属性列表 */ @@ -38,6 +37,10 @@ Component({ type:Boolean, value:true }, + isShowOk:{ + type:Boolean, + value:true + }, cancelButtonText:{ type:String, value:'取消' diff --git a/components/modalView/index.json b/components/modalView/index.json index e8cfaaf..8b37bbf 100644 --- a/components/modalView/index.json +++ b/components/modalView/index.json @@ -1,4 +1,5 @@ { "component": true, - "usingComponents": {} + "usingComponents": {}, + "styleIsolation": "apply-shared" } \ No newline at end of file diff --git a/components/modalView/index.wxml b/components/modalView/index.wxml index 13ebb74..e7ecf7d 100644 --- a/components/modalView/index.wxml +++ b/components/modalView/index.wxml @@ -8,9 +8,10 @@ placeholder="{{contentPlaceholder}}" focus="{{contentFocus}}" animation="{{contentAnimation}}" cursor-spacing="200rpx"> {{content}} - + + - + \ No newline at end of file diff --git a/components/modalView/index.wxss b/components/modalView/index.wxss index 6bc922e..fa65a03 100644 --- a/components/modalView/index.wxss +++ b/components/modalView/index.wxss @@ -5,7 +5,6 @@ font-size: 34rpx; font-weight: 500; line-height: 50rpx; - padding:0 20rpx; } .custom-modal-view .title.center{ text-align: center; diff --git a/components/number-box/index.js b/components/number-box/index.js new file mode 100644 index 0000000..31512a6 --- /dev/null +++ b/components/number-box/index.js @@ -0,0 +1,42 @@ +// components/number-box/index.js +Component({ + + /** + * 组件的属性列表 + */ + properties: { + value:{ + type:Number, + value:0 + }, + disabled:{ + type:Boolean, + value:false + } + }, + + /** + * 组件的初始数据 + */ + data: { + + }, + + /** + * 组件的方法列表 + */ + methods: { + reduce(){ + if(this.properties.value>1){ + this.setData({ + value:this.properties.value-1 + }) + } + }, + plus(){ + this.setData({ + value:this.properties.value+1 + }) + } + } +}) \ No newline at end of file diff --git a/components/number-box/index.json b/components/number-box/index.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/components/number-box/index.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/components/number-box/index.wxml b/components/number-box/index.wxml new file mode 100644 index 0000000..55fec6d --- /dev/null +++ b/components/number-box/index.wxml @@ -0,0 +1,5 @@ + + + {{value}} + + \ No newline at end of file diff --git a/components/number-box/index.wxss b/components/number-box/index.wxss new file mode 100644 index 0000000..8396771 --- /dev/null +++ b/components/number-box/index.wxss @@ -0,0 +1,46 @@ +.number-box{ + display: flex; + align-items: center; +} +.number-box .value{ + font-size: 36rpx; + padding:0 28rpx; +} +.number-box .button{ + width:48rpx;height:48rpx; + line-height: 1; + padding:0; + text-align: center; + color: #fff; + position: relative; + background-color: var(--main-color); + border-radius: 50%; + border: 1rpx solid #FFC300; +} +.number-box .button.disabled{ + background-color: #fff; +} +.number-box .reduce::before, +.number-box .plus::before, +.number-box .plus::after{ + content: ''; + width:50%; + height:4rpx; + background-color: #fff; + position:absolute; + left:25%;top:22rpx; +} +.number-box .reduce.disabled::before, +.number-box .plus.disabled::before, +.number-box .plus.disabled::after{ + background-color: var(--main-color); +} +.number-box .plus::after{ + width:4rpx; + height:50%; + left:22rpx;top:25%; + z-index: 100; +} +.number-box.disabled{ + opacity: .4; +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js index ab4c910..4987586 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -61,7 +61,9 @@ Page({ error:false, loading:true }, - unReadOrderCount:0 + unReadOrderCount:0, + + selectedOrderId:'' }, onLoad(){ this.orderBackgroundNotice = this.selectComponent('#orderBackgroundNotice'); @@ -296,23 +298,59 @@ Page({ }) },400) }, - showRefundConfirm(event){ + showMoreAS(event){ const item = event.currentTarget.dataset.item; const index = event.currentTarget.dataset.index; - if(item.receiving)return; - this.refundOrderIndex = index; - this.setData({ - isShowRefundConfirm:true + //这里不能记录 index 因为列表可能会因为网络等各种原因刷新,后续的操作就可能找到其他订单 + this.currentOrder = item; + const markupAction = ()=>{ + const markupView = this.selectComponent('#markupView'); + markupView.show(this.currentOrder) + } + const makePhoneCallAction = ()=>{ + wx.makePhoneCall({ + phoneNumber: this.currentOrder.address.phone, + }); + } + const refundAction = ()=>{ + if(this.currentOrder.receiving)return; + this.setData({ + isShowRefundConfirm:true + }); + } + let items = []; + let actions = []; + if(item.status==this.data.orderStatus.created){ + items = ['联系用户','取消订单']; + actions = [makePhoneCallAction,refundAction] + }else if(item.status==this.data.orderStatus.received){ + items = ['包裹加价','联系用户','取消订单']; + actions = [markupAction,makePhoneCallAction,refundAction] + }else if(item.status==this.data.orderStatus.delivering){ + items = ['联系用户']; + actions = [makePhoneCallAction] + } + if(items.length!=actions.length){ + throw new Error('sb') + } + wx.showActionSheet({ + itemList: items, + success:(res)=>{ + console.log(res); + actions[res.tapIndex](); + } }) }, refund(event){ - const index = this.refundOrderIndex; - const item = this.data.list[index]; + const item = this.currentOrder; if(item.receiving)return; - this.setData({ - [`list[${index}].receiving`]:true - }) + const index = this.data.list.findIndex((item)=>item.orderid==this.currentOrder.orderid); + if(index>-1){ + this.setData({ + [`list[${index}].receiving`]:true + }) + } orderApi.cancel(item.orderid,event.detail).then((data)=>{ wx.showToast({ title: '取消成功', @@ -405,7 +443,7 @@ Page({ this.setData({ completing:true }) - this.uploadImages().then(()=>{ + this.uploadImages().then((data)=>{ let urls = []; this.data.tempImgs.map((item)=>{ urls.push(item.serverUrl); @@ -457,11 +495,10 @@ Page({ this.data.tempImgs[imgIndex].onProgress = onProgress; let uploadResult = {}; try { - uploadResult = await userApi.uploadImg(file,onProgress); + uploadResult = await userApi.uploadImg(file,onProgress); } catch (error) { - await this.uploadImages(); - console.log(new Date().getTime()); - return; + // await this.uploadImages(); + // return; } if(uploadResult.url){ this.setData({ @@ -471,7 +508,14 @@ Page({ await this.uploadImages(); }else{ //上传失败 - return new Error('失败') + this.setData({ + completing:false + }) + wx.showToast({ + icon:'error', + title: '上传失败', + }) + throw new Error('失败') } }, removeImage(event){ diff --git a/pages/index/index.json b/pages/index/index.json index d7d0bc7..ef8827c 100644 --- a/pages/index/index.json +++ b/pages/index/index.json @@ -3,7 +3,8 @@ "list-view":"/components/listView", "swipe-button":"/components/swipeButton", "modal-view":"/components/modalView", - "background-notice":"/components/background-notice" + "background-notice":"/components/background-notice", + "mark-up":"./mark-up" }, "navigationStyle": "custom", "navigationBarTextStyle": "white" diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 872a590..640cc69 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -71,24 +71,32 @@ - + - + - --> + @@ -198,7 +206,9 @@ - + + + 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.setData({ + reason:'', + money:0, + }); + this.setData({ + isShowMarkup:false + }) + wx.showToast({ + title: '保存成功', + }) + }); + }else{ + orderApi.markUp.add({ + orderid:this.currentOrder.orderid, + reason:this.data.reason, + photo_urls:urls, + additional_fee_amount:this.data.money + }).then((data)=>{ + this.setData({ + reason:'', + money:0, + }); + this.setData({ + isShowMarkup:false + }) + 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.selectComponent('#imgUploader').setUploadedImgs(imgs); + }).catch((error)=>{ + this.setData({ + reason:'', + money:0, + }); + }) + } + }, + + lifetimes:{ + attached(){ + + } + } +}) \ No newline at end of file diff --git a/pages/index/mark-up/index.json b/pages/index/mark-up/index.json new file mode 100644 index 0000000..0bef832 --- /dev/null +++ b/pages/index/mark-up/index.json @@ -0,0 +1,9 @@ +{ + "component": true, + "usingComponents": { + "modal-view":"/components/modalView", + "number-box":"/components/number-box", + "img-uploader":"/components/img-uploader" + }, + "styleIsolation": "apply-shared" +} \ No newline at end of file diff --git a/pages/index/mark-up/index.wxml b/pages/index/mark-up/index.wxml new file mode 100644 index 0000000..7cac176 --- /dev/null +++ b/pages/index/mark-up/index.wxml @@ -0,0 +1,16 @@ + + + +