C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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