aboutThePrenatal.js 5.06 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
//aboutThePrenatal.js 产检须知

// 网络请求工具类
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 timeflag;
// 当前孕周
var currentWeek;
//获取应用实例
var app = getApp()
Page({
data: {
gridHeight:((wx.getSystemInfoSync().windowWidth) * 0.5)+'rpx',
colorList:['#f5bf6a','#54d7ba','#60c7ed','#ff9b8e','#60c7ed','#ff9b8e','#f5bf6a','#54d7ba'],
// 上方孕周列表
list:[],
// 检查项目item
checkItems:[],
// 下方卡片的信息
cardInfo:{},
hospitalId:0,
},
responseData:{}
,
/*---------生命周期--------*/
onLoad: function (e) {
// console.log(new Date(*1000))
networkUtil.showLoading()
var that = this
that.data.hospitalId = e.hospitalId
currentWeek = e.week
that.requestData()
},
onReady: function () {
// 页面渲染完成
this.setData({
vheight: wx.getSystemInfoSync().windowHeight - 50,
vw: wx.getSystemInfoSync().windowWidth
});

},
/*---------交互--------*/
// 点击年龄的滑动块
clickYear: function (e) {
var that = this;
// 每个块的宽度
var cell = that.data.vw / 7;
for (var i = 0; i < that.data.list.length; i++) {
var item = that.data.list[i];
if (item.id == e.currentTarget.id) {
var offset = cell * i;
this.setCardInfo(i)
this.setData({
scrollto: offset
})
break
}
}
},
myscroll: function(e) {
var that = this
clearTimeout(timeflag);
timeflag = setTimeout(function() {
// 每个块的宽度
var cell = that.data.vw / 7;
// 左侧偏移量
var left = e.detail.scrollLeft;
// 一个块与中线的偏移量
var ofset = left % cell;
// 四舍五入获取index
var index = parseInt(left / cell + 0.5)
that.setCardInfo(index)
if(ofset > cell / 2) {
that.setData({
scrollto: left - ofset + cell
});
} else {
that.setData({
scrollto: left - ofset
});
}
}, 300)
},
/*---------自定义函数--------*/
requestData(){
var self = this
var param = {page:0,limit:30,hospitalId:self.data.hospitalId}
networkUtil._get(api.checkInfoOfPregnancy,param,function(res){
console.log(res)
res.data.list.sort(function(a,b){
return a.weekStart - b.weekStart
})
self.responseData = res.data
self.setUIContent(res.data)
},function(res){

})
},
setUIContent(data){
// 孕周列表
var weekArray = []
var lastMenses = app.globalData.userInfo.lastMenses
data.list.map(function(item,index){
// 去掉项目最后的一个空格
var str = item.items
if(item.items.charAt(item.items.length - 1) == ' '){
str = item.items.substring(0,item.items.length - 1)
}
// 计算孕周的具体时间
var startDate = numberUtil.DateAdd('w ',item.weekStart - 1,new Date(app.globalData.userInfo.lastMenses * 1000))
var endDate = numberUtil.DateAdd('w ',item.weekEnd,new Date(app.globalData.userInfo.lastMenses * 1000 - 86400000))
var startDateStr = startDate.getFullYear()+'年'+(startDate.getMonth() + 1)+'年'+startDate.getDate()+'日'
var endDateStr = endDate.getFullYear()+'年'+(endDate.getMonth() + 1)+'年'+ (endDate.getDate()) +'日'
// 拼接孕周并放入数据
item.timeRange = startDateStr + '-' + endDateStr
weekArray.push({text:item.weekStart + '周',id:index,checkItems:str.split(' ')})
return item
})
this.setData({
list : weekArray,
})
// 跳转到当前孕周的信息
this.scrollToTheSpecifiedLocation()
},
setCardInfo(index){
var cardInfo = this.data.cardInfo
// 孕周
if(this.responseData.list[index].weekStart != this.responseData.list[index].weekEnd){
cardInfo.title = this.responseData.list[index].weekStart + '-' + this.responseData.list[index].weekEnd
} else {
cardInfo.title = this.responseData.list[index].weekStart
}
cardInfo.timeRange = this.responseData.list[index].timeRange
// 提醒文字
cardInfo.prompt = this.responseData.list[index].purpose
var arr = this.data.list
// 检查项目
cardInfo.checkItems = this.data.list[index].checkItems

this.setData({
cardInfo : cardInfo
})
},
// 跳转指定位置
scrollToTheSpecifiedLocation(){
var that = this
var toIndex = 0
that.responseData.list.map(function(item,index){
if(currentWeek <= item.weekEnd && currentWeek >= item.weekStart){
toIndex = index
}
return item
})
var cell = that.data.vw / 7;
var offset = cell * toIndex;
that.setCardInfo(toIndex)
that.setData({
scrollto: offset
})
}
})