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.

613 rivejä
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. // 登录
  316. that.getmemberId(app.globalData.token);
  317. // that.checkUserCarStatus();
  318. that.getUserInfo();
  319. that.getBannerlist();
  320. that.topicShow();
  321. that.getMallInfo(app.globalData.token);
  322. if (app.couponChannelListCallback) {
  323. app.couponChannelListCallback(app.globalData.token);
  324. }
  325. if (app.couponListCallback) {
  326. app.couponListCallback(app.globalData.token);
  327. }
  328. if (app.businessListCallback) {
  329. app.businessListCallback(app.globalData.token);
  330. }
  331. Http.get({
  332. url: config.api.getWeapNote,
  333. data: {
  334. appId: config.weapp.AppId,
  335. }
  336. })
  337. .then(res => {
  338. that.getGameOne(app.globalData.token)
  339. that.getStaticGame(app.globalData.token)
  340. let weapNote = JSON.parse(res.data.weapNote);
  341. that.setData({
  342. desc: weapNote.firstpage.desc,
  343. title: weapNote.firstpage.title
  344. })
  345. })
  346. .catch(err => {
  347. that.getGameOne(app.globalData.token)
  348. that.getStaticGame(app.globalData.token)
  349. wx.showModal({
  350. title: "提示",
  351. content: err.errMsg,
  352. showCancel: false
  353. });
  354. });
  355. },
  356. getStaticGame(token) {
  357. let _this = this;
  358. Http.get({
  359. url: config.api.getGame,
  360. data: {
  361. triggleAction: 2, // 固定入口
  362. token: token
  363. }
  364. }).then(res => {
  365. if (res.data.id) {
  366. _this.setData({
  367. showIf: true,
  368. newUrl: res.data.imgUrl
  369. })
  370. } else {
  371. _this.setData({
  372. showIf: false
  373. })
  374. }
  375. _this.setData({
  376. staticGamedata: res.data
  377. })
  378. })
  379. .catch(err => {
  380. _this.setData({
  381. showIf: false
  382. })
  383. console.log(err)
  384. })
  385. },
  386. getGameOne: function(token) {
  387. let _this = this;
  388. Http.get({
  389. url: config.api.getGame,
  390. data: {
  391. triggleAction: 1, // 登录触发
  392. token: token
  393. }
  394. }).then(res => {
  395. if (res.data.id) {
  396. _this.setData({
  397. showGame: true,
  398. })
  399. } else {
  400. _this.setData({
  401. showGame: false
  402. })
  403. }
  404. _this.setData({
  405. gamedata: res.data
  406. })
  407. })
  408. .catch(err => {
  409. _this.setData({
  410. showGame: false
  411. })
  412. this.alphaClick();
  413. })
  414. },
  415. /**
  416. * mallinfo
  417. */
  418. getMallInfo: function(token) {
  419. let that = this;
  420. Http.get({
  421. url: config.api.getMallInfo,
  422. data: {
  423. token: token,
  424. }
  425. }).then(res => {
  426. that.setData({
  427. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  428. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  429. });
  430. })
  431. .catch(err => {
  432. // 不需要错误提示
  433. });
  434. },
  435. /**
  436. * banner
  437. */
  438. getBannerlist: function() {
  439. let that = this;
  440. Http.get({
  441. url: config.api.bannerlist,
  442. data: {
  443. pageNum: 1,
  444. pageSize: 7
  445. }
  446. }).then(res => {
  447. // that.getmemberId(app.globalData.token);
  448. // that.checkUserCarStatus();
  449. that.setData({
  450. list: res.data.list
  451. });
  452. })
  453. .catch(err => {
  454. // that.getmemberId(app.globalData.token);
  455. // that.checkUserCarStatus();
  456. });
  457. },
  458. // 专题显示
  459. topicShow: function() {
  460. let that = this;
  461. Http.get({
  462. url: config.api.topicShow,
  463. data: {
  464. token: app.globalData.token
  465. }
  466. }).then(res => {
  467. if (res && res.data) {
  468. that.setData({
  469. cover: res.data.cover,
  470. id: res.data.id,
  471. showTopic: true
  472. })
  473. } else {
  474. that.setData({
  475. showTopic: false
  476. })
  477. }
  478. })
  479. .catch(err => {
  480. console.log(err);
  481. })
  482. },
  483. gotoTopic() {
  484. wx.navigateTo({
  485. url: `/pages/topicDetail/index?id=${this.data.id}`
  486. })
  487. },
  488. /**
  489. * 检查用户是否有车
  490. */
  491. // checkUserCarStatus: function() {
  492. // var that = this;
  493. // Http.get({
  494. // url: config.api.userCarCount,
  495. // data: {}
  496. // }).then(res => {
  497. // if (res.data > 0) {
  498. // // 用户名下有车
  499. // app.globalData.phone = res.data.phone;
  500. // app.globalData.supportCar = true;
  501. // // 共同登录
  502. // that.userCarLogin();
  503. // }
  504. // });
  505. // },
  506. /**
  507. * car共同登录
  508. */
  509. // userCarLogin: function() {
  510. // var that = this;
  511. // if (!app.globalData.carLogin) {
  512. // // 共同登录
  513. // Http.post({
  514. // url: config.api.carInit,
  515. // data: {
  516. // phone: app.globalData.phone
  517. // }
  518. // }).then(res => {
  519. // app.globalData.carLogin = true;
  520. // app.globalData.parkVendor = res.data.vendor;
  521. // if (res.data.token != "undefined") {
  522. // app.globalData.etcpToken = res.data.token;
  523. // }
  524. // });
  525. // }
  526. // },
  527. /**
  528. * 获取用户信息
  529. */
  530. getUserInfo: function() {
  531. // 获取用户信息
  532. wx.getSetting({
  533. success: res => {
  534. if (res.authSetting["scope.userInfo"]) {
  535. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  536. wx.getUserInfo({
  537. success: res => {
  538. // 可以将 res 发送给后台解码出 unionId
  539. }
  540. });
  541. }
  542. }
  543. });
  544. },
  545. gotoBargain: function() {
  546. wx.navigateTo({
  547. url: '/pages/bargain/bargain'
  548. })
  549. },
  550. /**
  551. * 刷新
  552. */
  553. onPullDownRefresh: function(e) {
  554. let that = this;
  555. that.userLogin();
  556. that.setData({
  557. page: 1
  558. })
  559. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  560. this.userLogin(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  561. } else {
  562. this.userLogin()
  563. }
  564. if (that.data.code == 0 || that.data.code == undefined) {
  565. that.selectComponent("#lists").getList(0, 1, "refresh");
  566. wx.stopPullDownRefresh();
  567. } else {
  568. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  569. wx.stopPullDownRefresh();
  570. };
  571. // 砍价下拉刷新
  572. that.selectComponent("#bargain").getList();
  573. that.selectComponent("#spellGroup").getList();
  574. that.selectComponent("#rushtobyCard").getList();
  575. wx.stopPullDownRefresh();
  576. },
  577. //加载更多
  578. onReachBottom: function() {
  579. let that = this;
  580. that.data.page++;
  581. that.setData({
  582. page: that.data.page
  583. });
  584. console.log("加载更多页数" + that.data.page);
  585. console.log("加载更多key" + that.data.code);
  586. //父组件获得子组件的方法
  587. //如果code == 0
  588. if (that.data.code == 0 || that.data.code == undefined) {
  589. that.selectComponent("#lists").getList(0, that.data.page);
  590. } else {
  591. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  592. }
  593. },
  594. // 用户点击右上角分享
  595. onShareAppMessage: function() {
  596. return {
  597. title: this.data.weappShareTitle,
  598. imageUrl: this.data.weappShareCoverImg,
  599. // desc: this.data.desc,
  600. success: function(res) {
  601. wx.showToast({
  602. title: "分享成功",
  603. duration: 1000,
  604. icon: "success"
  605. });
  606. }
  607. };
  608. }
  609. });