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.

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