index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // nova-tourism/components/home/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. },
  8. /**
  9. * 组件的初始数据
  10. */
  11. data: {
  12. //屏幕高度
  13. statusBarHeight: 0, // 状态栏高度
  14. screenHeight: 0, // 屏幕高度
  15. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  16. bottomNavHeight: 0, // 底部导航栏高度
  17. contentHeight: 0, // 可用内容高度
  18. // 轮播图数组
  19. //卡片数组
  20. cardarr: [1, 2, 3, 4, 5, 6, 7],
  21. //日历
  22. date_start: '',
  23. date_end:'',
  24. week_start:'',
  25. week_end:'',
  26. show: false,
  27. },
  28. lifetimes: {
  29. detached: function () {
  30. // 在组件实例被从页面节点树移除时执行
  31. },
  32. attached: async function () {
  33. // 在组件实例进入页面节点树时执行
  34. // 计算
  35. const systemInfo = wx.getSystemInfoSync();
  36. const statusBarHeight = systemInfo.statusBarHeight || 0;
  37. const screenHeight = systemInfo.screenHeight || 0;
  38. const custom = wx.getMenuButtonBoundingClientRect();
  39. const customHeight = custom.height + 10 + 2 || 0;
  40. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  41. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  42. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  43. this.setData({
  44. statusBarHeight,
  45. screenHeight,
  46. customHeight,
  47. bottomNavHeight,
  48. contentHeight,
  49. contentpadding
  50. });
  51. console.log(this.data.contentHeight);
  52. },
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. //选择日期
  59. //打开日历
  60. onDisplay() {
  61. this.setData({ show: true });
  62. },
  63. //关闭日历
  64. onClose() {
  65. this.setData({ show: false });
  66. },
  67. formatDate(date) {
  68. date = new Date(date);
  69. console.log(date);
  70. return `${date.getMonth() + 1}月${date.getDate()}日`;
  71. },
  72. onConfirm(event) {
  73. const [start, end] = event.detail;
  74. this.setData({
  75. show: false,
  76. date_start: `${this.formatDate(start)} `,
  77. date_end:`${this.formatDate(end)}`
  78. });
  79. console.log(this.data.date_start,this.data.date_end);
  80. },
  81. }
  82. })