index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. // 轮播
  6. backgrounds: [{
  7. "pic": "/images/banner1.png",
  8. // link:'../aboutme/index',
  9. },
  10. {
  11. "pic": "/images/banner2.png",
  12. // link:'../aboutme/index',
  13. },
  14. {
  15. "pic": "/images/banner3.png",
  16. // link:'../aboutme/index',
  17. },
  18. ],
  19. indicatorDots: true,
  20. vertical: false,
  21. autoplay: true,
  22. interval: 5000,
  23. duration: 500,
  24. number: {},
  25. msgList: []
  26. },
  27. goCollect() {
  28. wx.navigateTo({
  29. url: '/pages/userBook/userBook',
  30. })
  31. },
  32. goXunfang() {
  33. if (!wx.getStorageSync('openId')) {
  34. wx.login({
  35. success: res => {
  36. console.log("用户的code:" + res.code);
  37. wx.request({
  38. url: app.globalData.publicUrl + '/wx/getAppletOpenId',
  39. method: "GET",
  40. data: {
  41. cid: 'applet',
  42. code: res.code
  43. },
  44. success: res => {
  45. console.log("用户的openid:" + res.data.data.openid);
  46. wx.setStorageSync('openId', res.data.data.openid)
  47. this.isBInd(res.data.data.openid);
  48. }
  49. });
  50. }
  51. });
  52. } else {
  53. this.isBInd();
  54. }
  55. console.log(wx.getStorageSync('openId'))
  56. },
  57. // 判断是否绑定
  58. isBInd() {
  59. let id = wx.getStorageSync('openId');
  60. wx.request({
  61. url: app.globalData.publicUrl + '/wxinfo/visitIsExist',
  62. method: "GET",
  63. data: {
  64. openId: id
  65. // appletId: id
  66. },
  67. success: res => {
  68. if (res.data.code == 1) {
  69. console.log("用户没绑定", res);
  70. wx.navigateTo({
  71. url: '/pages/visitFind/visitFind',
  72. })
  73. } else if (res.data.code == 0) {
  74. console.log("用户已经绑定了", res);
  75. wx.navigateTo({
  76. url: '/pages/bindOld/bindOld',
  77. })
  78. } else {
  79. wx.showModal({
  80. showCancel: false,
  81. content: res.data.message,
  82. })
  83. }
  84. }
  85. });
  86. },
  87. goTongzhi() {
  88. wx.login({
  89. success: (res) => {
  90. if (res.code) {
  91. wx.request({
  92. url: app.globalData.publicUrl + '/wx/getAppletOpenId',
  93. method: "GET",
  94. data: {
  95. cid: 'applet',
  96. code: res.code
  97. },
  98. success: res => {
  99. // 获取到用户的 openid
  100. if (res.data.status == 200) {
  101. wx.setStorageSync('openId', res.data.data.openid)
  102. wx.request({
  103. url: app.globalData.publicUrl + '/applet/isExist',
  104. method: "GET",
  105. data: {
  106. appletsId: wx.getStorageSync('openId')
  107. },
  108. success: (res) => {
  109. console.log('app登录是否绑定的', res.data.code);
  110. if (res.data.code == 0) {
  111. if (res.data.data) {
  112. wx.navigateTo({
  113. url: '/pages/notice/notice',
  114. })
  115. }
  116. } else {
  117. wx.redirectTo({
  118. url: '/pages/login/login',
  119. })
  120. }
  121. }
  122. })
  123. }
  124. }
  125. });
  126. } else {
  127. console.log('获取用户登录态失败!' + res.errMsg);
  128. }
  129. }
  130. })
  131. // if (wx.getStorageSync('user') == '') {
  132. // wx.redirectTo({
  133. // url: '/pages/login/login',
  134. // })
  135. // } else {
  136. // wx.navigateTo({
  137. // url: '/pages/notice/notice',
  138. // })
  139. // }
  140. },
  141. goPaiming() {
  142. wx.login({
  143. success: (res) => {
  144. if (res.code) {
  145. wx.request({
  146. url: app.globalData.publicUrl + '/wx/getAppletOpenId',
  147. method: "GET",
  148. data: {
  149. cid: 'applet',
  150. code: res.code
  151. },
  152. success: res => {
  153. // 获取到用户的 openid
  154. if (res.data.status == 200) {
  155. wx.setStorageSync('openId', res.data.data.openid)
  156. wx.request({
  157. url: app.globalData.publicUrl + '/applet/isExist',
  158. method: "GET",
  159. data: {
  160. appletsId: wx.getStorageSync('openId')
  161. },
  162. success: (res) => {
  163. console.log('app登录是否绑定的', res.data.code);
  164. if (res.data.code == 0) {
  165. if (res.data.data) {
  166. wx.navigateTo({
  167. url: '/pages/paiming/paiming',
  168. })
  169. }
  170. } else {
  171. wx.redirectTo({
  172. url: '/pages/login/login',
  173. })
  174. }
  175. }
  176. })
  177. }
  178. }
  179. });
  180. } else {
  181. console.log('获取用户登录态失败!' + res.errMsg);
  182. }
  183. }
  184. })
  185. },
  186. goSaoMa() {
  187. wx.login({
  188. success: (res) => {
  189. if (res.code) {
  190. wx.request({
  191. url: app.globalData.publicUrl + '/wx/getAppletOpenId',
  192. method: "GET",
  193. data: {
  194. cid: 'applet',
  195. code: res.code
  196. },
  197. success: res => {
  198. // 获取到用户的 openid
  199. if (res.data.status == 200) {
  200. wx.setStorageSync('openId', res.data.data.openid)
  201. wx.request({
  202. url: app.globalData.publicUrl + '/applet/isExist',
  203. method: "GET",
  204. data: {
  205. appletsId: wx.getStorageSync('openId')
  206. },
  207. success: (res) => {
  208. console.log('app登录是否绑定的', res.data.code);
  209. if (res.data.code == 0) {
  210. if (res.data.data) {
  211. wx.scanCode({
  212. onlyFromCamera: true,
  213. success: (res) => {
  214. console.log(res, "扫码成功");
  215. let length = res.result.substring(res.result.lastIndexOf('/') + 1, res.result.length)
  216. wx.navigateTo({
  217. url: '/pages/love/love?id=' + length,
  218. })
  219. },
  220. fail: (res) => {
  221. console.log(res, "扫码失败");
  222. wx.showToast({
  223. title: '扫码失败',
  224. icon: 'none',
  225. duration: 2000,
  226. })
  227. }
  228. })
  229. }
  230. } else {
  231. wx.redirectTo({
  232. url: '/pages/login/login',
  233. })
  234. }
  235. }
  236. })
  237. }
  238. }
  239. });
  240. } else {
  241. console.log('获取用户登录态失败!' + res.errMsg);
  242. }
  243. }
  244. })
  245. },
  246. depts() {
  247. console.log("1111111111111111111111111111");
  248. wx.request({
  249. url: app.globalData.publicUrl + '/applet/homeStatistics',
  250. method: "GET",
  251. data: {
  252. appletsId: wx.getStorageSync('openId')
  253. },
  254. success: (res) => {
  255. console.log("resrrrrrrrrrrrrrrrrrrrrrrr", res);
  256. if (res.data.code == 0) {
  257. this.setData({
  258. number: res.data.data
  259. })
  260. }
  261. }
  262. })
  263. },
  264. welcomeMessage() {
  265. this.setData({
  266. msgList: []
  267. })
  268. wx.login({
  269. success: (res) => {
  270. if (res.code) {
  271. wx.request({
  272. url: app.globalData.publicUrl + '/wx/getAppletOpenId',
  273. method: "GET",
  274. data: {
  275. cid: 'applet',
  276. code: res.code
  277. },
  278. success: res => {
  279. // 获取到用户的 openid
  280. if (res.data.status == 200) {
  281. wx.setStorageSync('openId', res.data.data.openid)
  282. wx.request({
  283. url: app.globalData.publicUrl + '/applet/isExist',
  284. method: "GET",
  285. data: {
  286. appletsId: wx.getStorageSync('openId')
  287. },
  288. success: (res) => {
  289. console.log('app登录是否绑定的', res.data.code);
  290. if (res.data.code == 0) {
  291. if (res.data.data) {
  292. wx.request({
  293. url: app.globalData.publicUrl + '/appletNotice/listForAppletsFirst',
  294. method: "GET",
  295. header: {
  296. appletsId: wx.getStorageSync('openId')
  297. },
  298. success: (res) => {
  299. if (res.data.code == 0) {
  300. if (res.data.data.length == 0) {
  301. this.data.msgList.push({
  302. title: '暂无通知'
  303. });
  304. this.setData({
  305. msgList: this.data.msgList
  306. })
  307. } else {
  308. let result = res.data.data.title;
  309. this.data.msgList.push({
  310. title: result
  311. });
  312. this.setData({
  313. msgList: this.data.msgList
  314. })
  315. }
  316. }
  317. }
  318. })
  319. }
  320. } else {
  321. wx.request({
  322. url: app.globalData.publicUrl + '/welcomeMessage/list',
  323. method: "GET",
  324. success: (res) => {
  325. if (res.data.code == 0) {
  326. if (res.data.data.length != 0) {
  327. let result = res.data.data[0].title
  328. this.data.msgList.push({
  329. title: result
  330. });
  331. this.data.msgList.push({
  332. title: result
  333. });
  334. this.setData({
  335. msgList: this.data.msgList
  336. })
  337. }
  338. }
  339. }
  340. })
  341. }
  342. }
  343. })
  344. }
  345. }
  346. });
  347. } else {
  348. console.log('获取用户登录态失败!' + res.errMsg);
  349. }
  350. }
  351. })
  352. // if (wx.getStorageSync('user') == '') {
  353. // wx.request({
  354. // url: app.globalData.publicUrl + '/welcomeMessage/list',
  355. // method: "GET",
  356. // success: (res) => {
  357. // if (res.data.code == 0) {
  358. // if (res.data.data.length != 0) {
  359. // let result = res.data.data[0].title
  360. // this.data.msgList.push({
  361. // title: result
  362. // });
  363. // this.data.msgList.push({
  364. // title: result
  365. // });
  366. // this.setData({
  367. // msgList: this.data.msgList
  368. // })
  369. // }
  370. // }
  371. // }
  372. // })
  373. // } else {
  374. // wx.request({
  375. // url: app.globalData.publicUrl + '/appletNotice/listForAppletsFirst',
  376. // method: "GET",
  377. // header: {
  378. // appletsId: wx.getStorageSync('openId')
  379. // },
  380. // success: (res) => {
  381. // if (res.data.code == 0) {
  382. // if (res.data.data.length == 0) {
  383. // this.data.msgList.push({
  384. // title: '暂无通知'
  385. // });
  386. // this.setData({
  387. // msgList: this.data.msgList
  388. // })
  389. // } else {
  390. // let result = res.data.data.title;
  391. // this.data.msgList.push({
  392. // title: result
  393. // });
  394. // this.setData({
  395. // msgList: this.data.msgList
  396. // })
  397. // }
  398. // }
  399. // }
  400. // })
  401. // }
  402. },
  403. onShow() {
  404. this.depts();
  405. this.welcomeMessage();
  406. },
  407. onLoad: function () {
  408. const apps = getApp()
  409. apps.getAuthKey().then(() => {
  410. this.depts();
  411. })
  412. }
  413. })