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

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