let util = require("../../../../../utils/util") const apiArr = require('../../../../../api/water_filter') // packages/WaterPurifier/pages/device/deviceDesc/deviceDesc.js Page({ /** * 页面的初始数据 */ data: { progress_List: [{ "name": "HXTH滤芯", "progress": 97.41 }, { "name": "RO膜滤芯", "progress": 87.41 }, { "name": "PP+CB滤芯", "progress": 40.41 }, { "name": "PP棉滤芯", "progress": 90.41 } ], device_id:"", Info:{}, }, getInfo(){ let that= this util.postUrl(apiArr.deviceDesc,{ device_id:Number(that.data.device_id) },res=>{ console.log(res); res.device_part.forEach(item=>{ item.shengyuTime = that.getDaysDifference(item.expiration_time) item.parent = Math.round((Number(item.shengyuTime) / Number(item.availableDays)*100)) }) that.setData({ Info:res }) }) }, getDaysDifference(targetDate) { // 获取当前时间 const now = new Date(); // 将传递的时间转换为日期对象 const target = new Date(targetDate); // 计算时间差(以毫秒为单位) const timeDiff = target.getTime() - now.getTime(); // 将毫秒转换为天数 const daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)); return daysDiff; }, //开机 Open(){ let that = this util.postUrl(apiArr) }, //关机 Close(){ let that = this util.postUrl(apiArr) }, // 强冲 QC(){ let that = this util.postUrl(apiArr) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this console.log(options); that.setData({ device_id:options.device_id }) that.getInfo() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })