shell_device.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // pages/shell_device/shell_device.js
  2. const { formatDate, formatTime2, formatDateZyb, getDateDiff } = require('../../utils/util.js')
  3. var app=getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. thumbnail: app.globalData.thumbnail,
  10. baseImgUrl: app.globalData.baseImgUrl,
  11. hiddenModel:false,
  12. isTime:false,
  13. bindType:1,
  14. list: [
  15. // {
  16. // "beginDate": "2018.09.02",
  17. // "endDate": "2018.10.02",
  18. // "leagueName": "深圳共享馆",
  19. // "status": 1
  20. // },
  21. // {
  22. // "beginDate": "2018.09.02",
  23. // "endDate": "2018.10.02",
  24. // "leagueName": "深圳共享馆1",
  25. // "status": 2
  26. // }
  27. ]
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. options.parentVipLiIdx = app.getGlobalAttributeValue(`parentVipLiIdx-${app.getGlobalAttributeValue(`userId`)}`)
  34. console.log(options)
  35. var times = options.commuEndDate;
  36. var messageTime = formatDateZyb(times, 'Y-M-D')
  37. var nowTime = new Date().getTime();
  38. var today = formatDateZyb(nowTime / 1000, 'Y-M-D');
  39. var day1 = new Date(today);
  40. var day2 = new Date(messageTime);
  41. var differDay = (day2 - day1) / (1000 * 60 * 60 * 24);
  42. console.log(differDay)
  43. if (0 <= differDay) {
  44. this.setData({ isTime: true, dateTime: messageTime })
  45. } else if (differDay < 0) {
  46. this.setData({ isTime: false })
  47. }
  48. this.setData(options)
  49. if (options.isShell==0) {
  50. wx.setNavigationBarTitle({
  51. title: `小塾设备`,
  52. })
  53. }else {
  54. wx.setNavigationBarTitle({
  55. title: `学习系统服务`,
  56. })
  57. }
  58. },
  59. /**
  60. * 生命周期函数--监听页面初次渲染完成
  61. */
  62. onReady: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {
  68. const { isShell}=this.data;
  69. this.getInformation();
  70. if (isShell==1){
  71. this.chatHomeworkTime();
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面隐藏
  76. */
  77. onHide: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面卸载
  81. */
  82. onUnload: function () {
  83. },
  84. /**
  85. * 页面相关事件处理函数--监听用户下拉动作
  86. */
  87. onPullDownRefresh: function () {
  88. },
  89. /**
  90. * 页面上拉触底事件的处理函数
  91. */
  92. onReachBottom: function () {
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage: function () {
  98. },
  99. /**
  100. * 路由跳转
  101. */
  102. redirectCtl: app.redirectCtl,
  103. /**
  104. * 路由跳转
  105. */
  106. navigateCtl: app.navigateCtl,
  107. /**
  108. * 提示框隐藏
  109. */
  110. allShowModel: function () {
  111. this.setData({ hiddenModel: false })
  112. },
  113. /**
  114. * 解绑弹框
  115. */
  116. changeShell:function(){
  117. this.setData({ hiddenModel: true })
  118. },
  119. /**
  120. * 贝壳解绑
  121. */
  122. setShell:function(){
  123. const { derver}=this.data;
  124. const postData = { fn: this.setShell, param: { ...arguments } }
  125. app.post('/api/parents/parents/V2/untieDerver', { derver}, 0, postData).then(res => {
  126. wx.showToast({
  127. title: '解绑成功',
  128. icon: 'none'
  129. })
  130. this.setData({ derver: '', hiddenModel: false})
  131. this.getInformation()
  132. })
  133. },
  134. /**
  135. * 查询作业吧服务时间
  136. */
  137. chatHomeworkTime:function(){
  138. const { vipId } = this.data;
  139. const postData = { fn: this.chatHomeworkTime, param: { ...arguments } }
  140. app.post('/api/parents/parents/V2/service/findZybServiceList', { vipId}, 0, postData).then(res => {
  141. const { list}=res.data;
  142. this.setData({list});
  143. })
  144. },
  145. /**
  146. * 获取定位经纬度
  147. */
  148. getLocation: function () {
  149. app.getWxUserLocationSetting(res => {
  150. wx.showLoading({
  151. title: '定位中'
  152. })
  153. wx.getLocation({
  154. type: 'wgs84',
  155. success: res => {
  156. this.setData({
  157. longitude: res.longitude, // '113.36403' ||
  158. latitude: res.latitude // '23.14203' ||
  159. })
  160. this.addChildCtl();
  161. },
  162. fail: res => {
  163. setTimeout(() => {
  164. wx.showToast({
  165. title: '定位失败',
  166. icon: 'none'
  167. })
  168. }, 10)
  169. setTimeout(() => {
  170. wx.navigateBack({
  171. delta: 1
  172. })
  173. }, 1000)
  174. },
  175. complete: res => {
  176. wx.hideLoading()
  177. }
  178. })
  179. })
  180. },
  181. /**
  182. * 绑定孩子二维码
  183. */
  184. addChildCtl: function () {
  185. const postData = { fn: this.addChildCtl, param: { ...arguments } }
  186. const { vipId } = this.data;
  187. const { longitude, latitude } = this.data;
  188. if (!longitude) {
  189. wx.showToast({
  190. title: '请允许授权获取地理位置',
  191. icon: 'none'
  192. })
  193. return
  194. }
  195. wx.scanCode({
  196. // onlyFromCamera: true,
  197. success: (e) => {
  198. // if (e.result.indexOf('https://xt.sharingschool.com') != -1) {
  199. app.post('/api/parents/parents/V2/newSwipeQrCode', {
  200. vipId,
  201. longitude,
  202. latitude,
  203. qrCode: e.result
  204. }, 0, postData).then(res => {
  205. const { derver} = res.data
  206. // this.setData({ derver});
  207. this.bindAddChildCtl(derver);
  208. })
  209. // } else {
  210. // wx.showToast({
  211. // title: '二维码不正确',
  212. // icon: 'none',
  213. // duration: 1000
  214. // })
  215. // }
  216. }
  217. })
  218. },
  219. /**
  220. * 绑定孩子
  221. */
  222. bindAddChildCtl: function (str) {
  223. const postData = { fn: this.bindAddChildCtl, param: { ...arguments } }
  224. const { vipId, derver, bindType, longitude, latitude} = this.data;
  225. app.post('/api/parents/parents/V2/bindConch', {
  226. vipId,
  227. longitude,
  228. latitude,
  229. derver:str,
  230. type: bindType
  231. }, 0, postData).then(res => {
  232. this.setData({ derver:str});
  233. wx.showToast({
  234. title: '绑定成功',
  235. icon: 'success',
  236. duration: 1000
  237. });
  238. this.getInformation();
  239. })
  240. },
  241. /**
  242. * 获取个人信息
  243. */
  244. getInformation: function () {
  245. const postData = { fn: this.getInformation, param: { ...arguments } }
  246. const { vipId} = this.data
  247. app.post('/api/parents/parents/V2/getMyChildInfo', { vipId }, 0, postData).then(res => {
  248. const { derver, commuEndDate, childName, imgUrl, zybEndDate, derverType, isMain}=res.data;
  249. var times = commuEndDate;
  250. var messageTime = formatDateZyb(times, 'Y-M-D')
  251. var nowTime = new Date().getTime();
  252. var today = formatDateZyb(nowTime / 1000, 'Y-M-D');
  253. var day1 = new Date(today);
  254. var day2 = new Date(messageTime);
  255. var differDay = (day2 - day1) / (1000 * 60 * 60 * 24);
  256. console.log(differDay)
  257. if (0 <= differDay) {
  258. this.setData({ isTime: true, dateTime: messageTime })
  259. } else if (differDay < 0) {
  260. this.setData({ isTime: false })
  261. }
  262. this.setData({ derver, childName, imgUrl, zybEndDate, derverType, isMain});
  263. })
  264. },
  265. })