// 网络请求工具类
var networkUtil = require('../../utils/network_util.js')
var numUtil = require('../../utils/numberUtil.js')
var api = require('../../utils/apiFile.js')
var util = require('../../utils/util.js')
var event = require('../../utils/event.js')
Page({
data: {
dateList: {},
isShowOne: false,
isShowTwo: false,
isShowThree: false,
// 用户信息
userData:{},
// 时间下标
dateIndex:0,
monthText:'-',
yearText:'-',
todayInfo:'',
// 是否建档
subscribe:false,
flag: false,
// 问诊信息
wzInfo:'',
// 预约详细信息
subscribeDetails:'',
isShowLeft: false,
isShowRight: false,
// 没数据
noData: 'no',
// 获取到的所以patent数据
allPatient:[],
// 当前的pid
currentPID:'',
tourist:false
},
onLoad: function (option) {
this.setData({
userData: getApp().globalData.userInfo
})
if (!getApp().globalData.tourist){
networkUtil.showLoading()
this.getCheckList()
} else {
var today = new Date()
this.setData({
noData: false,
tourist: true,
monthText: (today.getMonth() + 1) + '月' + today.getDate() + '日',
yearText: today.getFullYear()
})
}
},
// 是否显示更多诊断信息
isShowMore: function (e) {
var self = this
var index = e.currentTarget.dataset.index
if (index == 1) {
self.setData({
isShowOne: !self.data.isShowOne,
isShowTwo: false,
isShowThree: false,
})
} if (index == 2) {
if (!self.data.wzInfo.handlSuggest){
return
}
self.setData({
isShowOne: false,
isShowTwo: !self.data.isShowTwo,
isShowThree: false,
})
} if (index == 3) {
if (!self.data.wzInfo.guideSuggest) {
return
}
self.setData({
isShowOne: false,
isShowTwo: false,
isShowThree: !self.data.isShowThree,
})
}
},
toDetailPage(e){
if (getApp().globalData.tourist) {
return
}
var index = e.currentTarget.dataset.index
wx.navigateTo({
url: '../checkTabList/checkTabList?current_index=' + index + '&checkTime=' + this.data.yearText + this.data.monthText + '&patientId=' + this.data.currentPID,
})
},
// 跳转上一条
toBefore(){
var index = this.data.dateIndex
index --
console.log('index',index)
var left = true
var right = true
if (index == 0) {
left = false
}
this.setData({
isShowLeft: left,
isShowRight : right
})
this.changeDateWithIndex(index)
},
// 跳转下一条
toAfter() {
var index = this.data.dateIndex
index++
console.log('index', index)
var left = true
var right = true
if (index == this.data.dateList.length - 1){
right = false
}
this.setData({
isShowLeft: left,
isShowRight: right
})
this.changeDateWithIndex(index)
},
// 返回上个页面
backPage(){
wx.navigateBack({})
},
// 选择检查日期
clickDate(e){
if (this.data.tourist == true){
return
}
var left = true
var right = true
if (e.detail.value == this.data.dateList.length - 1) {
right = false
}
if (e.detail.value == 0) {
left = false
}
this.setData({
isShowLeft: left,
isShowRight: right
})
this.changeDateWithIndex(e.detail.value)
},
// 查看预约建档
lookSubscribe(){
this.setData({ flag: true})
},
// 关闭预约建档
closeMask(){
this.setData({ flag: false})
},
// 通过日期列表下标改变日期文字
changeDateWithIndex(index){
var text = this.data.dateList[index]
var patientId = this.getPatientIdWithDateStr(text)
if (!patientId){
return
}
this.setData({
dateIndex: index,
yearText: this.setDateYearText(text),
monthText: this.setDateMonthText(text),
currentPID: patientId
})
networkUtil.showLoading()
this.getCheckDetails(patientId)
this.getWzXinxi(patientId)
},
// 获取检查日期列表
getCheckList() {
var self = this
// 列表
networkUtil._get(api.checkList, { patientId: getApp().globalData.currentId}, function (res) {
console.log('获取时间信息', res)
var showLeft = true
// 先遍历所有时间 存放
var allCheckTimeArr = []
res.data.data.map(function (item) {
var checkTimeArr = item.checkTime
allCheckTimeArr = allCheckTimeArr.concat(checkTimeArr)
})
if (allCheckTimeArr.length > 0){
// 只有一条数据两个圈圈都不显示
if (allCheckTimeArr.length == 1) {
showLeft = false
}
self.setData({
dateList: allCheckTimeArr.reverse(),
isShowLeft:showLeft,
noData: false,
allPatient: res.data.data
})
self.changeDateWithIndex(allCheckTimeArr.length - 1)
} else {
self.setData({
noData:true
})
}
}, function (res) {
})
},
// 依据时间获取当天检查信息
getCheckDetails(patientId) {
var self = this
var params = {}
params.patientId = patientId
// params.patientId = 88635
params.checkTime = this.data.dateList[this.data.dateIndex]
// 获取当天信息
networkUtil._get(api.checkDetails, params, function (res) {
console.log('获取当天信息', res)
var subscribe = false
var subscribeDetail = {}
// 下次产检信息
if (res.data.data && res.data.data.nextcheck && res.data.data.nextcheck.length > 0){
subscribe = true
subscribeDetail.checkhospital = res.data.data.checkhospital
subscribeDetail.nextcheck = res.data.data.nextcheck
// 距离下次检查日期间隔
subscribeDetail.nextInterval = '-'
var next = new Date(res.data.data.nextcheck)
var nextInterval = numUtil.calculateTimeInterval(new Date().getTime(), next.getTime())
if (nextInterval == 0){
subscribeDetail.nextInterval = '今天'
} else if (nextInterval < 0){
subscribeDetail.nextInterval = '已逾期'
} else {
subscribeDetail.nextInterval = '剩' + nextInterval + '天'
}
}
self.setData({
todayInfo: res.data.data,
subscribe: subscribe,
subscribeDetails: subscribeDetail
})
}, function (res) {
})
},
// 获取问诊信息
getWzXinxi(patientId) {
var self = this
var params = {}
params.patientId = patientId
// params.patientId = 88635
params.checkTime = this.data.dateList[this.data.dateIndex]
params.page = 0
params.limit = 30
// 具体检查信息
networkUtil._get(api.wzXinxi, params, function (res) {
console.log('获取详细信息', res)
if (res.data.diagnose && res.data.diagnose.length > 0) {
res.data.diagnose = res.data.diagnose.split(",")
}
self.setData({
wzInfo: res.data
})
}, function (res) {
})
},
// 设置年文字
setDateYearText(text){
return text.substr(0, 5)
},
// 设置月 日文字
setDateMonthText(text) {
return text.substring(5, text.length)
},
// 通过时间获取id
getPatientIdWithDateStr(dateStr){
var pid = null
this.data.allPatient.map(function(item){
console.log(item)
item.checkTime.map(function (str) {
if(dateStr == str){
pid = item.patientId
}
})
})
return pid
}
})