소스 검색

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

余思翰 1 일 전
부모
커밋
90173659f0
2개의 변경된 파일46개의 추가작업 그리고 17개의 파일을 삭제
  1. 20
    15
      oa-ui/src/views/flowable/form/budget/carTable.vue
  2. 26
    2
      oa-ui/src/views/flowable/form/budget/components/chooseCar.vue

+ 20
- 15
oa-ui/src/views/flowable/form/budget/carTable.vue 파일 보기

@@ -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) => {

+ 26
- 2
oa-ui/src/views/flowable/form/budget/components/chooseCar.vue 파일 보기

@@ -18,7 +18,7 @@
18 18
       </el-form-item>
19 19
     </el-form>
20 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 22
       <el-table-column label="车辆状态" align="center" prop="status">
23 23
         <template slot-scope="scope">
24 24
           <el-tag :type="statusTypeStyle(scope.row.status)">{{ statusTypeText(scope.row.status) }}</el-tag>
@@ -51,6 +51,12 @@
51 51
 import { listCar } from "@/api/oa/car/car";
52 52
 import { getUserByPost } from "@/api/system/post";
53 53
 export default {
54
+  props: {
55
+    selectedCarIds: {
56
+      type: Array,
57
+      default: () => []
58
+    }
59
+  },
54 60
   data() {
55 61
     return {
56 62
       queryParams: {
@@ -92,7 +98,25 @@ export default {
92 98
       return row.carId;
93 99
     },
94 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 121
     clearChoose() {
98 122
       this.$refs.chooseCar.clearSelection();

Loading…
취소
저장