C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

751 rinda
19 KiB

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