123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <template>
- <view class="handle-monthly">
- <view class="handle-monthly-item">
- <view>车牌选择</view>
- <view class="choose-license" @click="isShowCarLicense = true">
- <view>{{form.carLicense.label}}</view>
- <u-icon name="arrow-down" color="#7B7B7B" size="30"></u-icon>
- </view>
- </view>
- <u-select v-model="isShowCarLicense" :list="carLicenseList" @confirm="carLicenseListConfirm"></u-select>
- <view class="handle-monthly-item">
- <view>车辆信息</view>
- <view>{{form.carLicense.value | verifyStatusFilter}}</view>
- </view>
- <view class="handle-monthly-item">
- <view>包月金额</view>
- <view class="handle-monthly-money">{{form.monthAmount}}元</view>
- </view>
- <view class="handle-monthly-item">
- <view>包月时长</view>
- <view class="handle-monthly-time-long">
- <button @click="reduceMonthNum()">-</button>
- <view>{{form.month}}个月</view>
- <button @click="addMonthNum()">+</button>
- </view>
- </view>
- <view class="handle-monthly-item">
- <view>包期</view>
- <view>{{dateRange}}</view>
- </view>
- <view class="handle-monthly-explain">
- <view>包月说明</view>
- <view>1、停车不足30分钟,免费;</view>
- <view>2、停车 超过20分钟,按2元/小时收费;</view>
- <view>3、月卡会员在有效期内停车免费</view>
- </view>
- <view class="handle-monthly-confirm-button">
- <button type="default"@click="submit(roadNo)">确认包月</button>
- </view>
- <u-toast ref="uToast" />
- </view>
- </template>
- <script>
- import getUrlParams from "../../utils/getUrlParams.js";
- export default {
- data() {
- return {
- startTime:'',
- endTime:'',
- payUrl:'',
- monthId: '',
- vehicleNo:'',
- monthEndTime:'',
- monthStartTime:'',
- lastActiveDate:null,
- roadNo:null,
- carLicenseList: [],
- isShowCarLicense: false,
- form: {
- energyType:[],
- monthAmount: [],
- carLicense: {},
- month: 1,
- dateRange:""
- },
- label:""
- }
- },
- onLoad (page) {
- if (page.roadNo) {
- this.roadNo = page.roadNo;
- this.getMonthInfo(this.roadNo);
- }
-
- },
- mounted(){
- // console.log(this.lastActiveDate)
- // this.form.dateRange=this.getMonthRange(new Date(this.lastActiveDate),1)
- },
- methods: {
- /**
- * 获取几个月的日期范围
- * {date} Date 起始日期,往后推一天
- * {monthNum} Number 往后月数
- * */
- getMonthRange (date, monthNum) {
- let Date1 = this.lastActiveDate;
- // Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
- Date1 = new Date(Date1)
- const year = Date1.getFullYear()
- const month = Date1.getMonth()+1
- const day = Date1.getDate()
- const hours = Date1.getHours();
- const minutes = Date1.getMinutes();
- const seconds = Date1.getSeconds();
- let days = new Date(year, month, 0)
- days = days.getDate() //获取当前日期中的月的天数
- let year2 = year;
- let month2 = parseInt(month) + parseInt(monthNum)
- if (month2 > 12) {
- year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12))
- month2 = parseInt(month2) % 12;
- }
- let day2 = day;
- let days2 = new Date(year2, month2, 0)
- days2 = days2.getDate()
- if (day2 > days2) {
- day2 = days2
- }
- if (month2 < 10) {
- month2 = '0' + month2;
- }
- const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day)
- const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2)
- this.startTime=t1
- this.endTime=t2
- this.monthStartTime=year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' +seconds
- this.monthEndTime=year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' +seconds
- return t1 + '-' + t2
- },
- /**
- * 月操作 减1
- * */
- reduceMonthNum () {
- if (this.form.month > 1) {
- this.form.month -= 1
- this.form.dateRange = this.getMonthRange(new Date, this.form.month)
- }
- },
- /**
- * 月操作 加1
- * */
- addMonthNum () {
- if(this.form.month >=24){
- this.$refs.uToast.show({
- title: '最多24月',
- type: 'warning',
- })
- return
- }
- this.form.month += 1
-
- this.form.dateRange = this.getMonthRange(new Date, this.form.month)
- },
- carLicenseListConfirm (item) {
- console.log('this.carLicenseList',this.carLicenseList);
- console.log('item',item);
- this.form.carLicense = item[0]
- },
- getMonthInfo(roadNo){
- this.$u.api.monthInfo({roadNo: this.roadNo})
- .then(res => {
- if (res.code === 200){
- this.lastActiveDate = res.data.lastActiveDate;
- this.form.monthAmount=res.data.monthAmount;
- this.carLicenseList = [];
- res.data.vehicleList.forEach(item => {
- const obj = {
- value: item.energyType,
- label: item.vehicleNo,
- energyType:item.energyType
- }
- this.carLicenseList.push(obj)
- });
- console.log('this.carLicenseList',this.carLicenseList)
- this.form.carLicense = this.carLicenseList[0]
- }
-
- })
- },
- submit(roadNo){
- // console.log(this.monthStartTime)
- // console.log('this.form.carLicense',this.form.carLicense);
- this.$u.api.createMonth({
- roadNo:this.roadNo,
- vehicleNo:this.form.carLicense.label,
- energyType:this.form.carLicense.energyType,
- monthStartTime:this.monthStartTime,
- monthEndTime:this.monthEndTime,
- monthCount:this.form.month})
- .then(res => {
- console.log("createMonth",res)
- if(res.code === 200){
- this.monthId = res.data.monthId
- console.log(this.monthId)
- this.$u.api.monthPay({
- monthId:this.monthId
- }).then(res => {
- console.log("monthPay",res)
- if(res.code === 200){
- // this.payUrl=encodeURIComponent(res.data.url);
- // this.$u.route({
- // url: 'pages/handleMonthly/monthPay',
- // params: {
- // payUrl:this.payUrl
- // }
- // });
- window.location.href = res.data.url
- } else {
- this.$refs.uToast.show({
- title: res.msg,
- type: 'error',
- });
- }
- })
- }else{
- this.$refs.uToast.show({
- title: res.msg,
- type: 'warning',
- });
- }
- }).catch(err=>{
-
- });
- // this.getMonthInfo(roadNo)
- }
- },
- computed:{
- dateRange:function(){
- return this.getMonthRange(this.lastActiveDate,this.form.month)
- },
- },
- filters:{
- verifyStatusFilter(value) {
- if (value === 0) {
- return '';
- } else if(value === 1){
- return '汽油车';
- } else if(value === 2){
- return '新能源';
- } else {
- return '';
- }
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- @import './handleMonthly.scss';
- </style>
|