C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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