C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

628 rindas
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 ? res.data.credit:0,
  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. that.setData({
  442. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle:null,
  443. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg:null,
  444. });
  445. })
  446. .catch(err => {
  447. });
  448. },
  449. /**
  450. * banner
  451. */
  452. getBannerlist: function() {
  453. let that = this;
  454. Http.get({
  455. url: config.api.bannerlist,
  456. data: {
  457. pageNum: 1,
  458. pageSize: 7
  459. }
  460. }).then(res => {
  461. // that.getmemberId(app.globalData.token);
  462. // that.checkUserCarStatus();
  463. that.setData({
  464. list: res.data.list
  465. });
  466. })
  467. .catch(err => {
  468. // that.getmemberId(app.globalData.token);
  469. // that.checkUserCarStatus();
  470. })
  471. ;
  472. },
  473. // 专题显示
  474. topicShow: function () {
  475. let that = this;
  476. Http.get({
  477. url: config.api.topicShow,
  478. data: {
  479. token: app.globalData.token
  480. }
  481. }).then(res => {
  482. if (res&&res.data){
  483. that.setData({
  484. cover: res.data.cover,
  485. id: res.data.id,
  486. showTopic: true
  487. })
  488. }else{
  489. that.setData({
  490. showTopic: false
  491. })
  492. }
  493. })
  494. .catch(err => {
  495. console.log(err);
  496. })
  497. },
  498. gotoTopic(){
  499. wx.navigateTo({
  500. url: `/pages/topicDetail/index?id=${this.data.id}`
  501. })
  502. },
  503. /**
  504. * 检查用户是否有车
  505. */
  506. // checkUserCarStatus: function() {
  507. // var that = this;
  508. // Http.get({
  509. // url: config.api.userCarCount,
  510. // data: {}
  511. // }).then(res => {
  512. // if (res.data > 0) {
  513. // // 用户名下有车
  514. // app.globalData.phone = res.data.phone;
  515. // app.globalData.supportCar = true;
  516. // // 共同登录
  517. // that.userCarLogin();
  518. // }
  519. // });
  520. // },
  521. /**
  522. * car共同登录
  523. */
  524. // userCarLogin: function() {
  525. // var that = this;
  526. // if (!app.globalData.carLogin) {
  527. // // 共同登录
  528. // Http.post({
  529. // url: config.api.carInit,
  530. // data: {
  531. // phone: app.globalData.phone
  532. // }
  533. // }).then(res => {
  534. // app.globalData.carLogin = true;
  535. // app.globalData.parkVendor = res.data.vendor;
  536. // if (res.data.token != "undefined") {
  537. // app.globalData.etcpToken = res.data.token;
  538. // }
  539. // });
  540. // }
  541. // },
  542. /**
  543. * 获取用户信息
  544. */
  545. getUserInfo: function() {
  546. // 获取用户信息
  547. wx.getSetting({
  548. success: res => {
  549. if (res.authSetting["scope.userInfo"]) {
  550. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  551. wx.getUserInfo({
  552. success: res => {
  553. // 可以将 res 发送给后台解码出 unionId
  554. }
  555. });
  556. }
  557. }
  558. });
  559. },
  560. gotoBargain: function() {
  561. wx.navigateTo({
  562. url: '/pages/bargain/bargain'
  563. })
  564. },
  565. /**
  566. * 刷新
  567. */
  568. onPullDownRefresh: function(e) {
  569. let that = this;
  570. that.userLogin();
  571. that.setData({
  572. page: 1
  573. })
  574. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  575. this.userLogin(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  576. } else {
  577. this.userLogin()
  578. }
  579. if (that.data.code == 0 || that.data.code == undefined) {
  580. that.selectComponent("#lists").getList(0, 1, "refresh");
  581. wx.stopPullDownRefresh();
  582. } else {
  583. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  584. wx.stopPullDownRefresh();
  585. };
  586. // 砍价下拉刷新
  587. that.selectComponent("#bargain").getList();
  588. that.selectComponent("#spellGroup").getList();
  589. that.selectComponent("#rushtobyCard").getList();
  590. wx.stopPullDownRefresh();
  591. },
  592. //加载更多
  593. onReachBottom: function() {
  594. let that = this;
  595. that.data.page++;
  596. that.setData({
  597. page: that.data.page
  598. });
  599. console.log("加载更多页数" + that.data.page);
  600. console.log("加载更多key" + that.data.code);
  601. //父组件获得子组件的方法
  602. //如果code == 0
  603. if (that.data.code == 0 || that.data.code == undefined) {
  604. that.selectComponent("#lists").getList(0, that.data.page);
  605. } else {
  606. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  607. }
  608. },
  609. // 用户点击右上角分享
  610. onShareAppMessage: function() {
  611. return {
  612. title: this.data.weappShareTitle,
  613. imageUrl: this.data.weappShareCoverImg,
  614. // desc: this.data.desc,
  615. success: function(res) {
  616. wx.showToast({
  617. title: "分享成功",
  618. duration: 1000,
  619. icon: "success"
  620. });
  621. }
  622. };
  623. }
  624. });