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.

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