var e = getApp(), a = e.globalData.setting, os = a, t = e.request, d = e.globalData; Page({ /** * 页面的初始数据 */ data: { url: a.url, //接口网址 iurl: a.imghost, defimgurl: "/miniapp/images/no-head.jpg", stars_index: -1, //当前点击的星星下标 labels: [], //星级标签数组 sub_evaluate: 0, //是否评价成功 proposal: "", //用户输入的建议 proposal_size: 100, //评价意见和建议限定字数 number: "", //订单单号 beautician: "", //美容师信息 fromType: "服务评价", //评价来源 arrangeTime: "", //服务日期 is_evaluate: 0, //是否评价 EvaluateDatetime: "", //评价时间 is_act:0, //是否能购获取图片 actId:0, //活动ID giftBagId:0, //礼包ID ftype:0, isdg:0, //是否是导购 }, //点击星级 check_stars: function(e) { var th = this; var is_evaluate = th.data.is_evaluate; //0可点击 if (is_evaluate == 0) { var index = e.currentTarget.dataset.index; var stars_index = th.data.stars_index; if (index != stars_index) { var url = "/api/weshop/marketing/reservation/star/label/list"; getApp().request.promiseGet(url, { data: { Star: index + 1, storeId: a.stoid } }).then(res => { if (res.data.code == 0) { th.setData({ labels: res.data.data }) } else { getApp().my_warnning(res.data.msg, 0, th); return; } }) th.setData({ stars_index: index }) } } }, //输入评价意见和建议 input_proposal: function(e) { var th = this; var value = e.detail.value; th.setData({ proposal: value }) }, //图片失败,默认图片 bind_bnerr1: function (e) { var th = this; var _errImg = e.target.dataset.errorimg; var _Img = e.target.dataset.img; if (_Img != undefined) { var _errObj = {}; _errObj[_errImg] = "/miniapp/images/no-head.jpg"; th.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; } }, //选择标签 check_label: function(e) { var th = this; var evaluate = th.data.is_evaluate; //0为未评价,未评价才可点击标签 if (evaluate == 0) { var index = e.currentTarget.dataset.index; var label_id = th.data.labels[index].check; var labels = 'labels[' + index + '].check'; if (label_id) { label_id = 0 } else { label_id = 1 } th.setData({ [labels]: label_id }) } }, //查询美导信息 query_bea: function() { var th = this; var url = "/api/weshop/order/pagePosOrder"; //ftype =5 退款 switch (this.data.ftype){ case 3: break; case 4: url = "/api/weshop/serviceCard/pagePos"; break; case 5: url = "/api/weshop/serviceCard/pageCardOut"; break; default: break } var number = th.data.number; //订单编号 getApp().request.promiseGet(url, { data: { store_id: a.stoid, user_id: d.user_id, No: number } }).then(res => { if (res.data.code == 0) { var data = res.data.data.pageData; var arrangeTime = data[0].ArrangeTime; if (this.data.ftype==5 && data && data.length >0) { //退款是项目名称赋值到list里 data.map((item,i)=>{ if (item.list && item.list.length>0) { item.list.map((ite,j)=>{ data[i].list[j].ItemName = item.ItemName }) } }) } th.setData({ beautician: data, arrangeTime: arrangeTime }) } else { getApp().my_warnning(res.data.msg, 0, th); } }) }, //获取预约评价 evaluate_get: function() { var th = this; var url = "/api/weshop/evaluation/evaluate/get"; getApp().request.promiseGet(url, { data: { number: th.data.number, fromtype:th.data.ftype, storeId: a.stoid } }).then(res => { if (res.data.code == 0) { var list=[]; res.data.data.BillDate=res.data.data.BillDate.substring(0, 19); list.push(res.data.data); if (th.data.ftype==5 && list && list.length>0) { //退款时赋值项目名称到list list.map((item,i)=>{ if (item.list && item.list.length>0) { item.list.map((ite,j)=>{ list[i].list[j].ItemName = item.ItemName }) } }) } th.setData({ stars_index: res.data.data.Star-1, labels: res.data.data.EvaluationList, proposal: res.data.data.Remark, EvaluateDatetime: res.data.data.EvaluateDatetime.substring(0, 19), beautician:list, }) } else { getApp().my_warnning(res.data.msg, 0, th); } }) }, //提交评价 evaluate_save: function() { var th = this; var stars = th.data.stars_index; //评价星级 var proposal = th.data.proposal; //判断是否评级 if (stars < 0) { getApp().my_warnning("请进行评分", 0, th); return false; } else if (proposal == "") { getApp().my_warnning("给点建议呗", 0, th); return false; } if(this.data.lding) return false; this.data.lding=1; wx.showLoading({ title: '加载中', }) var labels = th.data.labels; //星级标签数组 var evaLabList = []; //用户选择的评价标签 // 查询评价标签 for (var i = 0; i < labels.length; i++) { if (labels[i].check) { evaLabList.push(labels[i].LabelName); } } var url = th.data.url + "/api/weshop/evaluation/evaluate/insert"; var posNo = th.data.number; //收银单号 var proposal = th.data.proposal; //用户建议内容 var fromType = th.data.ftype?th.data.ftype:1; //评价来源 var json = { "evaLabList": evaLabList, "fromType": fromType, "number": posNo, "remark": proposal, "star": stars + 1, "storeId": a.stoid }; //var data = JSON.stringify(json); //转换成json格式 getApp().request.promisePost(url, { data: json,is_json:1,is_normal:1 }).then(res => { wx.hideLoading(); if (res.data.code == 0) { getApp().my_warnning("评价成功", 1, th); var namber=th.data.number; var url="/packageB/pages/evaluate_list/evaluate_list?IsEvaluate=1"; if(th.data.ftype==4 || th.data.ftype==5){ url="/pages/user/index/index"; } setTimeout(function() { wx.reLaunch({ url: url }); }, 2000); } else { th.data.lding=0; getApp().my_warnning(res.data.msg, 0, th); } }).catch(function(err) { th.data.lding=0; wx.hideLoading(); }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { var th = this; th.setData({ number: options.number, //is_evaluate: options.evaluate }) if(options.fromtype){ this.setData({ftype:parseInt(options.fromtype)}) ; if(options.fromtype==4 || options.fromtype==1 ) th.judge_act(); } if (options.isdg) { this.setData({ isdg:options.isdg }) } //th.query_bea(); var userinfo=getApp().globalData.userInfo; console.log("userinfo",userinfo) if(!userinfo){ getApp().goto("/packageE/pages/togoin/togoin"); } }, /** * 生命周期函数--监听页面显示 */ onShow: function() { //var th = this; //var is_evaluate = th.data.is_evaluate; //if (is_evaluate == 1) { // th.evaluate_get(); //} //判断有没有评价 this.check_is_pj(); }, //评价其他跳转 evaluate_qt:function(e){ var status=e.currentTarget.dataset.status; if(!status) status=0; wx.redirectTo({ url: "/packageB/pages/evaluate_list/evaluate_list?IsEvaluate="+status }); }, //点击领取礼包 clike_lb:function(){ var id=this.data.actId; var gifbagid = this.data.gifbagid; console.log(id,"订单", this.data.number); var ty=this.data.ftype?this.data.ftype:2; var isdg = this.data.isdg wx.redirectTo({ url: "/packageF/pages/giftpack/evaluategift/evaluategift?actId="+id+ "&orderType="+ty+"&orderNumber="+this.data.number+"&isdg="+isdg }); }, //--评价有礼判断--- judge_act: function () { var th = this; var url = "/api/weshop/marketing/comment/act/judge"; var ty=this.data.ftype?this.data.ftype:2; getApp().request.promiseGet(url, { data: { orderNumber: th.data.number, orderType: ty, storeId: a.stoid, userId: d.user_id, isdg:1//是否是导购评价 } }).then(res => { if (res.data.code == 0) { var id = res.data.data.id; var giftbagid = res.data.data.giftbagid; th.setData({ is_act: 1, actId: id, giftBagId: giftbagid }) } else{ th.setData({ is_act:0 }) } }) }, //判断是不是已经评价了 check_is_pj:function(){ var th=this; var chekc_data={}; chekc_data['storeId'] = a.stoid; chekc_data['number'] =this.data.number; chekc_data['fromtype'] =this.data.ftype; getApp().request.get("/api/weshop/evaluation/evaluate/check",{ data:chekc_data, success:function(res){ if(res.data.code==0){ //没有评价的情况下 if(res.data.data==='0'){ th.query_bea(); th.setData({is_get:1}) }else if(res.data.data==="1"){ th.evaluate_get(); th.setData({is_evaluate:1,is_get:1}) } }else{ getApp().my_warnning(res.data.msg, 0, th); } } }) }, //跳转到链接地址 goto:function(e){ var url=e.currentTarget.dataset.url; getApp().goto(url); }, //弹出显示商品 show_goods:function(e){ var index=e.currentTarget.dataset.index; var item=this.data.beautician[index]; var show_goods_list=item.list; this.setData({ show_goods_list:show_goods_list, sh_pop:1 }) }, //关闭弹出 close_pop:function(){ this.setData({ show_goods_list:null,sh_pop:0 }) } })