C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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