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.

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