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

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