C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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