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

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