From e337f1433eff38c757d3f088246ff1a5ed3b9e20 Mon Sep 17 00:00:00 2001 From: caichunsheng Date: Fri, 12 Aug 2022 17:36:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=94=AF=E6=8C=81=E5=9B=BE?= =?UTF-8?q?=E7=89=87=EF=BC=8C=E5=8C=BF=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/order/comment/index.js | 195 +++++++++++++++++++++++++++------ pages/order/comment/index.wxml | 17 ++- pages/order/comment/index.wxss | 72 +++++++++++- pages/user/cartlist/list.wxml | 3 +- 4 files changed, 249 insertions(+), 38 deletions(-) diff --git a/pages/order/comment/index.js b/pages/order/comment/index.js index 44b07d1..9286452 100644 --- a/pages/order/comment/index.js +++ b/pages/order/comment/index.js @@ -6,93 +6,220 @@ Page({ * 页面的初始数据 */ data: { - info:null + info: null, + imgs: [], + upImgs:[], + checked:false, + rate:0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { - commonApi.user_post("order/query",{ - order_id:options.id - }).then(res=>{ + commonApi.user_post("order/query", { + order_id: options.id + }).then(res => { let list = []; - res.data.order_product_list.map(item=>{ + res.data.order_product_list.map(item => { item.star = 5; item.content = ""; - if(item.state=='WAIT_COMMENT'){ + if (item.state == 'WAIT_COMMENT') { list.push(item); } }) - if(list.length==0){ + if (list.length == 0) { wx.showToast({ title: '该订单没有待评价产品', - icon:'none' + icon: 'none' }) - setTimeout(()=>{ + setTimeout(() => { wx.navigateBack() - },1000) + }, 1000) return; } res.data.order_product_list = list; this.setData({ - info:res.data + info: res.data }) }) }, - changeStar:function(e){ + changeStar: function (e) { console.log(e) wx.showLoading({ title: '加载中' }) - let index = e.currentTarget.dataset.index,star = e.currentTarget.dataset.star; + let index = e.currentTarget.dataset.index, + star = e.currentTarget.dataset.star; let info = this.data.info; - info.order_product_list[index].star = Number(star)+1; + info.order_product_list[index].star = Number(star) + 1; this.setData({ - info:info - }) - wx.hideLoading({ + info: info, + rate:info.order_product_list[index].star }) + console.log(info); + wx.hideLoading({}) }, - changeContent:function(e){ + changeContent: function (e) { console.log(e) - let index = e.currentTarget.dataset.index,info = this.data.info; + let index = e.currentTarget.dataset.index, + info = this.data.info; info.order_product_list[index].content = e.detail.value; this.setData({ - info:info + info: info }) }, - submit:function(){ - let info = this.data.info,flag = true,ajax=[] - info.order_product_list.map(item=>{ - if(!item.content) { + submit: function () { + let info = this.data.info, + flag = true, + ajax = [] + info.order_product_list.map(item => { + if (!item.content) { wx.showToast({ title: '请输入评价内容', - icon:'none' + icon: 'none' }) flag = false; } - ajax.push(commonApi.user_post("product/product_comment",{ - product_id:item.product_id, - content:item.content, - order_id:this.data.id + console.log(item); + ajax.push(commonApi.user_post("product/product_comment", { + product_id: item.product_id, + content: item.content, + order_id: item.order_id, + integer:this.data.rate, + img_list:this.data.upImgs.join(','), + is_anonymous:this.data.checked?1:0 })) }) - if(!flag) return; - Promise.all(ajax).then(res=>{ + if (!flag) return; + Promise.all(ajax).then(res => { console.log(res) let flag = false; - res.map(item=>{ - if(item.code==1){ + res.map(item => { + if (item.code == 1) { flag = true } }) - if(flag){ + if (flag) { wx.navigateBack() } }) }, + //图片上传 + // 上传图片 + chooseImg: function (e) { + console.log(e); + var that = this; + var imgs = this.data.imgs; + if (imgs.length >= 8) { + wx.showToast({ + title: '最多上传八张图片哦..', + icon: 'none' + }) + return false; + } + wx.chooseImage({ + // count: 1, // 默认9 + sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 + sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 + success: function (res) { + // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 + let size = res.tempFiles[0].size + const temp = res.tempFilePaths[0] + if (size > 1024 * 1024 * 20) { + wx.showToast({ + title: '图片最大支持20M..', + icon: 'none' + }) + return + } else if (temp.substr(temp.length - 4, 4) == '.gif') { + wx.showToast({ + title: '图片格式错误', + icon: 'none' + }) + return; + } + var tempFilePaths = res.tempFilePaths; + var imgs = that.data.imgs; + wx.uploadFile({ + url: 'https://test.api.cloud.sz-trip.com/api/pbservice.other/upload', //这里是上传的服务器地址 + filePath: tempFilePaths[0], + name: 'file', + header: { + token: wx.getStorageSync('jstrip_token'), + }, + success(res) { + + var res = JSON.parse(res.data); + if (res.code!=1) { + wx.showToast({ + title: res.msg, + icon: 'none' + }) + return + } + let img = res.data.url; + let arr = that.data.upImgs + arr.push(img) + that.setData({ + upImgs:arr + }) + console.log(that.data.upImgs); + for (var i = 0; i < tempFilePaths.length; i++) { + if (imgs.length >= 9) { + that.setData({ + imgs: imgs + }); + return false; + } else { + imgs.push(tempFilePaths[i]); + } + } + // console.log(imgs); + that.setData({ + imgs: imgs + }); + console.log(that.data.imgs); + const data = res.data + } + }) + + } + }); + }, + // 删除图片 + deleteImg: function (e) { + let imgs = this.data.imgs; + let index = e.currentTarget.dataset.index; + let upimg = this.data.upImgs + imgs.splice(index, 1); + upimg.splice(index,1) + this.setData({ + imgs: imgs, + upImgs:upimg + }); + + }, + // 预览图片 + previewImg: function (e) { + //获取当前图片的下标 + var index = e.currentTarget.dataset.index; + //所有图片 + var imgs = this.data.imgs; + wx.previewImage({ + //当前显示图片 + current: imgs[index], + //所有图片 + urls: imgs + }) + }, + checkboxChange:function(){ + this.setData({ + checked:!this.data.checked + }) + console.log(this.data.checked); + }, /** * 生命周期函数--监听页面初次渲染完成 */ diff --git a/pages/order/comment/index.wxml b/pages/order/comment/index.wxml index 271c5d6..646d050 100644 --- a/pages/order/comment/index.wxml +++ b/pages/order/comment/index.wxml @@ -1,7 +1,7 @@ - + {{item.product_title}} @@ -18,6 +18,21 @@ + + + + + + + + 上传图片 + + + + + 提交 \ No newline at end of file diff --git a/pages/order/comment/index.wxss b/pages/order/comment/index.wxss index dc717b2..ffdcc18 100644 --- a/pages/order/comment/index.wxss +++ b/pages/order/comment/index.wxss @@ -1,7 +1,11 @@ /* pages/order/comment/index.wxss */ +page{ + background-color: #FBF8FB; +} .product-box { - margin: 0 30rpx; + padding: 0 30rpx 10rpx 30rpx; font-size: 28rpx; + background-color: #fff; } .product-top { display: flex; @@ -56,6 +60,7 @@ .product-box textarea { display: block; width: 100%; + height: 210rpx; } .btn { width: 360rpx; @@ -70,4 +75,67 @@ bottom: 40rpx; left: 50%; margin-left: -180rpx; -} \ No newline at end of file +} + +/* 图片 */ +.three{ + margin-top: 27rpx; +} +.weui-uploader{ + margin: 16rpx 0; +} +.tp_add{ + width: 152rpx; + height: 152rpx; + border-radius: 10rpx; + opacity: 1; + border: 2rpx dashed #999999; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + font-size: 22rpx; + color: #BCBCBC; +} + +.pics { + float:left; + position:relative; + margin-right:15px; + margin-bottom:15px; + } + .pics image{ + width: 152rpx; + height: 152rpx; + } + .delete-btn{ + width: 20rpx; + height: 20rpx; + position: absolute; + top: -15rpx; + right: -5rpx; + } + .weui-uploader{ + padding: 10rpx 0; + } + .prd{ + border-bottom: 1px solid #CCCCCC; + } + .checkbox{ + margin: 16rpx 20rpx; + color: #BCBCBC; + } + checkbox .wx-checkbox-input { + width: 30rpx; + height: 30rpx; + border-radius: 50%; + } + + checkbox .wx-checkbox-input.wx-checkbox-input-checked { + border-color: #18d6ff; + background-color: #18d6ff; + } + + checkbox .wx-checkbox-input.wx-checkbox-input-checked::before { + color:#fff; + } diff --git a/pages/user/cartlist/list.wxml b/pages/user/cartlist/list.wxml index cc7a05c..2123667 100644 --- a/pages/user/cartlist/list.wxml +++ b/pages/user/cartlist/list.wxml @@ -31,7 +31,8 @@ 合计: - ¥{{allPrice/100}} + ¥{{allPrice/100}} + 不含运费 去下单