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

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