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

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