2024-10-09 13:34:36 +08:00
|
|
|
<template>
|
|
|
|
<view class="container">
|
2024-10-13 23:24:23 +08:00
|
|
|
<VNavigationBar :title="pageTitle" background-color="#fff" title-color="#333"></VNavigationBar>
|
2024-10-09 13:34:36 +08:00
|
|
|
<view class="body">
|
2024-10-13 23:24:23 +08:00
|
|
|
<u-form labelPosition="top">
|
|
|
|
<view class="card">
|
|
|
|
<u-form-item borderBottom label="上传图片" labelWidth="200">
|
|
|
|
<u-upload></u-upload>
|
|
|
|
</u-form-item>
|
2024-10-18 17:15:20 +08:00
|
|
|
<u-form-item borderBottom label="车牌号" labelWidth="200" @click="carInputClick();">
|
2024-10-13 23:24:23 +08:00
|
|
|
<u-input
|
|
|
|
v-model="car.licenseNumber"
|
|
|
|
border="none"
|
|
|
|
disabled
|
|
|
|
disabledColor="#ffffff"
|
|
|
|
placeholder="请输入车牌号"
|
|
|
|
></u-input>
|
|
|
|
<u-icon
|
|
|
|
slot="right"
|
|
|
|
name="arrow-right"
|
|
|
|
></u-icon>
|
|
|
|
</u-form-item>
|
2024-10-18 17:15:20 +08:00
|
|
|
<u-form-item label="车辆品牌" labelWidth="200" @click="brandType = true;">
|
2024-10-17 21:34:02 +08:00
|
|
|
<u-input
|
|
|
|
v-model="car.brandStr"
|
|
|
|
border="none"
|
|
|
|
disabled
|
|
|
|
disabledColor="#ffffff"
|
|
|
|
placeholder="请选择车辆品牌"
|
|
|
|
></u-input>
|
|
|
|
<u-icon
|
|
|
|
slot="right"
|
|
|
|
name="arrow-right"
|
|
|
|
></u-icon>
|
|
|
|
</u-form-item>
|
2024-10-18 17:15:20 +08:00
|
|
|
<u-form-item label="车辆型号" labelWidth="200">
|
2024-10-13 23:24:23 +08:00
|
|
|
<u-input
|
2024-10-18 17:15:20 +08:00
|
|
|
v-model="car.carModel"
|
2024-10-13 23:24:23 +08:00
|
|
|
border="none"
|
2024-10-18 17:15:20 +08:00
|
|
|
placeholder="请输入车辆型号"
|
2024-10-13 23:24:23 +08:00
|
|
|
></u-input>
|
|
|
|
</u-form-item>
|
2024-10-09 13:34:36 +08:00
|
|
|
</view>
|
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
<view class="card">
|
|
|
|
<u-form-item borderBottom label="车架号" labelWidth="200">
|
2024-10-17 21:34:02 +08:00
|
|
|
<u-input v-model="car.vin" border="none" placeholder="请输入车架号"></u-input>
|
2024-10-13 23:24:23 +08:00
|
|
|
</u-form-item>
|
|
|
|
<u-form-item borderBottom label="发动机号" labelWidth="200">
|
2024-10-17 21:34:02 +08:00
|
|
|
<u-input v-model="car.engineNumber" border="none" placeholder="请输入发动机号"></u-input>
|
2024-10-13 23:24:23 +08:00
|
|
|
</u-form-item>
|
2024-10-18 17:15:20 +08:00
|
|
|
<u-form-item borderBottom label="年检时间" labelWidth="200" @click="openDatePicker('nj'); ">
|
2024-10-13 23:24:23 +08:00
|
|
|
<u-input
|
2024-10-17 21:34:02 +08:00
|
|
|
v-model="car.inspectionDate"
|
2024-10-13 23:24:23 +08:00
|
|
|
border="none"
|
|
|
|
disabled
|
|
|
|
disabledColor="#ffffff"
|
|
|
|
placeholder="请选择年检时间"
|
|
|
|
></u-input>
|
|
|
|
<u-icon
|
|
|
|
slot="right"
|
|
|
|
name="arrow-right"
|
|
|
|
></u-icon>
|
|
|
|
</u-form-item>
|
|
|
|
<u-form-item borderBottom label="保险时间" labelWidth="200" @click="openDatePicker('bx'); hideKeyboard()">
|
|
|
|
<u-input
|
2024-10-17 21:34:02 +08:00
|
|
|
v-model="car.insuranceDate"
|
2024-10-13 23:24:23 +08:00
|
|
|
border="none"
|
|
|
|
disabled
|
|
|
|
disabledColor="#ffffff"
|
|
|
|
placeholder="请选择保险时间"
|
|
|
|
></u-input>
|
|
|
|
<u-icon
|
|
|
|
slot="right"
|
|
|
|
name="arrow-right"
|
|
|
|
></u-icon>
|
|
|
|
</u-form-item>
|
|
|
|
<u-form-item label="注册日期时间" labelWidth="200" @click="openDatePicker('zcrq'); hideKeyboard()">
|
|
|
|
<u-input
|
2024-10-17 21:34:02 +08:00
|
|
|
v-model="car.carRegisterDate"
|
2024-10-13 23:24:23 +08:00
|
|
|
border="none"
|
|
|
|
disabled
|
|
|
|
disabledColor="#ffffff"
|
|
|
|
placeholder="请选择注册日期时间"
|
|
|
|
></u-input>
|
|
|
|
<u-icon
|
|
|
|
slot="right"
|
|
|
|
name="arrow-right"
|
|
|
|
></u-icon>
|
|
|
|
</u-form-item>
|
|
|
|
</view>
|
|
|
|
</u-form>
|
|
|
|
|
2024-10-17 21:34:02 +08:00
|
|
|
<!-- 车辆品牌 -->
|
|
|
|
<u-action-sheet
|
|
|
|
:actions="brandList"
|
|
|
|
:show="brandType"
|
|
|
|
title="请选择车辆品牌"
|
|
|
|
@close="brandType = false"
|
|
|
|
@select="brandSelect"
|
|
|
|
>
|
|
|
|
</u-action-sheet>
|
2024-10-13 23:24:23 +08:00
|
|
|
<!-- 车辆型号 -->
|
|
|
|
<u-action-sheet
|
|
|
|
:actions="typeList"
|
|
|
|
:show="showType"
|
|
|
|
title="请选择车辆型号"
|
|
|
|
@close="showType = false"
|
|
|
|
@select="typeSelect"
|
|
|
|
>
|
|
|
|
</u-action-sheet>
|
|
|
|
|
|
|
|
<keyboard-plate ref="plateNumber" :plateNum.sync='car.licenseNumber' isShow
|
|
|
|
@change="getPlateNum"></keyboard-plate>
|
|
|
|
<u-datetime-picker
|
|
|
|
v-model="datePickerValue"
|
|
|
|
:formatter="formatter"
|
|
|
|
:show="datePickerShow"
|
|
|
|
mode="date"
|
|
|
|
@cancel="datePickerCancel"
|
|
|
|
@confirm="datePickerConfirm"
|
|
|
|
></u-datetime-picker>
|
2024-10-09 13:34:36 +08:00
|
|
|
</view>
|
|
|
|
<view class="footer">
|
2024-10-13 23:24:23 +08:00
|
|
|
<view class="btnItem edit" @click="submit">
|
2024-10-09 13:34:36 +08:00
|
|
|
确定
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import VNavigationBar from '@/components/VNavigationBar.vue';
|
2024-10-13 23:24:23 +08:00
|
|
|
import {bus} from "@/utils/eventBus";
|
2024-10-17 21:34:02 +08:00
|
|
|
import request from "@/utils/request";
|
2024-10-09 13:34:36 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
VNavigationBar
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-10-13 23:24:23 +08:00
|
|
|
pageTitle: '',
|
2024-10-09 13:34:36 +08:00
|
|
|
car: {
|
|
|
|
// 车牌号
|
|
|
|
licenseNumber: '',
|
|
|
|
// 型号
|
|
|
|
carModelInput: '',
|
|
|
|
// 品牌id
|
2024-10-13 23:24:23 +08:00
|
|
|
carBrand: '',
|
2024-10-09 13:34:36 +08:00
|
|
|
// 车辆类别 字典字段
|
2024-10-13 23:24:23 +08:00
|
|
|
carCategory: '',
|
2024-10-09 13:34:36 +08:00
|
|
|
// 车辆性质 字典字段
|
2024-10-13 23:24:23 +08:00
|
|
|
carNature: '',
|
2024-10-09 13:34:36 +08:00
|
|
|
// 注册日期
|
2024-10-18 17:15:20 +08:00
|
|
|
carRegisterDate: '',
|
2024-10-17 21:34:02 +08:00
|
|
|
// 车辆品牌型号数组
|
2024-10-18 17:15:20 +08:00
|
|
|
brandAndModel: [],
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
2024-10-18 17:15:20 +08:00
|
|
|
userInfo: {},
|
2024-10-09 13:34:36 +08:00
|
|
|
bo1: false,
|
|
|
|
bo2: true,
|
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
datePickerShow: false,
|
|
|
|
datePickerValue: new Date().getTime(),
|
|
|
|
pickerConfirmField: 'njDate',
|
2024-10-17 21:34:02 +08:00
|
|
|
brandId:'',
|
2024-10-13 23:24:23 +08:00
|
|
|
|
|
|
|
showType: false,
|
2024-10-17 21:34:02 +08:00
|
|
|
brandType: false,
|
|
|
|
typeList: [],
|
|
|
|
brandList: [],
|
2024-10-09 13:34:36 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
onLoad(options) {
|
|
|
|
// 如果是修改
|
|
|
|
if (options.car) {
|
|
|
|
// 有数据为编辑 或 删除
|
|
|
|
this.car = JSON.parse(decodeURIComponent(options.car));
|
2024-10-21 18:11:30 +08:00
|
|
|
this.brandId = this.car.carBrand
|
2024-10-09 13:34:36 +08:00
|
|
|
console.log('初始化页面数据', this.car)
|
|
|
|
this.bo1 = true;
|
|
|
|
this.bo2 = false;
|
2024-10-13 23:24:23 +08:00
|
|
|
this.pageTitle = '修改车辆信息'
|
2024-10-09 13:34:36 +08:00
|
|
|
} else {
|
|
|
|
// 没有数据 需要赋值一下初始化
|
|
|
|
this.bo1 = false;
|
|
|
|
this.bo2 = true;
|
2024-10-13 23:24:23 +08:00
|
|
|
this.pageTitle = '添加车辆信息'
|
2024-10-09 13:34:36 +08:00
|
|
|
}
|
2024-10-18 17:15:20 +08:00
|
|
|
this.car.userId = JSON.parse(decodeURIComponent(options.userInfo)).userId;
|
|
|
|
this.userInfo = JSON.parse(decodeURIComponent(options.userInfo))
|
|
|
|
console.log(this.car)
|
2024-10-17 21:34:02 +08:00
|
|
|
this.getBrandList()
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2024-10-13 23:24:23 +08:00
|
|
|
typeSelect(e) {
|
|
|
|
console.log('e', e)
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
2024-10-17 21:34:02 +08:00
|
|
|
brandSelect(e) {
|
|
|
|
console.log('e', e)
|
|
|
|
this.brandId = e.value
|
2024-10-21 18:11:30 +08:00
|
|
|
this.car.brandStr = e.name
|
2024-10-18 17:15:20 +08:00
|
|
|
// this.getCarModule()
|
2024-10-17 21:34:02 +08:00
|
|
|
},
|
|
|
|
getBrandList() {
|
|
|
|
request({
|
|
|
|
url: '/admin-api/base/carBrand/page',
|
|
|
|
method: 'GET',
|
|
|
|
params: {
|
|
|
|
page: 1,
|
|
|
|
size: 10000
|
|
|
|
}
|
|
|
|
}).then(res => {
|
|
|
|
console.log(res);
|
|
|
|
res.data.records.forEach(item => {
|
|
|
|
item.name = item.brandName,
|
|
|
|
item.value = item.id
|
|
|
|
})
|
|
|
|
this.brandList = res.data.records
|
|
|
|
})
|
|
|
|
},
|
2024-10-09 13:34:36 +08:00
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
// 打开车牌选择器
|
|
|
|
carInputClick() {
|
|
|
|
this.$refs.plateNumber.open();
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
2024-10-13 23:24:23 +08:00
|
|
|
getPlateNum(e) {
|
2024-10-09 13:34:36 +08:00
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
},
|
2024-10-09 13:34:36 +08:00
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
openDatePicker(picker) {
|
|
|
|
if (picker === 'nj') {
|
2024-10-18 17:15:20 +08:00
|
|
|
this.pickerConfirmField = 'inspectionDate'
|
2024-10-13 23:24:23 +08:00
|
|
|
} else if (picker === 'bx') {
|
2024-10-18 17:15:20 +08:00
|
|
|
this.pickerConfirmField = 'insuranceDate'
|
2024-10-13 23:24:23 +08:00
|
|
|
} else if (picker === 'zcrq') {
|
2024-10-18 17:15:20 +08:00
|
|
|
this.pickerConfirmField = 'carRegisterDate'
|
2024-10-09 13:34:36 +08:00
|
|
|
}
|
2024-10-13 23:24:23 +08:00
|
|
|
this.datePickerShow = true
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
2024-10-13 23:24:23 +08:00
|
|
|
datePickerConfirm({value}, field, picker) {
|
2024-10-21 18:11:30 +08:00
|
|
|
let date;
|
|
|
|
|
|
|
|
// 检查 value 是否为时间戳
|
|
|
|
if (typeof value === 'number') {
|
|
|
|
// 如果是时间戳,确保是毫秒单位
|
|
|
|
date = new Date(value);
|
|
|
|
} else if (typeof value === 'string') {
|
|
|
|
// 如果是日期字符串,尝试解析
|
|
|
|
date = new Date(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 检查日期是否有效
|
|
|
|
if (isNaN(date.getTime())) {
|
|
|
|
console.error('Invalid date:', value);
|
|
|
|
return;
|
|
|
|
}
|
2024-10-13 23:24:23 +08:00
|
|
|
this.car[this.pickerConfirmField] = date.getFullYear() + '-' + (Number(date.getMonth()) + 1 + '').padStart(2, '0') + '-' + (date.getDate() + '').padStart(2, '0')
|
2024-10-21 18:11:30 +08:00
|
|
|
console.log("this.car[this.pickerConfirmField]",this.car[this.pickerConfirmField])
|
2024-10-13 23:24:23 +08:00
|
|
|
this.datePickerCancel(picker)
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
2024-10-13 23:24:23 +08:00
|
|
|
datePickerCancel(picker) {
|
|
|
|
this.datePickerValue = new Date().getTime()
|
|
|
|
this.datePickerShow = false
|
|
|
|
},
|
|
|
|
formatter(type, value) {
|
|
|
|
if (type === 'year') {
|
|
|
|
return `${value}年`
|
|
|
|
}
|
|
|
|
if (type === 'month') {
|
|
|
|
return `${value}月`
|
|
|
|
}
|
|
|
|
if (type === 'day') {
|
|
|
|
return `${value}日`
|
2024-10-09 13:34:36 +08:00
|
|
|
}
|
2024-10-13 23:24:23 +08:00
|
|
|
console.log('for value', value)
|
|
|
|
return value
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
|
|
|
// 新增
|
|
|
|
async submit() {
|
2024-10-18 17:15:20 +08:00
|
|
|
// bus.$emit('updateCarInfo', this.car)
|
|
|
|
this.car.brandAndModel = [this.brandId, this.car.carModel]
|
|
|
|
console.log("car",this.car)
|
2024-10-21 18:11:30 +08:00
|
|
|
//将日期转为时间戳
|
|
|
|
this.car.inspectionDate = new Date(this.car.inspectionDate).getTime()
|
|
|
|
this.car.insuranceDate = new Date(this.car.insuranceDate).getTime()
|
|
|
|
this.car.carRegisterDate = new Date(this.car.carRegisterDate).getTime()
|
2024-10-17 21:34:02 +08:00
|
|
|
if (this.car.id != null) {
|
|
|
|
request({
|
|
|
|
url: '/admin-api/base/carMain/update',
|
|
|
|
method: 'PUT',
|
|
|
|
data: this.car,
|
2024-10-21 18:11:30 +08:00
|
|
|
}).then(res => {
|
|
|
|
uni.navigateBack();
|
2024-10-17 21:34:02 +08:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
request({
|
|
|
|
url: '/admin-api/base/carMain/create',
|
|
|
|
method: 'POST',
|
|
|
|
data: this.car,
|
2024-10-18 17:15:20 +08:00
|
|
|
}).then(res => {
|
|
|
|
request({
|
|
|
|
url: '/admin-api/base/carMain/page',
|
|
|
|
method: 'GET',
|
|
|
|
params: {
|
|
|
|
licenseNumber:this.car.licenseNumber
|
|
|
|
}
|
|
|
|
}).then( res =>{
|
|
|
|
this.car = res.data.records[0]
|
|
|
|
console.log("执行")
|
|
|
|
request({
|
|
|
|
url: '/admin-api/base/custom/bindCustomerCar',
|
|
|
|
method: 'post',
|
|
|
|
data :{
|
|
|
|
carList: [this.car],
|
|
|
|
id: this.userInfo.id
|
|
|
|
}
|
|
|
|
}).then( res =>{
|
|
|
|
uni.navigateBack();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-10-17 21:34:02 +08:00
|
|
|
})
|
|
|
|
}
|
2024-10-18 17:15:20 +08:00
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
// let res = await request({
|
|
|
|
// url: '/userClient/base/myCar/create',
|
|
|
|
// method: 'POST',
|
|
|
|
// data: this.car,
|
|
|
|
// })
|
|
|
|
// if (res.code == 200) {
|
|
|
|
// // 新增成功返回上一个页面
|
|
|
|
// bus.$emit('updateCarInfo', res.result)
|
|
|
|
// uni.navigateBack();
|
|
|
|
// }
|
2024-10-09 13:34:36 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
|
|
|
|
|
|
|
.container {
|
|
|
|
box-sizing: border-box;
|
|
|
|
height: 100%;
|
|
|
|
background-color: #f3f5f7;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
.body {
|
|
|
|
flex: 1;
|
|
|
|
height: 0;
|
|
|
|
overflow: auto;
|
|
|
|
|
|
|
|
.card {
|
2024-10-13 23:24:23 +08:00
|
|
|
margin: 20rpx 30rpx;
|
|
|
|
padding: 0 30rpx;
|
2024-10-09 13:34:36 +08:00
|
|
|
background-color: #fff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
background: #ffffff;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2024-10-13 23:24:23 +08:00
|
|
|
justify-content: center;
|
2024-10-09 13:34:36 +08:00
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
padding: 30rpx 0;
|
2024-10-09 13:34:36 +08:00
|
|
|
|
|
|
|
.btnItem {
|
2024-10-13 23:24:23 +08:00
|
|
|
width: 510rpx;
|
|
|
|
height: 76rpx;
|
|
|
|
background: #0174F6;
|
|
|
|
border-radius: 38rpx 38rpx 38rpx 38rpx;
|
2024-10-09 13:34:36 +08:00
|
|
|
|
|
|
|
font-size: 32rpx;
|
2024-10-13 23:24:23 +08:00
|
|
|
color: #FFFFFF;
|
2024-10-09 13:34:36 +08:00
|
|
|
|
2024-10-13 23:24:23 +08:00
|
|
|
line-height: 76rpx;
|
|
|
|
text-align: center;
|
2024-10-09 13:34:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|