index.js 25.6 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 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
var auth = require("../../../utils/auth.js"),
	rq = require("../../../utils/request.js");
var e = getApp(),
	app = e,
	s = e.globalData.setting,
	os = s,
	app_d = e.globalData;
var regeneratorRuntime = require('../../../utils/runtime.js');
const {
	barcode,
	qrcode
} = require('../../../utils/index.js');
var ut = require("../../../utils/util.js");
let self = null;

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		length: 150,
		iurl: s.imghost,
		defaultAvatar: s.imghost + "/miniapp/images/no-head.jpg",
		userInfo: null,
		toji: null, //统计相关
		txmon: 0,
		byquan: 0,
		yuer: 0,
		is_no_plus: 1,
		currentPage: 1,
		recommend_list: [],
		tc_hide: true,
		sw_index: 0,
		qy_list: null,
		gradeId: null,
		is_init: 0,
		cz_val: 0,
		full_cz_val: 0,
		is_dengji: 0, //是不是等级
		is_banner: 0, //是不是有生日活动
		giftbagid: "", //生日活动的类型
		actId: "", //生日活动的id
		actImg: "",
		is_assistance: 0, //助力活动
		ad_img: "",
		usertop_ad: [],//会员顶部配置
		add_card_data: '',  //等级卡的内容
		getusercode_vailtime:10,//会员二维码时效
		hiddenCS: true,

		is_show_recommend:false,

		has_rj:0

	},
	goto_nav: function (e) {
		var th = this;
		var url = e.currentTarget.dataset.url;
		if (th.data.userInfo != null) {
      console.log('跳转');
			getApp().goto(url);
		} else {
			wx.navigateTo({
				url: '/packageE/pages/togoin/togoin',
			})
		}
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		self = this;
		var th = this;
		getApp().request.get("/api/weshop/ad/page?pid=401&store_id=" + os.stoid, {
			data: {
				enabled: 1
			},
			success: function (res) {
				if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length) {
          var item = res.data.data.pageData[0];
          if (item)
          {
              th.setData({ usertop_ad:item });
            	if (item.ad_code) th.setData({ ad_img: item.ad_code })
          }
				
				}
			}
		})

        var first_leader = options.first_leader;
		if(first_leader){
            //--  user_id代过来免登录 --
            getApp().globalData.first_leader = first_leader;
            //调用接口判断是不是会员
            getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
                if (res.data.code == 0) {
                    getApp().globalData.guide_id = res.data.data.id;
					getApp().globalData.guide_pick_id= res.data.data.pickup_id
                }
            })

            if(!getApp().globalData.user_id){
                ut.new_user_go(os.stoid,first_leader);
            }

		}else{
            app.getUserFir();
		}
		this.init_user_tool()
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		getApp().check_can_share();
		//看一下小程序是不是过期了
		getApp().getConfig2(function (config2) {
			if (config2 && config2.is_overdue == 1) {
				getApp().promiseGet("/store/storemoduleendtime/page?store_id=" + os.stoid + "&type=5", {}).then(res => {
					var o = res;
					if (o.data.code == 0) {
						var ob = { isout: 0, isbuy: 1 };
						var arr = o.data.data.pageData;
						var isbuy = 0;
						//----如果数组不为空----
						if (arr.length > 0) {
							arr.forEach(function (val, ind) {
								if (val.is_sy == 0 && val.type == 5) {
									isbuy = 1;
									var now = ut.gettimestamp();
									if (now > val.end_time) ob.isout = 1;
									return false;
								}
							})
						}
						ob.isbuy = isbuy;
						th.setappdata(ob);
					}
				})
			}
		})

		//调用接口判断商家plus有没有过期
		rq.promiseGet("/store/storemoduleendtime/page?store_id=" + os.stoid + "&type=3", {}).then(res => {
			if (res.data.code == 0) {
				var arr = res.data.data.pageData;
				if (arr.length > 0) {
					var item = arr[0];
					if (item.is_sy == 0) {
						var now = Date.parse(new Date()); now = now / 1000;
						if (item.end_time < now) {
							th.setData({ is_no_plus: 0 })
						}
					}
				}
			}
		})
		var th = this;



		if (typeof this.getTabBar === 'function' && this.getTabBar()) {
			var index = getApp().getPageIndex(this);
			this.getTabBar().setData({
				active: index //数字是当前页面在tabbar的索引
			});
			//getApp().requestCardNum(this);
		}


		var stoid = app_d.setting.stoid;
		var s = this, th = s,
			need_money = 0,
			cur_g_num = 0;

		/*------会员登录------*/
		var e = getApp().globalData.userInfo;



		if (e != undefined && e != null && e.mobile) {


			if(this.data.has_rj==0){
				var portrait_req = {
					ApiName:'api.slimming.member.portrait',
					store_id: e.store_id,
					//StaffId: that.idd,
					vipid: e.erpvipid,
				};

				getApp().getConfig(()=>{
					var url = '/api/weshop/delphiapi/pageErpApi?accdb='+getApp().globalData.config.erpid;
					getApp().request.promiseGet(url, {
						data: portrait_req
					})
						.then((res) => {
							if (res.data.code == 0 && res.data.data  && res.data.data.pageData && res.data.data.pageData.length) {
								th.setData({has_rj:1})
							}else {
								th.setData({has_rj:-1})
							}

						})
				})


			}


			// 判断是否开启美业
			getApp().promiseGet('/api/weshop/store/getTabSys/' + os.stoid, {}).then(res => {
				if (res.data.code == 0) {
					th.setData({
						enableMeiye: res.data.data.EnableMeiye,
					});
				};
			});

			getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?" + "storeId=" + os.stoid, {}).then(res => {
				if (res.data.code == 0) {
					var plusCard = res.data.data;
					for (var i = 0; i < plusCard.length; i++) {
						if (!plusCard[i].IsStopBuy) { th.setData({ show_buy_plus: 1 }); break; }
					}
				}
			})


			this.birthday();
			this.is_assistance();

			s.setData({
				userInfo: e
			});

			//-- 要调用接口,获取卡的钱 --
			var url = "/api/weshop/wxuser/getWxCardInfo?storeId=" + os.stoid + "&userId=" + e.user_id;
			rq.get(url, {
				isShowLoading: 0,
				success: function (su) {
					if (su.data.code == 0) {
						s.setData({
							add_card_data: su.data.data,
						});
					}
				}
			});

			/*-----统计-----*/
			rq.get("/api/weshop/order/waitlist", {
				isShowLoading: 0,
				data: {
					user_id: app_d.user_id,isdel:0
				},
				success: function (su) {
					s.setData({
						toji: su.data.data,
					});
				}
			})
			/*-----获取线下会员的预存款和优惠券的数量-----*/
			rq.get("/api/weshop/users/getinfo/" + os.stoid + "/" + e.user_id, {
				isShowLoading: 0,
				success: function (su) {
					if (su.data.code == 0 && su.data.data) {
						var data = su.data.data;
						if (!data) data = {};
						data.cashcount = parseInt(data.cashcount);
						s.setData({
							udata: data,
						});
					}

				}
			})
			/*-----获取会员提现金额-----*/
			rq.get("/api/weshop/withdrawals/summoney", {
				isShowLoading: 0,
				data: {
					user_id: e.user_id,
					store_id: os.stoid,
					status: 0
				},
				success: function (su) {
					if (su.data.code == 0) {
						var yuer = parseFloat(th.data.userInfo.user_money -
							th.data.userInfo.frozen_money - su.data.data.summoney).toFixed(2);
						th.setData({
							txmon: su.data.data.summoney,
							yuer: yuer
						});
					}
				}
			})

			/*-----获取会员包邮券的数量-----*/
			rq.get("/api/weshop/userfeemail/page", {
				isShowLoading: 0,
				data: {
					user_id: e.user_id,
					store_id: os.stoid,
					pageSize: 1,
					isuse: 0
				},
				success: function (su) {
					if (su.data.code == 0) {
						th.setData({
							byquan: parseInt(su.data.data.total)
						});
					}
				}
			});

			/*-----物流信息提醒-----*/
			rq.get('/api/weshop/order/countDadaOrder', {
				isShowLoading: 0,
				data: {
					user_id: e.user_id,
					store_id: os.stoid,
				},
				success: function (su) {
					if (su.data.code == 0) {
						th.setData({
							countDadaOrder: su.data.data
						});
					}
				}
			});




			//--初始化是否有打勾--
			getApp().request.get("/api/weshop/users/grade/vip/init/get", {
				data: {
					storeId: os.stoid
				},
				success: function (rs) {
					if (rs.data.code == 0 && rs.data.data.isBool) {
						th.setData({ is_init: 1 });
						/*-----获取会员权益列表-----*/
						rq.get("/api/weshop/users/grade/vipprivilegeinfo/page", {
							isShowLoading: 0,
							data: {
								storeId: os.stoid,
								pageSize: 100
							},
							success: async function (res) {

								//判断有没有值,没有值返回
								if (!ut.ajax_ok(res)) return false;

								var arr_data = res.data.data.pageData;
								var gid = null,
									g_qy_list = null,
									cz_vals = 0,
									need_money = 0,
									backClass = null,

									GradeName = '';

								//获取成长值
								await getApp().request.promiseGet("/api/weshop/users/grade/aftervipinfo/get", {
									data: {
										storeId: os.stoid,
										userId: app_d.user_id
									}
								}).then(res => {
									if (res.data.code == 0 && res.data.data) {
										gid = res.data.data.GradeId;
										var cz_val = res.data.data.GradeSum;
										cz_vals = parseInt(cz_val);
										GradeName = res.data.data.GradeName;
									}
									//th.setData({ cz_val: cz_vals, GradeName: res.data.data.GradeName, is_init: is_init, gradeId: gid});
								})
								var obj = {
									cz_val: cz_vals,
									GradeName: GradeName,
									gradeId: gid,
									is_grad_get: 1
								};

								//  获取最大值
								await getApp().request.promiseGet("/api/weshop/users/grade/vipgradeinfo/page", {
									data: {
										storeId: os.stoid
									}
								}).then(res => {
									if (res.data.data)
										backClass = res.data.data.pageData;
									if (backClass) {
										var full_cz_val = backClass[backClass.length - 1].BuyGradeSum;
										//th.setData({ full_cz_val: full_cz_val});
										obj.full_cz_val = full_cz_val
									}
								})

								//--会员权益中心页的修改--
								for (var i in backClass) {
									var im = backClass[i];
									if (cz_vals < im.BuyGradeSum && need_money == 0) {
										need_money = im.BuyGradeSum;
										obj.need_money = need_money;
									}
								}

								//获取当前等级的特权
								await getApp().request.promiseGet("/api/weshop/users/grade/privilegeform/list/page", {
									data: {
										storeId: os.stoid,
										GradeId: gid,
										userId: app_d.user_id,
										pageSize: 100
									}
								}).then(res => {
									if (res.data.data)
										g_qy_list = res.data.data.pageData;
								});

								for (var i in arr_data) {
									var item = arr_data[i];
									var FromId = th.check_is_has_qy(item, g_qy_list);
									arr_data[i].ishas = 0;
									if (FromId) {
										arr_data[i].ishas = 1;
										arr_data[i].FromId = FromId;
									}
								}
								arr_data.sort(function (a, b) {
									return b.ishas - a.ishas
								})

								//4个4个一组
								var arr = new Array();
								for (var i = 0; i < arr_data.length; i += 4) {
									arr.push(arr_data.slice(i, i + 4));
								}
								//th.setData({ qy_list: arr, need_money: need_money});
								obj.qy_list = arr;
								th.setData(obj);
							}
						})
					}
				}
			})

			/*-- 获取 --*/
			th.requestRecommend();

			/*-------系统是否开通等级卡,会员是等级卡-----*/
			getApp().getConfig2(function (e) {
				var t_swi = e.switch_list;
				if (t_swi) t_swi = JSON.parse(t_swi)
				if (t_swi) {
					th.setData({ sys_switch: t_swi });
					var user_tool = [];
					if (t_swi.usertool) user_tool = JSON.parse(t_swi.usertool);
          th.setData({ c_list: user_tool });
          if (t_swi.usercode_vailtime!=null && parseInt(t_swi.usercode_vailtime)>0)                              
          {
            th.setData({ getusercode_vailtime: t_swi.usercode_vailtime });
          }
        }
        
				if (parseInt(t_swi.rank_switch) == 2) {
					var userInfo = th.data.userInfo;
					if (userInfo.card_field != null && userInfo.card_field != undefined && userInfo.card_field != "") {
						var now = ut.gettimestamp();
						var str = userInfo.card_expiredate;
						var end = new Date(str);
						end = Date.parse(end) / 1000;
						//---判断是不是有过期---
						if (now < end) {
							th.setData({
								is_dengji: 1
							})
						} else {
							th.setData({
								is_dengji: 3
							})
						}
					} else {
						th.setData({
							is_dengji: 2
						})
					}
				}
			})
			//th.requestRecommend();

			//自定义组件一定要等到页面加载完了,才来调用selectComponnent
			setTimeout(function () {

				th.setData({ is_show_recommend:true })
				if (getApp().globalData.user_id) getApp().requestCardNum(th);
				var goods_list = th.selectComponent("#goods_recommend"); //组件的id

				if(goods_list){
					goods_list.init();
					goods_list.get_list();
				}

			}, 1000)
		}




	},

	//判断会员是后有改服务项目
	check_is_has_qy: function (item, g_qy_list) {
		if (!g_qy_list) return false;

		for (var i in g_qy_list) {
			var iter = g_qy_list[i];
			if (iter.FormId == item.Id) return g_qy_list[i].FormId;
		}
		return false;
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},
	setappdata: function (t) {
		var t = getApp().globalData.wxapp_buy_obj;
		if (t && t.isout == 1)
			wx.navigateTo({
				url: "/packageD/pages/error/error?msg=小程序已经过期",
			});
		if (t && t.isbuy == 0)
			wx.navigateTo({
				url: "/packageD/pages/error/error?msg=还未购买小程序",
			});
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		//!this.nomore && this.requestRecommend();
		var e = getApp().globalData.userInfo;
		if (e != undefined && e != null && e.mobile) {
			var goods_list = this.selectComponent("#goods_recommend"); //组件的id
			goods_list.init();
			setTimeout(function () {
				goods_list.get_list();
			}, 300)
		}
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		getApp().globalData.no_clear = 1;
        var url = "/pages/user/index/index";
		var userInfo = getApp().globalData.userInfo;
        if (userInfo) {
            url += "?first_leader=" + getApp().globalData.user_id;
        }
        var title = "会员中心"
        //分享 
        if (getApp().globalData.config && getApp().globalData.config.store_name) {
            title = getApp().globalData.config.store_name;
        } else if (getApp().globalData.setting.appName) {
            title = getApp().globalData.setting.appName;
        }

        var ob = {
            title: title,path: url,
        };
        return ob;
	},

	//------卡片的显示和关闭--------
	show_tc: function () {
    var that=this;
    if (!this.data.userInfo) return false;
    var getnowtime;
    rq.get("/api/weshop/users/getServerTime", {    
      success: function (res) {
        if (res.data.code == 0)
        {
          getnowtime=res.data.data;
          if (!getnowtime)
          {
            getApp().showWarning("获取服务时间失败");
            return;
          }
          //base64_encode($user.mobile.'|'.date('Y-m-d H:i:s')
          var val = that.data.userInfo.mobile + "|" +getnowtime+"|"+that.data.getusercode_vailtime;
          val = "^" + ut.base64_encode(val);

          qrcode('qrcode', val, 480, 480, that);
          that.setData({
            tc_hide: false,
          });
        }
      }
    })
    
	},
	hide_tc: function () {
		this.setData({
			tc_hide: true,
		});
	},

	//--跳转到预存款页面--
	deposit: function () {
		if (!this.data.userInfo) return false;
		wx.navigateTo({
			url: '/packageD/pages/user/deposit/deposit',
		})
	},
	//--跳转到余额页面--
	balance: function () {
		if (!this.data.userInfo) return false;
		wx.navigateTo({
			url: '/packageD/pages/user/member/menber',
		})
	},
	//--跳转到优惠券--
	coupon: function () {
		var th = this;
		if (!this.data.userInfo) return false;
		//  th.sendsm();
		wx.navigateTo({
			url: '/packageD/pages/user/coupons/coupons',
		})
	},
	//--跳转到积分--
	integral: function () {
		if (!this.data.userInfo) return false;
		wx.navigateTo({
			url: '/packageD/pages/user/integral/integral',
		})
	},
	//--跳到绑定页面--
	gobindtel: function () {
		wx.navigateTo({
			url: '/packageE/pages/togoin/togoin',
		})
	},

	go_order: function (e) {
		if (!this.data.userInfo) return false;
		var url = e.currentTarget.dataset.url;
		wx.navigateTo({
			url: url,
		})

	},

	//--加载更多商品--
	requestRecommend: function () {
		var e = this,
			t = '/api/weshop/goods/page?page=' + e.data.currentPage;
		var th_recommend_list = e.data.recommend_list;
		getApp().request.get(t, {
			data: {
				is_mainshow: 1,
				isonsale: 1,
				is_recommend: 1,
				is_on_sale: 1,
				store_id: os.stoid,
				pageSize: 10
			},
			success: function (ee) {

				if(ut.ajax_ok(ee)) {
                    var recommend_list = ee.data.data.pageData;
                    if (recommend_list && recommend_list.length > 0) {
                        var dd = [...th_recommend_list, ...recommend_list];
                        e.setData({
                            recommend_list,
                            dd
                        });
                        e.data.currentPage++;
                    } else {
                        e.setData({
                            nomore: 1
                        });
                    }
                }
			}
		})
	},

	//--跳转到权益页面--
	go_qy: function () {
		if (!this.data.userInfo) return false;
		var url = "/pages/user/userqy/userqy";
		getApp().goto(url);
	},

	//--跳转到商品详情页面--
	go_goods: function (e) {
		var gid = e.currentTarget.dataset.gid;
		var url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + gid;
		getApp().goto(url);
	},

	click_next: function () {
		var index = this.data.sw_index;
		index++;
		if (index >= this.data.qy_list.length) return;
		this.setData({
			sw_index: index
		})
	},

	click_pre: function () {
		var index = this.data.sw_index;
		index--;
		if (index < 0) return;
		this.setData({
			sw_index: index
		})
	},

	onSli: function (e) {
		var that = this;
		that.setData({
			sw_index: e.detail.current
		})
	},

	//--权益使用--
	go_qy_url: function (e) {
		var th = this;
		var no = e.currentTarget.dataset.no;
		var ind = e.currentTarget.dataset.ind;
		var find = e.currentTarget.dataset.find;
		var item = th.data.qy_list[find][ind];
		if (item.ishas == undefined || !item.ishas) {
			var qt_txt = th.selectComponent("#pop_txt"); //组件的id
			var ob = {
				title: "温馨提示",
				content: "当前会员暂无此权益"
			};
			qt_txt.open(ob);
			return false;
		}

		var url = e.currentTarget.dataset.img;
		if (!url || url == "") {
			url = `/public/upload/userqy/quanbg.jpg`
		}
		switch (no) {
			case "01":
				getApp().goto("/packageB/pages/user/user_coupon/user_coupon?img=" +
					url + "&gradeId=" + th.data.gradeId + "&FormId=" + item.Id);
				break;
			case "02":
				getApp().goto("/packageE/pages/user/user_fw/user_fw?gradeId=" + th.data.gradeId + "&FormId=" + item.Id);
				break;
			case "03":
				getApp().goto("/pages/user/user_spsy/user_spsy?img=" +
					url + "&gradeId=" + th.data.gradeId + "&FormId=" + item.Id);
				break;
			case "10":
				getApp().request.get("/api/weshop/users/grade/vipprivilegelist/other/get", {
					data: {
						storeId: os.stoid,
						formId: item.Id,
						userId: getApp().globalData.user_id,
						gradeId: th.data.gradeId
					},
					success: function (res) {
						var val = res.data.data.Remark;
						var title = res.data.data.PrivilegeName;
						var qt_txt = th.selectComponent("#pop_txt"); //组件的id
						var ob = {
							title: title,
							content: val
						};
						qt_txt.open(ob);
					}
				})
				break;
		}
	},

	//跳转到链接
	goto: function (e) {
    console.log(e);
    console.log('跳转');
    var url = e.currentTarget.dataset.url;
    wx.navigateTo({ url: url }) 
		// getApp().goto(url);
	},

	//---------联系客服------------
	contactService: function () {
		getApp().com_call(this);
	},

	// 获取客服热线
	getTel() {
		return new Promise((resolve, reject) => {
			var self = this;
			var s = getApp();
			s.getConfig(function (t) {
				if (t.store_tel == undefined) {
					getApp().request.get("/api/weshop/store/get/" + os.stoid, {
						isShowLoading: 1,
						data: {},
						success: function (rs) {
							getApp().globalData.config = rs.data.data;
							if (rs.data.data.store_tel == null && rs.data.data.store_tel == undefined) {
								getApp().showWarning("商家未设置电话");
								return false;
							} else {
								self.setData({
									store_tel: rs.data.data.store_tel,
								});
								// s.confirmBox("客服热线:" + rs.data.data.store_tel);
							};

						}
					})
				} else {
					self.setData({
						store_tel: t.store_tel,
					});
					// s.confirmBox("客服热线:" + t.store_tel);
				}
				resolve();
			});
		});
	},


	go_info: function () {
		getApp().goto("/pages/user/userinfo/userinfo");
	},

	jump: function () {
		getApp().goto("/packageE/pages/user/grow_value/grow_value")
	},
	// 判断生日营销的页面是不是存在
	birthday: function () {

		var th = this;
		rq.get("/api/weshop/marketing/birthday/act/judge", {
			data: { storeId: os.stoid, userId: app_d.user_id },
			success: function (res) {

				var code = res.data.code;
				if (code == 0) {
					var giftbagid = res.data.data.giftBagId;
					var actId = res.data.data.id;
					var actImg = res.data.data.actImg;
					th.setData({ giftbagid: giftbagid, actId: actId, actImg: actImg });
					th.setData({ is_banner: 1 });
				}

			}
		})
	},
	clike_banne: function () {
		var th = this;
		var actId = th.data.actId;
		var giftbagid = th.data.giftbagid;

		if (actId != "" && giftbagid != "") {

			getApp().goto("/pages/giftpack/birthdaygift/birthdaygift?actId=" + actId + "&gifbagid=" + giftbagid + "&orderType=" + 3);
		} else {

			getApp().showWarning("请稍后重试");
		}
	},

	// 判断助力活动是不是存在
	is_assistance: function () {
		var th = this, r = Math.random() * 100;
		rq.get("/api/weshop/marketing/help/act/judge", {
			data: {
				storeId: os.stoid,
				userId: app_d.user_id,
				r: r,
			},
			success: function (res) {
				var code = res.data.code;
				if (code == 0) {
					th.setData({
						is_assistance: 1
					});
				} else {
					th.setData({
						is_assistance: 0
					});
				}

			}
		})
	},

	//导航跳转
	nav_goto: function (e) {
		var url = e.currentTarget.dataset.url;
		if (!url || url == '') return;
		if (url[0] != '/') url = '/' + url;
		getApp().goto(url);
	},

	//添加卡包
	addcard: function () {
		var res = this.data.add_card_data;
		if (!res) return false;

		var arr = new Array(6)
		arr[0] = res.code;
		arr[1] = res.timestamp;
		arr[2] = res.jsapiTicket;
		arr[3] = res.openid;
		arr[4] = res.cardid;
		arr[5] = res.nonceStr;
		var c = arr.sort();
		var newstr = "";
		for (var i = 0; i < c.length; i++) {
			newstr += c[i];
		}

		var sh1 = ut.sha1(newstr);
		wx.addCard({
			cardList: [
				{
					cardId: res.cardid,
					cardExt: '{"code": "' + res.code + '", "openid": "' + res.openid + '","timestamp": "' + res.timestamp + '","nonce_str":"' + res.nonceStr + '","outer_str":"web", "signature":"' + sh1 + '"}'
				}

			],
			success: function (res) { },
			cancel: function (res) { }
		});
	},

	//订阅消息提醒
	sendsm: function () {
		var template_id = "";
		rq.get("/api/wx/weappSendlist/page", {
			data: {
				store_id: os.stoid,
				typeid: "1020"
			},
			success: function (res) {
				if (res.data.code == 0 && res.data.data.pageData.length > 0) {
					template_id = res.data.data.pageData[0].template_id;
					// //授权订阅
					wx.requestSubscribeMessage({
						tmplIds: [template_id],
						success(res) {

						},
						fail(res) {

						}
					})
				}
			}
		})
	},

	con_weixin: function () {
		getApp().con_wx(this);
	},

	//初始话按钮图标
	init_user_tool: async function () {
		var d_list = null;
		//读取user_tool按钮图标
		await getApp().promiseGet("/api/weshop/userTool/page?pageSize=100&store_id=" + os.stoid, {
		}).then(res => {
			if (ut.ajax_ok(res)) {
				d_list = res.data.data.pageData;
			}
		})
		
		if (!d_list) return false;
		//过滤掉分销关闭的
		let distribut_end_time = await getApp().user_tools_endTime(2);//过滤掉分销到期的
		await getApp().promiseGet("/api/weshop/storeDistribut/get/" + os.stoid, {}).then(rs => {
			if (rs.data.code == 0) {
				var dis = rs.data.data;
				for (var i in d_list) {
					if (d_list[i].name == '我的分销' && (!dis || dis.switch == 0) || (d_list[i].name == '我的分销' && !distribut_end_time)) {
						d_list.splice(i, 1);
					}
				}
			}
		})

		//判断有没有开AI测肤
		await getApp().promiseGet("/api/weshop/wx/weappSkin/get/" + os.stoid, {}).then(rs => {
			if (rs.data.code != 0 || !rs.data.data) {
				for (var i in d_list) {
					if (d_list[i].name == 'AI测肤') {
						d_list.splice(i, 1);
					}
				}
			}
		})
		this.setData({ user_tool: d_list });
	},


	click_contact: function () {
		getApp().globalData.no_clear = 1;
	},

	//打开客服操作菜单
	openCS() {
		// 判断会员状态
		let user_info = getApp().globalData.userInfo;
		if (user_info == null || user_info.mobile == undefined || user_info.mobile == '' || user_info.mobile == null) {
			wx.navigateTo({
				url: '/packageE/pages/togoin/togoin',
			})
			return false;
		};
		// csType/在线客服设置:
		// 0关闭(如果有设置热线电话,则显示拨打热线电话)、
		// 1小程序客服、
		// 2企业微信客服
		if (this.data.sys_switch) {
			let csType = this.data.sys_switch.weapp_customertype;
			if (csType == 0) {
				// 拨打电话号码
				this.contactService();
			} else {
				this.getTel()
					.then(() => {
						self.setData({
							hiddenCS: false,
						});
					});
			};
		};

	},

	//关闭客服操作菜单
	closeCS() {
		this.setData({
			hiddenCS: true,
		});
	},





})