| globalData: { | globalData: { | ||||
| openidSuccessFuc: null,//方法回调 | openidSuccessFuc: null,//方法回调 | ||||
| userInfoSuccessFuc: null,//方法回调 | userInfoSuccessFuc: null,//方法回调 | ||||
| userInfo: null, | |||||
| present_id:"",//判断用户是通过领取优惠券进来的还是直接进的 | present_id:"",//判断用户是通过领取优惠券进来的还是直接进的 | ||||
| number:"",//赠送优惠券的数量 | number:"",//赠送优惠券的数量 | ||||
| openId:"", | openId:"", |
| { | { | ||||
| "pages":[ | "pages":[ | ||||
| "pages/register/register", | |||||
| "pages/index/index", | "pages/index/index", | ||||
| "pages/register/register", | |||||
| "pages/shop/shop", | "pages/shop/shop", | ||||
| "pages/personalCenter/personalCenter", | "pages/personalCenter/personalCenter", | ||||
| "pages/buyTicket/buyTicket", | "pages/buyTicket/buyTicket", |
| } | } | ||||
| }, | }, | ||||
| buySuccess:function(){//购买下单 | buySuccess:function(){//购买下单 | ||||
| var state = wx.getStorageSync('state'); | |||||
| if (state == 1) {//已注册 | |||||
| } else if (state == 0) {//未注册 | |||||
| wx.navigateTo({ | |||||
| url: '/pages/register/register', | |||||
| }) | |||||
| return; | |||||
| } else if (state == -1) { | |||||
| app.globalData.userInfoBackFn = res => {//等待结果 | |||||
| console.log(res) | |||||
| if (res) { | |||||
| } else { | |||||
| wx.navigateTo({ | |||||
| url: '/pages/register/register', | |||||
| }) | |||||
| return; | |||||
| } | |||||
| } | |||||
| } | |||||
| if (!this.data.buyNumber) { | if (!this.data.buyNumber) { | ||||
| wx.showToast({ | wx.showToast({ | ||||
| title: '请先输入购买优惠券的数量', | title: '请先输入购买优惠券的数量', | ||||
| }) | }) | ||||
| return; | return; | ||||
| } | } | ||||
| console.log(this.data.yesClick) | |||||
| if (this.data.yesClick){ | if (this.data.yesClick){ | ||||
| return; | return; | ||||
| } | } | ||||
| console.log(res) | console.log(res) | ||||
| this.orderPay() | this.orderPay() | ||||
| }, | }, | ||||
| fail: res => { | |||||
| this.data.yesClick = false; | |||||
| }, | |||||
| complete: res => { | |||||
| this.data.yesClick = false; | |||||
| } | |||||
| }) | }) | ||||
| } else if (e.code == -3003){ | |||||
| } else if (e.code == -3003) { | |||||
| this.data.yesClick = false; | |||||
| wx.showToast({ | wx.showToast({ | ||||
| title: e.message, | title: e.message, | ||||
| icon:"none", | icon:"none", | ||||
| app.wxRequest(app.globalData.httpUrl + 'order/paid', { sign_num: this.data.sign_num}, e => { | app.wxRequest(app.globalData.httpUrl + 'order/paid', { sign_num: this.data.sign_num}, e => { | ||||
| console.log(e) | console.log(e) | ||||
| if (e.code == 200) { | if (e.code == 200) { | ||||
| this.data.yesClick = false; | |||||
| wx.reLaunch({ | wx.reLaunch({ | ||||
| url: '/pages/personalCenter/personalCenter' | url: '/pages/personalCenter/personalCenter' | ||||
| }) | }) |
| }, | }, | ||||
| getDataList:function(){ | getDataList:function(){ | ||||
| app.wxRequest(app.globalData.httpUrl + 'couponsell/list', {}, e => { | app.wxRequest(app.globalData.httpUrl + 'couponsell/list', {}, e => { | ||||
| // console.log(e) | |||||
| console.log(e) | |||||
| if (e.code == 200) { | if (e.code == 200) { | ||||
| this.setData({ | this.setData({ | ||||
| dataList:e.data[0] | dataList:e.data[0] |
| getHistory: [],//每次接口拉取的数据 | getHistory: [],//每次接口拉取的数据 | ||||
| getHistoryArr: [],//全部使用数据 | getHistoryArr: [],//全部使用数据 | ||||
| myTicketArr: [],//我的优惠券列表 | myTicketArr: [],//我的优惠券列表 | ||||
| headerImg:"../images/headerImg.png",//默认头像 | |||||
| userName:"",//昵称 | |||||
| }, | }, | ||||
| /** | /** | ||||
| * 生命周期函数--监听页面加载 | * 生命周期函数--监听页面加载 | ||||
| */ | */ | ||||
| onLoad: function (options) { | onLoad: function (options) { | ||||
| if (app.globalData.openId) { | |||||
| this.myTicket(); | |||||
| this.historyTicket(); | |||||
| } else { | |||||
| app.globalData.openidSuccessFuc = this.myTicket; | |||||
| app.globalData.openidSuccessFuc = this.historyTicket; | |||||
| } | |||||
| var userInfo = wx.getStorageSync('userInfo'); | |||||
| var phone = wx.getStorageSync('user_phone'); | |||||
| console.log(userInfo) | |||||
| if (userInfo) { | |||||
| var userArr = []; | |||||
| userArr.push(userInfo.avatarUrl); | |||||
| userArr.push(userInfo.nickName); | |||||
| phone = app.globalData.userInfo.user_phone | |||||
| console.log(phone) | |||||
| this.setData({ | |||||
| getUserArr: userArr, | |||||
| getUser: true, | |||||
| userPhone: phone | |||||
| }) | |||||
| } | |||||
| console.log(this.data.getUserArr) | |||||
| }, | |||||
| getToRsgisterFn:function(){//未注册点击跳到注册页 | |||||
| wx.navigateTo({ | |||||
| url: '/pages/register/register', | |||||
| }) | |||||
| }, | }, | ||||
| myTicket:function(){//获取我的优惠券列表 | myTicket:function(){//获取我的优惠券列表 | ||||
| app.wxRequest(app.globalData.httpUrl + 'couponbuy/validtype', {}, e => { | app.wxRequest(app.globalData.httpUrl + 'couponbuy/validtype', {}, e => { | ||||
| * 生命周期函数--监听页面显示 | * 生命周期函数--监听页面显示 | ||||
| */ | */ | ||||
| onShow: function () { | onShow: function () { | ||||
| if (!this.data.getUser) { | |||||
| var state = wx.getStorageSync('state'); | |||||
| if (state == 1) {//已注册 | |||||
| var userInfo = wx.getStorageSync('userInfo'); | |||||
| var state = wx.getStorageSync('state'); | |||||
| if (app.globalData.openId) { | |||||
| this.myTicket(); | |||||
| this.historyTicket(); | |||||
| } else { | |||||
| app.globalData.openidSuccessFuc = this.myTicket; | |||||
| app.globalData.openidSuccessFuc = this.historyTicket; | |||||
| } | |||||
| console.log(app.globalData.userInfo) | |||||
| var userInfo = wx.getStorageSync('userInfo'); | |||||
| var phone = wx.getStorageSync('user_phone'); | |||||
| this.setData({ | |||||
| headerImg: userInfo.avatarUrl, | |||||
| userName: userInfo.nickName, | |||||
| userPhone: phone, | |||||
| getUser: true | |||||
| }) | |||||
| } else if (state == 0) {//未注册 | |||||
| this.setData({ | |||||
| getUser: false | |||||
| }) | |||||
| } else if (state == -1) { | |||||
| app.globalData.userInfoBackFn = res => {//等待结果 | |||||
| console.log(res) | |||||
| if (res) { | |||||
| if (app.globalData.openId) { | |||||
| this.myTicket(); | |||||
| this.historyTicket(); | |||||
| } else { | |||||
| app.globalData.openidSuccessFuc = this.myTicket; | |||||
| app.globalData.openidSuccessFuc = this.historyTicket; | |||||
| } | |||||
| var userInfo = wx.getStorageSync('userInfo'); | |||||
| var phone = wx.getStorageSync('user_phone'); | |||||
| this.setData({ | |||||
| headerImg: userInfo.avatarUrl, | |||||
| userName: userInfo.nickName, | |||||
| userPhone: phone, | |||||
| getUser: true | |||||
| }) | |||||
| } else { | |||||
| this.setData({ | |||||
| getUser: false | |||||
| }) | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | }, | ||||
| /** | /** | ||||
| url: '../givePage/givePage?id=' + id, | url: '../givePage/givePage?id=' + id, | ||||
| }) | }) | ||||
| }, | }, | ||||
| getUser:function(e){//点击登陆获取用户信息 | |||||
| console.log(e) | |||||
| wx.setStorageSync('userInfo', e.detail.userInfo); | |||||
| var phone = wx.getStorageSync('user_phone'); | |||||
| var userArr = []; | |||||
| userArr.push(e.detail.userInfo.avatarUrl); | |||||
| userArr.push(e.detail.userInfo.nickName); | |||||
| // phone = app.globalData.user_phone | |||||
| console.log(phone) | |||||
| this.data.userChuan = e.detail.userInfo; | |||||
| this.setData({ | |||||
| getUserArr: userArr, | |||||
| getUser: true, | |||||
| userPhone: phone | |||||
| }) | |||||
| this.submitUser(); | |||||
| console.log(this.data.getUserArr) | |||||
| }, | |||||
| submitUser:function(){//提交用户信息 | |||||
| var params={ | |||||
| "province": this.data.userChuan.province, | |||||
| "language": this.data.userChuan.language, | |||||
| "city": this.data.userChuan.city, | |||||
| "gender": this.data.userChuan.gender, | |||||
| "nickname": this.data.userChuan.nickName, | |||||
| "headimgurl": this.data.userChuan.avatarUrl, | |||||
| } | |||||
| app.wxRequest(app.globalData.httpUrl + 'submit', params, e => { | |||||
| console.log(e) | |||||
| if (e.code == 200) { | |||||
| } | |||||
| }, this,"POST") | |||||
| } | |||||
| // getUser:function(e){//点击登陆获取用户信息 | |||||
| // console.log(e) | |||||
| // wx.setStorageSync('userInfo', e.detail.userInfo); | |||||
| // var phone = wx.getStorageSync('user_phone'); | |||||
| // var userArr = []; | |||||
| // userArr.push(e.detail.userInfo.avatarUrl); | |||||
| // userArr.push(e.detail.userInfo.nickName); | |||||
| // // phone = app.globalData.user_phone | |||||
| // console.log(phone) | |||||
| // this.data.userChuan = e.detail.userInfo; | |||||
| // this.setData({ | |||||
| // headerImg: userArr, | |||||
| // getUser: true, | |||||
| // userPhone: phone | |||||
| // }) | |||||
| // this.submitUser(); | |||||
| // console.log(this.data.getUserArr) | |||||
| // }, | |||||
| }) | }) |
| <image class="userCircle" src="../images/userCircle.png"></image> | <image class="userCircle" src="../images/userCircle.png"></image> | ||||
| <view class="userAll"> | <view class="userAll"> | ||||
| <view class="userHeader"> | <view class="userHeader"> | ||||
| <image class="userImg" src="{{getUserArr[0]}}"></image> | |||||
| <image class="userImg" src="{{headerImg}}"></image> | |||||
| </view> | </view> | ||||
| <button wx:if="{{!getUser}}" plain="true" size="mini" class="getUser" open-type="getUserInfo" bindgetuserinfo="getUser">登陆</button> | |||||
| <view class="userName">{{getUserArr[1]}}</view> | |||||
| <!-- <button wx:if="{{!getUser}}" plain="true" size="mini" class="getUser" open-type="getUserInfo" bindgetuserinfo="getUser">登陆</button> --> | |||||
| <image wx:if="{{!getUser}}" bindtap="getToRsgisterFn" class="getToRsgister" src="../images/getToRsgister.png"></image> | |||||
| <view wx:if="{{getUser}}" class="userName">{{userName}}</view> | |||||
| <view wx:if="{{getUser}}" class="userPhone">{{userPhone}}</view> | <view wx:if="{{getUser}}" class="userPhone">{{userPhone}}</view> | ||||
| </view> | </view> | ||||
| } | } | ||||
| .contAll{ | .contAll{ | ||||
| box-shadow: 50rpx 10rpx 20rpx #d4d2d2; | box-shadow: 50rpx 10rpx 20rpx #d4d2d2; | ||||
| } | |||||
| .getToRsgister{ | |||||
| width: 318rpx; | |||||
| height: 38rpx; | |||||
| margin-top: 20rpx; | |||||
| } | } |
| phone: "",//手机号 | phone: "",//手机号 | ||||
| phoneCode: "",//验证码 | phoneCode: "",//验证码 | ||||
| yesRegister:false,//防止重复点击注册 | yesRegister:false,//防止重复点击注册 | ||||
| showAll:false, | |||||
| userInfo:[],//用户信息 | |||||
| }, | }, | ||||
| /** | /** | ||||
| * 生命周期函数--监听页面加载 | * 生命周期函数--监听页面加载 | ||||
| */ | */ | ||||
| onLoad: function (options) { | onLoad: function (options) { | ||||
| var state = wx.getStorageSync('state'); | |||||
| if (state==1){//已注册 | |||||
| wx.switchTab({ | |||||
| url: '/pages/index/index' | |||||
| }) | |||||
| } else if (state == 0){//未注册 | |||||
| this.setData({ | |||||
| showAll:true | |||||
| }) | |||||
| } else if (state == -1){ | |||||
| app.globalData.userInfoBackFn = res=>{//等待结果 | |||||
| console.log(res) | |||||
| if (res){ | |||||
| wx.switchTab({ | |||||
| url: '/pages/index/index' | |||||
| }) | |||||
| }else{ | |||||
| this.setData({ | |||||
| showAll: true | |||||
| }) | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | }, | ||||
| /** | /** | ||||
| }) | }) | ||||
| console.log(this.data.minter) | console.log(this.data.minter) | ||||
| }, | }, | ||||
| registerBtn:function(){//点击按钮注册 | |||||
| submitUser: function () {//提交用户信息 | |||||
| var params = { | |||||
| "province": this.data.userInfo.province, | |||||
| "language": this.data.userInfo.language, | |||||
| "city": this.data.userInfo.city, | |||||
| "gender": this.data.userInfo.gender, | |||||
| "nickname": this.data.userInfo.nickName, | |||||
| "headimgurl": this.data.userInfo.avatarUrl, | |||||
| } | |||||
| app.wxRequest(app.globalData.httpUrl + 'submit', params, e => { | |||||
| console.log(e) | |||||
| if (e.code == 200) { | |||||
| } | |||||
| }, this, "POST") | |||||
| }, | |||||
| getUserFn:function(e){//点击按钮注册 | |||||
| console.log(e) | |||||
| this.data.userInfo = e.detail.userInfo; | |||||
| if (app.globalData.openId) { | if (app.globalData.openId) { | ||||
| this.registerFn(); | this.registerFn(); | ||||
| } else { | } else { | ||||
| if (e.code == 200) { | if (e.code == 200) { | ||||
| clearInterval(time); | clearInterval(time); | ||||
| wx.setStorageSync('user_phone', e.data.user_phone); | wx.setStorageSync('user_phone', e.data.user_phone); | ||||
| wx.setStorageSync("userInfo", this.data.userInfo) | |||||
| wx.setStorageSync('state', 1); | wx.setStorageSync('state', 1); | ||||
| app.globalData.userInfo = e.data; | |||||
| this.submitUser(); | |||||
| this.setData({ | this.setData({ | ||||
| minter: 60, | minter: 60, | ||||
| num: 60 | num: 60 | ||||
| }) | }) | ||||
| wx.showToast({ | |||||
| title: '注册成功', | |||||
| icon: 'success', | |||||
| duration: 500 | |||||
| }) | |||||
| setTimeout(function () { | |||||
| if (app.globalData.present_id){ | |||||
| wx.reLaunch({ | |||||
| url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number | |||||
| }) | |||||
| } else { | |||||
| wx.switchTab({ | |||||
| url: '../index/index' | |||||
| }) | |||||
| } | |||||
| }, 1000) | |||||
| if (app.globalData.present_id){ | |||||
| wx.reLaunch({ | |||||
| url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number | |||||
| }) | |||||
| } else { | |||||
| console.log(5555) | |||||
| wx.switchTab({ | |||||
| url: '../index/index' | |||||
| }) | |||||
| } | |||||
| } else { | } else { | ||||
| this.data.yesRegister = false; | this.data.yesRegister = false; | ||||
| wx.showToast({ | wx.showToast({ |
| <!--pages/register/register.wxml--> | <!--pages/register/register.wxml--> | ||||
| <view class="all" wx:if="{{showAll}}"> | |||||
| <view class="all"> | |||||
| <image class="registerBg" src="../images/registerBg.jpg"></image> | <image class="registerBg" src="../images/registerBg.jpg"></image> | ||||
| <view class="import"> | <view class="import"> | ||||
| <view class="phoneView"> | <view class="phoneView"> | ||||
| <view class="sendBtn" wx:if="{{yesSend}}">{{minter}}</view> | <view class="sendBtn" wx:if="{{yesSend}}">{{minter}}</view> | ||||
| <input class="codeInt" type="number" bindinput="getCode" placeholder="验证码" placeholder-class="placeholderClass"></input> | <input class="codeInt" type="number" bindinput="getCode" placeholder="验证码" placeholder-class="placeholderClass"></input> | ||||
| </view> | </view> | ||||
| <image bindtap="registerBtn" class="registerBtn" src="../images/registerBtn.png"></image> | |||||
| <button class="getUser" open-type="getUserInfo" bindgetuserinfo="getUserFn"> | |||||
| <image class="registerBtn" src="../images/registerBtn.png"></image> | |||||
| </button> | |||||
| </view> | </view> | ||||
| </view> | </view> |
| .registerBtn{ | .registerBtn{ | ||||
| width: 600rpx; | width: 600rpx; | ||||
| height: 98rpx; | height: 98rpx; | ||||
| /* bottom: 246rpx; */ | |||||
| margin-left: 75rpx; | |||||
| } | |||||
| .getUser::after{ | |||||
| border: none | |||||
| } | |||||
| .getUser{ | |||||
| margin-top: 130rpx; | margin-top: 130rpx; | ||||
| padding: 0; | |||||
| width: 600rpx; | |||||
| height: 98rpx; | |||||
| border: none; | |||||
| border-color: transparent; | |||||
| border-radius: 0; | |||||
| background-color: transparent; | |||||
| } | } |
| provinceIndex: value, | provinceIndex: value, | ||||
| cityIndex:0, | cityIndex:0, | ||||
| }) | }) | ||||
| console.log(this.data.changeCity) | |||||
| }else{ | }else{ | ||||
| this.setData({ | this.setData({ | ||||
| index: value, | index: value, | ||||
| }) | }) | ||||
| this.searchShop(); | this.searchShop(); | ||||
| // console.log(this.data.provinceArr) | |||||
| // console.log(this.data.cityArr) | |||||
| // console.log(this.data.provinceCityArr) | |||||
| } | } | ||||
| }, this) | }, this) | ||||
| }, | }, |