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.

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