Files
CompanyProject/衣莎项目/源码/YiShaXiYi/pages/auth/auth.js
2024-09-27 01:32:49 +08:00

293 lines
7.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/auth/auth.js
const app = getApp();
const util = app.loadUtils("util")
const regeneratorRuntime = app.loadAsync()
const model = app.loadModel("index")
const http = app.loadHttp()
const api = app.loadApi()
Page({
/**
* 页面的初始数据
*/
data: {
index: 1,//当前激活的下表
num: 0,//判断token在当前页面只生效一次
showSkeleton: true, //骨架屏显示隐藏
swiperList: [{
id: 0,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg'
}, {
id: 1,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg',
}, {
id: 2,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
}, {
id: 3,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
}, {
id: 4,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
}, {
id: 5,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
}, {
id: 6,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
}],
kfRight: 20,
isCoupon: false,//优惠券
couponList: [],//优惠券列表
isKf: false,//客服
userInfo: {},//用户信息
couponTitle: '恭喜获得优惠券',//优惠券标题
},
// 获取用户个人信息
async userInfo() {
let token = await util.token()
if (!token) {
return
}
let user = await http.http.request2({ url: `${http.api.personalInfo}`, method: "POST" })
this.setData({
userInfo: user.data.data
})
app.globalData.userInfo = user.data.data
model.storage.setStorage("userInfo", user.data.data)
// 每次获取userInfo时执行
this.selectComponent("#home").getUserInfo();
},
async tabSwitch(e) {
let index = e.currentTarget.dataset.index
let nav = e.currentTarget.dataset.nav
let islog = e.currentTarget.dataset.islog
if (islog == 'ok') {
let isLogin = await util.isLoginJump()
if (isLogin == 1) return;
}
// 跳转到预约
if (nav) {
if (app.globalData.userInfo.group_type == 39) {
wx.navigateTo({
url: '/pages/auth/auth?index=6&group_type=' + app.globalData.userInfo.group_type
})
} else {
wx.navigateTo({
url: "/user/appointment/appointment"
})
}
return
}
// 调转到洗衣
if (index == 2) {
wx.navigateTo({
url: '/pages/nearbyStore/nearbyStore'
})
return;
if (!this.data.userInfo.cupboard_num) {
wx.showModal({
title: '您不是衣柜会员',
content: '衣柜会员才可打开',
confirmText: "成为会员",
cancelText: "取消",
success(res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/joinWardrobe/joinWardrobe'
})
}
}
})
return;
}
wx.navigateTo({
url: "/user/wardrobe/wardrobe"
})
return
}
// 调转到商城
if (index == 4) {
wx.navigateTo({
url: "/mall/auth/auth?index=1"
})
return
}
this.setData({
index: index
})
if (index == 1) {
this.getCoupon()
}
},
// 优惠券显示关闭
_coupon() {
this.setData({
isCoupon: !this.data.isCoupon
})
},
// 优惠券领取
async _receive() {
let isLogin = await util.isLoginJump()
if (isLogin == 1) return;
this._coupon()
},
// 客服的显示关闭
_service() {
this.setData({
isKf: !this.data.isKf
})
},
// 获取系统推送的优惠券
async getCoupon() {
let isTel = app.globalData.userInfo.telnum
if(isTel == "点击授权手机号" || isTel == '' || !isTel) return;
if(app.globalData.userInfo.group_type !== 0) return;
let token = await util.token();
let isCoupon = await model.storage.getSetting('isCoupon');
let res = { data: { data: [] } }, couponTitle;
if (!token && isCoupon !== 'ok') {
res = await http.http.request1({ url: `${http.api.newPersonCoupon}/0`, method: "POST" })
couponTitle = '登录后领取'
model.storage.setStorage("isCoupon", 'ok')
} else if (token) {
res = await http.http.request2({ url: `${http.api.newPersonCoupon}/0`, method: "POST" })
}
let coupon = res.data.data
if (coupon.length > 0) {
let all = "";//优惠劵id 如果有优惠券直接领取
coupon.map((v, i) => {
coupon[i].coupon_price = parseInt(coupon[i].coupon_price)
all += coupon[i].coupon_id + ","
coupon[i].start_time = util.formatTime(v.start_time, 'Y-M-D')
coupon[i].end_time = util.formatTime(v.end_time, 'Y-M-D')
})
this.setData({
couponList: coupon,
isCoupon: true,
couponTitle: couponTitle
})
if (!!token) {
http.http.request2({ url: `${http.api.getNewPersonCoupon}/0`, method: "POST", data: { coupon_id: all.substr(0, all.length - 1) } })
this.userInfo()
}
}
},
// 客服电话
openTel() {
wx.makePhoneCall({
phoneNumber: '4000551071'
})
},
goUrl() {
wx.navigateTo({
url: '/pages/laundry/laundry?id=1'
})
this._coupon();
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 需要跳转到首页tabbar时需要路径参数index否则不激活
this.setData({
index: options.index || 1
})
app.setWatching('showSkeleton', (v) => {
this.setData({
showSkeleton: v
});
});
app.setWatching('isToken', (v) => {
this.userInfo()
});
if (!!options.group_type) {
this.selectComponent("#choice").tuanPic(options.group_type);
}
app.setWatching('userInfo', (v) => {
if (app.globalData.userInfo.group_type !== ''
&& app.globalData.userInfo.group_type !== 0
&& app.globalData.userInfo.group_type !== void 0
) {
this.selectComponent("#index").storeMenu();
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: async function () {
model.getauth.getSetting()
.then(res => {
if (res.authSetting['scope.userLocation']) {
this.selectComponent("#index").add();
}
})
this.userInfo();
this.getCoupon()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
clearInterval(this.time)
this.setData({
kfRight: 20
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
// 监听用户滑动页面
onPageScroll: function () {
this.setData({
kfRight: -70
})
clearInterval(this.time)
this.time = setTimeout(() => {
this.setData({
kfRight: 20
})
}, 1000)
}
})