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.

657 lines
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. giftHr: imgurl.giftHr.url,
  22. giftHr: imgurl.giftHr.url,
  23. next: imgurl.next.url,
  24. usergift: imgurl.usergift.url,
  25. guanbi1: imgurl.guanbi1.url,
  26. icon0001: imgurl.icon0001.url,
  27. icon0002: imgurl.icon0002.url,
  28. icon0003: imgurl.icon0003.url,
  29. icon0004: imgurl.icon0004.url,
  30. icon0005: imgurl.icon0005.url,
  31. icon0006: imgurl.icon0006.url,
  32. icon0007: imgurl.icon0007.url,
  33. icon0008: imgurl.icon0008.url,
  34. barcode: imgurl.barcode.url,
  35. leftarrows: imgurl.leftarrows.url,
  36. newcard: imgurl.newcard.url,
  37. newseckill: imgurl.newseckill.url,
  38. newbargain: imgurl.newbargain.url,
  39. newgroup: imgurl.newgroup.url,
  40. product: imgurl.product.url,
  41. barginicon: imgurl.barginicon.url,
  42. pintuan: imgurl.pintuan.url,
  43. duihuan: imgurl.duihuan.url,
  44. market: app.globalData.market,
  45. list: [],
  46. xslist:[],
  47. loading: true,
  48. fistLogin: null,
  49. alphaData: null,
  50. swiperCurrent: 0,
  51. title: null,
  52. weappShareTitle: '', //分享标题
  53. weappShareCoverImg: '', //分享图片
  54. desc: null,
  55. scrollTop: 0,
  56. showGame: false,
  57. showTopic: false,
  58. gamedata: {},
  59. couponId: '', //游戏返回时传回的字段
  60. played: false, //从游戏页面跳回首页返回true
  61. havePlayEd: app.globalData.havePlayEd,
  62. staticGamedata: {},
  63. showIf: false,
  64. showPages: false,
  65. display: 'none',
  66. display1: 'none',
  67. optionsData: null,
  68. credit: 0,
  69. score: '0',
  70. page: 1 ,// 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  71. // Ttitle:'',
  72. // xstitle:null,
  73. // priceStr:null,
  74. // salePriceStr:null,
  75. },
  76. close: function() {
  77. this.setData({
  78. showIf: false
  79. })
  80. },
  81. alphaClick: function(even) {
  82. var animation = wx.createAnimation({})
  83. animation.opacity(0).step({
  84. duration: 2000
  85. })
  86. this.setData({
  87. alphaData: animation.export()
  88. })
  89. },
  90. // 我的卡包
  91. mycard: function() {
  92. wx.navigateTo({
  93. url: '/pages/cardorder/index/index',
  94. })
  95. },
  96. //我的券包
  97. mycoupon: function() {
  98. wx.navigateTo({
  99. url: '/pages/couponorder/index/index',
  100. })
  101. },
  102. gotoSpellGroup: function() {
  103. wx.navigateTo({
  104. url: '/pages/spellGroup/spellGroup',
  105. })
  106. },
  107. qrcode: function() {
  108. var that = this;
  109. let memberId = that.data.memberId;
  110. if (memberId) {
  111. wx.navigateTo({
  112. url: '/pages/specialcourtesy/specialcourtesy'
  113. })
  114. }
  115. },
  116. // hideQrcode: function() {
  117. // let that = this;
  118. // that.setData({
  119. // showQrcode: false
  120. // })
  121. // },
  122. //跳往限时秒杀
  123. gotoRushBuy: function() {
  124. wx.navigateTo({
  125. url: '/pages/rushToBuy/index',
  126. })
  127. },
  128. //搜索门店
  129. // searchbar:function(){
  130. // wx.switchTab({
  131. // url: '/pages/index/searchbar/index',
  132. // })
  133. // },
  134. // createQrCode: function(url, canvasId, cavW, cavH) {
  135. // //调用插件中的draw方法,绘制二维码图片
  136. // QR.api.draw(url, canvasId, cavW, cavH);
  137. // },
  138. swiperChange: function(e) {
  139. this.setData({
  140. swiperCurrent: e.detail.current
  141. });
  142. },
  143. gotogame: function() {
  144. let that = this;
  145. Http.get({
  146. url: config.api.checkPhoneStatus,
  147. data: {}
  148. })
  149. .then(res => {
  150. var data = {
  151. couponChannelId: "" + that.data.couponChannelId,
  152. couponId: "" + that.data.couponId
  153. };
  154. if (that.data.couponChannelId == null) {
  155. var data = {
  156. couponId: "" + that.data.couponId
  157. };
  158. }
  159. wx.navigateTo({
  160. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  161. })
  162. })
  163. .catch(err => {
  164. if (err.code == 11005) {
  165. // 用户手机未授权
  166. /**
  167. * 将值传到用户手机号授权的页面
  168. *
  169. */
  170. wx.redirectTo({
  171. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  172. });
  173. } else if (err.code == 11006) {
  174. // 用户手机已加密
  175. wx.redirectTo({
  176. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  177. });
  178. } else {
  179. wx.showToast({
  180. title: err.message,
  181. icon: 'none',
  182. duration: 2000,
  183. mask: false
  184. });
  185. }
  186. })
  187. },
  188. mySpecial: function() {
  189. console.log("special");
  190. wx.navigateTo({
  191. url: '/pages/specialcourtesy/specialcourtesy',
  192. })
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onLoad: function(options) {
  198. let that = this;
  199. let optionss;
  200. if (wx.getStorageSync('options')){
  201. optionss = JSON.parse(wx.getStorageSync('options'));
  202. }
  203. if (options.played == "true") {
  204. that.setData({
  205. played: true
  206. })
  207. }
  208. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  209. that.setData({
  210. optionsData: optionss
  211. })
  212. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  213. } else {
  214. that.getWeapNote()
  215. }
  216. //获取条形码
  217. // util.barcode("barcode", optionss.quancode, 510, 100);
  218. },
  219. onShow: function() {
  220. let that = this;
  221. that.setData({
  222. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  223. })
  224. /**
  225. * couponNum 是否有普通的优惠券购买
  226. * couponNum2 是否有新买的消费卡
  227. */
  228. let num = wx.getStorageSync('couponNum');
  229. let num1 = wx.getStorageSync('couponNum2');
  230. if (num == 'couponNum' || num1 == 'couponNum2') {
  231. wx.showTabBarRedDot({
  232. index: 3
  233. })
  234. } else {
  235. wx.hideTabBarRedDot({
  236. index: 3
  237. })
  238. }
  239. if (app.globalData.score) {
  240. that.setData({
  241. fistLogin: app.globalData.score
  242. })
  243. }
  244. // 如果有游戏
  245. setTimeout(function() {
  246. that.alphaClick();
  247. }, 8000)
  248. },
  249. getmemberId: function(token) {
  250. let that = this;
  251. Http.get({
  252. url: config.api.getScore,
  253. data: {
  254. token: token
  255. }
  256. }).then(res => {
  257. that.setData({
  258. levelName: res.data.levelName,
  259. upgradePercent: res.data.upgradePercent,
  260. upgradeScore: res.data.upgradeScore,
  261. credit: res.data.credit ? res.data.credit : 0,
  262. score: res.data.score
  263. })
  264. if (res.data.nickName) {
  265. that.setData({
  266. ismember: true,
  267. memberId: res.data.id
  268. })
  269. var initUrl = JSON.stringify({
  270. flagid: res.data.id
  271. });
  272. }
  273. })
  274. .catch(err => {
  275. wx.showModal({
  276. title: '提示',
  277. content: err.message,
  278. showCancel: false
  279. })
  280. })
  281. },
  282. gotoChengzhangzhi: function() {
  283. wx.navigateTo({
  284. url: '/pages/czdetail/czdetail',
  285. })
  286. },
  287. gotoBargain: function () {
  288. wx.navigateTo({
  289. url: '/pages/bargain/bargain',
  290. })
  291. },
  292. gotoSpellGroup: function () {
  293. wx.navigateTo({
  294. url: '/pages/spellGroup/spellGroup',
  295. })
  296. },
  297. gotoCard: function () {
  298. wx.navigateTo({
  299. url: '/pages/discountCardList/discountCardList',
  300. })
  301. },
  302. gotoGame: function () {
  303. wx.navigateTo({
  304. url: '/pages/game/index',
  305. })
  306. },
  307. gotoJfsc: function () {
  308. wx.navigateTo({
  309. url: '/pages/integralmall/index',
  310. })
  311. },
  312. /**
  313. *
  314. * @param {code,page}
  315. * 子组件向父组件传值
  316. */
  317. onGetCode: function(e) {
  318. this.setData({
  319. code: e.detail.val,
  320. page: e.detail.pageNum,
  321. });
  322. console.log(e.detail.val)
  323. console.log(e.detail.pageNum)
  324. },
  325. getWeapNote: function(couponChannelId, couponId, orderId) {
  326. var that = this;
  327. // 登录
  328. that.getmemberId(app.globalData.token);
  329. that.getBannerlist();
  330. that.topicShow();
  331. that.getxsList();
  332. that.getMallInfo(app.globalData.token);
  333. if (app.couponChannelListCallback) {
  334. app.couponChannelListCallback(app.globalData.token);
  335. }
  336. if (app.couponListCallback) {
  337. app.couponListCallback(app.globalData.token);
  338. }
  339. if (app.businessListCallback) {
  340. app.businessListCallback(app.globalData.token);
  341. }
  342. Http.get({
  343. url: config.api.getWeapNote,
  344. data: {
  345. appId: config.weapp.AppId,
  346. }
  347. })
  348. .then(res => {
  349. that.getGameOne(app.globalData.token)
  350. that.getStaticGame(app.globalData.token)
  351. let weapNote = JSON.parse(res.data.weapNote);
  352. that.setData({
  353. desc: weapNote.firstpage.desc,
  354. title: weapNote.firstpage.title
  355. })
  356. })
  357. .catch(err => {
  358. that.getGameOne(app.globalData.token)
  359. that.getStaticGame(app.globalData.token)
  360. wx.showModal({
  361. title: "提示",
  362. content: err.errMsg,
  363. showCancel: false
  364. });
  365. });
  366. },
  367. getStaticGame(token) {
  368. let _this = this;
  369. Http.get({
  370. url: config.api.getGame,
  371. data: {
  372. triggleAction: 2, // 固定入口
  373. token: token
  374. }
  375. }).then(res => {
  376. if (res.data.id) {
  377. _this.setData({
  378. showIf: true,
  379. newUrl: res.data.imgUrl
  380. })
  381. } else {
  382. _this.setData({
  383. showIf: false
  384. })
  385. }
  386. _this.setData({
  387. staticGamedata: res.data
  388. })
  389. })
  390. .catch(err => {
  391. _this.setData({
  392. showIf: false
  393. })
  394. console.log(err)
  395. })
  396. },
  397. getGameOne: function(token) {
  398. let _this = this;
  399. Http.get({
  400. url: config.api.getGame,
  401. data: {
  402. triggleAction: 1, // 登录触发
  403. token: token
  404. }
  405. }).then(res => {
  406. if (res.data.id) {
  407. _this.setData({
  408. showGame: true,
  409. })
  410. } else {
  411. _this.setData({
  412. showGame: false
  413. })
  414. }
  415. _this.setData({
  416. gamedata: res.data
  417. })
  418. })
  419. .catch(err => {
  420. _this.setData({
  421. showGame: false
  422. })
  423. this.alphaClick();
  424. })
  425. },
  426. /**
  427. * mallinfo
  428. */
  429. getMallInfo: function(token) {
  430. let that = this;
  431. Http.get({
  432. url: config.api.getMallInfo,
  433. data: {
  434. token: token,
  435. }
  436. }).then(res => {
  437. that.setData({
  438. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  439. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  440. });
  441. })
  442. .catch(err => {
  443. // 不需要错误提示
  444. });
  445. },
  446. //获取限时抢购列表
  447. getxsList(){
  448. let that = this;
  449. Http.get({
  450. url: config.api.couponChannelList,
  451. data: {
  452. pageNum: 1,
  453. pageSize: 3,
  454. targetAd: 2
  455. }
  456. }).then(res => {
  457. if (res && res.data) {
  458. that.setData({
  459. xslist: res.data.list,
  460. });
  461. }
  462. })
  463. .catch(err => {
  464. console.log(err)
  465. wx.showToast({
  466. title: err.errMsg,
  467. icon: 'none',
  468. duration: 2000,
  469. mask: false
  470. });
  471. })
  472. },
  473. /**
  474. * banner
  475. */
  476. getBannerlist: function() {
  477. let that = this;
  478. Http.get({
  479. url: config.api.bannerlist,
  480. data: {
  481. pageNum: 1,
  482. pageSize: 7
  483. }
  484. }).then(res => {
  485. // that.getmemberId(app.globalData.token);
  486. // that.checkUserCarStatus();
  487. that.setData({
  488. list: res.data.list
  489. });
  490. })
  491. .catch(err => {
  492. // that.getmemberId(app.globalData.token);
  493. // that.checkUserCarStatus();
  494. });
  495. },
  496. // 专题显示
  497. topicShow: function() {
  498. let that = this;
  499. Http.get({
  500. url: config.api.topicShow,
  501. data: {
  502. token: app.globalData.token
  503. }
  504. }).then(res => {
  505. if (res && res.data) {
  506. that.setData({
  507. name: res.data.name,
  508. cover: res.data.cover,
  509. Ttitle: 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. });