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

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