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.

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