// pages/shell_device/shell_device.js const { formatDate, formatTime2, formatDateZyb, getDateDiff } = require('../../utils/util.js') var app=getApp() Page({ /** * 页面的初始数据 */ data: { thumbnail: app.globalData.thumbnail, baseImgUrl: app.globalData.baseImgUrl, hiddenModel:false, isTime:false, bindType:1, list: [ // { // "beginDate": "2018.09.02", // "endDate": "2018.10.02", // "leagueName": "深圳共享馆", // "status": 1 // }, // { // "beginDate": "2018.09.02", // "endDate": "2018.10.02", // "leagueName": "深圳共享馆1", // "status": 2 // } ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { options.parentVipLiIdx = app.getGlobalAttributeValue(`parentVipLiIdx-${app.getGlobalAttributeValue(`userId`)}`) console.log(options) var times = options.commuEndDate; var messageTime = formatDateZyb(times, 'Y-M-D') var nowTime = new Date().getTime(); var today = formatDateZyb(nowTime / 1000, 'Y-M-D'); var day1 = new Date(today); var day2 = new Date(messageTime); var differDay = (day2 - day1) / (1000 * 60 * 60 * 24); console.log(differDay) if (0 <= differDay) { this.setData({ isTime: true, dateTime: messageTime }) } else if (differDay < 0) { this.setData({ isTime: false }) } this.setData(options) if (options.isShell==0) { wx.setNavigationBarTitle({ title: `小塾设备`, }) }else { wx.setNavigationBarTitle({ title: `学习系统服务`, }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { const { isShell}=this.data; this.getInformation(); if (isShell==1){ this.chatHomeworkTime(); } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 路由跳转 */ redirectCtl: app.redirectCtl, /** * 路由跳转 */ navigateCtl: app.navigateCtl, /** * 提示框隐藏 */ allShowModel: function () { this.setData({ hiddenModel: false }) }, /** * 解绑弹框 */ changeShell:function(){ this.setData({ hiddenModel: true }) }, /** * 贝壳解绑 */ setShell:function(){ const { derver}=this.data; const postData = { fn: this.setShell, param: { ...arguments } } app.post('/api/parents/parents/V2/untieDerver', { derver}, 0, postData).then(res => { wx.showToast({ title: '解绑成功', icon: 'none' }) this.setData({ derver: '', hiddenModel: false}) this.getInformation() }) }, /** * 查询作业吧服务时间 */ chatHomeworkTime:function(){ const { vipId } = this.data; const postData = { fn: this.chatHomeworkTime, param: { ...arguments } } app.post('/api/parents/parents/V2/service/findZybServiceList', { vipId}, 0, postData).then(res => { const { list}=res.data; this.setData({list}); }) }, /** * 获取定位经纬度 */ getLocation: function () { app.getWxUserLocationSetting(res => { wx.showLoading({ title: '定位中' }) wx.getLocation({ type: 'wgs84', success: res => { this.setData({ longitude: res.longitude, // '113.36403' || latitude: res.latitude // '23.14203' || }) this.addChildCtl(); }, fail: res => { setTimeout(() => { wx.showToast({ title: '定位失败', icon: 'none' }) }, 10) setTimeout(() => { wx.navigateBack({ delta: 1 }) }, 1000) }, complete: res => { wx.hideLoading() } }) }) }, /** * 绑定孩子二维码 */ addChildCtl: function () { const postData = { fn: this.addChildCtl, param: { ...arguments } } const { vipId } = this.data; const { longitude, latitude } = this.data; if (!longitude) { wx.showToast({ title: '请允许授权获取地理位置', icon: 'none' }) return } wx.scanCode({ // onlyFromCamera: true, success: (e) => { // if (e.result.indexOf('https://xt.sharingschool.com') != -1) { app.post('/api/parents/parents/V2/newSwipeQrCode', { vipId, longitude, latitude, qrCode: e.result }, 0, postData).then(res => { const { derver} = res.data // this.setData({ derver}); this.bindAddChildCtl(derver); }) // } else { // wx.showToast({ // title: '二维码不正确', // icon: 'none', // duration: 1000 // }) // } } }) }, /** * 绑定孩子 */ bindAddChildCtl: function (str) { const postData = { fn: this.bindAddChildCtl, param: { ...arguments } } const { vipId, derver, bindType, longitude, latitude} = this.data; app.post('/api/parents/parents/V2/bindConch', { vipId, longitude, latitude, derver:str, type: bindType }, 0, postData).then(res => { this.setData({ derver:str}); wx.showToast({ title: '绑定成功', icon: 'success', duration: 1000 }); this.getInformation(); }) }, /** * 获取个人信息 */ getInformation: function () { const postData = { fn: this.getInformation, param: { ...arguments } } const { vipId} = this.data app.post('/api/parents/parents/V2/getMyChildInfo', { vipId }, 0, postData).then(res => { const { derver, commuEndDate, childName, imgUrl, zybEndDate, derverType, isMain}=res.data; var times = commuEndDate; var messageTime = formatDateZyb(times, 'Y-M-D') var nowTime = new Date().getTime(); var today = formatDateZyb(nowTime / 1000, 'Y-M-D'); var day1 = new Date(today); var day2 = new Date(messageTime); var differDay = (day2 - day1) / (1000 * 60 * 60 * 24); console.log(differDay) if (0 <= differDay) { this.setData({ isTime: true, dateTime: messageTime }) } else if (differDay < 0) { this.setData({ isTime: false }) } this.setData({ derver, childName, imgUrl, zybEndDate, derverType, isMain}); }) }, })