handleMonthly.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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.carLicense.value | 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. startTime:'',
  49. endTime:'',
  50. payUrl:'',
  51. monthId: '',
  52. vehicleNo:'',
  53. monthEndTime:'',
  54. monthStartTime:'',
  55. lastActiveDate:null,
  56. roadNo:null,
  57. carLicenseList: [],
  58. isShowCarLicense: false,
  59. form: {
  60. energyType:[],
  61. monthAmount: [],
  62. carLicense: {},
  63. month: 1,
  64. dateRange:""
  65. },
  66. label:""
  67. }
  68. },
  69. onLoad (page) {
  70. if (page.roadNo) {
  71. this.roadNo = page.roadNo;
  72. this.getMonthInfo(this.roadNo);
  73. }
  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 > 9 ? day2 : '0' + day2)
  114. this.startTime=t1
  115. this.endTime=t2
  116. this.monthStartTime=year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' +seconds
  117. this.monthEndTime=year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' +seconds
  118. return t1 + '-' + t2
  119. },
  120. /**
  121. * 月操作 减1
  122. * */
  123. reduceMonthNum () {
  124. if (this.form.month > 1) {
  125. this.form.month -= 1
  126. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  127. }
  128. },
  129. /**
  130. * 月操作 加1
  131. * */
  132. addMonthNum () {
  133. if(this.form.month >=24){
  134. this.$refs.uToast.show({
  135. title: '最多24月',
  136. type: 'warning',
  137. })
  138. return
  139. }
  140. this.form.month += 1
  141. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  142. },
  143. carLicenseListConfirm (item) {
  144. console.log('this.carLicenseList',this.carLicenseList);
  145. console.log('item',item);
  146. this.form.carLicense = item[0]
  147. },
  148. getMonthInfo(roadNo){
  149. this.$u.api.monthInfo({roadNo: this.roadNo})
  150. .then(res => {
  151. if (res.code === 200){
  152. this.lastActiveDate = res.data.lastActiveDate;
  153. this.form.monthAmount=res.data.monthAmount;
  154. this.carLicenseList = [];
  155. res.data.vehicleList.forEach(item => {
  156. const obj = {
  157. value: item.energyType,
  158. label: item.vehicleNo,
  159. energyType:item.energyType
  160. }
  161. this.carLicenseList.push(obj)
  162. });
  163. console.log('this.carLicenseList',this.carLicenseList)
  164. this.form.carLicense = this.carLicenseList[0]
  165. }
  166. })
  167. },
  168. submit(roadNo){
  169. // console.log(this.monthStartTime)
  170. // console.log('this.form.carLicense',this.form.carLicense);
  171. this.$u.api.createMonth({
  172. roadNo:this.roadNo,
  173. vehicleNo:this.form.carLicense.label,
  174. energyType:this.form.carLicense.energyType,
  175. monthStartTime:this.monthStartTime,
  176. monthEndTime:this.monthEndTime,
  177. monthCount:this.form.month})
  178. .then(res => {
  179. console.log("createMonth",res)
  180. if(res.code === 200){
  181. this.monthId = res.data.monthId
  182. console.log(this.monthId)
  183. this.$u.api.monthPay({
  184. monthId:this.monthId
  185. }).then(res => {
  186. console.log("monthPay",res)
  187. if(res.code === 200){
  188. // this.payUrl=encodeURIComponent(res.data.url);
  189. // this.$u.route({
  190. // url: 'pages/handleMonthly/monthPay',
  191. // params: {
  192. // payUrl:this.payUrl
  193. // }
  194. // });
  195. window.location.href = res.data.url
  196. } else {
  197. this.$refs.uToast.show({
  198. title: res.msg,
  199. type: 'error',
  200. });
  201. }
  202. })
  203. }else{
  204. this.$refs.uToast.show({
  205. title: res.msg,
  206. type: 'warning',
  207. });
  208. }
  209. }).catch(err=>{
  210. });
  211. // this.getMonthInfo(roadNo)
  212. }
  213. },
  214. computed:{
  215. dateRange:function(){
  216. return this.getMonthRange(this.lastActiveDate,this.form.month)
  217. },
  218. },
  219. filters:{
  220. verifyStatusFilter(value) {
  221. if (value === 0) {
  222. return '';
  223. } else if(value === 1){
  224. return '汽油车';
  225. } else if(value === 2){
  226. return '新能源';
  227. } else {
  228. return '';
  229. }
  230. },
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. @import './handleMonthly.scss';
  236. </style>