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.

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