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.

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