hardwareDetails.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/hardwareDetails/hardwareDetails.js
  2. const app = getApp();
  3. const request = require('../../utils/request.js');
  4. const tools = require('../../utils/tools.js');
  5. import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. elderId: '',
  12. dict: [],
  13. deviceArr: []
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. },
  20. async getDetails() {
  21. let options = {
  22. url: 'resource/miniapp/user/getEquipList',
  23. data: {
  24. openId: wx.getStorageSync('openid'),
  25. type: app.globalData.type
  26. },
  27. method: 'post'
  28. }
  29. let res = await request.query(options);
  30. if (res.data.code === 200) {
  31. let arr = res.data.data.length > 0 ? res.data.data : []
  32. arr.map((item, index) => {
  33. item.regdateTime = this.toDate(item.regdateTime);
  34. item.kind = this.toKind(item.kind);
  35. })
  36. this.setData({
  37. deviceArr: arr
  38. })
  39. console.log(this.data.deviceArr)
  40. } else {
  41. Toast.fail(res.data.msg);
  42. }
  43. },
  44. async getDict() {
  45. let options = {
  46. url: 'system/app/home/dict/data/type/znyj_yj_kind',
  47. method: 'get'
  48. }
  49. let res = await request.query(options);
  50. if (res.data.code === 200) {
  51. this.setData({
  52. dict: res.data.data.length > 0 ? res.data.data : []
  53. })
  54. this.getDetails();
  55. } else {
  56. Toast.fail(res.data.msg);
  57. }
  58. },
  59. toDate(date_time) {
  60. let date = new Date(+new Date(date_time)).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
  61. return date
  62. },
  63. toKind(kind) {
  64. let a = this.data.dict.map(item => {
  65. console.log(item.dictValue)
  66. if (kind == item.dictValue) {
  67. console.log(item.dictLabel)
  68. return item.dictLabel
  69. }
  70. })
  71. return a[0];
  72. },
  73. /**
  74. * 生命周期函数--监听页面初次渲染完成
  75. */
  76. onReady: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. onShow: function () {
  82. if(!wx.getStorageSync('userId')){
  83. wx.showModal({
  84. title: '提示',
  85. content: '请扫描二维码进入小程序',
  86. showCancel: false,
  87. success: (res) => {
  88. if (res.confirm) {
  89. wx.navigateTo({
  90. url: '/pages/login/login',
  91. })
  92. }
  93. }
  94. })
  95. return false;
  96. }
  97. tools.isLogin().then((res) => {
  98. this.getDict();
  99. }, (error) => {
  100. console.log(error);
  101. })
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload: function () {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh: function () {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function () {
  122. },
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage: function () {
  127. }
  128. })