handleMonthly.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. this.getCarsLicenseList()
  67. },
  68. methods: {
  69. /**
  70. * 获取几个月的日期范围
  71. * {date} Date 起始日期,往后推一天
  72. * {monthNum} Number 往后月数
  73. * */
  74. getMonthRange (date, monthNum) {
  75. let Date1 = new Date(date)
  76. Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
  77. Date1 = new Date(Date1)
  78. const year = Date1.getFullYear()
  79. const month = Date1.getMonth()
  80. const day = Date1.getDate()
  81. let days = new Date(year, month, 0)
  82. days = days.getDate() //获取当前日期中的月的天数
  83. let year2 = year;
  84. let month2 = parseInt(month) + parseInt(monthNum)
  85. if (month2 >12) {
  86. year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12))
  87. month2 = parseInt(month2) % 12;
  88. }
  89. const day2 = day;
  90. let days2 = new Date(year2, month2, 0)
  91. days2 = days2.getDate()
  92. if (day2 > days2) {
  93. day2 = days2
  94. }
  95. if (month2 < 10) {
  96. month2 = '0' + month2;
  97. }
  98. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day)
  99. const t2 = year2 + '.' + month2 + '.' + day2
  100. return t1 + '-' + t2
  101. },
  102. /**
  103. * 月操作 减1
  104. * */
  105. reduceMonthNum () {
  106. if (this.form.month > 1) {
  107. this.form.month -= 1
  108. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  109. }
  110. },
  111. /**
  112. * 月操作 加1
  113. * */
  114. addMonthNum () {
  115. this.form.month += 1
  116. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  117. },
  118. carLicenseListConfirm (item) {
  119. this.form.carLicense = item[0]
  120. },
  121. getCarsLicenseList () {
  122. this.$u.api.getMycars()
  123. .then(res => {
  124. console.log(res)
  125. if (res.code === 200) {
  126. if (res.data) {
  127. this.carLicenseList = []
  128. res.data.rows.forEach(item => {
  129. const obj = {
  130. value: item.id,
  131. label: item.vehicleNo
  132. }
  133. this.carLicenseList.push(obj)
  134. })
  135. this.form.carLicense = this.carLicenseList[0]
  136. }
  137. }
  138. })
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. @import './handleMonthly.scss';
  145. </style>