|
|
@@ -2,15 +2,15 @@
|
|
2
|
2
|
<div>
|
|
3
|
3
|
<el-form ref="form" :model="form" style="padding: 20px 100px 0">
|
|
4
|
4
|
<el-form-item label="选择车辆:">
|
|
5
|
|
- <span v-if="chooseCar.length != 0">
|
|
6
|
|
- <el-tag effect="plain" type="success" v-for="item in chooseCar" style="margin: 5px; font-size: 14px"
|
|
7
|
|
- :key="item.licensePlate">
|
|
|
5
|
+ <span v-if="chooseCarList.length != 0">
|
|
|
6
|
+ <el-tag effect="plain" type="success" v-for="item in chooseCarList" style="margin: 5px; font-size: 14px"
|
|
|
7
|
+ :key="item.carId" closable @close="removeCar(item.carId)">
|
|
8
|
8
|
{{ item.licensePlate + item.brand }}
|
|
9
|
9
|
</el-tag>
|
|
10
|
10
|
</span>
|
|
11
|
|
- <el-button type="success" plain icon="el-icon-plus" @click="openCar = true" size="mini">选择</el-button>
|
|
|
11
|
+ <el-button type="success" plain icon="el-icon-plus" @click="openCar = true" size="mini">新增</el-button>
|
|
12
|
12
|
</el-form-item>
|
|
13
|
|
- <el-form-item v-if="chooseCar.length != 0">
|
|
|
13
|
+ <el-form-item v-if="chooseCarList.length != 0">
|
|
14
|
14
|
<table border="1">
|
|
15
|
15
|
<tr>
|
|
16
|
16
|
<td :colspan="4" class="head">车辆成本预算</td>
|
|
|
@@ -21,7 +21,7 @@
|
|
21
|
21
|
<td style="width: 110px">预算天数</td>
|
|
22
|
22
|
<td style="width: 100px">总额</td>
|
|
23
|
23
|
</tr>
|
|
24
|
|
- <tr v-for="car in chooseCar" :key="car.carId">
|
|
|
24
|
+ <tr v-for="car in chooseCarList" :key="car.carId">
|
|
25
|
25
|
<td>{{ car.licensePlate + car.brand }}</td>
|
|
26
|
26
|
<td>
|
|
27
|
27
|
{{ car.dayCost }}
|
|
|
@@ -41,7 +41,7 @@
|
|
41
|
41
|
</el-form>
|
|
42
|
42
|
<!-- 选择车辆对话框 -->
|
|
43
|
43
|
<el-dialog title="选择车辆" :visible.sync="openCar" width="700px" append-to-body>
|
|
44
|
|
- <chooseCar @chooseList="getChooseCar"></chooseCar>
|
|
|
44
|
+ <chooseCar @chooseList="getChooseCar" :selectedCarIds="chooseCarList.map(c => c.carId)"></chooseCar>
|
|
45
|
45
|
</el-dialog>
|
|
46
|
46
|
</div>
|
|
47
|
47
|
</template>
|
|
|
@@ -64,7 +64,7 @@ export default {
|
|
64
|
64
|
form: {
|
|
65
|
65
|
carCost: 0
|
|
66
|
66
|
},
|
|
67
|
|
- chooseCar: [],
|
|
|
67
|
+ chooseCarList: [],
|
|
68
|
68
|
openCar: false,
|
|
69
|
69
|
}
|
|
70
|
70
|
},
|
|
|
@@ -77,7 +77,7 @@ export default {
|
|
77
|
77
|
budgetId() {
|
|
78
|
78
|
this.initForm()
|
|
79
|
79
|
},
|
|
80
|
|
- chooseCar: {
|
|
|
80
|
+ chooseCarList: {
|
|
81
|
81
|
handler(newVal) {
|
|
82
|
82
|
this.$emit('chooseCar', newVal)
|
|
83
|
83
|
},
|
|
|
@@ -92,8 +92,8 @@ export default {
|
|
92
|
92
|
initForm() {
|
|
93
|
93
|
if (this.budgetId != '') {
|
|
94
|
94
|
listBudgetCar({ pageSize: 100, budgetId: this.budgetId }).then((res) => {
|
|
95
|
|
- this.chooseCar = res.rows
|
|
96
|
|
- for (let car of this.chooseCar) {
|
|
|
95
|
+ this.chooseCarList = res.rows
|
|
|
96
|
+ for (let car of this.chooseCarList) {
|
|
97
|
97
|
car.fuel = car.car.fuel
|
|
98
|
98
|
car.insurance = car.car.insurance
|
|
99
|
99
|
car.maintenance = car.car.maintenance
|
|
|
@@ -107,22 +107,27 @@ export default {
|
|
107
|
107
|
},
|
|
108
|
108
|
initCarCost() {
|
|
109
|
109
|
let carCost = 0;
|
|
110
|
|
- for (let car of this.chooseCar) {
|
|
|
110
|
+ for (let car of this.chooseCarList) {
|
|
111
|
111
|
carCost = carCost + Number(car.amount);
|
|
112
|
112
|
}
|
|
113
|
113
|
this.form.carCost = carCost.toFixed(2)
|
|
114
|
114
|
},
|
|
115
|
115
|
getChooseCar(val) {
|
|
116
|
|
- this.chooseCar = val;
|
|
|
116
|
+ const newCars = val.filter(v => !this.chooseCarList.some(c => c.carId === v.carId));
|
|
|
117
|
+ this.chooseCarList = this.chooseCarList.concat(newCars);
|
|
117
|
118
|
this.openCar = false;
|
|
118
|
|
- this.recalculateCost(val, 'amount', 'carCost');
|
|
|
119
|
+ this.recalculateCost(this.chooseCarList, 'amount', 'carCost');
|
|
|
120
|
+ },
|
|
|
121
|
+ removeCar(carId) {
|
|
|
122
|
+ this.chooseCarList = this.chooseCarList.filter(c => c.carId !== carId);
|
|
|
123
|
+ this.recalculateCost(this.chooseCarList, 'amount', 'carCost');
|
|
119
|
124
|
},
|
|
120
|
125
|
calculateCarTotal(car) {
|
|
121
|
126
|
let total = Number(car.dayCost) * Number(car.days);
|
|
122
|
127
|
let sum = total.toFixed(2);
|
|
123
|
128
|
this.$set(car, "depreciation", car.dayCost);
|
|
124
|
129
|
this.$set(car, "amount", sum);
|
|
125
|
|
- this.getCost("amount", "carCost", this.chooseCar);
|
|
|
130
|
+ this.getCost("amount", "carCost", this.chooseCarList);
|
|
126
|
131
|
},
|
|
127
|
132
|
recalculateCost(arr, name, formName) {
|
|
128
|
133
|
let sum = arr.reduce((accumulator, item) => {
|