lanan-system-vue/src/views/repair/Components/CarChoose.vue

114 lines
2.5 KiB
Vue
Raw Normal View History

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;">
<el-option v-for="car in carList" :key="car.id" :label="car.licenseNumber" :value="car.id"/>
</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>
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,
},
2025-10-14 15:31:35 +08:00
customerInfo: {
type: Object,
required: true
},
inList:{
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) {
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;
},
cusName(val, old) {
2024-09-21 20:42:56 +08:00
if (val !== old) {
// this.carSelected = null
2024-09-19 19:46:32 +08:00
this.getCarList()
}
},
inList(val){
if (val){
const flag = this.carList.findIndex(item => item.id === val.id)
if (flag > 0){
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>
<style scoped lang="scss">
</style>