Преглед изворни кода

网页端:更新项目预算里车辆预算的选择逻辑

余思翰 пре 1 дан
родитељ
комит
90173659f0

+ 20
- 15
oa-ui/src/views/flowable/form/budget/carTable.vue Прегледај датотеку

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

+ 26
- 2
oa-ui/src/views/flowable/form/budget/components/chooseCar.vue Прегледај датотеку

18
       </el-form-item>
18
       </el-form-item>
19
     </el-form>
19
     </el-form>
20
     <el-table ref="chooseCar" :data="list" @selection-change="handleSelectionChange" :row-key="getRowKeys">
20
     <el-table ref="chooseCar" :data="list" @selection-change="handleSelectionChange" :row-key="getRowKeys">
21
-      <el-table-column type="selection" width="50" align="center" :reserve-selection="true" />
21
+      <el-table-column type="selection" width="50" align="center" :reserve-selection="true" :selectable="isSelectable" />
22
       <el-table-column label="车辆状态" align="center" prop="status">
22
       <el-table-column label="车辆状态" align="center" prop="status">
23
         <template slot-scope="scope">
23
         <template slot-scope="scope">
24
           <el-tag :type="statusTypeStyle(scope.row.status)">{{ statusTypeText(scope.row.status) }}</el-tag>
24
           <el-tag :type="statusTypeStyle(scope.row.status)">{{ statusTypeText(scope.row.status) }}</el-tag>
51
 import { listCar } from "@/api/oa/car/car";
51
 import { listCar } from "@/api/oa/car/car";
52
 import { getUserByPost } from "@/api/system/post";
52
 import { getUserByPost } from "@/api/system/post";
53
 export default {
53
 export default {
54
+  props: {
55
+    selectedCarIds: {
56
+      type: Array,
57
+      default: () => []
58
+    }
59
+  },
54
   data() {
60
   data() {
55
     return {
61
     return {
56
       queryParams: {
62
       queryParams: {
92
       return row.carId;
98
       return row.carId;
93
     },
99
     },
94
     confirmChoose() {
100
     confirmChoose() {
95
-      this.$emit('chooseList', this.chooseList)
101
+      if (!this.chooseList || this.chooseList.length === 0) {
102
+        return;
103
+      }
104
+      const existedCars = this.chooseList.filter(c => this.selectedCarIds.includes(c.carId));
105
+      let cars = this.chooseList.filter(c => !this.selectedCarIds.includes(c.carId));
106
+      if (cars.length === 0) {
107
+        const names = existedCars.map(c => c.licensePlate + c.brand).join('、');
108
+        this.$message.warning(`所选车辆【${names}】已存在,无法重复添加`);
109
+        return;
110
+      }
111
+      if (existedCars.length > 0) {
112
+        const names = existedCars.map(c => c.licensePlate + c.brand).join('、');
113
+        this.$message.warning(`车辆【${names}】已存在,已自动过滤`);
114
+      }
115
+      this.$emit('chooseList', cars);
116
+      this.clearChoose();
117
+    },
118
+    isSelectable(row) {
119
+      return !this.selectedCarIds.includes(row.carId);
96
     },
120
     },
97
     clearChoose() {
121
     clearChoose() {
98
       this.$refs.chooseCar.clearSelection();
122
       this.$refs.chooseCar.clearSelection();

Loading…
Откажи
Сачувај