Files
sykl-hy/pages/index/index.js

189 lines
5.2 KiB
JavaScript

/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
//任务列表
case : '',
case_log : '',
experience : '',
order : '',
payment : '',
register : '',
stepsSign : '',
subscribe : '',
loginCode : '',
code : '', //公众号二维码
showSymptom : '', //是否显示报告列表
max : '',
min : '',
goutCaseId : '', //档案id
count : '', //数量
sign : '', //签到
nowStatus : '', //流程判断
popStatus : false, //流程判断弹出层状态
authState : false,
applyState : false, //申请体验馆状态
hasCase : '',
userLogin : '', //登录状态
detailsImg : '',
offsetStatus: false , //抵值券弹出
identityId : '' , //身份
symptomsArr: '' , //报告列表
isOfficial : app.globalData.isOfficial, //公众号-场景值
followState: false //公众号弹出
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
wx.login({
success: res => {
this.setData({
loginCode: res.code
})
}
})
// 商品详情数据
wx.$api.index.goods(1).then(res => {
this.setData({
detailsImg: res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
})
}).catch(err => {})
// 获取登录状态
if(wx.getStorageSync("token")){
this.setData({
userLogin: true
})
// 获取用户信息
this.userInfo();
// 获取公众号二维码
wx.$api.user.invitesCode().then(res => {
this.setData({
code: res.data.code
})
}).catch(err => {})
}
// 获取首页数据
this.mallData();
},
/**
* 首页数据
*/
mallData() {
wx.$api.index.home().then(res => {
this.setData({
case : res.data.steps.lists.case,
case_log : res.data.steps.lists.case_log,
experience : res.data.steps.lists.experience,
order : res.data.steps.lists.order,
payment : res.data.steps.lists.payment,
register : res.data.steps.lists.register,
stepsSign : res.data.steps.lists.sign,
subscribe : res.data.steps.lists.subscribe,
showSymptom : res.data.showSymptoms,
max : res.data.steps.max,
min : res.data.steps.min,
count : res.data.count,
hasCase : res.data.hasCase,
sign : res.data.user.sign
})
if(res.data.case != '') {
this.setData({
symptomsArr: res.data.case.all_symptoms,
goutCaseId : res.data.case.gout_case_id
})
}
if(res.data.user.identity) {
this.setData({
identityId: res.data.identity.order
})
}
}).catch(err => {})
},
/**
* 用户信息
*/
userInfo() {
wx.$api.user.userIndex().then(res => {
this.setData({
nowStatus : res.data.nowStatus
})
}).catch(err => {})
},
/**
* 申请体验馆状态隐藏
*/
applySee() {
this.setData({
applyState: false
})
},
/**
* 获取code
*/
followCode() {
wx.getUserProfile({
desc : "获取你的昵称、头像、地区及性别",
success : e => {
if(e.errMsg == "getUserProfile:ok"){
wx.$api.user.wechatMini({
code :this.data.loginCode,
iv : e.iv,
encryptedData: e.encryptedData
}).then(res => {
// subscribe == 0未关注公众号
if (res.data.subscribe == 0) {
this.setData({
followState: true
})
return
}
// 获取首页数据 subscribe == 1已 关注公众号
this.mallData();
}).catch(err => {})
}
},
fail: err => {
return;
}
})
},
/**
* 公众号弹出
*/
followHide() {
this.setData({
followState: !this.data.followState
})
}
})