//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 }) } })