C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

614 行
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;
  206. if (wx.getStorageSync('options')){
  207. optionss = JSON.parse(wx.getStorageSync('options'));
  208. }
  209. if (options.played == "true") {
  210. that.setData({
  211. played: true
  212. })
  213. }
  214. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  215. that.setData({
  216. optionsData: optionss
  217. })
  218. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  219. } else {
  220. that.getWeapNote()
  221. }
  222. //获取条形码
  223. // util.barcode("barcode", optionss.quancode, 510, 100);
  224. },
  225. onShow: function() {
  226. let that = this;
  227. that.setData({
  228. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  229. })
  230. /**
  231. * couponNum 是否有普通的优惠券购买
  232. * couponNum2 是否有新买的消费卡
  233. */
  234. let num = wx.getStorageSync('couponNum');
  235. let num1 = wx.getStorageSync('couponNum2');
  236. if (num == 'couponNum' || num1 == 'couponNum2') {
  237. wx.showTabBarRedDot({
  238. index: 3
  239. })
  240. } else {
  241. wx.hideTabBarRedDot({
  242. index: 3
  243. })
  244. }
  245. if (app.globalData.score) {
  246. that.setData({
  247. fistLogin: app.globalData.score
  248. })
  249. }
  250. // 如果有游戏
  251. setTimeout(function() {
  252. that.alphaClick();
  253. }, 8000)
  254. },
  255. getmemberId: function(token) {
  256. let that = this;
  257. Http.get({
  258. url: config.api.getScore,
  259. data: {
  260. token: token
  261. }
  262. }).then(res => {
  263. that.setData({
  264. levelName: res.data.levelName,
  265. upgradePercent: res.data.upgradePercent,
  266. upgradeScore: res.data.upgradeScore,
  267. credit: res.data.credit ? res.data.credit : 0,
  268. score: res.data.score
  269. })
  270. if (res.data && res.data.score) {
  271. if (res.data.score != 0) {
  272. app.globalData.score = res.data.score;
  273. }
  274. }
  275. if (res.data.nickName) {
  276. that.setData({
  277. ismember: true,
  278. memberId: res.data.id
  279. })
  280. var initUrl = JSON.stringify({
  281. flagid: res.data.id
  282. });
  283. }
  284. })
  285. .catch(err => {
  286. wx.showModal({
  287. title: '提示',
  288. content: err.message,
  289. showCancel: false
  290. })
  291. })
  292. },
  293. gotoChengzhangzhi: function() {
  294. wx.navigateTo({
  295. url: '/pages/czdetail/czdetail',
  296. })
  297. },
  298. /**
  299. *
  300. * @param {code,page}
  301. * 子组件向父组件传值
  302. */
  303. onGetCode: function(e) {
  304. this.setData({
  305. code: e.detail.val,
  306. page: e.detail.pageNum,
  307. });
  308. console.log(e.detail.val)
  309. console.log(e.detail.pageNum)
  310. },
  311. onBargain: function(e) {
  312. console.log(e)
  313. },
  314. getWeapNote: function(couponChannelId, couponId, orderId) {
  315. var that = this;
  316. // 登录
  317. that.getmemberId(app.globalData.token);
  318. that.getBannerlist();
  319. that.topicShow();
  320. that.getMallInfo(app.globalData.token);
  321. if (app.couponChannelListCallback) {
  322. app.couponChannelListCallback(app.globalData.token);
  323. }
  324. if (app.couponListCallback) {
  325. app.couponListCallback(app.globalData.token);
  326. }
  327. if (app.businessListCallback) {
  328. app.businessListCallback(app.globalData.token);
  329. }
  330. Http.get({
  331. url: config.api.getWeapNote,
  332. data: {
  333. appId: config.weapp.AppId,
  334. }
  335. })
  336. .then(res => {
  337. that.getGameOne(app.globalData.token)
  338. that.getStaticGame(app.globalData.token)
  339. let weapNote = JSON.parse(res.data.weapNote);
  340. that.setData({
  341. desc: weapNote.firstpage.desc,
  342. title: weapNote.firstpage.title
  343. })
  344. })
  345. .catch(err => {
  346. that.getGameOne(app.globalData.token)
  347. that.getStaticGame(app.globalData.token)
  348. wx.showModal({
  349. title: "提示",
  350. content: err.errMsg,
  351. showCancel: false
  352. });
  353. });
  354. },
  355. getStaticGame(token) {
  356. let _this = this;
  357. Http.get({
  358. url: config.api.getGame,
  359. data: {
  360. triggleAction: 2, // 固定入口
  361. token: token
  362. }
  363. }).then(res => {
  364. if (res.data.id) {
  365. _this.setData({
  366. showIf: true,
  367. newUrl: res.data.imgUrl
  368. })
  369. } else {
  370. _this.setData({
  371. showIf: false
  372. })
  373. }
  374. _this.setData({
  375. staticGamedata: res.data
  376. })
  377. })
  378. .catch(err => {
  379. _this.setData({
  380. showIf: false
  381. })
  382. console.log(err)
  383. })
  384. },
  385. getGameOne: function(token) {
  386. let _this = this;
  387. Http.get({
  388. url: config.api.getGame,
  389. data: {
  390. triggleAction: 1, // 登录触发
  391. token: token
  392. }
  393. }).then(res => {
  394. if (res.data.id) {
  395. _this.setData({
  396. showGame: true,
  397. })
  398. } else {
  399. _this.setData({
  400. showGame: false
  401. })
  402. }
  403. _this.setData({
  404. gamedata: res.data
  405. })
  406. })
  407. .catch(err => {
  408. _this.setData({
  409. showGame: false
  410. })
  411. this.alphaClick();
  412. })
  413. },
  414. /**
  415. * mallinfo
  416. */
  417. getMallInfo: function(token) {
  418. let that = this;
  419. Http.get({
  420. url: config.api.getMallInfo,
  421. data: {
  422. token: token,
  423. }
  424. }).then(res => {
  425. that.setData({
  426. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  427. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  428. });
  429. })
  430. .catch(err => {
  431. // 不需要错误提示
  432. });
  433. },
  434. /**
  435. * banner
  436. */
  437. getBannerlist: function() {
  438. let that = this;
  439. Http.get({
  440. url: config.api.bannerlist,
  441. data: {
  442. pageNum: 1,
  443. pageSize: 7
  444. }
  445. }).then(res => {
  446. // that.getmemberId(app.globalData.token);
  447. // that.checkUserCarStatus();
  448. that.setData({
  449. list: res.data.list
  450. });
  451. })
  452. .catch(err => {
  453. // that.getmemberId(app.globalData.token);
  454. // that.checkUserCarStatus();
  455. });
  456. },
  457. // 专题显示
  458. topicShow: function() {
  459. let that = this;
  460. Http.get({
  461. url: config.api.topicShow,
  462. data: {
  463. token: app.globalData.token
  464. }
  465. }).then(res => {
  466. if (res && res.data) {
  467. that.setData({
  468. cover: res.data.cover,
  469. id: res.data.id,
  470. showTopic: true
  471. })
  472. } else {
  473. that.setData({
  474. showTopic: false
  475. })
  476. }
  477. })
  478. .catch(err => {
  479. console.log(err);
  480. })
  481. },
  482. gotoTopic() {
  483. wx.navigateTo({
  484. url: `/pages/topicDetail/index?id=${this.data.id}`
  485. })
  486. },
  487. /**
  488. * 检查用户是否有车
  489. */
  490. // checkUserCarStatus: function() {
  491. // var that = this;
  492. // Http.get({
  493. // url: config.api.userCarCount,
  494. // data: {}
  495. // }).then(res => {
  496. // if (res.data > 0) {
  497. // // 用户名下有车
  498. // app.globalData.phone = res.data.phone;
  499. // app.globalData.supportCar = true;
  500. // // 共同登录
  501. // that.userCarLogin();
  502. // }
  503. // });
  504. // },
  505. /**
  506. * car共同登录
  507. */
  508. // userCarLogin: function() {
  509. // var that = this;
  510. // if (!app.globalData.carLogin) {
  511. // // 共同登录
  512. // Http.post({
  513. // url: config.api.carInit,
  514. // data: {
  515. // phone: app.globalData.phone
  516. // }
  517. // }).then(res => {
  518. // app.globalData.carLogin = true;
  519. // app.globalData.parkVendor = res.data.vendor;
  520. // if (res.data.token != "undefined") {
  521. // app.globalData.etcpToken = res.data.token;
  522. // }
  523. // });
  524. // }
  525. // },
  526. /**
  527. * 获取用户信息
  528. */
  529. // getUserInfo: function() {
  530. // // 获取用户信息
  531. // wx.getSetting({
  532. // success: res => {
  533. // if (res.authSetting["scope.userInfo"]) {
  534. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  535. // wx.getUserInfo({
  536. // success: res => {
  537. // // 可以将 res 发送给后台解码出 unionId
  538. // }
  539. // });
  540. // }
  541. // }
  542. // });
  543. // },
  544. gotoBargain: function() {
  545. wx.navigateTo({
  546. url: '/pages/bargain/bargain'
  547. })
  548. },
  549. /**
  550. * 刷新
  551. */
  552. onPullDownRefresh: function(e) {
  553. let that = this;
  554. that.getWeapNote();
  555. that.setData({
  556. page: 1
  557. })
  558. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  559. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  560. } else {
  561. this.getWeapNote()
  562. }
  563. if (that.data.code == 0 || that.data.code == undefined) {
  564. that.selectComponent("#lists").getList(0, 1, "refresh");
  565. wx.stopPullDownRefresh();
  566. } else {
  567. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  568. wx.stopPullDownRefresh();
  569. };
  570. // 砍价下拉刷新
  571. that.selectComponent("#bargain").getList();
  572. that.selectComponent("#spellGroup").getList();
  573. that.selectComponent("#rushtobyCard").getList();
  574. wx.stopPullDownRefresh();
  575. },
  576. //加载更多
  577. onReachBottom: function() {
  578. let that = this;
  579. that.data.page++;
  580. that.setData({
  581. page: that.data.page
  582. });
  583. console.log("加载更多页数" + that.data.page);
  584. console.log("加载更多key" + that.data.code);
  585. //父组件获得子组件的方法
  586. //如果code == 0
  587. if (that.data.code == 0 || that.data.code == undefined) {
  588. that.selectComponent("#lists").getList(0, that.data.page);
  589. } else {
  590. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  591. }
  592. },
  593. // 用户点击右上角分享
  594. onShareAppMessage: function() {
  595. return {
  596. title: this.data.weappShareTitle,
  597. imageUrl: this.data.weappShareCoverImg,
  598. // desc: this.data.desc,
  599. success: function(res) {
  600. wx.showToast({
  601. title: "分享成功",
  602. duration: 1000,
  603. icon: "success"
  604. });
  605. }
  606. };
  607. }
  608. });