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

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