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.

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