evaluate.js 10.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
 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
	  })
  }
  
})