C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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