C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

655 lines
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. score: res.data.score
  318. })
  319. if (res.data.nickName) {
  320. that.setData({
  321. ismember: true,
  322. memberId: res.data.id
  323. })
  324. var size = this.setCanvasSize();
  325. var initUrl = JSON.stringify({
  326. flagid: res.data.id
  327. });
  328. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  329. }
  330. })
  331. .catch(err => {
  332. wx.showModal({
  333. title: '提示',
  334. content: err.message,
  335. showCancel: false
  336. })
  337. })
  338. },
  339. /**
  340. *
  341. * @param {code,page}
  342. * 子组件向父组件传值
  343. */
  344. onGetCode: function(e) {
  345. this.setData({
  346. code: e.detail.val,
  347. page: e.detail.pageNum,
  348. });
  349. console.log(e.detail.val)
  350. console.log(e.detail.pageNum)
  351. },
  352. onBargain:function(e){
  353. console.log(e)
  354. },
  355. /**
  356. * 用户登录
  357. */
  358. userLogin: function(couponChannelId, couponId, orderId) {
  359. var that = this;
  360. // 登录
  361. that.getmemberId(app.globalData.token);
  362. // that.checkUserCarStatus();
  363. that.getUserInfo();
  364. that.getBannerlist();
  365. that.topicShow();
  366. that.getMallInfo(app.globalData.token);
  367. if (app.couponChannelListCallback) {
  368. app.couponChannelListCallback(app.globalData.token);
  369. }
  370. if (app.couponListCallback) {
  371. app.couponListCallback(app.globalData.token);
  372. }
  373. if (app.businessListCallback) {
  374. app.businessListCallback(app.globalData.token);
  375. }
  376. Http.get({
  377. url: config.api.getWeapNote,
  378. data: {
  379. appId: config.weapp.AppId,
  380. }
  381. })
  382. .then(res => {
  383. that.getGameOne(app.globalData.token)
  384. that.getStaticGame(app.globalData.token)
  385. let weapNote = JSON.parse(res.data.weapNote);
  386. that.setData({
  387. desc: weapNote.firstpage.desc,
  388. title: weapNote.firstpage.title
  389. })
  390. })
  391. .catch(err => {
  392. that.getGameOne(app.globalData.token)
  393. that.getStaticGame(app.globalData.token)
  394. wx.showModal({
  395. title: "提示",
  396. content: err.errMsg,
  397. showCancel: false
  398. });
  399. });
  400. },
  401. getStaticGame(token) {
  402. let _this = this;
  403. Http.get({
  404. url: config.api.getGame,
  405. data: {
  406. triggleAction: 2, // 固定入口
  407. token: token
  408. }
  409. }).then(res => {
  410. if (res.data.id) {
  411. _this.setData({
  412. showIf: true,
  413. newUrl: res.data.imgUrl
  414. })
  415. }else{
  416. _this.setData({
  417. showIf: false
  418. })
  419. }
  420. _this.setData({
  421. staticGamedata: res.data
  422. })
  423. })
  424. .catch(err => {
  425. _this.setData({
  426. showIf: false
  427. })
  428. console.log(err)
  429. })
  430. },
  431. getGameOne: function(token) {
  432. let _this = this;
  433. Http.get({
  434. url: config.api.getGame,
  435. data: {
  436. triggleAction: 1, // 登录触发
  437. token: token
  438. }
  439. }).then(res => {
  440. if (res.data.id) {
  441. _this.setData({
  442. showGame: true,
  443. })
  444. }else{
  445. _this.setData({
  446. showGame: false
  447. })
  448. }
  449. _this.setData({
  450. gamedata: res.data
  451. })
  452. })
  453. .catch(err => {
  454. _this.setData({
  455. showGame: false
  456. })
  457. this.alphaClick();
  458. })
  459. },
  460. /**
  461. * mallinfo
  462. */
  463. getMallInfo: function (token) {
  464. let that = this;
  465. Http.get({
  466. url: config.api.getMallInfo,
  467. data: {
  468. token: token,
  469. }
  470. }).then(res => {
  471. console.log(res.data+"eeee");
  472. that.setData({
  473. weappShareTitle: res.data.weappShareTitle,
  474. weappShareCoverImg: res.data.weappShareCoverImg,
  475. });
  476. })
  477. .catch(err => {
  478. })
  479. ;
  480. },
  481. /**
  482. * banner
  483. */
  484. getBannerlist: function() {
  485. let that = this;
  486. Http.get({
  487. url: config.api.bannerlist,
  488. data: {
  489. pageNum: 1,
  490. pageSize: 7
  491. }
  492. }).then(res => {
  493. // that.getmemberId(app.globalData.token);
  494. // that.checkUserCarStatus();
  495. that.setData({
  496. list: res.data.list
  497. });
  498. })
  499. .catch(err => {
  500. // that.getmemberId(app.globalData.token);
  501. // that.checkUserCarStatus();
  502. })
  503. ;
  504. },
  505. // 专题显示
  506. topicShow: function () {
  507. let that = this;
  508. Http.get({
  509. url: config.api.topicShow,
  510. data: {
  511. token: app.globalData.token
  512. }
  513. }).then(res => {
  514. if (res&&res.data){
  515. that.setData({
  516. cover: res.data.cover,
  517. id: res.data.id,
  518. showTopic: true
  519. })
  520. }
  521. })
  522. .catch(err => {
  523. console.log(err);
  524. })
  525. },
  526. gotoTopic(){
  527. wx.navigateTo({
  528. url: `/pages/topicDetail/index?id=${this.data.id}`
  529. })
  530. },
  531. /**
  532. * 检查用户是否有车
  533. */
  534. // checkUserCarStatus: function() {
  535. // var that = this;
  536. // Http.get({
  537. // url: config.api.userCarCount,
  538. // data: {}
  539. // }).then(res => {
  540. // if (res.data > 0) {
  541. // // 用户名下有车
  542. // app.globalData.phone = res.data.phone;
  543. // app.globalData.supportCar = true;
  544. // // 共同登录
  545. // that.userCarLogin();
  546. // }
  547. // });
  548. // },
  549. /**
  550. * car共同登录
  551. */
  552. // userCarLogin: function() {
  553. // var that = this;
  554. // if (!app.globalData.carLogin) {
  555. // // 共同登录
  556. // Http.post({
  557. // url: config.api.carInit,
  558. // data: {
  559. // phone: app.globalData.phone
  560. // }
  561. // }).then(res => {
  562. // app.globalData.carLogin = true;
  563. // app.globalData.parkVendor = res.data.vendor;
  564. // if (res.data.token != "undefined") {
  565. // app.globalData.etcpToken = res.data.token;
  566. // }
  567. // });
  568. // }
  569. // },
  570. /**
  571. * 获取用户信息
  572. */
  573. getUserInfo: function() {
  574. // 获取用户信息
  575. wx.getSetting({
  576. success: res => {
  577. if (res.authSetting["scope.userInfo"]) {
  578. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  579. wx.getUserInfo({
  580. success: res => {
  581. // 可以将 res 发送给后台解码出 unionId
  582. }
  583. });
  584. }
  585. }
  586. });
  587. },
  588. gotoBargain: function() {
  589. wx.navigateTo({
  590. url: '/pages/bargain/bargain'
  591. })
  592. },
  593. /**
  594. * 刷新
  595. */
  596. onPullDownRefresh: function(e) {
  597. let that = this;
  598. that.userLogin();
  599. that.setData({
  600. page: 1
  601. })
  602. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  603. this.userLogin(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  604. } else {
  605. this.userLogin()
  606. }
  607. if (that.data.code == 0 || that.data.code == undefined) {
  608. that.selectComponent("#lists").getList(0, 1, "refresh");
  609. wx.stopPullDownRefresh();
  610. } else {
  611. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  612. wx.stopPullDownRefresh();
  613. };
  614. // 砍价下拉刷新
  615. that.selectComponent("#bargain").getList();
  616. that.selectComponent("#spellGroup").getList();
  617. that.selectComponent("#rushtobyCard").getList();
  618. wx.stopPullDownRefresh();
  619. },
  620. //加载更多
  621. onReachBottom: function() {
  622. let that = this;
  623. that.data.page++;
  624. that.setData({
  625. page: that.data.page
  626. });
  627. console.log("加载更多页数" + that.data.page);
  628. console.log("加载更多key" + that.data.code);
  629. //父组件获得子组件的方法
  630. //如果code == 0
  631. if (that.data.code == 0 || that.data.code == undefined) {
  632. that.selectComponent("#lists").getList(0, that.data.page);
  633. } else {
  634. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  635. }
  636. },
  637. // 用户点击右上角分享
  638. onShareAppMessage: function() {
  639. return {
  640. title: this.data.weappShareTitle,
  641. imageUrl: this.data.weappShareCoverImg,
  642. // desc: this.data.desc,
  643. success: function(res) {
  644. wx.showToast({
  645. title: "分享成功",
  646. duration: 1000,
  647. icon: "success"
  648. });
  649. }
  650. };
  651. }
  652. });