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

496 行
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. }
  337. _this.setData({
  338. staticGamedata: res.data
  339. })
  340. })
  341. .catch(err => {
  342. console.log(err)
  343. })
  344. },
  345. getGameOne: function(token) {
  346. let _this = this;
  347. Http.get({
  348. url: config.api.getGame,
  349. data: {
  350. triggleAction: 1,
  351. token: token
  352. }
  353. }).then(res => {
  354. if (res.data.id) {
  355. _this.setData({
  356. showGame: true
  357. })
  358. }
  359. _this.setData({
  360. gamedata: res.data
  361. })
  362. })
  363. .catch(err => {
  364. console.log(err)
  365. })
  366. },
  367. /**
  368. * banner
  369. */
  370. getBannerlist: function() {
  371. let that = this;
  372. Http.get({
  373. url: config.api.bannerlist,
  374. data: {
  375. pageNum: 1,
  376. pageSize: 7
  377. }
  378. }).then(res => {
  379. that.setData({
  380. list: res.data.list
  381. });
  382. });
  383. },
  384. /**
  385. * 检查用户是否有车
  386. */
  387. checkUserCarStatus: function() {
  388. var that = this;
  389. Http.get({
  390. url: config.api.userCarCount,
  391. data: {}
  392. }).then(res => {
  393. if (res.data > 0) {
  394. // 用户名下有车
  395. app.globalData.phone = res.data.phone;
  396. app.globalData.supportCar = true;
  397. // 共同登录
  398. that.userCarLogin();
  399. }
  400. });
  401. },
  402. /**
  403. * car共同登录
  404. */
  405. userCarLogin: function() {
  406. var that = this;
  407. if (!app.globalData.carLogin) {
  408. // 共同登录
  409. Http.post({
  410. url: config.api.carInit,
  411. data: {
  412. phone: app.globalData.phone
  413. }
  414. }).then(res => {
  415. app.globalData.carLogin = true;
  416. app.globalData.parkVendor = res.data.vendor;
  417. if (res.data.token != "undefined") {
  418. app.globalData.etcpToken = res.data.token;
  419. }
  420. });
  421. }
  422. },
  423. /**
  424. * 获取用户信息
  425. */
  426. getUserInfo: function() {
  427. // 获取用户信息
  428. wx.getSetting({
  429. success: res => {
  430. if (res.authSetting["scope.userInfo"]) {
  431. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  432. wx.getUserInfo({
  433. success: res => {
  434. // 可以将 res 发送给后台解码出 unionId
  435. }
  436. });
  437. }
  438. }
  439. });
  440. },
  441. gotoBargain: function() {
  442. wx.navigateTo({
  443. url: '/pages/bargain/bargain'
  444. })
  445. },
  446. /**
  447. * 刷新
  448. */
  449. onPullDownRefresh: function(e) {
  450. let that = this;
  451. that.userLogin();
  452. that.setData({
  453. page: 1
  454. })
  455. if (that.data.code == 0 || that.data.code == undefined) {
  456. that.selectComponent("#lists").getList(0, 1, "refresh");
  457. wx.stopPullDownRefresh();
  458. } else {
  459. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  460. wx.stopPullDownRefresh();
  461. };
  462. },
  463. //加载更多
  464. onReachBottom: function() {
  465. let that = this;
  466. that.data.page++;
  467. that.setData({
  468. page: that.data.page
  469. });
  470. console.log("加载更多页数" + that.data.page);
  471. console.log("加载更多key" + that.data.code);
  472. //父组件获得子组件的方法
  473. //如果code == 0
  474. if (that.data.code == 0 || that.data.code == undefined) {
  475. that.selectComponent("#lists").getList(0, that.data.page);
  476. } else {
  477. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  478. }
  479. },
  480. // 用户点击右上角分享
  481. onShareAppMessage: function() {
  482. return {
  483. title: this.data.title,
  484. desc: this.data.desc,
  485. success: function(res) {
  486. wx.showToast({
  487. title: "分享成功",
  488. duration: 1000,
  489. icon: "success"
  490. });
  491. }
  492. };
  493. }
  494. });