C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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