handleMonthly.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="handle-monthly">
  3. <view class="handle-monthly-item">
  4. <view>车牌选择</view>
  5. <view class="choose-license" @click="isShowCarLicense = true">
  6. <view>{{form.carLicense.label}}</view>
  7. <u-icon name="arrow-down" color="#7B7B7B" size="30"></u-icon>
  8. </view>
  9. </view>
  10. <u-select v-model="isShowCarLicense" :list="carLicenseList" @confirm="carLicenseListConfirm"></u-select>
  11. <view class="handle-monthly-item">
  12. <view>车辆信息</view>
  13. <view>汽油车</view>
  14. </view>
  15. <view class="handle-monthly-item">
  16. <view>包月金额</view>
  17. <view class="handle-monthly-money">200元</view>
  18. </view>
  19. <view class="handle-monthly-item">
  20. <view>包月时长</view>
  21. <view class="handle-monthly-time-long">
  22. <button @click="reduceMonthNum()">-</button>
  23. <view>{{form.month}}个月</view>
  24. <button @click="addMonthNum()">+</button>
  25. </view>
  26. </view>
  27. <view class="handle-monthly-item">
  28. <view>包期</view>
  29. <view>{{form.dateRange}}</view>
  30. </view>
  31. <view class="handle-monthly-explain">
  32. <view>包月说明</view>
  33. <view>1、停车不足30分钟,免费;</view>
  34. <view>2、停车 超过20分钟,按2元/小时收费;</view>
  35. <view>3、月卡会员在有效期内停车免费</view>
  36. </view>
  37. <view class="handle-monthly-confirm-button">
  38. <button type="default">确认包月</button>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. carLicenseList: [
  47. {
  48. value: 1, label: '贵AWE45T'
  49. },
  50. {
  51. value: 2, label: '贵AWE45F'
  52. },
  53. ],
  54. isShowCarLicense: false,
  55. form: {
  56. carLicense: {
  57. value: 2,
  58. label: '贵AWE45F'
  59. },
  60. month: 1,
  61. dateRange: this.getMonthRange(new Date(), 1)
  62. }
  63. }
  64. },
  65. onLoad () {
  66. },
  67. methods: {
  68. /**
  69. * 获取几个月的日期范围
  70. * {date} Date 起始日期,往后推一天
  71. * {monthNum} Number 往后月数
  72. * */
  73. getMonthRange (date, monthNum) {
  74. let Date1 = new Date(date)
  75. Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
  76. Date1 = new Date(Date1)
  77. const year = Date1.getFullYear()
  78. const month = Date1.getMonth()
  79. const day = Date1.getDate()
  80. let days = new Date(year, month, 0)
  81. days = days.getDate() //获取当前日期中的月的天数
  82. let year2 = year;
  83. let month2 = parseInt(month) + parseInt(monthNum)
  84. if (month2 >12) {
  85. year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12))
  86. month2 = parseInt(month2) % 12;
  87. }
  88. const day2 = day;
  89. let days2 = new Date(year2, month2, 0)
  90. days2 = days2.getDate()
  91. if (day2 > days2) {
  92. day2 = days2
  93. }
  94. if (month2 < 10) {
  95. month2 = '0' + month2;
  96. }
  97. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day)
  98. const t2 = year2 + '.' + month2 + '.' + day2
  99. return t1 + '-' + t2
  100. },
  101. /**
  102. * 月操作 减1
  103. * */
  104. reduceMonthNum () {
  105. if (this.form.month > 1) {
  106. this.form.month -= 1
  107. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  108. }
  109. },
  110. /**
  111. * 月操作 加1
  112. * */
  113. addMonthNum () {
  114. this.form.month += 1
  115. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  116. },
  117. carLicenseListConfirm (item) {
  118. this.form.carLicense = item[0]
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. @import './handleMonthly.scss';
  125. </style>