C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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