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.

620 lines
16 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. const util = require("../../utils/util");
  6. const bgColor = require("../../utils/bgColor.js")
  7. let app = getApp();
  8. Page({
  9. data: {
  10. chengzhangBox: bgColor.colorFirst.main.chengzhangBox,
  11. activeColor: bgColor.colorFirst.main.activeColor,
  12. qg: bgColor.colorFirst.main.qg,
  13. newUrl: "",
  14. cover: "",
  15. kanjia:imgurl.kanjia.url,
  16. pintuan: imgurl.pintuan.url,
  17. xiaofeika: imgurl.xiaofeika.url,
  18. xingyun: imgurl.xingyun.url,
  19. jfshangcheng: imgurl.jfshangcheng.url,
  20. toutiao: imgurl.toutiao.url,
  21. usergift: imgurl.usergift.url,
  22. guanbi1: imgurl.guanbi1.url,
  23. icon0001: imgurl.icon0001.url,
  24. icon0002: imgurl.icon0002.url,
  25. icon0003: imgurl.icon0003.url,
  26. icon0004: imgurl.icon0004.url,
  27. icon0005: imgurl.icon0005.url,
  28. icon0006: imgurl.icon0006.url,
  29. icon0007: imgurl.icon0007.url,
  30. icon0008: imgurl.icon0008.url,
  31. barcode: imgurl.barcode.url,
  32. leftarrows: imgurl.leftarrows.url,
  33. newcard: imgurl.newcard.url,
  34. newseckill: imgurl.newseckill.url,
  35. newbargain: imgurl.newbargain.url,
  36. newgroup: imgurl.newgroup.url,
  37. product: imgurl.product.url,
  38. barginicon: imgurl.barginicon.url,
  39. pintuan: imgurl.pintuan.url,
  40. duihuan: imgurl.duihuan.url,
  41. market: app.globalData.market,
  42. list: [],
  43. loading: true,
  44. fistLogin: null,
  45. alphaData: null,
  46. swiperCurrent: 0,
  47. title: null,
  48. weappShareTitle: '', //分享标题
  49. weappShareCoverImg: '', //分享图片
  50. desc: null,
  51. scrollTop: 0,
  52. showGame: false,
  53. showTopic: false,
  54. gamedata: {},
  55. couponId: '', //游戏返回时传回的字段
  56. played: false, //从游戏页面跳回首页返回true
  57. havePlayEd: app.globalData.havePlayEd,
  58. staticGamedata: {},
  59. showIf: false,
  60. showPages: false,
  61. display: 'none',
  62. display1: 'none',
  63. optionsData: null,
  64. credit: 0,
  65. score: '0',
  66. page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  67. },
  68. close: function() {
  69. this.setData({
  70. showIf: false
  71. })
  72. },
  73. alphaClick: function(even) {
  74. var animation = wx.createAnimation({})
  75. animation.opacity(0).step({
  76. duration: 2000
  77. })
  78. this.setData({
  79. alphaData: animation.export()
  80. })
  81. },
  82. // 我的卡包
  83. mycard: function() {
  84. wx.navigateTo({
  85. url: '/pages/cardorder/index/index',
  86. })
  87. },
  88. //我的券包
  89. mycoupon: function() {
  90. wx.navigateTo({
  91. url: '/pages/couponorder/index/index',
  92. })
  93. },
  94. gotoSpellGroup: function() {
  95. wx.navigateTo({
  96. url: '/pages/spellGroup/spellGroup',
  97. })
  98. },
  99. qrcode: function() {
  100. var that = this;
  101. let memberId = that.data.memberId;
  102. if (memberId) {
  103. wx.navigateTo({
  104. url: '/pages/specialcourtesy/specialcourtesy'
  105. })
  106. }
  107. },
  108. // hideQrcode: function() {
  109. // let that = this;
  110. // that.setData({
  111. // showQrcode: false
  112. // })
  113. // },
  114. //跳往限时秒杀
  115. gotoRushBuy: function() {
  116. wx.navigateTo({
  117. url: '/pages/rushToBuy/index',
  118. })
  119. },
  120. //搜索门店
  121. // searchbar:function(){
  122. // wx.switchTab({
  123. // url: '/pages/index/searchbar/index',
  124. // })
  125. // },
  126. // createQrCode: function(url, canvasId, cavW, cavH) {
  127. // //调用插件中的draw方法,绘制二维码图片
  128. // QR.api.draw(url, canvasId, cavW, cavH);
  129. // },
  130. swiperChange: function(e) {
  131. this.setData({
  132. swiperCurrent: e.detail.current
  133. });
  134. },
  135. gotogame: function() {
  136. let that = this;
  137. Http.get({
  138. url: config.api.checkPhoneStatus,
  139. data: {}
  140. })
  141. .then(res => {
  142. var data = {
  143. couponChannelId: "" + that.data.couponChannelId,
  144. couponId: "" + that.data.couponId
  145. };
  146. if (that.data.couponChannelId == null) {
  147. var data = {
  148. couponId: "" + that.data.couponId
  149. };
  150. }
  151. wx.navigateTo({
  152. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  153. })
  154. })
  155. .catch(err => {
  156. if (err.code == 11005) {
  157. // 用户手机未授权
  158. /**
  159. * 将值传到用户手机号授权的页面
  160. *
  161. */
  162. wx.redirectTo({
  163. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  164. });
  165. } else if (err.code == 11006) {
  166. // 用户手机已加密
  167. wx.redirectTo({
  168. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  169. });
  170. } else {
  171. wx.showToast({
  172. title: err.message,
  173. icon: 'none',
  174. duration: 2000,
  175. mask: false
  176. });
  177. }
  178. })
  179. },
  180. mySpecial: function() {
  181. console.log("special");
  182. wx.navigateTo({
  183. url: '/pages/specialcourtesy/specialcourtesy',
  184. })
  185. },
  186. /**
  187. * 生命周期函数--监听页面初次渲染完成
  188. */
  189. onLoad: function(options) {
  190. let that = this;
  191. let optionss;
  192. if (wx.getStorageSync('options')){
  193. optionss = JSON.parse(wx.getStorageSync('options'));
  194. }
  195. if (options.played == "true") {
  196. that.setData({
  197. played: true
  198. })
  199. }
  200. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  201. that.setData({
  202. optionsData: optionss
  203. })
  204. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  205. } else {
  206. that.getWeapNote()
  207. }
  208. //获取条形码
  209. // util.barcode("barcode", optionss.quancode, 510, 100);
  210. },
  211. onShow: function() {
  212. let that = this;
  213. that.setData({
  214. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  215. })
  216. /**
  217. * couponNum 是否有普通的优惠券购买
  218. * couponNum2 是否有新买的消费卡
  219. */
  220. let num = wx.getStorageSync('couponNum');
  221. let num1 = wx.getStorageSync('couponNum2');
  222. if (num == 'couponNum' || num1 == 'couponNum2') {
  223. wx.showTabBarRedDot({
  224. index: 3
  225. })
  226. } else {
  227. wx.hideTabBarRedDot({
  228. index: 3
  229. })
  230. }
  231. if (app.globalData.score) {
  232. that.setData({
  233. fistLogin: app.globalData.score
  234. })
  235. }
  236. // 如果有游戏
  237. setTimeout(function() {
  238. that.alphaClick();
  239. }, 8000)
  240. },
  241. getmemberId: function(token) {
  242. let that = this;
  243. Http.get({
  244. url: config.api.getScore,
  245. data: {
  246. token: token
  247. }
  248. }).then(res => {
  249. that.setData({
  250. levelName: res.data.levelName,
  251. upgradePercent: res.data.upgradePercent,
  252. upgradeScore: res.data.upgradeScore,
  253. credit: res.data.credit ? res.data.credit : 0,
  254. score: res.data.score
  255. })
  256. if (res.data.nickName) {
  257. that.setData({
  258. ismember: true,
  259. memberId: res.data.id
  260. })
  261. var initUrl = JSON.stringify({
  262. flagid: res.data.id
  263. });
  264. }
  265. })
  266. .catch(err => {
  267. wx.showModal({
  268. title: '提示',
  269. content: err.message,
  270. showCancel: false
  271. })
  272. })
  273. },
  274. gotoChengzhangzhi: function() {
  275. wx.navigateTo({
  276. url: '/pages/czdetail/czdetail',
  277. })
  278. },
  279. gotoBargain: function () {
  280. wx.navigateTo({
  281. url: '/pages/bargain/bargain',
  282. })
  283. },
  284. gotoSpellGroup: function () {
  285. wx.navigateTo({
  286. url: '/pages/spellGroup/spellGroup',
  287. })
  288. },
  289. gotoCard: function () {
  290. wx.navigateTo({
  291. url: '/pages/discountCardList/discountCardList',
  292. })
  293. },
  294. gotoGame: function () {
  295. wx.navigateTo({
  296. url: '/pages/game/index',
  297. })
  298. },
  299. gotoJfsc: function () {
  300. wx.navigateTo({
  301. url: '/pages/integralmall/index',
  302. })
  303. },
  304. /**
  305. *
  306. * @param {code,page}
  307. * 子组件向父组件传值
  308. */
  309. onGetCode: function(e) {
  310. this.setData({
  311. code: e.detail.val,
  312. page: e.detail.pageNum,
  313. });
  314. console.log(e.detail.val)
  315. console.log(e.detail.pageNum)
  316. },
  317. getWeapNote: function(couponChannelId, couponId, orderId) {
  318. var that = this;
  319. // 登录
  320. that.getmemberId(app.globalData.token);
  321. that.getBannerlist();
  322. that.topicShow();
  323. that.getMallInfo(app.globalData.token);
  324. if (app.couponChannelListCallback) {
  325. app.couponChannelListCallback(app.globalData.token);
  326. }
  327. if (app.couponListCallback) {
  328. app.couponListCallback(app.globalData.token);
  329. }
  330. if (app.businessListCallback) {
  331. app.businessListCallback(app.globalData.token);
  332. }
  333. Http.get({
  334. url: config.api.getWeapNote,
  335. data: {
  336. appId: config.weapp.AppId,
  337. }
  338. })
  339. .then(res => {
  340. that.getGameOne(app.globalData.token)
  341. that.getStaticGame(app.globalData.token)
  342. let weapNote = JSON.parse(res.data.weapNote);
  343. that.setData({
  344. desc: weapNote.firstpage.desc,
  345. title: weapNote.firstpage.title
  346. })
  347. })
  348. .catch(err => {
  349. that.getGameOne(app.globalData.token)
  350. that.getStaticGame(app.globalData.token)
  351. wx.showModal({
  352. title: "提示",
  353. content: err.errMsg,
  354. showCancel: false
  355. });
  356. });
  357. },
  358. getStaticGame(token) {
  359. let _this = this;
  360. Http.get({
  361. url: config.api.getGame,
  362. data: {
  363. triggleAction: 2, // 固定入口
  364. token: token
  365. }
  366. }).then(res => {
  367. if (res.data.id) {
  368. _this.setData({
  369. showIf: true,
  370. newUrl: res.data.imgUrl
  371. })
  372. } else {
  373. _this.setData({
  374. showIf: false
  375. })
  376. }
  377. _this.setData({
  378. staticGamedata: res.data
  379. })
  380. })
  381. .catch(err => {
  382. _this.setData({
  383. showIf: false
  384. })
  385. console.log(err)
  386. })
  387. },
  388. getGameOne: function(token) {
  389. let _this = this;
  390. Http.get({
  391. url: config.api.getGame,
  392. data: {
  393. triggleAction: 1, // 登录触发
  394. token: token
  395. }
  396. }).then(res => {
  397. if (res.data.id) {
  398. _this.setData({
  399. showGame: true,
  400. })
  401. } else {
  402. _this.setData({
  403. showGame: false
  404. })
  405. }
  406. _this.setData({
  407. gamedata: res.data
  408. })
  409. })
  410. .catch(err => {
  411. _this.setData({
  412. showGame: false
  413. })
  414. this.alphaClick();
  415. })
  416. },
  417. /**
  418. * mallinfo
  419. */
  420. getMallInfo: function(token) {
  421. let that = this;
  422. Http.get({
  423. url: config.api.getMallInfo,
  424. data: {
  425. token: token,
  426. }
  427. }).then(res => {
  428. that.setData({
  429. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  430. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  431. });
  432. })
  433. .catch(err => {
  434. // 不需要错误提示
  435. });
  436. },
  437. /**
  438. * banner
  439. */
  440. getBannerlist: function() {
  441. let that = this;
  442. Http.get({
  443. url: config.api.bannerlist,
  444. data: {
  445. pageNum: 1,
  446. pageSize: 7
  447. }
  448. }).then(res => {
  449. // that.getmemberId(app.globalData.token);
  450. // that.checkUserCarStatus();
  451. that.setData({
  452. list: res.data.list
  453. });
  454. })
  455. .catch(err => {
  456. // that.getmemberId(app.globalData.token);
  457. // that.checkUserCarStatus();
  458. });
  459. },
  460. // 专题显示
  461. topicShow: function() {
  462. let that = this;
  463. Http.get({
  464. url: config.api.topicShow,
  465. data: {
  466. token: app.globalData.token
  467. }
  468. }).then(res => {
  469. if (res && res.data) {
  470. that.setData({
  471. cover: res.data.cover,
  472. id: res.data.id,
  473. showTopic: true
  474. })
  475. } else {
  476. that.setData({
  477. showTopic: false
  478. })
  479. }
  480. })
  481. .catch(err => {
  482. console.log(err);
  483. })
  484. },
  485. gotoTopic() {
  486. wx.navigateTo({
  487. url: `/pages/topicDetail/index?id=${this.data.id}`
  488. })
  489. },
  490. /**
  491. * 检查用户是否有车
  492. */
  493. // checkUserCarStatus: function() {
  494. // var that = this;
  495. // Http.get({
  496. // url: config.api.userCarCount,
  497. // data: {}
  498. // }).then(res => {
  499. // if (res.data > 0) {
  500. // // 用户名下有车
  501. // app.globalData.phone = res.data.phone;
  502. // app.globalData.supportCar = true;
  503. // // 共同登录
  504. // that.userCarLogin();
  505. // }
  506. // });
  507. // },
  508. /**
  509. * car共同登录
  510. */
  511. // userCarLogin: function() {
  512. // var that = this;
  513. // if (!app.globalData.carLogin) {
  514. // // 共同登录
  515. // Http.post({
  516. // url: config.api.carInit,
  517. // data: {
  518. // phone: app.globalData.phone
  519. // }
  520. // }).then(res => {
  521. // app.globalData.carLogin = true;
  522. // app.globalData.parkVendor = res.data.vendor;
  523. // if (res.data.token != "undefined") {
  524. // app.globalData.etcpToken = res.data.token;
  525. // }
  526. // });
  527. // }
  528. // },
  529. /**
  530. * 获取用户信息
  531. */
  532. // getUserInfo: function() {
  533. // // 获取用户信息
  534. // wx.getSetting({
  535. // success: res => {
  536. // if (res.authSetting["scope.userInfo"]) {
  537. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  538. // wx.getUserInfo({
  539. // success: res => {
  540. // // 可以将 res 发送给后台解码出 unionId
  541. // }
  542. // });
  543. // }
  544. // }
  545. // });
  546. // },
  547. gotoBargain: function() {
  548. wx.navigateTo({
  549. url: '/pages/bargain/bargain'
  550. })
  551. },
  552. /**
  553. * 刷新
  554. */
  555. onPullDownRefresh: function(e) {
  556. let that = this;
  557. that.getWeapNote();
  558. that.setData({
  559. page: 1
  560. })
  561. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  562. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  563. } else {
  564. this.getWeapNote()
  565. }
  566. if (that.data.code == 0 || that.data.code == undefined) {
  567. that.selectComponent("#lists").getList(0, 1, "refresh");
  568. wx.stopPullDownRefresh();
  569. } else {
  570. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  571. wx.stopPullDownRefresh();
  572. };
  573. // 砍价下拉刷新
  574. that.selectComponent("#hot").getList();
  575. that.selectComponent("#hot").getptList();
  576. // that.selectComponent("#bargain").getList();
  577. // that.selectComponent("#spellGroup").getList();
  578. // that.selectComponent("#rushtobyCard").getList();
  579. wx.stopPullDownRefresh();
  580. },
  581. //加载更多
  582. onReachBottom: function() {
  583. let that = this;
  584. that.data.page++;
  585. that.setData({
  586. page: that.data.page
  587. });
  588. console.log("加载更多页数" + that.data.page);
  589. console.log("加载更多key" + that.data.code);
  590. //父组件获得子组件的方法
  591. //如果code == 0
  592. if (that.data.code == 0 || that.data.code == undefined) {
  593. that.selectComponent("#lists").getList(0, that.data.page);
  594. } else {
  595. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  596. }
  597. },
  598. // 用户点击右上角分享
  599. onShareAppMessage: function() {
  600. return {
  601. title: this.data.weappShareTitle,
  602. imageUrl: this.data.weappShareCoverImg,
  603. // desc: this.data.desc,
  604. success: function(res) {
  605. wx.showToast({
  606. title: "分享成功",
  607. duration: 1000,
  608. icon: "success"
  609. });
  610. }
  611. };
  612. }
  613. });