handleMonthly.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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>{{form.energyType| verifyStatusFilter}}</view>
  14. </view>
  15. <view class="handle-monthly-item">
  16. <view>包月金额</view>
  17. <view class="handle-monthly-money">{{form.monthAmount}}元</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>{{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"@click="submit(roadNo)">确认包月</button>
  39. </view>
  40. <u-toast ref="uToast" />
  41. </view>
  42. </template>
  43. <script>
  44. import getUrlParams from "../../utils/getUrlParams.js";
  45. export default {
  46. data() {
  47. return {
  48. lastActiveDate:null,
  49. roadNo:null,
  50. carLicenseList: [],
  51. isShowCarLicense: false,
  52. form: {
  53. energyType:[],
  54. monthAmount: [],
  55. carLicense: {},
  56. month: 1,
  57. dateRange:""
  58. },
  59. label:""
  60. }
  61. },
  62. onLoad (page) {
  63. let locationLocaturl = window.location.hash;
  64. // this.roadNo = this.$u.queryParams(page).slice();
  65. this.roadNo = getUrlParams(locationLocaturl,"roadNo");
  66. console.log("roadNo" ,this.roadNo)
  67. this.getMonthInfo(this.roadNo);
  68. // this.form.dateRange=this.getMonthRange(this.lastActiveDate,1)
  69. // this.getCarsLicenseList();
  70. },
  71. mounted(){
  72. // console.log(this.lastActiveDate)
  73. // this.form.dateRange=this.getMonthRange(new Date(this.lastActiveDate),1)
  74. },
  75. methods: {
  76. /**
  77. * 获取几个月的日期范围
  78. * {date} Date 起始日期,往后推一天
  79. * {monthNum} Number 往后月数
  80. * */
  81. getMonthRange (date, monthNum) {
  82. let Date1 = this.lastActiveDate;
  83. // Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
  84. Date1 = new Date(Date1)
  85. const year = Date1.getFullYear()
  86. const month = Date1.getMonth()+1
  87. const day = Date1.getDate()
  88. let days = new Date(year, month, 0)
  89. days = days.getDate() //获取当前日期中的月的天数
  90. let year2 = year;
  91. let month2 = parseInt(month) + parseInt(monthNum)
  92. if (month2 >12) {
  93. year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12))
  94. month2 = parseInt(month2) % 12;
  95. }
  96. let day2 = day;
  97. let days2 = new Date(year2, month2, 0)
  98. days2 = days2.getDate()
  99. if (day2 > days2) {
  100. day2 = days2
  101. }
  102. if (month2 < 10) {
  103. month2 = '0' + month2;
  104. }
  105. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day)
  106. const t2 = year2 + '.' + month2 + '.' + day2
  107. return t1 + '-' + t2
  108. },
  109. /**
  110. * 月操作 减1
  111. * */
  112. reduceMonthNum () {
  113. if (this.form.month > 1) {
  114. this.form.month -= 1
  115. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  116. }
  117. },
  118. /**
  119. * 月操作 加1
  120. * */
  121. addMonthNum () {
  122. if(this.form.month >=24){
  123. this.$refs.uToast.show({
  124. title: '最多24月',
  125. type: 'warning',
  126. })
  127. return
  128. }
  129. this.form.month += 1
  130. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  131. },
  132. carLicenseListConfirm (item) {
  133. this.form.carLicense = item[0]
  134. },
  135. getMonthInfo(roadNo){
  136. this.$u.api.monthInfo({roadNo: this.roadNo})
  137. .then(res => {
  138. console.log('getMonthInfo',res)
  139. if (res.code === 200){
  140. this.lastActiveDate = res.data.lastActiveDate;
  141. this.form.energyType=res.data.vehicleList[0].energyType;
  142. this.form.monthAmount=res.data.monthAmount;
  143. this.carLicenseList = [];
  144. res.data.vehicleList.forEach(item => {
  145. const obj = {
  146. value: item.id,
  147. label: item.vehicleNo
  148. }
  149. this.carLicenseList.push(obj)
  150. })
  151. this.form.carLicense = this.carLicenseList[0]
  152. }
  153. })
  154. },
  155. submit(roadNo){
  156. // this.$u.api.createMonth({roadNo:})
  157. // this.getMonthInfo(roadNo)
  158. }
  159. },
  160. computed:{
  161. dateRange:function(){
  162. return this.getMonthRange(this.lastActiveDate,this.form.month)
  163. }
  164. },
  165. filters:{
  166. verifyStatusFilter(value) {
  167. if (value === 0) {
  168. return '';
  169. } else if(value === 1){
  170. return '汽油车';
  171. } else if(value === 2){
  172. return '新能源';
  173. } else {
  174. return '';
  175. }
  176. },
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. @import './handleMonthly.scss';
  182. </style>