lanan-repair-app/pages/myCar/carDetail.vue

478 lines
14 KiB
Vue
Raw Normal View History

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">
2024-10-30 15:53:34 +08:00
<u-upload
:fileList="fileList1"
@afterRead="afterRead"
@delete="deletePic"
name="1"
:maxCount="1"
multiple
></u-upload>
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="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-30 15:53:34 +08:00
<!-- @click="brandType = true;"-->
<u-form-item label="车辆品牌" labelWidth="200">
2024-10-31 14:34:44 +08:00
<picker @change="picker($event)" :value="arrayIndex" :range="brandList" range-key="brandName" v-if="brandList">
2024-10-30 15:53:34 +08:00
<view class="uni-input">{{ brandList && brandList[arrayIndex] ? brandList[arrayIndex].brandName : '' }}</view>
</picker>
2024-10-17 21:34:02 +08:00
</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-30 15:53:34 +08:00
<u-form-item class="formItem" label="车辆性质" labelWidth="200">
2024-10-31 14:34:44 +08:00
<picker @change="natureChange" :value="natureIndex" :range="natureList" range-key="value" v-if="natureList">
2024-10-30 15:53:34 +08:00
<view class="uni-input">{{ natureList[natureIndex].value}}</view>
</picker>
</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>
<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-17 21:34:02 +08:00
import request from "@/utils/request";
2024-10-30 15:53:34 +08:00
import config from '@/config'
import upload from "@/utils/upload";
import {getDictByCode} from "@/utils/utils";
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-30 15:53:34 +08:00
arrayIndex: 0,
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-30 15:53:34 +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-30 15:53:34 +08:00
fileList1: [],
imageUrl: '',
//可选车辆性质范围
natureList: [],
natureIndex: 0,
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-30 15:53:34 +08:00
if (this.car.carLicenseImg) {
this.fileList1.push({
url: config.baseImageUrl + this.car.carLicenseImg
})
}
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-30 15:53:34 +08:00
this.getBrandList()
this.getNatureList()
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-30 15:53:34 +08:00
2024-10-09 13:34:36 +08:00
},
methods: {
2024-10-13 23:24:23 +08:00
typeSelect(e) {
2024-10-09 13:34:36 +08:00
},
2024-10-30 15:53:34 +08:00
picker(e) {
// 或者
this.arrayIndex = e.target.value;
this.brandId = this.brandList[e.target.value].value
},
// 车辆性质选择事件
natureChange(event) {
const newIndex = event.detail.value;
this.natureIndex = newIndex;
//
this.car.carNature = this.natureList[newIndex].value;
2024-10-17 21:34:02 +08:00
},
getBrandList() {
request({
url: '/admin-api/base/carBrand/page',
method: 'GET',
params: {
2024-10-30 15:53:34 +08:00
pageNo: 1,
pageSize: 10000
2024-10-17 21:34:02 +08:00
}
}).then(res => {
res.data.records.forEach(item => {
item.name = item.brandName,
2024-10-30 15:53:34 +08:00
item.value = item.id
2024-10-17 21:34:02 +08:00
})
this.brandList = res.data.records
2024-10-30 15:53:34 +08:00
if (this.car) {
for (let i = 0; i < this.brandList.length; i++) {
if (this.car.carBrand == this.brandList[i].id) {
this.arrayIndex = i;
}
}
}
2024-10-17 21:34:02 +08:00
})
},
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')
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
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]
2024-10-21 18:11:30 +08:00
//将日期转为时间戳
2024-10-30 15:53:34 +08:00
if (this.car.inspectionDate) {
this.car.inspectionDate = new Date(this.car.inspectionDate).getTime()
}else {
this.car.inspectionDate = undefined
}
if (this.car.insuranceDate) {
this.car.insuranceDate = new Date(this.car.insuranceDate).getTime()
}else {
this.car.insuranceDate = undefined
}
if (this.car.carRegisterDate) {
this.car.carRegisterDate = new Date(this.car.carRegisterDate).getTime()
}else {
this.car.carRegisterDate = undefined
}
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: {
2024-10-30 15:53:34 +08:00
licenseNumber: this.car.licenseNumber
2024-10-18 17:15:20 +08:00
}
2024-10-30 15:53:34 +08:00
}).then(res => {
2024-10-18 17:15:20 +08:00
this.car = res.data.records[0]
request({
url: '/admin-api/base/custom/bindCustomerCar',
method: 'post',
2024-10-30 15:53:34 +08:00
data: {
2024-10-18 17:15:20 +08:00
carList: [this.car],
id: this.userInfo.id
}
2024-10-30 15:53:34 +08:00
}).then(res => {
2024-10-18 17:15:20 +08:00
uni.navigateBack();
})
})
2024-10-17 21:34:02 +08:00
})
}
2024-10-30 15:53:34 +08:00
},
// 查询下拉 车辆性质
async getNatureList() {
this.natureList= getDictByCode('car_nature')
if (this.bo2 == true) {
2024-10-31 14:34:44 +08:00
// setTimeout(() => {
// this.car.carNature = this.natureList[0].value;
// }, 15000)
2024-10-30 15:53:34 +08:00
} else {
// 如果是修改 遍历当前集合 将index 同步
this.natureList.forEach((item, index) => {
if (item.value == this.car.carNature) {
this.natureIndex = index;
}
})
}
2024-10-18 17:15:20 +08:00
2024-10-30 15:53:34 +08:00
},
// 删除图片
deletePic(event) {
this[`fileList${event.name}`].splice(event.index, 1)
},
// 新增图片
async afterRead(event) {
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file)
let fileListLen = this[`fileList${event.name}`].length
lists.map((item) => {
this[`fileList${event.name}`].push({
...item,
status: 'uploading',
message: '上传中'
})
})
for (let i = 0; i < lists.length; i++) {
const result = await this.uploadFilePromise(lists[i].url)
let item = this[`fileList${event.name}`][fileListLen]
this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
status: 'success',
message: '',
url: result
}))
fileListLen++
}
},
uploadFilePromise(url) {
return new Promise((resolve, reject) => {
upload({
url: '/admin-api/infra/file/upload',
filePath: url
}).then(res => {
resolve(config.baseImageUrl +res.data)
this.car.carLicenseImg = res.data
this.imageUrl = config.baseImageUrl + res.data
request({
url: '/admin-api/base/carMain/vehicleLicenseOCR',
method: 'POST',
data: this.imageUrl,
tenantIdFlag: false
}).then((res) => {
this.car.vin = res.data.vin
this.car.licenseNumber = res.data.plateNo
this.car.carRegisterDate = res.data.issueDate
this.car.engineNumber = res.data.engineNo
//车辆品牌自动定位
this.brandList.forEach((item, index) => {
if (item.brandName == res.data.brand) {
this.arrayIndex = index;
this.brandId = this.brandList[index].id;
}
})
//车辆性质自动定位
this.natureList.forEach((item, index) => {
if (item.label == res.data.useCharacter) {
this.natureIndex = index;
this.car.carNature = this.natureList[index].value;
}
})
})
})
})
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>