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

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