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"); 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, 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:"", add_card_data:'', //等级卡的内容 }, goto_nav: function(e) { var th = this; var url = e.currentTarget.dataset.url; if (th.data.userInfo != null) { getApp().goto(url); } else { wx.navigateTo({ url: '/pages/togoin/togoin', }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { var th=this; //-- 读取会员中心按钮列表 -- getApp().request.promiseGet("/api/weshop/userTool/page?pageSize=100", { }).then(res => { if(res.data.code==0 ){ var d_list=res.data.data.pageData; getApp().promiseGet("/api/weshop/storeDistribut/get/"+os.stoid,{}).then(rs=>{ var dis=rs.data.data; for(var i in d_list){ if(d_list[i].name=='我的分销' && dis && dis.switch==0){ d_list.splice(i,1); } } th.setData({user_tool:d_list}); }) } }) this.birthday(); getApp().request.promiseGet("/api/weshop/ad/page?pid=401&store_id=" + os.stoid, { data: { enabled: 1 } }).then(res => { if(res.data.code==0 && res.data.data){ var item=res.data.data.pageData[0]; if (item && item.ad_code) th.setData({ad_img:item.ad_code}) } }) app.getUserFir(); }, /** * 生命周期函数--监听页面显示 */ onShow: function() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { var index=getApp().getPageIndex(this); this.getTabBar().setData({ active: index //数字是当前页面在tabbar的索引 }); getApp().requestCardNum(this); } this.is_assistance(); var stoid = app_d.setting.stoid; var s = this, th = s, need_money = 0, cur_g_num = 0; 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); } }) } }) setTimeout(function () { if (getApp().globalData.user_id) getApp().requestCardNum(th); },500) /*------会员登录------*/ var e=getApp().globalData.userInfo; if (e != undefined && e != null && e.mobile) { s.setData({ userInfo: e }); //-- 要调用接口,获取卡的钱 -- var url="/api/weshop/wxuser/getWxCardInfo?storeId="+os.stoid+"&userId="+e.user_id; rq.get(url,{ success: function(su) { if(su.data.code==0){ s.setData({ add_card_data: su.data.data, }); } } }); /*-----统计-----*/ rq.get("/api/weshop/order/waitlist", { data: { user_id: app_d.user_id }, success: function(su) { s.setData({ toji: su.data.data, }); } }) /*-----获取线下会员的预存款和优惠券的数量-----*/ rq.get("/api/weshop/users/getinfo/" + os.stoid + "/" + e.user_id, { 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", { 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", { 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/users/grade/vipprivilegeinfo/page", { data: { storeId: os.stoid, pageSize: 100 }, success: async function(res) { var arr_data = res.data.data.pageData; var gid = null, g_qy_list = null, cz_vals = 0, need_money = 0, backClass = null, is_init = 0, GradeName = ''; //--初始化是否有打勾-- await getApp().request.promiseGet("/api/weshop/users/grade/vip/init/get", { data: { storeId: os.stoid } }).then(res => { is_init = res.data.data.isBool; }) //获取成长值 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, is_init: is_init, gradeId: gid }; // 获取最大值 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 (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(); } /*-- var t_swi= getApp().globalData.config2.switch_list if (t_swi){ t_swi = JSON.parse(t_swi); var user_tool=[]; if(t_swi.usertool) user_tool=JSON.parse(t_swi.usertool); th.setData({c_list:user_tool}) } --*/ var goods_list = this.selectComponent("#goods_recommend"); //组件的id goods_list.init(); goods_list.get_list(); }, //判断会员是后有改服务项目 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() { for(var i = 1; i < 100; i++) { clearInterval(i); } }, setappdata: function(t) { var t=getApp().globalData.wxapp_buy_obj; if (t.isout == 1) wx.navigateTo({ url: "/pages/error/error?msg=小程序已经过期", }); if (t.isbuy == 0) wx.navigateTo({ url: "/pages/error/error?msg=还未购买小程序", }); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { //!this.nomore && this.requestRecommend(); var goods_list = this.selectComponent("#goods_recommend"); //组件的id goods_list.init(); setTimeout(function() { goods_list.get_list(); }, 300) }, /** * 用户点击右上角分享 */ onShareAppMessage: function() {}, //------卡片的显示和关闭-------- show_tc: function() { if (!this.data.userInfo) return false; //base64_encode($user.mobile.'|'.date('Y-m-d H:i:s') var val=this.data.userInfo.mobile+"|"+ut.formatTime(); val="^"+ut.base64_encode(val); qrcode('qrcode', val, 480, 480, this); this.setData({ tc_hide: false, }); }, hide_tc: function() { this.setData({ tc_hide: true, }); }, //--跳转到预存款页面-- deposit: function() { if (!this.data.userInfo) return false; wx.navigateTo({ url: '../deposit/deposit', }) }, //--跳转到余额页面-- balance: function() { if (!this.data.userInfo) return false; wx.navigateTo({ url: '../member/menber', }) }, //--跳转到优惠券-- coupon: function() { var th = this; if (!this.data.userInfo) return false; // th.sendsm(); wx.navigateTo({ url: '../coupons/coupons', }) }, //--跳转到积分-- integral: function() { if (!this.data.userInfo) return false; wx.navigateTo({ url: '../integral/integral', }) }, //--跳到绑定页面-- gobindtel: function() { wx.navigateTo({ url: '/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) { 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; 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("/pages/user/user_fw/user_fw?gradeId=" + th.data.gradeId + "&FormId=" + item.Id); break; case "03": getApp().goto("/pages/user/user_spsy/user_spsy"); 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) { var url = e.currentTarget.dataset.url; getApp().goto(url); }, //---------联系客服------------ contactService: function() { 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; } s.confirmBox("请联系客服:" + rs.data.data.store_tel); } }) } else { s.confirmBox("请联系客服:" + t.store_tel); } }); }, go_info: function() { getApp().goto("/pages/user/userinfo/userinfo"); }, jump: function() { getApp().goto("/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 0) { template_id = res.data.data.pageData[0].template_id; // //授权订阅 wx.requestSubscribeMessage({ tmplIds: [template_id], success(res) { }, fail(res) { } }) } } }) }, })