/*首页*/ // 网络请求工具类 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() Page({ /*---------属性变量--------*/ data: { isHiddenOrder: true, showAdvertising:false, showHighrisk:false, unTotleReadCount:0, // 1建档页面 2我的孕期 3精准指导 isDocument: '', // 孕周 week: '-', // 下次产检 nextCheckTime: '-', // 距离预产期 intervalDays: '-', avatar: '', username: '-', hospitalName: '-', docList:[], // 文章列表 articleList: [], // 主机类型 HOSTTypeText: ['测试环境', '', '演示环境', ''][networkUtil.Builing_Release_AppStore], HOSTType: networkUtil.Builing_Release_AppStore, // 医院ID hospitalId: 0, // 孕期报告高危等级的图片 crisisInfo: { image: '../../source/imageSource/page1_yunqi_green_Image@3x.png', color: '#43bf67' }, // 高危栏目 crisisCategorie: '', hw: false, showModal: false, //显示对话框 emergencyMessage: "", //危机信息 member: [], // 是否开通vip isVIp: false, modalhidden: true, serviceName: '', tabBar: { leftArtive: true, rightArtive: false }, crisisList: [], showQuestion: false, smallH: wx.getSystemInfoSync().windowWidth / 4 - 2, yyHospitalId: '', Babyimg:[], week:"已分娩", leftCheckDay: "已分娩", intervalDays: "已分娩", userInfo: { username: '李芳芳', newPatientId: "12312341234", } }, /*---------生命周期--------*/ onLoad: function (options) { console.log('666666666666666') console.log(options) wx.setStorageSync('yyHospitalId', options.hospitalId); wx.setStorageSync('yyHospitaName', options.hospitalName); wx.setStorageSync('yyPhone', options.phone); // options.expert = true var self = this var that = this.data.Babyimg var num = 20 for (var i = 0 ; i<20;++i){ that.push('https://img1.healthbaby.com.cn/Group%'+num+i+'.png') } self.setData({ yyHospitalId: wx.getStorageSync('yyHospitalId'), Babyimg:that, }) this.networkStatusChange() // 下载介绍图 networkUtil.checkIsNeedDownload() // this.networkstatus() if (wx.getStorageSync('advertisingInfo') && app.globalData.token.length > 0){ if (options.expert == true){ setTimeout(function(){ self.tabBar_clickRight() },2000) } this.showAdvertisingPage(wx.getStorageSync('advertisingInfo')) } if (app.globalData.token == null || app.globalData.token == '') { this.documentPage() } else { networkUtil.showLoading() this.getUserInfo() 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 }); } }) event.on('refreshVip', this, function(data) { console.log('重新刷新vip') self.getvipService(app.globalData.days) }) } }, onShow: function(option) { /* console.log('首页的op__', option) wx.setStorageSync('isSocketConnnected', false) // 生命周期函数--监听页面显示 if (app.globalData.token.length > 0 && this.data.isDocument == 1) { this.getUserInfo() this.homePage() } if (app.globalData.token.length > 0 && this.data.isDocument == 3) { this.getUserInfo() } if (wx.getStorageSync("access_token") != null) { } this.getEmergencyMessage() this.setData({ yyHospitalId: wx.getStorageSync('yyHospitalId') }) */ }, onUnload: function() { // 移除监听 event.remove('likeChanged', this); }, /*---------交互--------*/ // 下拉刷新回调接口 onPullDownRefresh: function() { if (app.globalData.token == null || app.globalData.token == '' || this.data.isDocument == 3 || this.data.isDocument == 4) { wx.stopPullDownRefresh() return } // 网络请求,重新请求一遍数据 this.requestData() }, requestData() { this.getUserInfo() this.homePage() this.getEmergencyMessage() }, // 孕期报告页面 reportDuringPregnancyTap: function() { wx.navigateTo({ url: '../reportDuringPregnancy/reportDuringPregnancy?leftCheckDay=' + this.data.leftCheckDay }) }, // 点击头像 tapAvatar: function() { var that = this wx.showActionSheet({ itemList: ['退出当前用户','停止当前用户(终止妊娠)'], success: function(res) { if (res.tapIndex == 0) { that.exitUser() that.documentPage() } if (res.tapIndex == 1) { // that.exitUser() // that.documentPage() wx.showModal({ title: '提醒', content: '是否要停用当前用户(终止妊娠)!', success(res) { if (res.confirm) { that.stopService() } else if (res.cancel) { console.log('用户点击取消') } } }) } }, fail: function(res) { console.log(res.errMsg) } }) }, orderIsShow: function(e) { var that = this; that.setData({ isHiddenOrder: (!that.data.isHiddenOrder), }) }, showOrderDialog: function(e) { if (this.data.nextCheckTime != '-') { this.setData({ showCheckDialog: true }) } }, clickCheckItem(){ if (this.data.vipArr.indexOf('产检提醒服务') != -1) { wx.navigateTo({ url: '../checkItemInfo/checkItemInfo', }) } else { wx.navigateTo({ url: '../newOpenVip/newOpenVip?defaultId=6', }) } }, exitUser() { getApp().globalData.token = '' wx.setStorageSync('userToken', '') wx.setStorageSync('hxName', '') wx.setStorageSync('hxPassWord', '') wx.setStorageSync('openRiskSever', '') getApp().globalData.token = '' }, // 点击产检须知事件处理 aboutThePrenatalTap: function() { wx.navigateTo({ url: '../aboutThePrenatal/aboutThePrenatal?hospitalId=' + this.data.hospitalId + '&week=' + this.data.currentWeek }) }, /*---------自定义函数--------*/ bindMpid(mpid) { networkUtil._get(api.repVercode, { gzopenid:mpid }, function (res) { console.log(res) }, function (res) { networkUtil.showErrorToast(res.errormsg) }) }, homePage() { var that = this that.setData({ isDocument: 2 }) wx.setStorage({ key: "myUsername", data: wx.getStorageSync('hxName') }) if (getApp().globalData.goVIPOpen == 'true') { getApp().globalData.goVIPOpen = 'false' wx.navigateTo({ url: '../vipOpen/vipOpen?haveRisk=true', }) } }, getRoster() { var that = this }, moveFriend: function (message) { }, handleFriendMsg: function (message) { }, documentPage() { var that = this that.setData({ isDocument: 1 }) }, getOpenIdCode(code) { var self = this // 获取openid networkUtil._get(api.getOpenId, { code: code }, function(res) { app.globalData.openInfo.openId = res.openId }, function(res) { }) }, getAccessToken() { console.log('getAccessToken') }, // 监听网络状态 networkStatusChange() { var that = this wx.onNetworkStatusChange(function(res) { console.log('网络状态改变', res) if (res.isConnected == true) { } }) }, //获取危机信息提醒内容 getEmergencyMessage() { var self = this var param = {} var time = wx.getStorageSync('emergencyTime') console.log(time) networkUtil._get(api.getemergency + time, param, function(res) { console.log("getEmergencyMessage:", res) var time = new Date().getTime(); var time_sec = Math.floor(time / 1000); wx.setStorageSync("emergencyTime", time_sec) if (res.data.message.length > 5) { self.setData({ showModal: true, emergencyMessage: res.data.message }) } else { self.setData({ showModal: false, }) } }, function(res) { console.log("getEmergencyMessage:", res) }) }, showBindStep(){ this.setData({ showStepDialog:true }) }, hideStepDialog() { this.setData({ showStepDialog: false }) }, // 获取用户信息 getUserInfo() { var self = this var param = { 'token': app.globalData.token } networkUtil._get(api.getUserInfo, param, function(res) { console.log("getUserInfo:", res) wx.setStorageSync('userInfo', res.data) var hasBindmpid = res.data.gzopenid; var mpid = getApp().globalData.openInfo.mpid // if (hasBindmpid && mpid != hasBindmpid){ // self.bindMpid(mpid); // }else if (!hasBindmpid){ // if (mpid) { // self.bindMpid(mpid); // }else{ // self.setData({ // showTag:true, // }) // } // } var days = numberUtil.calculateTimeInterval(res.data.lastMenses * 1000, new Date().getTime()) self.setData({ docInfo: res.data.doctorsInfo ? res.data.doctorsInfo[0] : '', userInfo:res.data }) app.globalData.days = days app.globalData.hospitalId = res.data.hospitalId if (!app.globalData.hospitalId && res.data.doctorsInfo && res.data.doctorsInfo.length){ app.globalData.hospitalId = res.data.doctorsInfo[0].hospitalId } self.getHighRiskArticles(days, false) self.getArticleInfo(days) self.setUserInfo(res.data) self.getvipService(days) }, function(res) { networkUtil.showErrorToast(res.errormsg) if (res.errorcode == 4002 || res.errorcode == 4003) { self.exitUser() self.documentPage() } }) networkUtil._get(api.userRisk, {}, function (res) { console.log(res) var str = res.data.data self.setData({ riskStr: str }) }, function (res) { }) }, getArticleInfo(days) { var self = this // 文章列表 networkUtil._get(api.homeArtList, { page: 0, limit: 100, days: days }, function(res) { wx.stopPullDownRefresh() if (res.data.hospitalId) app.globalData.hospitalId = res.data.hospitalId self.hasQuestion() self.setData({ articleList: res.data.list, hospitalId: res.data.hospitalId }) self.getDoctorList() self.getAdvertisingInfo() }, function(res) { wx.stopPullDownRefresh() }) }, // 广告页 getAdvertisingInfo() { var self = this networkUtil._get(api.advertising_doc, { hospitalId: app.globalData.hospitalId }, function (res) { console.log(res) wx.setStorageSync('advertisingInfo', res.data.list) }, function (res) { }) }, getDoctorList(keyword) { var self = this networkUtil.showLoading() // 医生列表 networkUtil._get(api.TeamdoctorList, { page: 0, limit: 100, deptId: this.data.hospitalId, hospitalId: this.data.hospitalId, doctorName: keyword ? keyword : '' }, function (res) { self.setData({ docList:res.data.list }) wx.stopPullDownRefresh() console.log('没错就是我', res) }, function (res) { wx.stopPullDownRefresh() }) }, searchDoctor(e){ this.getDoctorList(e.detail.value) }, hasQuestion() { if (app.globalData.hospitalId == 1374 || app.globalData.hospitalId == 2100001305 || app.globalData.hospitalId == 1000000116 || app.globalData.hospitalId == 1334) { var self = this this.setData({ showQuestion: true }) // 文章列表 networkUtil._get(api.hasQuestions, {}, function(res) { if (res.data.data != undefined) { app.globalData.hasQuestion = res.data.data } }, function(res) { }) } }, // 获取vip服务 getvipService(days) { var self = this var showVIP = false var arr = '' var riskVIP = false networkUtil._get(api.getvipServiceList, {}, function(res) { console.log('vip', res.data.data) // 从模板进入开通页面 获取开通状态 wx.setStorageSync('openRiskSever', '') res.data.data.map(function(item) { if (item.status == 1) { showVIP = true arr += item.name // 专家咨询 if (item.id == 5) { app.globalData.canChat = true } // 精准医疗 if (item.id == 1) { riskVIP = true // 从模板进入开通页面 获取开通状态 wx.setStorageSync('openRiskSever', 'opend') } // 体重和营养管理 if (item.id == 2) { app.globalData.canAddWeightNumber = true } else if (item.id == 3) { // 血糖管理 app.globalData.canAddBloodSugerNumber = true } else if (item.id == 4) { // 血压管理 app.globalData.canAddBloodPresureNumber = true } } else if (item.status == 3) { //已过期状态 arr += item.name if (item.name == '专家咨询') { app.globalData.canChat = false } if (item.name == '体重和营养管理') { app.globalData.canAddWeightNumber = false } else if (item.name == '血糖管理') { app.globalData.canAddBloodSugerNumber = false } else if (item.name == '血压管理') { app.globalData.canAddBloodPresureNumber = false } } else { // 专家咨询 if (item.id == 5) { app.globalData.canChat = false } // 体重和营养管理 if (item.id == 2) { app.globalData.canAddWeightNumber = false } else if (item.id == 3) { // 血糖管理 app.globalData.canAddBloodSugerNumber = false } else if (item.id == 4) { // 血压管理 app.globalData.canAddBloodPresureNumber = false } } }) self.setData({ isVIp: showVIP, vipArr: arr }) }, function(res) { }) }, getHighRiskArticles(days, riskVIP) { var self = this // 文章列表 networkUtil._get(api.homeArtList, { page: 0, limit: 100, days: days, type: 1 }, function(res) { console.log('homelus', res) self.setData({ crisisCategorie: res.data.highRiskArticles, crisisList: res.data.list }) }, function(res) { wx.stopPullDownRefresh() }) }, stopService() { var self = this networkUtil._get(api.stopService, { hospitalId: self.data.hospitalId, patientId: app.globalData.userInfo.patientId }, function(res) { self.requestData() }, function(res) { wx.stopPullDownRefresh() }) }, // 设置UI数据 setUserInfo(data) { var self = this var today = new Date() var interval = numberUtil.calculateTimeInterval(today.getTime(), data.dueDate * 1000) var date = new Date(data.nextCheckTime) var leftCheckDay = '' var checkWeek = '' self.data.currentWeek = numberUtil.calculateGestationalWeeks(data.lastMenses * 1000) wx.setStorage({ key: 'currentWeek', data: self.data.currentWeek, }) var checkTimeText = '' if (data.nextCheckTime == 0 || data.nextCheckTime == null) { checkTimeText = '-' leftCheckDay = '' } else { checkTimeText = data.nextCheckTime // 剩余几天产检 leftCheckDay = numberUtil.calculateTimeInterval(today.getTime(), date.getTime()) if(leftCheckDay < 0){ leftCheckDay = '已逾期' } else if(leftCheckDay == 0){ leftCheckDay = '今天' } else { leftCheckDay += '天后' } var weekS = ['日','一', '二', '三', '四', '五', '六'][new Date(data.nextCheckTime).getDay()] checkWeek = '(周' + weekS + ')' } getApp().globalData.userInfo = data // 孕周余数天 var day = numberUtil.calculateGestationalWeekDay(data.lastMenses * 1000) > 0 ? numberUtil.calculateGestationalWeekDay(data.lastMenses * 1000) + '天' : '' var intervalText = interval + '天' var week = '孕' + self.data.currentWeek + '周' + '+' + day if (day == 0) { week = '孕' + self.data.currentWeek + '周' } if(data.type == 3){ week = "已分娩" } if (interval < 0) { intervalText = '已逾期' } if (data.status == 2) { intervalText = '-' networkUtil.showErrorToast('您已经分娩或终止妊娠,当前孕程服务已终止') week = '-' } if (data.type == 3) { intervalText = '已逾期' } self.setData({ week: week, intervalDays: intervalText, username: data.username, avatar: data.avatar.medium, hospitalName: data.hospitalName, // 关联危急值 crisisInfo: numberUtil.home_getRiskInfo(data.crisis), nextCheckTime: checkTimeText, leftCheckDay, checkWeek }) networkUtil._get(api.BodyWeight, {dueWeek:week,patientId: getApp().globalData.userInfo.newPatientId}, function (res) { console.log(res,'222222'); var Bobystr = res.data self.setData({ lenght: Bobystr.lenght, weight:Bobystr.weight, index:Bobystr.index, desc:Bobystr.desc, content:Bobystr.content, currentIndex:Bobystr.index, riskScore:Bobystr.riskScore }) }, function (res) { self.setData({ index:0, currentIndex:0 }) console.log(88888888); console.log(res); }) }, submitOk: function(e) { this.setData({ showModal: false }) }, /*---------------------------生命周期--------------------------*/ myVip: function() { wx.navigateTo({ // url: '../vipOpen/vipOpen', url: '../newOpenVip/newOpenVip', }) }, jumpToWeightManage: function() { if (this.data.vipArr.indexOf("体重和营养管理") == -1) { this.setData({ modalhidden: false, serviceName: "体重和营养管理" }) } else { // weightManager wx.navigateTo({ url: '../weightManager/weightManager', // url: '../newOpenVip/newOpenVip', }) } }, jumpToTemp: function() { if (this.data.vipArr.indexOf("体温管理") == -1) { this.setData({ modalhidden: false, serviceName: "体温管理" }) } else { wx.navigateTo({ url: '../TemperatureMaanger/TemperatureMaanger', // url: '../newOpenVip/newOpenVip', }) } }, jumpToBloodSuger: function() { if (this.data.vipArr.indexOf("血糖管理") == -1) { this.setData({ modalhidden: false, serviceName: "血糖管理" }) } else { wx.navigateTo({ url: '../BloodSugerHomeNew/BloodSugerHomeNew', // url: '../newOpenVip/newOpenVip', }) } }, jumpToBloodSugarDaily:function() { if (this.data.vipArr.indexOf("血糖管理") == -1) { this.setData({ modalhidden: false, serviceName: "血糖管理" }) } else { wx.navigateTo({ url: '../bloodSugarDaily/bloodSugarDaily', // url: '../newOpenVip/newOpenVip', }) } }, jumpToBloodPresure: function() { if (this.data.vipArr.indexOf("血压管理") == -1) { this.setData({ modalhidden: false, serviceName: "血压管理" }) } else { wx.navigateTo({ url: '../BloodPressureManager/BloodPressureManager', // url: '../newOpenVip/newOpenVip', }) } }, junpToChat: function() { if (this.data.vipArr.indexOf("专家咨询") == -1) { this.setData({ modalhidden: false, serviceName: "专家咨询" }) } else { wx.navigateTo({ url: '../chat/chat', }) } }, modalConfirm: function() { this.setData({ modalhidden: true }) wx.navigateTo({ url: '../newOpenVip/newOpenVip', // url: '../vipOpen/vipOpen', }) }, modalCancle: function() { this.setData({ modalhidden: true }) }, // 切换tabbar tabBar_clickLeft() { // 下载介绍图 networkUtil.checkIsNeedDownload() this.setData({ isDocument: 2, tabBar: { leftArtive: true, mArtive: false, rightArtive: false } }) }, tabBar_clickMiddle(){ // 下载介绍图 networkUtil.checkIsNeedDownload() this.setData({ isDocument: 3, tabBar: { leftArtive: false, mArtive: true, rightArtive: false } }) }, tabBar_clickRight() { // 下载介绍图 if(!this.data.docList){ this.getDoctorList() } networkUtil.checkIsNeedDownload() this.setData({ isDocument: 4, tabBar: { leftArtive: false, mArtive: false, rightArtive: true } }) }, toQuestion() { if (app.globalData.hasQuestion != undefined) { if (app.globalData.hasQuestion == true) { wx.navigateTo({ url: '../assessmentResult/assessmentResult', }) } else { wx.navigateTo({ url: '../Questionnaire/Questionnaire', }) } } }, preventTouchMove(){}, hideCheckDialog(){ this.setData({ showCheckDialog:false}) }, doAnimation: function () { const animation = wx.createAnimation({ duration: 2000, timingFunction: 'ease', }) this.animation = animation var self = this animation.opacity(0).step() this.setData({ animationData: animation.export() }) setTimeout(function(){ self.setData({ showAdvertising: false}) wx.setNavigationBarTitle({ title: 'Bornew啵妞', }) wx.setNavigationBarColor({ backgroundColor: '#f4879b', frontColor: '#ffffff' }) },2002) }, showAdvertisingPage(list) { var self = this this.setData({ list: list, showAdvertising: true }) wx.setNavigationBarTitle({ title: '', }) wx.setNavigationBarColor({ backgroundColor: '#C8F0FF', frontColor: '#ffffff' }) setTimeout(function(){ self.doAnimation() },4000) }, skip(){ this.doAnimation() }, lookAdvertising(){ this.doAnimation() this.tabBar_clickRight() }, //专家咨询start expertConsultation(){ console.log('专家咨询') console.log(this.data.isVIp) if(this.data.isVIp){ wx.navigateTo({ url: '../doctorsList/doctorsList', }) }else{ wx.showModal({ title: '温馨提示', content: '您还没有开通该项服务哦', confirmText: '立即开通', success: function(res) { if (res.confirm) { wx.navigateTo({ url:'../newOpenVip/newOpenVip', }) } } }) } }, settingLive() { var that = this this.setData({ showHighrisk:!that.data.showHighrisk }) // wx.navigateTo({url: '/pages/settingLive/settingLive'}) }, toLeft: function (e) { var index = Number(this.data.index) if (index > 0) { this.setData({ currentIndex: index - 1 }) } else { this.setData({ currentIndex: 0 }) } }, toRight: function (e) { var index = Number(this.data.index) if (index >= 19) { this.setData({ currentIndex: 0 }) } else { this.setData({ currentIndex: index + 1 }) } }, changeIndex:function (e) { console.log(e.detail.current); var swiperCurrent = e.detail.current; this.setData({ index: swiperCurrent }) }, goMenu1(e) { wx.navigateTo({ url: '../premaritalCheckup/premaritalCheckup', }) }, goMenu2(e) { wx.navigateTo({ url: '../eugenics/eugenics', }) }, goMenu3(e) { wx.navigateTo({ url: '../cancerCheck/cancerCheck', }) }, goMenu4(e) { wx.navigateTo({ url: '../folicAcid/folicAcid', }) }, /* 菜单栏*/ goMenu5(e) { wx.navigateTo({ url: '../doctorList/doctorList', }) }, })