lanan-app/pages/my/carManageForm.vue

500 lines
12 KiB
Vue
Raw Normal View History

2024-08-20 20:02:05 +08:00
<template>
2024-08-22 19:34:47 +08:00
<view class="carManageFormContent">
<v-navigation-bar title="新增车辆"></v-navigation-bar>
<view class="body">
<view class="ail">
<view class="dis_">
<view class="">车辆类型</view>
<view class="right_" @click="show= true">{{carInfo.rescueCarTypeStr||'请选择'}}</view>
2024-08-20 20:02:05 +08:00
</view>
2024-08-22 19:34:47 +08:00
<view class="dis_">
<view class="">车牌号</view>
<view class="right_"> <input placeholder-class="inputPlaceholder" type="text" placeholder="请输入"
v-model="carInfo.rescueCarNum" /> </view>
2024-08-20 20:02:05 +08:00
</view>
2024-08-22 19:34:47 +08:00
<view class="dis_">
<view class="">品牌型号</view>
<view class="right_"> <input placeholder-class="inputPlaceholder" placeholder="请输入" type="text"
v-model="carInfo.rescueCarBrand" /> </view>
2024-08-20 20:02:05 +08:00
</view>
2024-08-22 19:34:47 +08:00
<view class="dis_">
<view class="">车辆图片</view>
<view class="rightImg">
<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic1" name="1" :maxCount="1">
<view class="uploadBtn">
<image class="uploadBtnIcon" src="/static/icons/carManage/image.png" mode="aspectFit"></image>
</view>
</u-upload>
</view>
2024-08-20 20:02:05 +08:00
</view>
2024-08-22 19:34:47 +08:00
<view class="dis_">
<view class="">行驶证</view>
<view class="rightImg">
<u-upload :fileList="fileList2" @afterRead="afterRead2" @delete="deletePic2" name="2" :maxCount="1">
<view class="uploadBtn">
<image class="uploadBtnIcon" src="/static/icons/carManage/image.png" mode="aspectFit"></image>
</view>
</u-upload>
</view>
2024-08-20 20:02:05 +08:00
</view>
2024-08-22 19:34:47 +08:00
<view class="dis_">
<view class="">购买时间</view>
<view class="right_" @click="seletTime('buy')">{{carInfo.carBuyTime||'请选择'}}
</view>
2024-08-20 20:02:05 +08:00
</view>
2024-08-22 19:34:47 +08:00
<view class="dis_">
<view class="">保养到期时间</view>
<view class="right_" @click="seletTime('by')"> {{carInfo.carKeepTime||'请选择'}}
</view>
2024-08-20 20:02:05 +08:00
</view>
2024-08-22 19:34:47 +08:00
<view class="dis_">
<view class="">保险到期时间</view>
<view class="right_" @click="seletTime('bx')"> {{carInfo.carInsuranceTime||'请选择'}}
</view>
</view>
<view class="dis_">
<view class="">年检到期时间</view>
<view class="right_" @click="seletTime('nj')">{{carInfo.carCheckTime||'请选择'}}
</view>
</view>
<view class="dis_">
<view class="">车牌颜色</view>
<view class="right_" @click="carColorShow = true">{{carInfo.carLicenseColorStr||'请选择'}}
</view>
</view>
<view class="dis_">
<view class="">车架号</view>
<view class="right_"> <input placeholder-class="inputPlaceholder" placeholder="请输入" type="text"
v-model="carInfo.frameNumber" />
</view>
</view>
<view class="bo_dis">
<!-- <u-button type="error" v-if="carId" @click="delItem()" text="删除"></u-button> -->
<view class="deleteBtn" v-if="carId" @click="delItem()">删除</view>
<view class="saveBtn" @click="saveOrUpdate" >保存</view>
</view>
2024-08-20 20:02:05 +08:00
</view>
</view>
2024-08-22 19:34:47 +08:00
<tab-bar-vue msg="1"></tab-bar-vue>
<view>
<u-picker :show="show" :columns="jycType" keyName="dictLabel" @confirm="confirm" @cancel="cancel"></u-picker>
<u-picker :show="carColorShow" :columns="licenseColor" keyName="dictLabel" @confirm="confirmClor"
@cancel="cancel"></u-picker>
<u-datetime-picker :show="showtime" mode="date" @confirm="confirmtime"
@cancel="showtime = false"></u-datetime-picker>
2024-08-20 20:02:05 +08:00
</view>
</view>
</template>
<script>
import request from '../../utils/request';
import upload from '@/utils/upload.js'
2024-08-22 19:34:47 +08:00
import VNavigationBar from '@/components/VNavigationBar.vue'
import tabBarVue from '../../components/tabBar/tabBar.vue'
2024-08-20 20:02:05 +08:00
export default {
2024-08-22 19:34:47 +08:00
components: {
VNavigationBar,
tabBarVue
},
2024-08-20 20:02:05 +08:00
data() {
return {
show: false,
carColorShow: false,
showtime: false,
carId: null,
timeType: 'buy',
fileList1: [],
fileList2: [],
imageList1: [],
imageList2: [],
carInfo: {
rescueCarType: "", //车辆类型
rescueCarNum: "", //车牌号
rescueCarBrand: "", //品牌型号
carImage: "", //车辆图片
driveLicenseImage: "", //行驶证
carBuyTime: "", //购买时间
carKeepTime: "", //保养到期时间
carInsuranceTime: "", //保险到期时间
carCheckTime: "", //年检到期时间
carLicenseColor: "", //车牌颜色
carUseNature: "", //使用性质
frameNumber: "" //车架号
},
carUseNature: [], //使用性质列表
jycType: [], //救援车类型
licenseColor: [] //车牌颜色
}
},
onLoad(option) {
this.carId = option.id
this.getDictList()
if (this.carId) {
this.getCarInfo()
}
},
onShow() {
},
methods: {
delItem() {
request({
url: "/system/rescueCar/" + this.carId,
method: 'delete',
}).then(res => {
uni.showToast({
title: "删除成功"
})
setTimeout(function() {
uni.navigateBack()
}.bind(this), 1000); // 2000毫秒后执行
})
},
// 删除图片
deletePic1(event) {
this.imageList1.splice(event.index, 1)
this.fileList1.splice(event.index, 1)
console.log(this.fileList1, this.fileList2);
},
// 删除图片
deletePic2(event) {
this.imageList2.splice(event.index, 1)
this.fileList2.splice(event.index, 1)
console.log(this.fileList1, this.fileList2);
},
// 新增图片
async afterRead2(event) {
console.log('执行了', event);
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file)
let fileListLen = this.fileList2.length
lists.map((item) => {
this.fileList2.push({
...item,
})
})
for (let i = 0; i < lists.length; i++) {
console.log('路径', lists[i].url);
const result = await this.uploadFilePromise2(lists[i].url)
let item = this.fileList2[fileListLen]
this.fileList2.splice(fileListLen, 1, Object.assign(item, {
status: 'success',
message: '',
url: result
}))
fileListLen++
}
},
// 新增图片
async afterRead(event) {
console.log('执行了', event);
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file)
let fileListLen = this.fileList1.length
lists.map((item) => {
this.fileList1.push({
...item,
})
})
for (let i = 0; i < lists.length; i++) {
console.log('路径', lists[i].url);
const result = await this.uploadFilePromise1(lists[i].url)
}
console.log('当前list', this.fileList1);
},
uploadFilePromise1(url) {
uni.compressImage({
src: url,
success: res => {
upload({
url: '/common/upload',
filePath: res.tempFilePath,
}).then((res) => {
this.imageList1.push(res.fileName)
console.log(res);
})
}
})
},
uploadFilePromise2(url) {
uni.compressImage({
src: url,
success: res => {
upload({
url: '/common/upload',
filePath: res.tempFilePath,
}).then((res) => {
this.imageList2.push(res.fileName)
console.log(res);
})
}
})
},
seletTime(type) {
this.timeType = type
this.showtime = true
},
getback() {
uni.navigateBack()
},
confirmClor(e) {
this.carColorShow = false
this.carInfo.carLicenseColor = e.value[0].dictValue
this.carInfo.carLicenseColorStr = e.value[0].dictLabel
},
confirm(e) {
this.show = false
this.carInfo.rescueCarType = e.value[0].dictValue
this.carInfo.rescueCarTypeStr = e.value[0].dictLabel
},
cancel() {
this.show = false
},
confirmtime(e) {
this.showtime = false
const timestamp = e.value
const date = new Date(timestamp);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
let timeTemp = `${year}-${month}-${day}`
console.log(this.rescueTime);
if (this.timeType == 'buy') {
this.carInfo.carBuyTime = timeTemp
}
if (this.timeType == 'bx') {
this.carInfo.carInsuranceTime = timeTemp
}
if (this.timeType == 'by') {
this.carInfo.carKeepTime = timeTemp
}
if (this.timeType == 'nj') {
this.carInfo.carCheckTime = timeTemp
}
},
canceltiem(e) {
console.log(e);
this.showtime = false
},
async saveOrUpdate() {
if (this.imageList1.length > 0) {
this.carInfo.carImage = this.imageList1[0]
}
if (this.imageList2.length > 0) {
this.carInfo.driveLicenseImage = this.imageList2[0]
}
if (!this.carId) {
request({
url: "/system/rescueCar",
method: 'post',
data: this.carInfo
}).then(res => {
uni.showToast({
title: "保存成功"
})
setTimeout(function() {
uni.navigateBack()
}.bind(this), 1000); // 2000毫秒后执行
})
} else {
console.log(this.carInfo, 'update');
request({
url: "/system/rescueCar",
method: 'put',
data: this.carInfo
}).then(res => {
2024-08-22 19:34:47 +08:00
console.log('res: ',res);
2024-08-20 20:02:05 +08:00
uni.showToast({
title: "保存成功"
})
setTimeout(function() {
uni.navigateBack()
}.bind(this), 1000); // 2000毫秒后执行
})
}
},
async getCarInfo() {
this.fileList1 = []
this.fileList2 = []
request({
url: "/system/rescueCar/" + this.carId,
method: 'get',
}).then(res => {
this.carInfo = res.data
if (this.carInfo.carImage) {
this.fileList1.push({
url: this.$baseUrl + this.carInfo.carImage
})
this.imageList1.push(this.carInfo.carImage)
console.log(this.fileList1);
}
if (this.carInfo.driveLicenseImage) {
this.fileList2.push({
url: this.$baseUrl + this.carInfo.driveLicenseImage
})
this.imageList2.push(this.carInfo.driveLicenseImage)
}
})
},
async getDictList() {
request({
url: "/system/dict/data/type/car_use_nature",
method: 'get',
}).then(res => {
this.carUseNature.push(res.data)
})
request({
url: "/system/dict/data/type/jyc_type",
method: 'get',
}).then(res => {
this.jycType.push(res.data)
})
request({
url: "/system/dict/data/type/car_license_color",
method: 'get',
}).then(res => {
this.licenseColor.push(res.data)
})
},
}
}
</script>
<style scoped lang="scss">
2024-08-22 19:34:47 +08:00
.carManageFormContent {
height: 100%;
2024-08-20 20:02:05 +08:00
display: flex;
2024-08-22 19:34:47 +08:00
flex-direction: column;
background: #F7F8FC;
2024-08-20 20:02:05 +08:00
}
2024-08-22 19:34:47 +08:00
.body {
flex: 1;
height: 0;
padding-bottom: 100rpx;
overflow: auto;
2024-08-20 20:02:05 +08:00
}
.ail {
box-sizing: border-box;
2024-08-22 19:34:47 +08:00
padding: 32rpx;
2024-08-20 20:02:05 +08:00
}
.dis_ {
width: 100%;
2024-08-22 19:34:47 +08:00
background: #FFFFFF;
border-radius: 16rpx;
border: 2rpx solid rgba(0, 0, 0, 0.05);
2024-08-20 20:02:05 +08:00
display: flex;
align-items: center;
justify-content: space-between;
margin: 10px auto;
box-sizing: border-box;
2024-08-22 19:34:47 +08:00
padding: 32rpx 38rpx;
color: #000;
font-size: 28rpx;
font-weight: 500;
2024-08-20 20:02:05 +08:00
}
.right_ {
2024-08-22 19:34:47 +08:00
font-weight: normal;
color: #929292;
font-size: 24rpx;
2024-08-20 20:02:05 +08:00
width: 55%;
text-align: right;
input {
width: 100%;
}
2024-08-22 19:34:47 +08:00
/deep/ .inputPlaceholder {
color: #929292;
font-size: 24rpx;
}
}
.uploadBtn {
width: 120rpx;
height: 120rpx;
background: #F7F8FC;
display: flex;
align-items: center;
justify-content: center;
}
.uploadBtnIcon {
width: 44rpx;
height: 44rpx;
2024-08-20 20:02:05 +08:00
}
.rightImg {
color: #666;
2024-08-22 19:34:47 +08:00
// width: 25%;
2024-08-20 20:02:05 +08:00
text-align: right;
}
.bo_dis {
width: 100%;
display: flex;
align-items: center;
justify-content: space-around;
box-sizing: border-box;
2024-08-22 19:34:47 +08:00
column-gap: 20rpx;
}
.deleteBtn {
background: rgb(245,108,108);
width: 686rpx;
height: 88rpx;
border-radius: 12rpx;
color: #FFF;
font-size: 28rpx;
display: flex;
align-items: center;
justify-content: center;
}
.saveBtn {
width: 686rpx;
height: 88rpx;
background: #327DFB;
border-radius: 12rpx;
color: #FFF;
font-size: 28rpx;
display: flex;
align-items: center;
justify-content: center;
2024-08-20 20:02:05 +08:00
}
</style>