C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

665 righe
17 KiB

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