C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

610 satır
15 KiB

  1. const Http = require("../../utils/HttpBasics");
  2. const imgurl = require("../../utils/imgurl");
  3. const config = require("../../config/config");
  4. const QR = require("../../utils/memberqrcode.js");
  5. const util = require("../../utils/util");
  6. let app = getApp();
  7. Page({
  8. data: {
  9. newUrl: "",
  10. cover: "",
  11. usergift: imgurl.usergift.url,
  12. guanbi1: imgurl.guanbi1.url,
  13. icon0001: imgurl.icon0001.url,
  14. icon0002: imgurl.icon0002.url,
  15. icon0003: imgurl.icon0003.url,
  16. icon0004: imgurl.icon0004.url,
  17. icon0005: imgurl.icon0005.url,
  18. icon0006: imgurl.icon0006.url,
  19. icon0007: imgurl.icon0007.url,
  20. icon0008: imgurl.icon0008.url,
  21. barcode: imgurl.barcode.url,
  22. leftarrows: imgurl.leftarrows.url,
  23. newcard: imgurl.newcard.url,
  24. newseckill: imgurl.newseckill.url,
  25. newbargain: imgurl.newbargain.url,
  26. newgroup: imgurl.newgroup.url,
  27. product: imgurl.product.url,
  28. barginicon: imgurl.barginicon.url,
  29. pintuan: imgurl.pintuan.url,
  30. duihuan: imgurl.duihuan.url,
  31. market: app.globalData.market,
  32. list: [],
  33. loading: true,
  34. fistLogin: null,
  35. alphaData: null,
  36. swiperCurrent: 0,
  37. title: null,
  38. weappShareTitle: '', //分享标题
  39. weappShareCoverImg: '', //分享图片
  40. desc: null,
  41. scrollTop: 0,
  42. showGame: false,
  43. showTopic: false,
  44. gamedata: {},
  45. couponId: '', //游戏返回时传回的字段
  46. played: false, //从游戏页面跳回首页返回true
  47. havePlayEd: app.globalData.havePlayEd,
  48. staticGamedata: {},
  49. showIf: false,
  50. showPages: false,
  51. display: 'none',
  52. display1: 'none',
  53. optionsData: null,
  54. credit: 0,
  55. score: '0',
  56. page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  57. },
  58. close: function() {
  59. this.setData({
  60. showIf: false
  61. })
  62. },
  63. alphaClick: function(even) {
  64. var animation = wx.createAnimation({})
  65. animation.opacity(0).step({
  66. duration: 2000
  67. })
  68. this.setData({
  69. alphaData: animation.export()
  70. })
  71. },
  72. // 我的卡包
  73. mycard: function() {
  74. wx.navigateTo({
  75. url: '/pages/cardorder/index/index',
  76. })
  77. },
  78. //我的券包
  79. mycoupon: function() {
  80. wx.navigateTo({
  81. url: '/pages/couponorder/index/index',
  82. })
  83. },
  84. gotoSpellGroup: function() {
  85. wx.navigateTo({
  86. url: '/pages/spellGroup/spellGroup',
  87. })
  88. },
  89. qrcode: function() {
  90. var that = this;
  91. let memberId = that.data.memberId;
  92. if (memberId) {
  93. wx.navigateTo({
  94. url: '/pages/specialcourtesy/specialcourtesy'
  95. })
  96. }
  97. },
  98. // hideQrcode: function() {
  99. // let that = this;
  100. // that.setData({
  101. // showQrcode: false
  102. // })
  103. // },
  104. //跳往限时秒杀
  105. gotoRushBuy: function() {
  106. wx.navigateTo({
  107. url: '/pages/rushToBuy/index',
  108. })
  109. },
  110. // 跳往卡列表
  111. gotodiscountcard: function() {
  112. wx.navigateTo({
  113. url: '/pages/discountCardList/discountCardList',
  114. })
  115. },
  116. //跳往积分商城
  117. gotouser: function() {
  118. wx.navigateTo({
  119. url: `/pages/integralmall/index`
  120. })
  121. },
  122. //跳往砍价专场
  123. gobargain: function() {
  124. wx.navigateTo({
  125. url: '/pages/bargain/bargain',
  126. })
  127. },
  128. //跳往拼团专场
  129. gogroup: function() {
  130. wx.navigateTo({
  131. url: '/pages/spellGroup/spellGroup',
  132. })
  133. },
  134. //搜索门店
  135. // searchbar:function(){
  136. // wx.switchTab({
  137. // url: '/pages/index/searchbar/index',
  138. // })
  139. // },
  140. // createQrCode: function(url, canvasId, cavW, cavH) {
  141. // //调用插件中的draw方法,绘制二维码图片
  142. // QR.api.draw(url, canvasId, cavW, cavH);
  143. // },
  144. swiperChange: function(e) {
  145. this.setData({
  146. swiperCurrent: e.detail.current
  147. });
  148. },
  149. gotogame: function() {
  150. let that = this;
  151. Http.get({
  152. url: config.api.checkPhoneStatus,
  153. data: {}
  154. })
  155. .then(res => {
  156. var data = {
  157. couponChannelId: "" + that.data.couponChannelId,
  158. couponId: "" + that.data.couponId
  159. };
  160. if (that.data.couponChannelId == null) {
  161. var data = {
  162. couponId: "" + that.data.couponId
  163. };
  164. }
  165. wx.navigateTo({
  166. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  167. })
  168. })
  169. .catch(err => {
  170. if (err.code == 11005) {
  171. // 用户手机未授权
  172. /**
  173. * 将值传到用户手机号授权的页面
  174. *
  175. */
  176. wx.redirectTo({
  177. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  178. });
  179. } else if (err.code == 11006) {
  180. // 用户手机已加密
  181. wx.redirectTo({
  182. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  183. });
  184. } else {
  185. wx.showToast({
  186. title: err.message,
  187. icon: 'none',
  188. duration: 2000,
  189. mask: false
  190. });
  191. }
  192. })
  193. },
  194. mySpecial: function() {
  195. console.log("special");
  196. wx.navigateTo({
  197. url: '/pages/specialcourtesy/specialcourtesy',
  198. })
  199. },
  200. /**
  201. * 生命周期函数--监听页面初次渲染完成
  202. */
  203. onLoad: function(options) {
  204. let that = this;
  205. let optionss = JSON.parse(wx.getStorageSync('options'));
  206. if (options.played == "true") {
  207. that.setData({
  208. played: true
  209. })
  210. }
  211. if (optionss.couponChannelId || optionss.orderId) {
  212. that.setData({
  213. optionsData: optionss
  214. })
  215. that.userLogin(optionss.couponChannelId, optionss.orderId);
  216. } else {
  217. that.userLogin()
  218. }
  219. //获取条形码
  220. // util.barcode("barcode", optionss.quancode, 510, 100);
  221. },
  222. onShow: function() {
  223. let that = this;
  224. that.setData({
  225. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  226. })
  227. /**
  228. * couponNum 是否有普通的优惠券购买
  229. * couponNum2 是否有新买的消费卡
  230. */
  231. let num = wx.getStorageSync('couponNum');
  232. let num1 = wx.getStorageSync('couponNum2');
  233. if (num == 'couponNum' || num1 == 'couponNum2') {
  234. wx.showTabBarRedDot({
  235. index: 3
  236. })
  237. } else {
  238. wx.hideTabBarRedDot({
  239. index: 3
  240. })
  241. }
  242. if (app.globalData.score) {
  243. that.setData({
  244. fistLogin: app.globalData.score
  245. })
  246. }
  247. // 如果有游戏
  248. setTimeout(function() {
  249. that.alphaClick();
  250. }, 8000)
  251. },
  252. // 会员码获取
  253. getmemberId: function(token) {
  254. let that = this;
  255. Http.get({
  256. url: config.api.getScore,
  257. data: {
  258. token: token
  259. }
  260. }).then(res => {
  261. that.setData({
  262. levelName: res.data.levelName,
  263. upgradePercent: res.data.upgradePercent,
  264. upgradeScore: res.data.upgradeScore,
  265. credit: res.data.credit ? res.data.credit : 0,
  266. score: res.data.score
  267. })
  268. if (res.data.nickName) {
  269. that.setData({
  270. ismember: true,
  271. memberId: res.data.id
  272. })
  273. var initUrl = JSON.stringify({
  274. flagid: res.data.id
  275. });
  276. }
  277. })
  278. .catch(err => {
  279. wx.showModal({
  280. title: '提示',
  281. content: err.message,
  282. showCancel: false
  283. })
  284. })
  285. },
  286. gotoChengzhangzhi: function() {
  287. wx.navigateTo({
  288. url: '/pages/czdetail/czdetail',
  289. })
  290. },
  291. /**
  292. *
  293. * @param {code,page}
  294. * 子组件向父组件传值
  295. */
  296. onGetCode: function(e) {
  297. this.setData({
  298. code: e.detail.val,
  299. page: e.detail.pageNum,
  300. });
  301. console.log(e.detail.val)
  302. console.log(e.detail.pageNum)
  303. },
  304. onBargain: function(e) {
  305. console.log(e)
  306. },
  307. /**
  308. * 用户登录
  309. */
  310. userLogin: function(couponChannelId, couponId, orderId) {
  311. var that = this;
  312. // 登录
  313. that.getmemberId(app.globalData.token);
  314. // that.checkUserCarStatus();
  315. that.getUserInfo();
  316. that.getBannerlist();
  317. that.topicShow();
  318. that.getMallInfo(app.globalData.token);
  319. if (app.couponChannelListCallback) {
  320. app.couponChannelListCallback(app.globalData.token);
  321. }
  322. if (app.couponListCallback) {
  323. app.couponListCallback(app.globalData.token);
  324. }
  325. if (app.businessListCallback) {
  326. app.businessListCallback(app.globalData.token);
  327. }
  328. Http.get({
  329. url: config.api.getWeapNote,
  330. data: {
  331. appId: config.weapp.AppId,
  332. }
  333. })
  334. .then(res => {
  335. that.getGameOne(app.globalData.token)
  336. that.getStaticGame(app.globalData.token)
  337. let weapNote = JSON.parse(res.data.weapNote);
  338. that.setData({
  339. desc: weapNote.firstpage.desc,
  340. title: weapNote.firstpage.title
  341. })
  342. })
  343. .catch(err => {
  344. that.getGameOne(app.globalData.token)
  345. that.getStaticGame(app.globalData.token)
  346. wx.showModal({
  347. title: "提示",
  348. content: err.errMsg,
  349. showCancel: false
  350. });
  351. });
  352. },
  353. getStaticGame(token) {
  354. let _this = this;
  355. Http.get({
  356. url: config.api.getGame,
  357. data: {
  358. triggleAction: 2, // 固定入口
  359. token: token
  360. }
  361. }).then(res => {
  362. if (res.data.id) {
  363. _this.setData({
  364. showIf: true,
  365. newUrl: res.data.imgUrl
  366. })
  367. } else {
  368. _this.setData({
  369. showIf: false
  370. })
  371. }
  372. _this.setData({
  373. staticGamedata: res.data
  374. })
  375. })
  376. .catch(err => {
  377. _this.setData({
  378. showIf: false
  379. })
  380. console.log(err)
  381. })
  382. },
  383. getGameOne: function(token) {
  384. let _this = this;
  385. Http.get({
  386. url: config.api.getGame,
  387. data: {
  388. triggleAction: 1, // 登录触发
  389. token: token
  390. }
  391. }).then(res => {
  392. if (res.data.id) {
  393. _this.setData({
  394. showGame: true,
  395. })
  396. } else {
  397. _this.setData({
  398. showGame: false
  399. })
  400. }
  401. _this.setData({
  402. gamedata: res.data
  403. })
  404. })
  405. .catch(err => {
  406. _this.setData({
  407. showGame: false
  408. })
  409. this.alphaClick();
  410. })
  411. },
  412. /**
  413. * mallinfo
  414. */
  415. getMallInfo: function(token) {
  416. let that = this;
  417. Http.get({
  418. url: config.api.getMallInfo,
  419. data: {
  420. token: token,
  421. }
  422. }).then(res => {
  423. that.setData({
  424. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  425. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  426. });
  427. })
  428. .catch(err => {
  429. // 不需要错误提示
  430. });
  431. },
  432. /**
  433. * banner
  434. */
  435. getBannerlist: function() {
  436. let that = this;
  437. Http.get({
  438. url: config.api.bannerlist,
  439. data: {
  440. pageNum: 1,
  441. pageSize: 7
  442. }
  443. }).then(res => {
  444. // that.getmemberId(app.globalData.token);
  445. // that.checkUserCarStatus();
  446. that.setData({
  447. list: res.data.list
  448. });
  449. })
  450. .catch(err => {
  451. // that.getmemberId(app.globalData.token);
  452. // that.checkUserCarStatus();
  453. });
  454. },
  455. // 专题显示
  456. topicShow: function() {
  457. let that = this;
  458. Http.get({
  459. url: config.api.topicShow,
  460. data: {
  461. token: app.globalData.token
  462. }
  463. }).then(res => {
  464. if (res && res.data) {
  465. that.setData({
  466. cover: res.data.cover,
  467. id: res.data.id,
  468. showTopic: true
  469. })
  470. } else {
  471. that.setData({
  472. showTopic: false
  473. })
  474. }
  475. })
  476. .catch(err => {
  477. console.log(err);
  478. })
  479. },
  480. gotoTopic() {
  481. wx.navigateTo({
  482. url: `/pages/topicDetail/index?id=${this.data.id}`
  483. })
  484. },
  485. /**
  486. * 检查用户是否有车
  487. */
  488. // checkUserCarStatus: function() {
  489. // var that = this;
  490. // Http.get({
  491. // url: config.api.userCarCount,
  492. // data: {}
  493. // }).then(res => {
  494. // if (res.data > 0) {
  495. // // 用户名下有车
  496. // app.globalData.phone = res.data.phone;
  497. // app.globalData.supportCar = true;
  498. // // 共同登录
  499. // that.userCarLogin();
  500. // }
  501. // });
  502. // },
  503. /**
  504. * car共同登录
  505. */
  506. // userCarLogin: function() {
  507. // var that = this;
  508. // if (!app.globalData.carLogin) {
  509. // // 共同登录
  510. // Http.post({
  511. // url: config.api.carInit,
  512. // data: {
  513. // phone: app.globalData.phone
  514. // }
  515. // }).then(res => {
  516. // app.globalData.carLogin = true;
  517. // app.globalData.parkVendor = res.data.vendor;
  518. // if (res.data.token != "undefined") {
  519. // app.globalData.etcpToken = res.data.token;
  520. // }
  521. // });
  522. // }
  523. // },
  524. /**
  525. * 获取用户信息
  526. */
  527. getUserInfo: function() {
  528. // 获取用户信息
  529. wx.getSetting({
  530. success: res => {
  531. if (res.authSetting["scope.userInfo"]) {
  532. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  533. wx.getUserInfo({
  534. success: res => {
  535. // 可以将 res 发送给后台解码出 unionId
  536. }
  537. });
  538. }
  539. }
  540. });
  541. },
  542. gotoBargain: function() {
  543. wx.navigateTo({
  544. url: '/pages/bargain/bargain'
  545. })
  546. },
  547. /**
  548. * 刷新
  549. */
  550. onPullDownRefresh: function(e) {
  551. let that = this;
  552. that.userLogin();
  553. that.setData({
  554. page: 1
  555. })
  556. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  557. this.userLogin(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  558. } else {
  559. this.userLogin()
  560. }
  561. if (that.data.code == 0 || that.data.code == undefined) {
  562. that.selectComponent("#lists").getList(0, 1, "refresh");
  563. wx.stopPullDownRefresh();
  564. } else {
  565. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  566. wx.stopPullDownRefresh();
  567. };
  568. // 砍价下拉刷新
  569. that.selectComponent("#bargain").getList();
  570. that.selectComponent("#spellGroup").getList();
  571. that.selectComponent("#rushtobyCard").getList();
  572. wx.stopPullDownRefresh();
  573. },
  574. //加载更多
  575. onReachBottom: function() {
  576. let that = this;
  577. that.data.page++;
  578. that.setData({
  579. page: that.data.page
  580. });
  581. console.log("加载更多页数" + that.data.page);
  582. console.log("加载更多key" + that.data.code);
  583. //父组件获得子组件的方法
  584. //如果code == 0
  585. if (that.data.code == 0 || that.data.code == undefined) {
  586. that.selectComponent("#lists").getList(0, that.data.page);
  587. } else {
  588. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  589. }
  590. },
  591. // 用户点击右上角分享
  592. onShareAppMessage: function() {
  593. return {
  594. title: this.data.weappShareTitle,
  595. imageUrl: this.data.weappShareCoverImg,
  596. // desc: this.data.desc,
  597. success: function(res) {
  598. wx.showToast({
  599. title: "分享成功",
  600. duration: 1000,
  601. icon: "success"
  602. });
  603. }
  604. };
  605. }
  606. });