C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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