// pages/order/comment/index.js import commonApi from "../../../utils/https/common" Page({ /** * 页面的初始数据 */ data: { info:null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { commonApi.user_post("order/query",{ order_id:options.id }).then(res=>{ let list = []; res.data.order_product_list.map(item=>{ item.star = 5; item.content = ""; if(item.state=='WAIT_COMMENT'){ list.push(item); } }) if(list.length==0){ wx.showToast({ title: '该订单没有待评价产品', icon:'none' }) setTimeout(()=>{ wx.navigateBack() },1000) return; } res.data.order_product_list = list; this.setData({ info:res.data }) }) }, changeStar:function(e){ console.log(e) wx.showLoading({ title: '加载中' }) 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; this.setData({ info:info }) wx.hideLoading({ }) }, changeContent:function(e){ console.log(e) let index = e.currentTarget.dataset.index,info = this.data.info; info.order_product_list[index].content = e.detail.value; this.setData({ info:info }) }, submit:function(){ let info = this.data.info,flag = true,ajax=[] info.order_product_list.map(item=>{ if(!item.content) { wx.showToast({ title: '请输入评价内容', 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 })) }) if(!flag) return; Promise.all(ajax).then(res=>{ console.log(res) let flag = false; res.map(item=>{ if(item.code==1){ flag = true } }) if(flag){ wx.navigateBack() } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })