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.

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