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.

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