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.

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