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.

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