/*首页*/
var strophe = require('../../utils/strophe.js')
var WebIM = require('../../utils/WebIM.js').default
// 网络请求工具类
var networkUtil = require('../../utils/network_util.js')
var api = require('../../utils/apiFile.js')
// 数字类数据处理
var numberUtil = require('../../utils/numberUtil.js')
var util = require('../../utils/util.js')
// 事件监听
var event = require('../../utils/event.js')
// 获取应用实例
var app = getApp()
var timeCount = 60;
var timer;
var phone;
var name;
// 用户信息的缓存
var babyCache = ['','']
// 文章的缓存
var artCache = ['','']
Page({
/*---------属性变量--------*/
data: {
isLogin: '',
item_big_height: 0,
item_small: 0,
// 首页类型 1登录 2用户首页 3欢迎页
pageType: 0,
time: '0s',
list:[],
userInfo:'',
inputFocus: { nameInput: false, phoneInput: false, codeInput: false },
currentBabyIndex:0,
babys:[],
tourist:true,
vipList: [{ title: '高危指导', icon: 'gaoweizhidao', content: '医生依据新生儿娩出情况、新生儿患病情况及新生儿先天性疾病筛查结果辨识、诊断高危儿。针对医生的高危诊断,结合高危儿的月龄、生理因素、高危状态、检查结果、需监测指标等提供精准医疗服务。向早产儿、低出生体重儿、发育迟缓等特殊婴幼儿家长提供育儿帮助。' },
{ title: '精准医疗服务', icon: 'jingzunyiliao', content: '依据新生儿特有的生理情况,结合其每天都会快速生长发育的特点,对可能遇到的生理病理问题,提供精确到天的健康教育。新生儿期过后,结合婴幼儿体格生长发育特点,针对不同月龄,进行喂养方式、营养补充、辅食添加、动作发育、习惯培养等宣教指导。' },
{ title: '检查预约提醒', icon: 'chakanyuyuetixing', content: '每次检查后,医生会结合当前检查实际情况为儿童预约下次检查时间,届时提前通知家长带孩子进行相关检查。' },
{ title: '随访提醒', icon: 'suifangtixing', content: '依据新生儿特有的生理情况,结合其每天都会快速生长发育的特点,对可能遇到的生理病理问题,提供精确到天的健康教育。新生儿期过后,结合婴幼儿体格生长发育特点,针对不同月龄,进行喂养方式、营养补充、辅食添加、动作发育、习惯培养等宣教指导。' },
{ title: '查看检查记录', icon: 'chakanjilv', content: '医生依据新生儿娩出情况、新生儿患病情况及新生儿先天性疾病筛查结果辨识、诊断高危儿。针对医生的高危诊断,结合高危儿的月龄、生理因素、高危状态、检查结果、需监测指标等提供精准医疗服务。向早产儿、低出生体重儿、发育迟缓等特殊婴幼儿家长提供育儿帮助。' },
{ title: '高危指导', icon: 'gaoweizhidao', content: '随时随地可查看因幼儿问诊检查、儿科检查、一般检查、辅助检查的各项指标,以及相关指标存在的异常情况。' }]
},
/*---------生命周期--------*/
onLoad: function () {
this.calculatePageSize()
// 网络监听
this.networkStatusChange()
if (app.globalData.token == null || app.globalData.token == '') {
this.welcomePage()
} else {
this.homePage()
// 监听事件
event.on('likeChanged', this, function (data) {
if (data.categoryIndex == -1) {
var artList = this.data.crisisCategorie
artList[data.articleIdIndex].likeCount++
this.setData({
crisisCategorie: artList
});
} else {
var artList = this.data.articleList
artList[data.categoryIndex].article[data.articleIdIndex].likeCount++
this.setData({
articleList: artList
});
}
})
}
},
onUnload: function () {
// 移除监听
event.remove('likeChanged', this);
},
/*---------交互--------*/
// 下拉刷新回调接口
onPullDownRefresh: function () {
if (app.globalData.token == null || app.globalData.token == '') {
wx.stopPullDownRefresh()
return
}
// 网络请求,重新请求一遍数据
this.homePage()
},
// 点击头像
tapAvatar: function () {
var that = this
wx.showActionSheet({
itemList: ['退出当前用户'],
success: function (res) {
if (res.tapIndex == 0) {
wx.setStorageSync('userToken', '')
wx.setStorageSync('userId', '')
getApp().globalData.token = ''
getApp().globalData.userId = ''
that.toLogin()
}
},
fail: function (res) {
console.log(res.errMsg)
}
})
},
getNameFocus:function(){
var self = this
var inputFocus = { nameInput: true, phoneInput: false, codeInput: false }
self.setData({
inputFocus: inputFocus
})
},
getPhoneFocus: function () {
var self = this
var inputFocus = { nameInput: false, phoneInput: true, codeInput: false }
self.setData({
inputFocus: inputFocus
})
},
getCodeFocus: function () {
var self = this
var inputFocus = { nameInput: false, phoneInput: false, codeInput: true }
self.setData({
inputFocus: inputFocus
})
},
loseNameFocus: function () {
var self = this
var inputFocus = { nameInput: false}
self.setData({
inputFocus: inputFocus
})
},
losePhoneFocus: function () {
var self = this
var inputFocus = { phoneInput: false, }
self.setData({
inputFocus: inputFocus
})
},
loseCodeFocus: function () {
var self = this
var inputFocus = { codeInput: false }
self.setData({
inputFocus: inputFocus
})
},
// 改变baby
changeBaby(e){
this.setData({
currentBabyIndex: e.currentTarget.dataset.index
})
this.setUserInfo(babyCache[e.currentTarget.dataset.index])
this.setArtInfo(artCache[e.currentTarget.dataset.index])
},
/*---------自定义函数--------*/
homePage() {
var that = this
this.requestHomeInfo()
that.setData({
pageType: 2,
// babys: [1,2]
babys: app.globalData.userId
})
},
toLogin() {
var that = this
that.setData({
pageType: 1
})
},
welcomePage(){
var that = this
that.setData({
pageType: 3
})
},
toVipPage(){
wx.navigateTo({
url: '../vipService/vipService',
})
},
calculatePageSize() {
var windowWidth = wx.getSystemInfoSync().windowWidth
var smallWidth = ((windowWidth - 10) / 2 - 10)
this.setData({
item_big_height: 'height:' + windowWidth / 4 + 'px',
item_small: 'width:' + windowWidth / 4 * 0.45 + 'px;height:' + windowWidth / 4 * 0.45 + 'px',
})
},
// 监听网络状态
networkStatusChange() {
var that = this
wx.onNetworkStatusChange(function (res) {
if (res.isConnected == true) {
that.connectWebIM()
}
})
},
requestHomeInfo(){
// 需要先请求用户信息
this.getUserInfo()
},
// 获取用户信息
getUserInfo(userId) {
networkUtil.showLoading()
var self = this
var param = { 'token': app.globalData.token ,'type':0}
if (getApp().globalData.tourist == true) {
param.type = 1
}
networkUtil._get(api.userInfo + app.globalData.currentId, param, function (res) {
console.log('获取用户信息',res)
self.getArticleInfo(res.data.data.days)
self.setUserInfo(res.data.data)
babyCache[self.data.currentBabyIndex] = res.data.data
}, function (res) {
networkUtil.showErrorToast(res.errormsg)
})
},
getArticleInfo(days) {
var self = this
// 文章列表
networkUtil._get(api.homeArtList, { page: 0, limit: 100, days: days }, function (res) {
console.log('获取文章信息', res.data.list)
artCache[self.data.currentBabyIndex] = res.data.list
self.setArtInfo(res.data.list)
}, function (res) {
wx.stopPullDownRefresh()
})
},
// 设置UI 用户信息
setUserInfo(data){
var self = this
app.globalData.days = data.days
app.globalData.userInfo = data
self.setData({
userData: data,
tourist: getApp().globalData.tourist
})
},
// 设置UI 文章信息
setArtInfo(list) {
var self = this
app.globalData.artList = list
self.setData({
list: list
})
},
// 文章点赞
articleLike(e) {
console.log(e)
var self = this
// 已经点赞
if (e.currentTarget.dataset.islike == 1) {
networkUtil.showErrorToast('您已经点过赞啦')
return;
}
networkUtil._post(api.articleLike, { id: e.currentTarget.dataset.artid }, function (res) {
var artList = self.data.list
artList[e.currentTarget.dataset.categaryindex].article[e.currentTarget.dataset.artindex].likeCount++
artList[e.currentTarget.dataset.categaryindex].article[e.currentTarget.dataset.artindex].isLike = 1
self.setData({
list: artList
});
}, function (res) {
console.log(res)
})
},
// 标签页面
clickLabel(e){
console.log(e)
wx.navigateTo({
url: '../articleLists/articleLists?category=' + e.currentTarget.dataset.categary,
})
},
/*---------------欢迎介绍页面---------------*/
toRegister(){
wx.navigateTo({
url: '../Register/Register',
})
},
// 获取验证码
getVerifyCode: function (e) {
console.log("name:" + name)
console.log("phone:" + phone)
// name = '小向阳'
// phone = '18202810912'
if (timeCount < 60) {
return
}
if (numberUtil.IsTelPhoneNumber(phone) && name.length>0) {
var that = this
networkUtil._post(api.bindDoc, { username: name, phone: phone }, function (res) {
console.log("getVerifyCode:", res)
}, function (res) {
timeCount = 60
clearTimeout(timer);
that.setData({
time: '0s'
})
if (res.errorcode == 4003) {
wx.showModal({
title: '提示',
content: '您还没有在医院建档,是否立即使用游客身份注册',
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '../Register/Register',
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
} else {
networkUtil.showErrorToast(res.errormsg)
}
})
if (timeCount == 60) {
this.keepTime()
}
} else {
networkUtil.showErrorToast('请输入正确手机号码和姓名')
return
}
},
// 计时器
keepTime: function () {
var that = this
timeCount--
that.setData({
time: timeCount + 's'
})
if (timeCount == 0) {
timeCount = 60
clearTimeout(timer);
return
}
timer = setTimeout(function () {
that.keepTime()
}, 1000)
},
blurInput: function (e) {
phone = e.detail.value
// console.log(e)
},
blurNameInput:function(e){
name = e.detail.value
// console.log(e)
},
// 提交表单
formSubmit: function (e) {
var self = this
if (e.detail.value.code == "") {
wx.showModal({
title: '提示',
content: '请输入验证码',
showCancel: false,
success: function (res) {
}
})
return
}
networkUtil.showLoading()
var param = { code: e.detail.value.code, phone: phone }
if (getApp().globalData.openInfo.mpid) {
param.gzopenid = getApp().globalData.openInfo.mpid
console.log('绑定mpid', param)
}
if (getApp().globalData.openInfo.code) {
param.jscode = getApp().globalData.openInfo.code
console.log('绑定code', param)
}
networkUtil._get(api.verifyCode, param, function (res) {
console.log(res)
self.loginSuccess(res.data)
}, function (res) {
networkUtil.showErrorToast(res.errormsg)
})
},
loginSuccess(data) {
// 游客用户
if (data.patientIds && data.patientIds.length == 0){
data.patientIds = [data.id]
getApp().globalData.tourist = true
wx.setStorageSync('tourist', true)
} else {
getApp().globalData.tourist = false
wx.setStorageSync('tourist', false)
}
wx.setStorageSync('userToken', data.token)
wx.setStorageSync('userId', data.patientIds)
wx.setStorageSync('hxName', data.hxName)
wx.setStorageSync('hxPassWord', data.hxPassWord)
getApp().globalData.token = data.token
getApp().globalData.userId = data.patientIds
getApp().globalData.currentId = data.patientIds[0]
this.homePage()
}
})