index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // pages/mine/mine.js
  2. const defaultAvatarUrl = "../../static/images/no-login.png"
  3. const homeApi_empower = "https://aipush.aidsleep.cn";
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showAuthorizedDialog: false,
  10. showTipsA: false,
  11. showTipsB: false,
  12. hasAuth: false,
  13. avatarUrl: defaultAvatarUrl,
  14. nickName: "用户登录",
  15. phoneNumber: "",
  16. menuCardList: [{
  17. icon: "../../static/index/icon/ic_fjkz.png",
  18. bgIcon: "../../static/index/bg/bg_fjkz.png",
  19. title: "房间控制",
  20. type: "navigate",
  21. color: "#3C84D9",
  22. bgColor: "#EEF4FF",
  23. url: "/subpages/main/main"
  24. }, {
  25. icon: "../../static/index/icon/ic_sm.png",
  26. bgIcon: "../../static/index/bg/bg_sm.png",
  27. title: "扫码",
  28. type: "navigate",
  29. color: "#10B09C",
  30. bgColor: "#E6FFFC",
  31. url: "/subpages/scan/scan"
  32. }, {
  33. icon: "../../static/index/icon/ic_jrsmbg.png",
  34. bgIcon: "../../static/index/bg/bg_jrsmbg.png",
  35. title: "最新睡眠报告",
  36. type: "navigate",
  37. color: "#8658B9",
  38. bgColor: "#F6F3FF",
  39. url: "/subpages/data/data"
  40. }, {
  41. icon: "../../static/index/icon/ic_lssmbg.png",
  42. bgIcon: "../../static/index/bg/bg_lssmbg.png",
  43. title: "历史睡眠报告",
  44. type: "navigate",
  45. color: "#BB6268",
  46. bgColor: "#FFF6F7",
  47. url: "/subpages/sleepReport/sleepReport"
  48. }, {
  49. icon: "../../static/index/icon/ic_wdcd.png",
  50. bgIcon: "../../static/index/bg/bg_wdcd.png",
  51. title: "我的床垫",
  52. type: "navigate",
  53. color: "#317A9B",
  54. bgColor: "#E6FFFC",
  55. url: "/subpages/myMattress/myMattress"
  56. }, {
  57. icon: "../../static/index/icon/ic_zxsc.png",
  58. bgIcon: "../../static/index/bg/bg_zxsc.png",
  59. title: "在线商城",
  60. type: "miniProgram",
  61. color: "#C2714B",
  62. bgColor: "#FFF8F4",
  63. appId: "wx63f79b3d61ba632b" || "gh_78da4ac5d0cc",
  64. url: "pages/home/dashboard/index"
  65. }],
  66. menuList: [{
  67. icon: "../../static/mine/dcwj.png",
  68. title: "调查问卷",
  69. type: "navigate",
  70. url: "/subpages/testSAS/testSAS"
  71. }, {
  72. icon: "../../static/mine/zxkf.png",
  73. title: "在线客服",
  74. type: "contact",
  75. url: ""
  76. }, {
  77. icon: "../../static/mine/bzzx.png",
  78. title: "帮助中心",
  79. type: "navigate",
  80. url: ""
  81. }, {
  82. icon: "../../static/mine/gywm.png",
  83. title: "关于我们",
  84. type: "navigate",
  85. url: ""
  86. }]
  87. },
  88. onCloseTipsDialog() {
  89. this.setData({
  90. showTipsA: false,
  91. showTipsB:false
  92. })
  93. },
  94. onMenuClick(e) {
  95. console.log(e.currentTarget.dataset);
  96. const { index } = e.currentTarget.dataset;
  97. var hasAuth = wx.getStorageSync("hasAuth");
  98. switch (index - 0) {
  99. case 0:
  100. // need Login
  101. if (hasAuth) {
  102. this.toPage(index);
  103. } else {
  104. this.showDialog();
  105. }
  106. break;
  107. default:
  108. this.toPage(index);
  109. break;
  110. }
  111. },
  112. toPage(index) {
  113. const type = this.data.menuList[index].type;
  114. const url = this.data.menuList[index].url;
  115. if (!url) {
  116. return
  117. }
  118. if (type == 'switchTab') {
  119. wx.switchTab({
  120. url: url
  121. })
  122. } else if (type == 'navigate') {
  123. wx.navigateTo({
  124. url: url
  125. })
  126. } else if (type == 'miniProgram') {
  127. //develop开发版;trial体验版;release正式版
  128. const appId = this.data.menuCardList[index].appId;
  129. wx.navigateToMiniProgram({
  130. appId: appId,
  131. path: url,
  132. extraData: {
  133. },
  134. envVersion: 'develop',
  135. success(res) {
  136. // 打开成功
  137. }
  138. })
  139. }
  140. },
  141. onMenuCardClick(e) {
  142. console.log(e.currentTarget.dataset);
  143. const { index } = e.currentTarget.dataset;
  144. var hasAuth = wx.getStorageSync("hasAuth");
  145. switch (index - 0) {
  146. case 0:
  147. case 1:
  148. case 2:
  149. case 3:
  150. // need Login
  151. if (hasAuth) {
  152. if (index == 0) {
  153. var hasHotelAuth = wx.getStorageSync("hasHotelAuth");
  154. if (!hasHotelAuth) {
  155. this.setData({
  156. showTipsB:true
  157. })
  158. return
  159. }
  160. }
  161. if (index == 2) {
  162. var hasReportAuth = wx.getStorageSync("hasReportAuth");
  163. var unionid = wx.getStorageSync("unionid");
  164. if (!unionid) {
  165. this.setData({
  166. showTipsA: true
  167. })
  168. return
  169. }
  170. if (!hasReportAuth) {
  171. wx.showModal({
  172. title: '提示',
  173. content: '没有睡眠报告',
  174. showCancel: false
  175. });
  176. return
  177. }
  178. }
  179. this.toCardPage(index);
  180. } else {
  181. this.showDialog();
  182. }
  183. break;
  184. default:
  185. this.toCardPage(index);
  186. break;
  187. }
  188. },
  189. toCardPage(index) {
  190. const type = this.data.menuCardList[index].type;
  191. const url = this.data.menuCardList[index].url;
  192. if (!url) {
  193. return
  194. }
  195. if (type == 'switchTab') {
  196. wx.switchTab({
  197. url: url
  198. })
  199. } else if (type == 'navigate') {
  200. wx.navigateTo({
  201. url: url
  202. })
  203. } else if (type == 'miniProgram') {
  204. //develop开发版;trial体验版;release正式版
  205. const appId = this.data.menuCardList[index].appId;
  206. wx.navigateToMiniProgram({
  207. appId: appId,
  208. path: url,
  209. extraData: {
  210. },
  211. envVersion: 'develop',
  212. success(res) {
  213. // 打开成功
  214. }
  215. })
  216. }
  217. },
  218. /**
  219. * 生命周期函数--监听页面加载
  220. */
  221. onLoad(options) {
  222. wx.hideTabBar()
  223. },
  224. /**
  225. * 生命周期函数--监听页面初次渲染完成
  226. */
  227. onReady() {
  228. wx.hideTabBar()
  229. },
  230. /**
  231. * 生命周期函数--监听页面显示
  232. */
  233. onShow() {
  234. wx.hideTabBar()
  235. this.checkAuth()
  236. },
  237. showDialog() {
  238. var hasAuth = wx.getStorageSync("hasAuth");
  239. if (hasAuth) {
  240. return
  241. }
  242. this.setData({
  243. showAuthorizedDialog: true
  244. })
  245. },
  246. checkAuth() {
  247. var hasAuth = wx.getStorageSync("hasAuth");
  248. this.setData({
  249. hasAuth: hasAuth
  250. })
  251. if (hasAuth) {
  252. var userInfo = wx.getStorageSync("userInfo");
  253. this.setData({
  254. nickName: userInfo.nickName || "用户登录",
  255. avatarUrl: userInfo.avatarUrl || defaultAvatarUrl,
  256. phoneNumber: userInfo.phoneNumber || ""
  257. })
  258. // 判断扫码控制权限
  259. wx.request({
  260. url: `${homeApi_empower}/wxstatus`,
  261. data: {
  262. unionid: wx.getStorageSync('unionid'),
  263. openid: wx.getStorageSync('openid'),
  264. token: wx.getStorageSync('token'),
  265. },
  266. method: 'POST',
  267. success: function (intervalRes) {
  268. console.log('intervalRes=' + JSON.stringify(intervalRes));
  269. console.log('intervalRes.data=' + JSON.stringify(intervalRes.data));
  270. //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
  271. if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '1') {
  272. wx.setStorageSync('hasHotelAuth', true);
  273. wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
  274. wx.setStorageSync('roomEmpower', intervalRes.data.room);
  275. wx.setStorageSync('hname', intervalRes.data.hname);
  276. wx.setStorageSync('rname', intervalRes.data.rname);
  277. } else {
  278. wx.setStorageSync('hasHotelAuth', false);
  279. }
  280. },
  281. fail: function (error) {
  282. }
  283. });
  284. }
  285. return hasAuth;
  286. },
  287. authorizationSuccessful() {
  288. console.log("授权成功");
  289. this.setData({ showAuthorizedDialog: false })
  290. this.checkAuth();
  291. },
  292. /**
  293. * 生命周期函数--监听页面隐藏
  294. */
  295. onHide() {
  296. },
  297. /**
  298. * 生命周期函数--监听页面卸载
  299. */
  300. onUnload() {
  301. },
  302. /**
  303. * 页面相关事件处理函数--监听用户下拉动作
  304. */
  305. onPullDownRefresh() {
  306. },
  307. /**
  308. * 页面上拉触底事件的处理函数
  309. */
  310. onReachBottom() {
  311. },
  312. /**
  313. * 用户点击右上角分享
  314. */
  315. onShareAppMessage() {
  316. }
  317. })