C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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