diff --git a/pages/user/plus/plus.js b/pages/user/plus/plus.js index 92502be..48eff7b 100644 --- a/pages/user/plus/plus.js +++ b/pages/user/plus/plus.js @@ -1,12 +1,13 @@ var t = getApp(), a = t.request, - o = t.globalData.setting, + o = t.globalData.setting, os = o, i = require("../../../utils/util.js"), ut = i, s = require("../../../utils/common.js"), - w = require("../../../utils/wxParse/wxParse.js"),t_pay = require("../../../utils/pay2.js"); - var regeneratorRuntime = require('../../../utils/runtime.js'); + w = require("../../../utils/wxParse/wxParse.js"), + t_pay = require("../../../utils/pay2.js"); +var regeneratorRuntime = require('../../../utils/runtime.js'); Page({ /** @@ -19,24 +20,24 @@ Page({ screenheight: 0, canvasHidden: true, shareImgPath: null, - is_plusCard: "",//卡的列表 + is_plusCard: "", //卡的列表 imagePath: "", - is_pulscardname: "",//plus会员的名字 - is_card: 0,//用于判断是否是续费页和购买页面 0不是PLUS会员 - content: "",//等级卡规则 - is_card_rule: "",//等级卡规则判断用 - is_show: 0, //页面要加载完才能显示 - open_yq: 0, //显示打开邀请码的弹窗 - by_index:null, //购买卡的下班 + is_pulscardname: "", //plus会员的名字 + is_card: 0, //用于判断是否是续费页和购买页面 0不是PLUS会员 + content: "", //等级卡规则 + is_card_rule: "", //等级卡规则判断用 + is_show: 0, //页面要加载完才能显示 + open_yq: 0, //显示打开邀请码的弹窗 + by_index: null, //购买卡的下班 - isyaoqingma:0, //是否邀请码 - is_salesman:0, //是否营业员 - inp_recommon: null, //输入的邀请码 + isyaoqingma: 0, //是否邀请码 + is_salesman: 0, //是否营业员 + inp_recommon: null, //输入的邀请码 inp_serviceman: null, //输入的营业员 - is_fengxiang: 0, //是不是分享过来的 - def_recommon: null, //分享人的手机号 - def_serviceman: null, //分享人的营业员 - fir_leader:0, //分享人的ID + is_fengxiang: 0, //是不是分享过来的 + def_recommon: null, //分享人的手机号 + def_serviceman: null, //分享人的营业员 + fir_leader: 0, //分享人的ID }, swiperChange: function (e) { var currentId = e.detail.current; @@ -48,34 +49,41 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - var that = this,th=that; - var store_id=getApp().globalData.setting.stoid; + var that = this, + th = that; + var store_id = getApp().globalData.setting.stoid; //获取用户设备信息,屏幕宽度 wx.getSystemInfo({ success: res => { - that.setData({screenWidth: res.screenWidth}) + that.setData({ + screenWidth: res.screenWidth + }) } }) var fir_leader = options.scene; - if (fir_leader) that.setData({fir_leader:fir_leader}) + if (fir_leader) that.setData({ + fir_leader: fir_leader + }) //--先判断会员状态-- var user_info = getApp().globalData.userInfo; if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { - wx.navigateTo({ url: '/pages/togoin/togoin?first_leader=' + fir_leader, }) - return false; - } + wx.navigateTo({ + url: '/pages/togoin/togoin?first_leader=' + fir_leader, + }) + return false; + } //-----------商家配置信息----- 等级卡规则,是否又开邀请码,营业员------------ getApp().request.get("/api/weshop/storeconfig/get/" + store_id, { success: function (res) { var is_cardrule = res.data.data.cardrules; - var switch_list= res.data.data.switch_list; - var swi_arr=JSON.parse(switch_list); + var switch_list = res.data.data.switch_list; + var swi_arr = JSON.parse(switch_list); w.wxParse("content", "html", is_cardrule, that, 6); that.setData({ - is_card_rule: is_cardrule, - isyaoqingma:parseInt(swi_arr.isyaoqingma), - is_salesman:parseInt(swi_arr.is_staffno) + is_card_rule: is_cardrule, + isyaoqingma: parseInt(swi_arr.isyaoqingma), + is_salesman: parseInt(swi_arr.is_staffno) }); } }); @@ -85,12 +93,14 @@ Page({ * 生命周期函数--监听页面显示 */ onShow: function () { - var user_info = getApp().globalData.userInfo; - if(!user_info) return false; - - var th=this,that=th,app_d=getApp().globalData; - var store_id=os.stoid; - var fir_leader=this.data.fir_leader; + var user_info = getApp().globalData.userInfo; + if (!user_info) return false; + + var th = this, + that = th, + app_d = getApp().globalData; + var store_id = os.stoid; + var fir_leader = this.data.fir_leader; if (fir_leader != null && fir_leader != undefined && fir_leader != "") { var r_url = "/api/weshop/plus/vip/mem/list?storeId=" + store_id + "&userId=" + fir_leader @@ -126,8 +136,12 @@ Page({ } if (is_ok == 1) { //--保存或者更新会员信息-- - that.setData({ def_recommon: user_information.MobileTel, def_serviceman: user_information.StaffNo, is_fengxiang: 1 }) - th.save_th_plus_user(); + that.setData({ + def_recommon: user_information.MobileTel, + def_serviceman: user_information.StaffNo, + is_fengxiang: 1 + }) + th.save_th_plus_user(); } } }); @@ -138,14 +152,16 @@ Page({ getApp().request.get("/api/weshop/users/get/" + os.stoid + "/" + app_d.user_id, { success: function (e) { var userInfo = e.data.data; - if(userInfo['card_field'] && !getApp().globalData.is_card_back){ - var u_url = "/pages/user/cardinfo/cardinfo"; - wx.reLaunch({url: u_url}) + if (userInfo['card_field'] && !getApp().globalData.is_card_back) { + var u_url = "/pages/user/cardinfo/cardinfo"; + wx.reLaunch({ + url: u_url + }) } }, }); - this.getPlusCardType(); + this.getPlusCardType(); }, /** @@ -170,18 +186,23 @@ Page({ var plusCard = res.data.data; var arr = [1219, 2089, 3031]; var new_arr = new Array(); - var parr=[]; + var parr = []; for (var i = 0; i < plusCard.length; i++) { - //plusCard[i].free=arr[i]; - if(plusCard[i].IsStopBuy) { continue; } - if (plusCard[i].CardImg == "") plusCard[i].CardImg = th.data.url + "/miniapp/images/plus/bg"+(i + 1)+ ".jpg?v=1"; - var item = {"fee": plusCard[i].CardFee, 'index': i} - new_arr.push(item); - parr.push(plusCard[i]); + //plusCard[i].free=arr[i]; + if (plusCard[i].IsStopBuy) { + continue; + } + if (plusCard[i].CardImg == "") plusCard[i].CardImg = th.data.url + "/miniapp/images/plus/bg" + (i + 1) + ".jpg?v=1"; + var item = { + "fee": plusCard[i].CardFee, + 'index': i + } + new_arr.push(item); + parr.push(plusCard[i]); } //看是不是还有卡项是可以购买的 - if(new_arr && new_arr.length>0){ + if (new_arr && new_arr.length > 0) { //根據距離遠近排序,越近在前面,升序 new_arr.sort(function (a, b) { if (a.fee < b.fee) { @@ -195,39 +216,48 @@ Page({ //里面和外面要显示统一 switch (new_arr.length) { - case 1:arr=[3031]; break; - case 2: arr = [2089, 3031]; break; - case 3: arr = [1219, 2089, 3031];break; + case 1: + arr = [3031]; + break; + case 2: + arr = [2089, 3031]; + break; + case 3: + arr = [1219, 2089, 3031]; + break; } //---给数组添加立省多少钱--- for (i = 0; i < parr.length; i++) { - //判断是否停用 - for (var j = 0; j < new_arr.length; j++) { - if (i == new_arr[j].index) { - parr[i].free = arr[j]; - break; - } + //判断是否停用 + for (var j = 0; j < new_arr.length; j++) { + if (i == new_arr[j].index) { + parr[i].free = arr[j]; + break; + } } } th.setData({ - is_plusCard: parr, is_show: 1 + is_plusCard: parr, + is_show: 1 }) - }else{ - th.setData({is_show: 1}); - wx.showToast({ - title: "暂无可购买的等级卡项", - icon: 'none', - duration: 4000 - }) + } else { + th.setData({ + is_show: 1 + }); + wx.showToast({ + title: "暂无可购买的等级卡项", + icon: 'none', + duration: 4000 + }) - } - setTimeout(function(){ - var goods_list = th.selectComponent("#goods_list"); //组件的id - goods_list.init(); - goods_list.get_list(); - },1000) + } + setTimeout(function () { + var goods_list = th.selectComponent("#goods_list"); //组件的id + goods_list.init(); + goods_list.get_list(); + }, 1000) }) }, @@ -241,33 +271,57 @@ Page({ th.buy_card(); } else { //--如果后台都没有勾邀请码,营业员,立即购买-- - if (!th.data.isyaoqingma && !th.data.is_salesman) {th.buy_card(); return false;} - th.setData({open_yq: 1}) + if (!th.data.isyaoqingma && !th.data.is_salesman) { + th.buy_card(); + return false; + } + th.setData({ + open_yq: 1 + }) } }, - + //--绑定邀请码的输入-- + b_input: function (e) { + var value = e.detail.value.trim(); + // let { isyaoqingma, is_salesman }=this.data; + var name = e.currentTarget.dataset.name; + // if((name=="isyaoqingma" && isyaoqingma) || (name=="is_salesman" && is_salesman) ){ + // if(!value){ + // wx.showToast({ + // title: '不能为空', + // }) + // return false; + // } + // } + var ob = {}; + ob[name] = value; + this.setData(ob); + }, //--立即购买卡-- buy_card: async function () { var th = this; var is_card = 0; //--商家是不是有等级卡功能,开通的人数是不是够用,开通是时间是不是到期-- - await getApp().request.promiseGet("/api/weshop/plus/plus/card/register", - {data: {storeId: os.stoid}}).then(res => { + await getApp().request.promiseGet("/api/weshop/plus/plus/card/register", { + data: { + storeId: os.stoid + } + }).then(res => { if (res.data.code == 0) is_card = 1; }) if (is_card == 0) { - getApp().my_warnning("请联系商家升级plus功能", 0, th); - return false; - } - + getApp().my_warnning("请联系商家升级plus功能", 0, th); + return false; + } + var item = th.data.is_plusCard[th.data.by_index]; var req = {}; req.cardId = item.CardId; req.rechargeType = 3; //如果不是你导购,也不是等级会员分享 if (th.data.is_fengxiang == 1) { - if (th.data.def_recommon) req.recommon = th.data.def_recommon - if (th.data.def_serviceman) req.serviceman = th.data.def_serviceman + if (th.data.def_recommon) req.recommon = th.data.def_recommon + if (th.data.def_serviceman) req.serviceman = th.data.def_serviceman } else { //---后台要求要输入邀请码--- if (th.data.isyaoqingma) { @@ -275,13 +329,12 @@ Page({ getApp().my_warnning("请输入邀请码", 0, th); return false; } - - //--邀请人不能是自己的手机号-- - if(th.data.inp_recommon==getApp().globalData.userInfo.mobile){ - getApp().my_warnning("邀请人不能填自已", 0, th); - return false; - } - + + //--邀请人不能是自己的手机号-- + if (th.data.inp_recommon == getApp().globalData.userInfo.mobile) { + getApp().my_warnning("邀请人不能填自已", 0, th); + return false; + } req.recommon = th.data.inp_recommon } //--后台要求要输入营业员-- @@ -296,137 +349,166 @@ Page({ req.storeId = os.stoid; req.userId = getApp().globalData.user_id; //--如果有邀请码,和营业员的情况下-- - if(req.recommon || req.serviceman ) { - var req_data = {storeId: os.stoid, userId: req.userId}; - if(req.recommon) req_data.inviteCode=req.recommon; - if(req.serviceman) req_data.staffNo=req.serviceman; + if (req.recommon || req.serviceman) { + var req_data = { + storeId: os.stoid, + userId: req.userId + }; + if (req.recommon) req_data.inviteCode = req.recommon; + if (req.serviceman) req_data.staffNo = req.serviceman; getApp().request.get("/api/weshop/plus/vip/mem/referee/code/check", { - data:req_data, - success:function(res){ - if(res.data.code==0) { - t_pay.pay(req, th.success, function () { - getApp().my_warnning("支付失败", 0, th); - }); - }else{ - getApp().my_warnning(res.data.msg, 0, th); - } - } + data: req_data, + success: function (res) { + if (res.data.code == 0) { + t_pay.pay(req, th.success, function () { + getApp().my_warnning("支付失败", 0, th); + }); + } else { + getApp().my_warnning(res.data.msg, 0, th); + } + } }) - }else{ + } else { t_pay.pay(req, th.success, function () { getApp().my_warnning("支付失败", 0, th); }); } }, //返回会员页面 - OpeningClose: function() { - this.setData({open_yq:0}); + OpeningClose: function () { + this.setData({ + open_yq: 0 + }); }, //返回会员中心 - back_user:function () { + back_user: function () { setTimeout(function () { - wx.reLaunch({url:"/pages/user/index/index"}); - },1000) + wx.reLaunch({ + url: "/pages/user/index/index" + }); + }, 1000) }, - + //--支付成功,跳转到等级卡续费页面-- - success:function () { - //调一次就不再调用了 - if(getApp().globalData.is_card_back) return false; - if(getApp().globalData.plus_buy_back){ - //值在这里换 - getApp().globalData.is_card_back=1; - getApp().globalData.plus_buy_back=0; - //返回购物车购买 - wx.navigateBack({ delta: 1,}); - return false; - }else{ - var u_url = "/pages/user/cardinfo/cardinfo"; - wx.reLaunch({url: u_url}) - } - - }, + success: function () { + //调一次就不再调用了 + if (getApp().globalData.is_card_back) return false; + if (getApp().globalData.plus_buy_back) { + //值在这里换 + getApp().globalData.is_card_back = 1; + getApp().globalData.plus_buy_back = 0; + //返回购物车购买 + wx.navigateBack({ + delta: 1, + }); + return false; + } else { + var u_url = "/pages/user/cardinfo/cardinfo"; + wx.reLaunch({ + url: u_url + }) + } - //--绑定邀请码的输入-- - b_input:function (e) { - var value=e.detail.value; - var name=e.currentTarget.dataset.name; - var ob={}; - ob[name]=value - this.setData(ob); }, - get_user_plus:async function(){ - var user_id=getApp().globalData.user_id; - var fuser=null; - var user_information =null; - var store_id = os.stoid; - var that=this; - //--获取登记卡邀请信息-- - await getApp().request.promiseGet("/api/weshop/usersPlus/get/" + os.stoid + "/" + user_id,{1:1}).then(res=>{ - if (res.data.code==0){ - fuser=res.data.data; - } - }) - if (!fuser) return false; - var r_url = "/api/weshop/plus/vip/mem/list?storeId=" + store_id + "&userId=" + fuser.plus_user_id; - //--获取等级卡信息-- - await getApp().request.promiseGet(r_url,{1:1}).then(res=>{ - if (res.data.code == 0) { - user_information = res.data.data[0]; - } - }) - if (user_information){ - var now = ut.gettimestamp(); - var is_ok = 1; - if (user_information['ExpiryDate']) { - var str = user_information['ExpiryDate'].replace(/-/g, '/'); - var end = new Date(str); - end = Date.parse(end) / 1000; - if (end < now) { is_ok = 0;} - } else { + + + get_user_plus: async function () { + var user_id = getApp().globalData.user_id; + var fuser = null; + var user_information = null; + var store_id = os.stoid; + var that = this; + //--获取登记卡邀请信息-- + await getApp().request.promiseGet("/api/weshop/usersPlus/get/" + os.stoid + "/" + user_id, { + 1: 1 + }).then(res => { + if (res.data.code == 0) { + fuser = res.data.data; + } + }) + if (!fuser) return false; + var r_url = "/api/weshop/plus/vip/mem/list?storeId=" + store_id + "&userId=" + fuser.plus_user_id; + //--获取等级卡信息-- + await getApp().request.promiseGet(r_url, { + 1: 1 + }).then(res => { + if (res.data.code == 0) { + user_information = res.data.data[0]; + } + }) + if (user_information) { + var now = ut.gettimestamp(); + var is_ok = 1; + if (user_information['ExpiryDate']) { + var str = user_information['ExpiryDate'].replace(/-/g, '/'); + var end = new Date(str); + end = Date.parse(end) / 1000; + if (end < now) { is_ok = 0; } + } else { + is_ok = 0; + } - if (is_ok == 1) { - var fir_leader=fuser.plus_user_id - that.setData({ def_recommon: user_information.MobileTel, def_serviceman: user_information.StaffNo, is_fengxiang: 1,fir_leader:fir_leader }) - //--先判断会员状态-- - var user_info = getApp().globalData.userInfo; - if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { - wx.navigateTo({ url: '/pages/togoin/togoin?first_leader=' + fir_leader, }) - return false; - } + if (is_ok == 1) { + var fir_leader = fuser.plus_user_id + that.setData({ + def_recommon: user_information.MobileTel, + def_serviceman: user_information.StaffNo, + is_fengxiang: 1, + fir_leader: fir_leader + }) + //--先判断会员状态-- + var user_info = getApp().globalData.userInfo; + if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { + wx.navigateTo({ + url: '/pages/togoin/togoin?first_leader=' + fir_leader, + }) + return false; + } } - } + } }, - - save_th_plus_user:async function(){ - var f_user_id=this.data.fir_leader; - if (f_user_id){ + + save_th_plus_user: async function () { + var f_user_id = this.data.fir_leader; + if (f_user_id) { var user_id = getApp().globalData.user_id; var user_plus = null; - var now=ut.gettimestamp(); + var now = ut.gettimestamp(); //--获取登记卡邀请信息-- - await getApp().request.promiseGet("/api/weshop/usersPlus/get/" + os.stoid + "/" + user_id, { 1: 1 }).then(res => { + await getApp().request.promiseGet("/api/weshop/usersPlus/get/" + os.stoid + "/" + user_id, { + 1: 1 + }).then(res => { if (res.data.code == 0) { user_plus = res.data.data; } - }) - + }) + //--如果有值,要更新-- - if (!user_plus){ - getApp().request.post("/api/weshop/usersPlus/save", { - data: { store_id: os.stoid, user_id: user_id, plus_user_id: f_user_id, addtime: now }, - success: function (res) { } - }) - }else{ - getApp().request.put("/api/weshop/usersPlus/update",{ - data: { store_id: os.stoid, user_id: user_id, plus_user_id: f_user_id, edittime: now}, - success:function(res){ } - }) + if (!user_plus) { + getApp().request.post("/api/weshop/usersPlus/save", { + data: { + store_id: os.stoid, + user_id: user_id, + plus_user_id: f_user_id, + addtime: now + }, + success: function (res) {} + }) + } else { + getApp().request.put("/api/weshop/usersPlus/update", { + data: { + store_id: os.stoid, + user_id: user_id, + plus_user_id: f_user_id, + edittime: now + }, + success: function (res) {} + }) } - } + } } }) \ No newline at end of file