2024-09-19 19:46:32 +08:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2025-10-14 15:31:35 +08:00
|
|
|
<div style="display: flex; align-items: center;">
|
|
|
|
|
<el-select v-model="carSelected" clearable style="width: 200px;">
|
2025-11-28 10:21:16 +08:00
|
|
|
<el-option v-for="car in carList" :key="car.id" :label="car.licenseNumber" :value="car.id" />
|
2025-10-14 15:31:35 +08:00
|
|
|
</el-select>
|
|
|
|
|
<el-button type="primary" size="small" @click="addNewCar" style="margin-left: 8px;">
|
|
|
|
|
新增车辆
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<AddCarForm ref="addCarForm" :customer-info="customerInfo" @success="handleCarAddSuccess" />
|
2024-09-19 19:46:32 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
2025-11-28 10:21:16 +08:00
|
|
|
import { remindCarMainPage } from "@/api/base/carmain";
|
2025-10-14 15:31:35 +08:00
|
|
|
import AddCarForm from "./AddCarForm.vue";
|
2024-09-19 19:46:32 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "CarChoose",
|
2025-10-14 15:31:35 +08:00
|
|
|
components: {
|
|
|
|
|
AddCarForm
|
|
|
|
|
},
|
2024-09-19 19:46:32 +08:00
|
|
|
props: {
|
|
|
|
|
value: {
|
|
|
|
|
type: Object
|
|
|
|
|
},
|
|
|
|
|
cusName: {
|
|
|
|
|
type: String,
|
2024-10-08 18:28:36 +08:00
|
|
|
},
|
2025-10-14 15:31:35 +08:00
|
|
|
customerInfo: {
|
|
|
|
|
type: Object,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
2025-11-28 10:21:16 +08:00
|
|
|
inList: {
|
2024-10-08 18:28:36 +08:00
|
|
|
type: Object,
|
|
|
|
|
default: null,
|
|
|
|
|
required: false
|
2024-09-19 19:46:32 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
carSelected(val) {
|
2024-09-21 20:42:56 +08:00
|
|
|
if (val) {
|
2024-11-16 12:05:12 +08:00
|
|
|
let car = this.carList.find(item => item.id === val);
|
|
|
|
|
car = {
|
|
|
|
|
...car,
|
|
|
|
|
modelStr: car?.brandStr + " " + car?.carModel
|
|
|
|
|
}
|
2024-09-21 20:42:56 +08:00
|
|
|
this.$emit('input', car);
|
|
|
|
|
}
|
2024-09-19 19:46:32 +08:00
|
|
|
},
|
|
|
|
|
value(val) {
|
|
|
|
|
this.carSelected = val ? val.id : null;
|
|
|
|
|
},
|
2025-11-28 10:21:16 +08:00
|
|
|
cusName: {
|
|
|
|
|
handler(val, old) {
|
|
|
|
|
if (val !== old) {
|
|
|
|
|
// this.carSelected = null
|
|
|
|
|
this.getCarList()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
immediate: true
|
2024-10-08 18:28:36 +08:00
|
|
|
},
|
2025-11-28 10:21:16 +08:00
|
|
|
inList(val) {
|
|
|
|
|
if (val) {
|
2024-10-08 18:28:36 +08:00
|
|
|
const flag = this.carList.findIndex(item => item.id === val.id)
|
2025-11-28 10:21:16 +08:00
|
|
|
if (flag > 0) {
|
2024-10-08 18:28:36 +08:00
|
|
|
this.carList.splice(flag, 1)
|
|
|
|
|
}
|
|
|
|
|
this.carList.unshift(val)
|
|
|
|
|
this.carSelected = val.id
|
|
|
|
|
}
|
2024-09-19 19:46:32 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
carSelected: null,
|
|
|
|
|
carList: [],
|
|
|
|
|
queryParams: {
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
cusName: null
|
|
|
|
|
},
|
|
|
|
|
total: 0
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
async getCarList() {
|
|
|
|
|
try {
|
|
|
|
|
if (this.cusName) {
|
|
|
|
|
this.queryParams["cusName"] = this.cusName
|
|
|
|
|
const res = await remindCarMainPage(this.queryParams)
|
|
|
|
|
this.carList = res.data.records
|
|
|
|
|
this.total = res.data.total
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
}
|
2025-10-14 15:31:35 +08:00
|
|
|
},
|
|
|
|
|
addNewCar() {
|
|
|
|
|
// 打开新增车辆表单
|
|
|
|
|
this.$refs.addCarForm.open();
|
|
|
|
|
},
|
|
|
|
|
handleCarAddSuccess(carInfo) {
|
|
|
|
|
// 新增成功后刷新车辆列表
|
|
|
|
|
this.getCarList();
|
|
|
|
|
// 自动选中新添加的车辆
|
|
|
|
|
this.carSelected = carInfo.id;
|
2024-09-19 19:46:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2025-11-28 10:21:16 +08:00
|
|
|
<style scoped lang="scss"></style>
|