C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

668 lines
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. Http.get({
  147. url: config.api.checkPhoneStatus,
  148. data: {}
  149. })
  150. .then(res => {
  151. var data = {
  152. couponChannelId: "" + that.data.couponChannelId,
  153. couponId: "" + that.data.couponId
  154. };
  155. if (that.data.couponChannelId == null) {
  156. var data = {
  157. couponId: "" + that.data.couponId
  158. };
  159. }
  160. wx.redirectTo({
  161. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  162. })
  163. })
  164. .catch(err => {
  165. if (err.code == 11005) {
  166. // 用户手机未授权
  167. /**
  168. * 将值传到用户手机号授权的页面
  169. *
  170. */
  171. wx.redirectTo({
  172. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  173. });
  174. } else if (err.code == 11006) {
  175. // 用户手机已加密
  176. wx.redirectTo({
  177. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  178. });
  179. } else {
  180. wx.showToast({
  181. title: err.message,
  182. icon: 'none',
  183. duration: 2000,
  184. mask: false
  185. });
  186. }
  187. })
  188. },
  189. mySpecial: function() {
  190. console.log("special");
  191. wx.navigateTo({
  192. url: '/pages/specialcourtesy/specialcourtesy',
  193. })
  194. },
  195. /**
  196. * 生命周期函数--监听页面初次渲染完成
  197. */
  198. onLoad: function(options) {
  199. let that = this;
  200. let optionss;
  201. if (wx.getStorageSync('options')){
  202. optionss = JSON.parse(wx.getStorageSync('options'));
  203. }
  204. if (options.played == "true") {
  205. that.setData({
  206. played: true
  207. })
  208. }
  209. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  210. that.setData({
  211. optionsData: optionss
  212. })
  213. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  214. } else {
  215. that.getWeapNote()
  216. }
  217. //获取条形码
  218. // util.barcode("barcode", optionss.quancode, 510, 100);
  219. },
  220. onShow: function() {
  221. let that = this;
  222. that.setData({
  223. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  224. })
  225. /**
  226. * couponNum 是否有普通的优惠券购买
  227. * couponNum2 是否有新买的消费卡
  228. */
  229. let num = wx.getStorageSync('couponNum');
  230. let num1 = wx.getStorageSync('couponNum2');
  231. if (num == 'couponNum' || num1 == 'couponNum2') {
  232. wx.showTabBarRedDot({
  233. index: 3
  234. })
  235. } else {
  236. wx.hideTabBarRedDot({
  237. index: 3
  238. })
  239. }
  240. if (app.globalData.score) {
  241. that.setData({
  242. fistLogin: app.globalData.score
  243. })
  244. }
  245. // 如果有游戏
  246. setTimeout(function() {
  247. that.alphaClick();
  248. }, 8000)
  249. },
  250. getmemberId: function(token) {
  251. let that = this;
  252. Http.get({
  253. url: config.api.getScore,
  254. data: {
  255. token: token
  256. }
  257. }).then(res => {
  258. that.setData({
  259. levelName: res.data.levelName,
  260. upgradePercent: res.data.upgradePercent,
  261. upgradeScore: res.data.upgradeScore,
  262. credit: res.data.credit ? res.data.credit : 0,
  263. score: res.data.score
  264. })
  265. if (res.data.nickName) {
  266. that.setData({
  267. ismember: true,
  268. memberId: res.data.id
  269. })
  270. var initUrl = JSON.stringify({
  271. flagid: res.data.id
  272. });
  273. }
  274. })
  275. .catch(err => {
  276. wx.showModal({
  277. title: '提示',
  278. content: err.message,
  279. showCancel: false
  280. })
  281. })
  282. },
  283. gotoChengzhangzhi: function() {
  284. wx.navigateTo({
  285. url: '/pages/czdetail/czdetail',
  286. })
  287. },
  288. gotoBargain: function () {
  289. wx.navigateTo({
  290. url: '/pages/bargain/bargain',
  291. })
  292. },
  293. gotoSpellGroup: function () {
  294. wx.navigateTo({
  295. url: '/pages/spellGroup/spellGroup',
  296. })
  297. },
  298. gotoCard: function () {
  299. wx.navigateTo({
  300. url: '/pages/discountCardList/discountCardList',
  301. })
  302. },
  303. gotoGame: function () {
  304. wx.navigateTo({
  305. url: '/pages/game/index',
  306. })
  307. },
  308. gotoJfsc: function () {
  309. wx.navigateTo({
  310. url: '/pages/integralmall/index',
  311. })
  312. },
  313. /**
  314. *
  315. * @param {code,page}
  316. * 子组件向父组件传值
  317. */
  318. onGetCode: function(e) {
  319. this.setData({
  320. code: e.detail.val,
  321. page: e.detail.pageNum,
  322. });
  323. console.log(e.detail.val)
  324. console.log(e.detail.pageNum)
  325. },
  326. getWeapNote: function(couponChannelId, couponId, orderId) {
  327. var that = this;
  328. // 登录
  329. that.getmemberId(app.globalData.token);
  330. that.getBannerlist();
  331. that.topicShow();
  332. that.getxsList();
  333. that.getMallInfo(app.globalData.token);
  334. if (app.couponChannelListCallback) {
  335. app.couponChannelListCallback(app.globalData.token);
  336. }
  337. if (app.couponListCallback) {
  338. app.couponListCallback(app.globalData.token);
  339. }
  340. if (app.businessListCallback) {
  341. app.businessListCallback(app.globalData.token);
  342. }
  343. Http.get({
  344. url: config.api.getWeapNote,
  345. data: {
  346. appId: config.weapp.AppId,
  347. }
  348. })
  349. .then(res => {
  350. that.getGameOne(app.globalData.token)
  351. that.getStaticGame(app.globalData.token)
  352. let weapNote = JSON.parse(res.data.weapNote);
  353. that.setData({
  354. desc: weapNote.firstpage.desc,
  355. title: weapNote.firstpage.title
  356. })
  357. })
  358. .catch(err => {
  359. that.getGameOne(app.globalData.token)
  360. that.getStaticGame(app.globalData.token)
  361. wx.showModal({
  362. title: "提示",
  363. content: err.errMsg,
  364. showCancel: false
  365. });
  366. });
  367. },
  368. getStaticGame(token) {
  369. let _this = this;
  370. Http.get({
  371. url: config.api.getGame,
  372. data: {
  373. triggleAction: 2, // 固定入口
  374. token: token
  375. }
  376. }).then(res => {
  377. if (res.data.id) {
  378. _this.setData({
  379. showIf: true,
  380. newUrl: res.data.imgUrl
  381. })
  382. } else {
  383. _this.setData({
  384. showIf: false
  385. })
  386. }
  387. _this.setData({
  388. staticGamedata: res.data
  389. })
  390. })
  391. .catch(err => {
  392. _this.setData({
  393. showIf: false
  394. })
  395. console.log(err)
  396. })
  397. },
  398. getGameOne: function(token) {
  399. let _this = this;
  400. Http.get({
  401. url: config.api.getGame,
  402. data: {
  403. triggleAction: 1, // 登录触发
  404. token: token
  405. }
  406. }).then(res => {
  407. if (res.data.id) {
  408. _this.setData({
  409. showGame: true,
  410. })
  411. } else {
  412. _this.setData({
  413. showGame: false
  414. })
  415. }
  416. _this.setData({
  417. gamedata: res.data
  418. })
  419. })
  420. .catch(err => {
  421. _this.setData({
  422. showGame: false
  423. })
  424. this.alphaClick();
  425. })
  426. },
  427. /**
  428. * mallinfo
  429. */
  430. getMallInfo: function(token) {
  431. let that = this;
  432. Http.get({
  433. url: config.api.getMallInfo,
  434. data: {
  435. token: token,
  436. }
  437. }).then(res => {
  438. that.setData({
  439. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  440. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  441. });
  442. })
  443. .catch(err => {
  444. // 不需要错误提示
  445. });
  446. },
  447. //获取限时抢购列表
  448. getxsList(){
  449. let that = this;
  450. Http.get({
  451. url: config.api.couponChannelList,
  452. data: {
  453. pageNum: 1,
  454. pageSize: 3,
  455. targetAd: 2
  456. }
  457. }).then(res => {
  458. if (res && res.data) {
  459. that.setData({
  460. xslist: res.data.list,
  461. showQg:true
  462. });
  463. }else{
  464. that.setData({
  465. showQg:false
  466. })
  467. }
  468. })
  469. .catch(err => {
  470. console.log(err)
  471. wx.showToast({
  472. title: err.errMsg,
  473. icon: 'none',
  474. duration: 2000,
  475. mask: false
  476. });
  477. })
  478. },
  479. /**
  480. * banner
  481. */
  482. getBannerlist: function() {
  483. let that = this;
  484. Http.get({
  485. url: config.api.bannerlist,
  486. data: {
  487. pageNum: 1,
  488. pageSize: 7
  489. }
  490. }).then(res => {
  491. // that.getmemberId(app.globalData.token);
  492. // that.checkUserCarStatus();
  493. that.setData({
  494. list: res.data.list
  495. });
  496. })
  497. .catch(err => {
  498. // that.getmemberId(app.globalData.token);
  499. // that.checkUserCarStatus();
  500. });
  501. },
  502. // 专题显示
  503. topicShow: function() {
  504. let that = this;
  505. Http.get({
  506. url: config.api.topicShow,
  507. data: {
  508. token: app.globalData.token
  509. }
  510. }).then(res => {
  511. if (res && res.data) {
  512. that.setData({
  513. name: res.data.name,
  514. cover: res.data.cover,
  515. topicTitle: 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. that.selectComponent("#hot").getChange();
  625. if(!that.kSize||!that.pSize){
  626. that.pSize = 0
  627. }
  628. },
  629. //加载更多
  630. onReachBottom: function() {
  631. let that = this;
  632. that.data.page++;
  633. that.setData({
  634. page: that.data.page
  635. });
  636. console.log("加载更多页数" + that.data.page);
  637. console.log("加载更多key" + that.data.code);
  638. //父组件获得子组件的方法
  639. //如果code == 0
  640. if (that.data.code == 0 || that.data.code == undefined) {
  641. that.selectComponent("#lists").getList(0, that.data.page);
  642. } else {
  643. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  644. }
  645. },
  646. // 用户点击右上角分享
  647. onShareAppMessage: function() {
  648. return {
  649. title: this.data.weappShareTitle,
  650. imageUrl: this.data.weappShareCoverImg,
  651. // desc: this.data.desc,
  652. success: function(res) {
  653. wx.showToast({
  654. title: "分享成功",
  655. duration: 1000,
  656. icon: "success"
  657. });
  658. }
  659. };
  660. }
  661. });