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.

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