// pages/diet/measuret.js var networkUtil = require('../../utils/network_util.js') var api = require('../../utils/apiFile.js') var exchgeDate = require('../../utils/exchgeDate.js') var app = getApp() Page({ /** * 页面的初始数据 */ data: { foodListNames : [ "铁强化米粉", "肉泥", "蛋黄泥", "蔬菜泥", "水果泥", "食用油",// "稠粥、烂面条", "肝泥", "蛋黄碎", "蔬菜汁", "淡果汁", "鱼虾类", "软馒头片", "肉末", "蛋黄羹", "蔬菜末", "水果末", "豆腐", "粗粮薯类", "肉碎", "全蛋", "蔬菜碎", "水果碎", "稍硬食物", ], foodList : [ { type:"3", id:"1", add:0, love:0, }, { type:"5", id:"2", add:0, love:0, }, { type:"2", id:"3", add:0, love:0, }, { type:"1", id:"4", add:0, love:0, }, { type:"8", id:"5", add:0, love:0, }, { type:"9", id:"9", add:0, love:0, }, { type:"3", id:"6", add:0, love:0, }, { type:"5", id:"10", add:0, love:0, }, { type:"2", id:"11", add:0, love:0, }, { type:"1", id:"7", add:0, love:0, }, { type:"8", id:"8", add:0, love:0, }, { type:"4", id:"16", add:0, love:0, }, { type:"3", id:"23", add:0, love:0, }, { type:"5", id:"12", add:0, love:0, }, { type:"2", id:"13", add:0, love:0, }, { type:"1", id:"14", add:0, love:0, }, { type:"8", id:"15", add:0, love:0, }, { type:"6", id:"21", add:0, love:0, }, { type:"3", id:"19", add:0, love:0, }, { type:"5", id:"20", add:0, love:0, }, { type:"2", id:"22", add:0, love:0, }, { type:"1", id:"17", add:0, love:0, }, { type:"8", id:"18", add:0, love:0, }, { type:"7", id:"24", add:0, love:0, }, ], foodList1:[], foodList2:[], foodList3:[], foodList4:[], foodListNames1:[ "铁强化米粉", "蔬菜泥", "水果泥", "蛋黄泥", "肉泥", "稠粥、烂面条", ], foodListNames2:[ "稠粥、烂面条", "蔬菜末", "水果末", "蛋黄羹", "肉末", "食用油", "肝泥", "豆腐" ], foodListNames3:[ "稠粥、烂面条", "蔬菜碎", "水果碎", "蛋黄碎", "肉碎", "肝泥", "豆腐" ], foodListNames4:[ "稠粥、烂面条", "蔬菜碎", "水果碎" ], hospitalId: "", toDay:"", pid:"", show:false, array:[], yl:0 }, foodClick(e) { const Names = this.data.foodListNames; const items = this.data.foodList; const values = e.detail.value; console.log('哈哈哈',values); for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].add = 0; items[i].love = 0; for (let j = 0, lenJ = values.length; j < lenJ; ++j) { if (Names[i]+'1' === values[j]) { items[i].add = 1; }else if (Names[i]+'2' === values[j]) { items[i].love = 1; } } if(items[i].add === 0){ items[i].love = 0; } } this.setData({ foodList:items }) console.log(values) // if(this.foodList[i].add == 0){ // this.foodList[i].love = 0; // } }, foodClick1(e) { let Names = this.data.foodListNames; let items = this.data.foodList; const values = e.detail.value; console.log('哈哈哈',values); const yf=this.getLeadingNumbers1(values[0]) console.log('yf',yf); if(yf=='11'||yf=='21'){ Names = this.data.foodListNames1; items = this.data.foodList1; }else if(yf=='12'||yf=='22'){ Names = this.data.foodListNames2; items = this.data.foodList2; }else if(yf=='13'||yf=='23'){ Names = this.data.foodListNames3; items = this.data.foodList3; }else if(yf=='14'||yf=='24'){ Names = this.data.foodListNames4; items = this.data.foodList4; } for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].add = 0; items[i].love = 0; for (let j = 0, lenJ = values.length; j < lenJ; ++j) { if(yf=='11'||yf=='21'){ if (Names[i]+'11' === values[j]) { items[i].add = 1; }else if (Names[i]+'21' === values[j]) { items[i].love = 1; } }else if(yf=='12'||yf=='22'){ if (Names[i]+'12' === values[j]) { items[i].add = 1; }else if (Names[i]+'22' === values[j]) { items[i].love = 1; } }else if(yf=='13'||yf=='23'){ if (Names[i]+'13' === values[j]) { items[i].add = 1; }else if (Names[i]+'23' === values[j]) { items[i].love = 1; } }else if(yf=='14'||yf=='24'){ if (Names[i]+'14' === values[j]) { items[i].add = 1; }else if (Names[i]+'24' === values[j]) { items[i].love = 1; } } } // if (Names[i]+yf === values[j]) { // items[i].add = 1; // }else if (Names[i]+yf === values[j]) { // items[i].love = 1; // } if(items[i].add === 0){ items[i].love = 0; } } if(yf=='11'||yf=='21'){ this.setData({ foodList1:items }) console.log('list1',this.data.foodList1); }else if(yf=='12'||yf=='22'){ this.setData({ foodList2:items }) console.log('list2',this.data.foodList2); }else if(yf=='13'||yf=='23'){ this.setData({ foodList3:items }) console.log('list3',this.data.foodList3); }else if(yf=='14'||yf=='24'){ this.setData({ foodList4:items }) console.log('list4',this.data.foodList4); } console.log('list'); // if(this.foodList[i].add == 0){ // this.foodList[i].love = 0; // } }, saveFoodlist(){ var that = this; let listss=that.data.foodList if(that.data.hospitalId==666668&&(that.data.yl<5||that.data.yl>23)){ networkUtil.showErrorToast('孩子目前还未到六月龄') return } this.setData({ show : true }) if(that.data.hospitalId==666668){ listss=[...that.data.foodList1,...that.data.foodList2,...that.data.foodList3,...that.data.foodList4] } networkUtil._post(api.setFootList,{ hospitalId:this.data.hospitalId, pid:this.data.pid, diets:listss },(res) => { if(0 == res.data.errorcode){ this.getList(); that.setData({ show : false }) wx.showModal({ title: '成功提交', content: '检查信息已提交!', showCancel: false }); }else{ wx.showModal({ title: '网络异常', content: res.data.errormsg, showCancel: false }); } },(err) => { wx.showModal({ title: '服务器异常', content: err.errormsg, showCancel: false }); that.setData({ show : false }) },'application/json;charset=utf-8') }, getList() { networkUtil._post(api.getFootHistory, { keyword: this.data.pid, sort: this.data.hospitalId, }, res => { if (res.statusCode == 200 && res.data.errorcode == 0) { var data = res.data.data; data.forEach(item => { item.createTime = exchgeDate.getYearMD(item.createTime ) }); console.log(data) let ss=[] if(res.data.data.length>0){ ss=res.data.data ss.forEach((item,index)=>{ item.diets1=item.diets.slice(0,6) item.diets2=item.diets.slice(6,14) item.diets3=item.diets.slice(14,21) item.diets4=item.diets.slice(21,24) }) } console.log('sss',ss); this.setData({ array: res.data.data }) console.log(this.data.array) } }, err => { }, 'application/json') }, // 获取膳食检查列表 getBabyNutritionList:function(){ wx.navigateTo({ url: '../weightReportList/weightReportList', }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var d = new Date(); var toDay = d.getFullYear() + "-" + ("00" + (d.getMonth() + 1)).substr(-2) + "-" + ("00" + d.getDate()).substr(-2); this.setData({ toDay: toDay, }) this.setData({ hospitalId: app.globalData.userInfo.hospitalId, pid:app.globalData.userInfo.pid, }) var list1=this.data.foodList.slice(0,6) var list2=this.data.foodList.slice(6,14) var list3=this.data.foodList.slice(14,21) var list4=this.data.foodList.slice(21,24) this.setData({ foodList1:list1, foodList2:list2, foodList3:list3, foodList4:list4 }) if(app.globalData.userInfo.hospitalId==666668){ if(app.globalData.userInfo.monthage.includes("月")){ let yl=this.getLeadingNumbers(app.globalData.userInfo.monthage) console.log('月龄',yl); this.setData({ yl:yl }) } } this.getList(); }, getLeadingNumbers(str) { // const match = str.match(/\d+$/); const match = str.match(/^\d+/); return match ? match[0] : null; }, getLeadingNumbers1(str) { const match = str.match(/\d+$/); return match ? match[0] : null; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })