handleMonthly.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. payUrl:'',
  49. monthId: '',
  50. vehicleNo:'',
  51. monthEndTime:'',
  52. monthStartTime:'',
  53. lastActiveDate:null,
  54. roadNo:null,
  55. carLicenseList: [],
  56. isShowCarLicense: false,
  57. form: {
  58. energyType:[],
  59. monthAmount: [],
  60. carLicense: {},
  61. month: 1,
  62. dateRange:""
  63. },
  64. label:""
  65. }
  66. },
  67. onLoad (page) {
  68. let locationLocaturl = window.location.hash;
  69. // this.roadNo = this.$u.queryParams(page).slice();
  70. this.roadNo = getUrlParams(locationLocaturl,"roadNo");
  71. this.getMonthInfo(this.roadNo);
  72. // this.form.dateRange=this.getMonthRange(this.lastActiveDate,1)
  73. // this.getCarsLicenseList();
  74. },
  75. mounted(){
  76. // console.log(this.lastActiveDate)
  77. // this.form.dateRange=this.getMonthRange(new Date(this.lastActiveDate),1)
  78. },
  79. methods: {
  80. /**
  81. * 获取几个月的日期范围
  82. * {date} Date 起始日期,往后推一天
  83. * {monthNum} Number 往后月数
  84. * */
  85. getMonthRange (date, monthNum) {
  86. let Date1 = this.lastActiveDate;
  87. // Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
  88. Date1 = new Date(Date1)
  89. const year = Date1.getFullYear()
  90. const month = Date1.getMonth()+1
  91. const day = Date1.getDate()
  92. const hours = Date1.getHours();
  93. const minutes = Date1.getMinutes();
  94. const seconds = Date1.getSeconds();
  95. let days = new Date(year, month, 0)
  96. days = days.getDate() //获取当前日期中的月的天数
  97. let year2 = year;
  98. let month2 = parseInt(month) + parseInt(monthNum)
  99. if (month2 >12) {
  100. year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12))
  101. month2 = parseInt(month2) % 12;
  102. }
  103. let day2 = day;
  104. let days2 = new Date(year2, month2, 0)
  105. days2 = days2.getDate()
  106. if (day2 > days2) {
  107. day2 = days2
  108. }
  109. if (month2 < 10) {
  110. month2 = '0' + month2;
  111. }
  112. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day)
  113. const t2 = year2 + '.' + month2 + '.' + day2
  114. this.monthStartTime=year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' +seconds
  115. this.monthEndTime=year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' +seconds
  116. return t1 + '-' + t2
  117. },
  118. /**
  119. * 月操作 减1
  120. * */
  121. reduceMonthNum () {
  122. if (this.form.month > 1) {
  123. this.form.month -= 1
  124. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  125. }
  126. },
  127. /**
  128. * 月操作 加1
  129. * */
  130. addMonthNum () {
  131. if(this.form.month >=24){
  132. this.$refs.uToast.show({
  133. title: '最多24月',
  134. type: 'warning',
  135. })
  136. return
  137. }
  138. this.form.month += 1
  139. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  140. },
  141. carLicenseListConfirm (item) {
  142. this.form.carLicense = item[0]
  143. },
  144. getMonthInfo(roadNo){
  145. this.$u.api.monthInfo({roadNo: this.roadNo})
  146. .then(res => {
  147. if (res.code === 200){
  148. this.vehicleNo = res.data.vehicleList[0].vehicleNo
  149. this.lastActiveDate = res.data.lastActiveDate;
  150. this.form.energyType=res.data.vehicleList[0].energyType;
  151. this.form.monthAmount=res.data.monthAmount;
  152. this.carLicenseList = [];
  153. res.data.vehicleList.forEach(item => {
  154. const obj = {
  155. value: item.id,
  156. label: item.vehicleNo
  157. }
  158. this.carLicenseList.push(obj)
  159. })
  160. this.form.carLicense = this.carLicenseList[0]
  161. }
  162. })
  163. },
  164. submit(roadNo){
  165. // console.log(this.monthStartTime)
  166. this.$u.api.createMonth({
  167. roadNo:this.roadNo,
  168. vehicleNo:this.form.carLicense.label,
  169. energyType:this.form.energyType,
  170. monthStartTime:this.monthStartTime,
  171. monthEndTime:this.monthEndTime,
  172. monthCount:this.form.monthAmount})
  173. .then(res => {
  174. console.log("1111",res)
  175. if(res.code === 200){
  176. this.monthId = res.data.monthId
  177. console.log(this.monthId)
  178. this.$u.api.monthPay({
  179. monthId:this.monthId
  180. }).then(res => {
  181. console.log("monthPay",res)
  182. if(res.code === 200){
  183. this.payUrl=encodeURIComponent(res.data.url);
  184. this.$u.route({
  185. url: 'pages/handleMonthly/monthPay',
  186. params: {
  187. payUrl:this.payUrl
  188. }
  189. });
  190. }
  191. })
  192. }
  193. })
  194. // this.getMonthInfo(roadNo)
  195. }
  196. },
  197. computed:{
  198. dateRange:function(){
  199. return this.getMonthRange(this.lastActiveDate,this.form.month)
  200. },
  201. },
  202. filters:{
  203. verifyStatusFilter(value) {
  204. if (value === 0) {
  205. return '';
  206. } else if(value === 1){
  207. return '汽油车';
  208. } else if(value === 2){
  209. return '新能源';
  210. } else {
  211. return '';
  212. }
  213. },
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. @import './handleMonthly.scss';
  219. </style>