handleMonthly.vue 6.8 KB

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