// pages/myCenter/myCenter.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { imgUrl: app.globalData.urlStatic,//图片路径 isAgreement: true,//是否同意协议 phoneInputShow: false,//是否显示电话输入框 siteSelect: false,//是否显示位置选择框 isLogin:false,//登录状态 selectNow:0,//现在的选项 taskNow:1,//现在的任务类型 recordNow: 1,//现在的记录类型 taskList: [],//任务列表 shareFriendList:[],//星探小分队列表 recordList:[],//获奖记录列表 provinceArr: [],//省 provinceValue: 0,//选中的省下标 storeArr: [],//店铺 storeValue: 0,//选中的店铺下标 verificationCode: '获取验证码',//验证码文案 sendCode: true, appointment: true, subscribeData: { realname: "",//姓名 mobile: "",//手机号 captcha: "",//验证码 province: "",//省份 agent_code: "",//经销商编码 agentDetail: "",//经销商详细信息 parentOpenid: app.globalData.friendOpenid,//好友openid }, userData:{ avatarUrl: null, nickName: null, userLevel: 0 }, descFrameShow:false,//是否显示奖品详情 ruleShow: false,//是否显示星探等级规则 // isRegister: false,//查询是否已注册 parames:{ page:1, count:20 }, noData:false, optionsData:null, lookDescId: null, agreement: false,//是否显示协议 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { app.globalData.nowPage = 4; if (options.sourcePage){ this.data.optionsData = options.sourcePage; } if (app.globalData.openid) { this.loadFun(); } else { app.globalData.openidSuccessFuc = this.loadFun; } }, loadFun: function () { this.getUserInfo(); if (app.globalData.userMobile) { this.data.subscribeData.mobile = app.globalData.userMobile; this.setData({ phoneInputShow: true, subscribeData: this.data.subscribeData }) this.getUserLocation(); } if (app.globalData.myCenterData) { this.setData({ provinceArr: app.globalData.myCenterData.provinceArr, storeArr: app.globalData.myCenterData.storeArr, provinceValue: app.globalData.myCenterData.provinceValue, storeValue: app.globalData.myCenterData.storeValue, // isRegister: app.globalData.isRegister }) this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province; this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail; this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code; } // if (!app.globalData.isRegister) { // this.getOrderInfo(); // } if (app.globalData.userInfoData) { this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl; this.data.userData.nickName = app.globalData.userInfoData.nickName; this.setData({ userData: this.data.userData }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return app.sharePack(); }, selectChange:function(e){ this.setData({ selectNow: e.currentTarget.dataset.value }) if (e.currentTarget.dataset.value == 1) { this.getTaskProgress(); } else if (e.currentTarget.dataset.value == 2) { this.getMyAwardList(); } else if (e.currentTarget.dataset.value == 3){ this.data.parames.page = 0; this.setData({ parames: this.data.parames, shareFriendList:[] }) this.getShareList(); } }, selectTask: function (e) { if (e.currentTarget.dataset.type==2){ return; } this.setData({ taskNow: e.currentTarget.dataset.type }) }, selectRecord: function (e) { if (this.data.recordNow == e.currentTarget.dataset.type) { return; } this.setData({ recordList:[], recordNow: e.currentTarget.dataset.type }) this.getMyAwardList(); }, getUserLocation: function (e) { wx.getLocation({ type: 'gcj02', //wgs84 success: (res) => { this.getDistributorList(res.longitude, res.latitude); }, fail: (res) => { this.getDistributorList("", ""); }, complete: (res) => { this.setData({ siteSelect: true, }) } }) }, getDistributorList: function (longitude, latitude) {//获取经销商列表 app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => { if (res.code == 200) { app.globalData.myCenterData = {}; this.setData({ provinceArr: res.data.list, storeArr: res.data.list[res.data.nearData.provinceIndex].children, provinceValue: res.data.nearData.provinceIndex, storeValue: res.data.nearData.cityIndex }) this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province; this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail; this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code; app.globalData.myCenterData.provinceArr = res.data.list; app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children; app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex; app.globalData.myCenterData.storeValue = res.data.nearData.cityIndex; } else { wx.showToast({ title: res.msg, icon: "none" }) } }, this); }, provinceChane: function (e) {//选中省 this.setData({ provinceValue: e.detail.value, storeArr: this.data.provinceArr[e.detail.value].children, storeValue: 0 }) this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province; this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail; this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code; }, storeChane: function (e) {//选中店铺 this.setData({ storeValue: e.detail.value, }) this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail; this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code; }, getCode: function (e) {//获取验证码 if (!app.mobileVerify(this.data.subscribeData.mobile)) { if (this.data.subscribeData.mobile) { wx.showToast({ title: '请输入正确的电话', icon: 'none' }) } else { wx.showToast({ title: '请输入电话', icon: 'none' }) } return; } if (!this.data.sendCode) { return; } this.data.sendCode = false; app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => { if (res.code == 200) { this.countDown(); wx.showToast({ title: '验证码获取成功', icon: "none" }) this.setData({ verificationCode: 60 }) } else { this.data.sendCode = true; wx.showToast({ title: res.msg, icon: "none" }) } }, this) }, countDown: function () {//倒计时 setTimeout(() => { this.setData({ verificationCode: this.data.verificationCode - 1 }) if (this.data.verificationCode > 0) { this.countDown(); } else { this.setData({ verificationCode: "获取验证码" }) this.data.sendCode = true; } }, 1000); }, getRealname: function (e) {//获取用户输入的姓名 this.data.subscribeData.realname = e.detail.value; }, getMobile: function (e) {//获取用户输入的电话 this.data.subscribeData.mobile = e.detail.value; }, getCaptcha: function (e) {//获取用户输入的验证码 this.data.subscribeData.captcha = e.detail.value; }, subscribeFun: function (e) {//预约鉴赏 if(!this.data.subscribeData.realname){ wx.showToast({ title: '请输入姓名', icon:"none" }) return; } if (!this.data.subscribeData.mobile) { wx.showToast({ title: '请输入电话', icon: "none" }) return; } if (!this.data.subscribeData.captcha) { wx.showToast({ title: '请输入验证码', icon: "none" }) return; } if (!this.data.isAgreement) { wx.showToast({ title: '请同意协议', icon: 'none' }) return; } if (!this.data.appointment) { return; } this.data.appointment = false; app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => { this.data.appointment = true; if (res.code == 200) { wx.showToast({ title: '预约成功' }) this.data.subscribeData.realname = ""; this.data.subscribeData.captcha = ""; this.setData({ subscribeData: this.data.subscribeData, verificationCode: '获取验证码', }) // this.setData({ // isRegister: true // }) // app.globalData.isRegister = true; app.globalData.userMobile = this.data.subscribeData.mobile; } else { wx.showToast({ title: res.msg, icon: "none" }) } }, this, "POST") }, getUserWxMsg:function(e){//通过微信获取用户信息 if (e.detail.errMsg == "getUserInfo:ok") { this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl; this.data.userData.nickName = e.detail.userInfo.nickName; this.setData({ userData: this.data.userData, isLogin: true }) app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName); } }, getUserInfo:function(e){//获取个人信息 app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => { if(res.code==200){ if (res.data && res.data.avatarUrl) { this.data.userData.userLevel = res.data.userLevel; if (!app.globalData.userInfoData) { this.data.userData.avatarUrl = res.data.avatarUrl; this.data.userData.nickName = res.data.nickName; app.globalData.userInfoData = {}; app.globalData.userInfoData.avatarUrl = res.data.avatarUrl; app.globalData.userInfoData.nickName = res.data.nickName; wx.setStorageSync('userInfoData', { avatarUrl: res.data.avatarUrl, nickName: res.data.nickName }) } this.setData({ userData: this.data.userData, isLogin: true }) } } },this) }, getTaskProgress: function () {//获取任务完成度 1每日任务 app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{ if(res.code==200){ for (let i = 0; i < res.data.length; i++) { res.data[i]['unlockNum']=0; for (let j = 0; j < res.data[i].childIdArr['lockArr'].length; j++) { if (res.data[i].childIdArr['lockArr'][j]) { res.data[i]['unlockNum'] += 1; } } } console.log(res.data); this.setData({ taskList:res.data }) } },this) }, lookDesc:function(e){//查看奖品详情 this.setData({ descFrameShow: !this.data.descFrameShow, lookDescId: e.currentTarget.dataset.value || e.currentTarget.dataset.value==0 ? e.currentTarget.dataset.value:null }) }, lookRule: function (e) {//查看奖品详情 this.setData({ ruleShow: e.currentTarget.dataset.value }) }, getShareList: function () {//星探小分队 app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{ if(res.code==200){ for(let i=0;i { if (res.code == 200) { if (res.data) { this.setData({ isRegister: true }) app.globalData.isRegister = true; app.globalData.userMobile = res.data.mobile; } else { if (app.globalData.userMobile) { this.data.subscribeData.mobile = app.globalData.userMobile; this.setData({ phoneInputShow: true, subscribeData: this.data.subscribeData }) this.getUserLocation(); } } } else { console.log(res.msg) } }, this); }, scrolltolower:function(){//星探小分队滚动条触底时执行 if(!this.data.noData){ this.data.parames.page+=1; this.getShareList(); } }, getMyAwardList: function () {//获取获奖记录 app.wxRequest(app.globalData.urlRoot + "award/getMyAwardList", { awardType: this.data.recordNow},res=>{ if(res.code == 200){ this.setData({ recordList:res.data }) } },this) }, getUserPhone: function (e) {//获取用户手机号 this.setData({ phoneInputShow: true }) if (!app.globalData.myCenterData) { this.getUserLocation();//获取用户当前位置 } if (e.detail.errMsg == 'getPhoneNumber:ok') { app.getMobile(e.detail.encryptedData, e.detail.iv, res => { if (res.code == 200) { if (res.data && res.data.decodeData){ this.data.subscribeData.mobile = res.data.decodeData.phoneNumber; this.setData({ subscribeData: this.data.subscribeData }) } } else { wx.showToast({ title: res.msg, icon: "none" }) } }, this); } }, addressControl:function(){//跳转到地址管理 wx.navigateTo({ url: '../address/address' }) }, agreementState: function () {//协议 this.setData({ isAgreement: !this.data.isAgreement }) }, agreementControl: function () { this.setData({ agreement: !this.data.agreement }) } })