C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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