spring
7 天以前 61955574b77ffa740802bb8b45836ab91cb5be55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<template>
  <div class="app-container">
    <div class="search_form">
      <div>
        <span class="search_title">车牌号码:</span>
        <el-input
          v-model="searchForm.plateNo"
          style="width: 240px"
          placeholder="请输入车牌号码"
          clearable
          :prefix-icon="Search"
          @change="handleQuery"
        />
        <el-button type="primary" @click="handleQuery" style="margin-left: 10px">
          搜索
        </el-button>
      </div>
      <div>
        <el-button type="primary" @click="openForm('add')">新增</el-button>
        <el-button type="danger" plain @click="handleDelete">删除</el-button>
      </div>
    </div>
 
    <div class="table_list">
      <PIMTable
        rowKey="id"
        :column="tableColumn"
        :tableData="tableData"
        :page="page"
        :isSelection="true"
        :tableLoading="tableLoading"
        @selection-change="handleSelectionChange"
        @pagination="pagination"
      />
    </div>
 
    <!-- 新增/编辑车辆信息弹窗 -->
    <el-dialog
      v-model="dialogVisible"
      :title="operationType === 'add' ? '新增车辆信息' : '编辑车辆信息'"
      width="70%"
      @close="closeFormDialog"
    >
      <el-form
        ref="formRef"
        :model="form"
        :rules="rules"
        label-width="140px"
        label-position="top"
      >
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="车牌号码" prop="plateNo">
              <el-input v-model="form.plateNo" placeholder="请输入车牌号码" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="号牌颜色" prop="plateColor">
              <el-input v-model="form.plateColor" placeholder="请输入号牌颜色" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="车辆类型" prop="carType">
              <el-input v-model="form.carType" placeholder="请输入车辆类型" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆识别代码(VIN)" prop="carVin">
              <el-input v-model="form.carVin" placeholder="请输入 VIN 码" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="车辆型号" prop="carModel">
              <el-input v-model="form.carModel" placeholder="请输入车辆型号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发动机型号" prop="engineModel">
              <el-input v-model="form.engineModel" placeholder="请输入发动机型号" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="发动机生产厂" prop="engineProductFactory">
              <el-input v-model="form.engineProductFactory" placeholder="请输入发动机生产厂" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发动机编号" prop="engineNo">
              <el-input v-model="form.engineNo" placeholder="请输入发动机编号" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="排放标准" prop="emissionStandard">
              <el-input v-model="form.emissionStandard" placeholder="请输入排放标准" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="注册登记日期" prop="registeDate">
              <el-date-picker
                v-model="form.registeDate"
                type="date"
                style="width: 100%"
                value-format="YYYY-MM-DD"
                placeholder="请选择注册登记日期"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="使用性质" prop="natureOfUse">
              <el-input v-model="form.natureOfUse" placeholder="请输入使用性质" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="燃料类型" prop="fuelType">
              <el-input v-model="form.fuelType" placeholder="请输入燃料类型" clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确认</el-button>
          <el-button @click="closeFormDialog">取消</el-button>
        </div>
      </template>
    </el-dialog>
 
    <!-- 审核弹窗 -->
    <el-dialog
      v-model="auditDialogVisible"
      title="车辆信息审核"
      width="500px"
      @close="closeAuditDialog"
    >
      <el-form :model="auditForm" label-width="100px">
        <el-form-item label="审核结果" prop="status">
          <el-radio-group v-model="auditForm.status">
            <el-radio label="approved">通过</el-radio>
            <el-radio label="rejected">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见" prop="comment">
          <el-input
            v-model="auditForm.comment"
            type="textarea"
            :rows="3"
            placeholder="请输入审核意见(选填)"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitAudit">确认</el-button>
          <el-button @click="closeAuditDialog">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { ref, reactive } from "vue";
import { Search } from "@element-plus/icons-vue";
import { ElMessage, ElMessageBox } from "element-plus";
import PIMTable from "@/components/PIMTable/PIMTable.vue";
import {
  listVehicleInfo,
  addVehicleInfo,
  updateVehicleInfo,
  delVehicleInfo,
  reviewVehicleInfo,
} from "@/api/environmentAccess/vehicleInfo";
 
// 查询条件
const searchForm = reactive({
  plateNo: "",
});
 
// 表格列配置
const tableColumn = ref([
  {
    label: "车牌号码",
    prop: "plateNo",
    align: "center",
    width: 140,
  },
  {
    label: "号牌颜色",
    prop: "plateColor",
    align: "center",
    width: 100,
  },
  {
    label: "车辆类型",
    prop: "carType",
    align: "center",
    width: 120,
  },
  {
    label: "车辆识别代码(VIN)",
    prop: "carVin",
    align: "center",
    minWidth: 200,
    showOverflowTooltip: true,
  },
  {
    label: "车辆型号",
    prop: "carModel",
    align: "center",
    width: 140,
  },
  {
    label: "发动机型号",
    prop: "engineModel",
    align: "center",
    width: 140,
  },
  {
    label: "发动机生产厂",
    prop: "engineProductFactory",
    align: "center",
    width: 160,
  },
  {
    label: "发动机编号",
    prop: "engineNo",
    align: "center",
    width: 140,
  },
  {
    label: "排放标准",
    prop: "emissionStandard",
    align: "center",
    width: 120,
  },
  {
    label: "注册登记日期",
    prop: "registeDate",
    align: "center",
    width: 140,
  },
  {
    label: "使用性质",
    prop: "natureOfUse",
    align: "center",
    width: 120,
  },
  {
    label: "燃料类型",
    prop: "fuelType",
    align: "center",
    width: 120,
  },
  {
    label: "审核状态",
    prop: "reviewStatus",
    align: "center",
    dataType: "tag",
    width: 120,
    formatData: (value) => {
      if (value === "approved") return "已通过";
      if (value === "rejected") return "未通过";
      if (value === "pending") return "待审核";
      return "未提交";
    },
    formatType: (value) => {
      if (value === "approved") return "success";
      if (value === "rejected") return "danger";
      if (value === "pending") return "warning";
      return "";
    },
  },
  {
    dataType: "action",
    label: "操作",
    align: "center",
    fixed: "right",
    width: 220,
    operation: [
      {
        name: "编辑",
        type: "text",
        clickFun: (row) => openForm("edit", row),
      },
      {
        name: "审核",
        type: "text",
        clickFun: (row) => openAuditDialog(row),
      },
      {
        name: "删除",
        type: "text",
        clickFun: (row) => deleteRow(row),
      },
    ],
  },
]);
 
// 表格数据
const tableData = ref([]);
const tableLoading = ref(false);
const selectedRows = ref([]);
 
// 分页
const page = reactive({
  current: 1,
  size: 10,
  total: 0,
});
 
// 表单相关
const dialogVisible = ref(false);
const operationType = ref("add");
const formRef = ref(null);
const form = reactive(createEmptyForm());
 
function createEmptyForm() {
  return {
    id: undefined,
    plateNo: "",
    plateColor: "",
    carType: "",
    carVin: "",
    carModel: "",
    engineModel: "",
    engineProductFactory: "",
    engineNo: "",
    emissionStandard: "",
    registeDate: "",
    natureOfUse: "",
    fuelType: "",
    reviewStatus: "pending",
  };
}
 
const rules = {
  plateNo: [{ required: true, message: "请输入车牌号码", trigger: "blur" }],
  carVin: [{ required: true, message: "请输入 VIN 码", trigger: "blur" }],
};
 
// 审核相关
const auditDialogVisible = ref(false);
const currentAuditRow = ref(null);
const auditForm = reactive({
  status: "approved",
  comment: "",
});
 
// 查询
function handleQuery() {
  page.current = 1;
  loadTableData();
}
 
// 加载数据
function loadTableData() {
  tableLoading.value = true;
  listVehicleInfo({
    pageNum: page.current,
    pageSize: page.size,
    ...searchForm,
  })
    .then((res) => {
      const { records, total } = res.data;
      tableData.value = records || [];
      page.total = total || 0;
    })
    .finally(() => {
      tableLoading.value = false;
    });
}
 
// 分页变化
function pagination({ page: current, limit }) {
  page.current = current;
  page.size = limit;
  loadTableData();
}
 
// 选择行
function handleSelectionChange(selection) {
  selectedRows.value = selection;
}
 
// 打开表单
function openForm(type, row) {
  operationType.value = type;
  if (type === "edit" && row) {
    Object.assign(form, row);
  } else {
    Object.assign(form, createEmptyForm());
  }
  dialogVisible.value = true;
}
 
function closeFormDialog() {
  dialogVisible.value = false;
  formRef.value?.resetFields();
}
 
// 提交表单
function submitForm() {
  formRef.value?.validate((valid) => {
    if (!valid) return;
 
    const api = operationType.value === "add" ? addVehicleInfo : updateVehicleInfo;
    api({ ...form })
      .then(() => {
        ElMessage.success(operationType.value === "add" ? "新增成功" : "编辑成功");
        dialogVisible.value = false;
        loadTableData();
      })
      .catch(() => {});
  });
}
 
// 删除单条
function deleteRow(row) {
  ElMessageBox.confirm("确认删除该车辆信息吗?", "提示", {
    type: "warning",
  })
    .then(() => {
      delVehicleInfo([row.id]).then(() => {
        ElMessage.success("删除成功");
        loadTableData();
      });
    })
    .catch(() => {});
}
 
// 批量删除
function handleDelete() {
  if (!selectedRows.value.length) {
    ElMessage.warning("请先选择要删除的记录");
    return;
  }
  ElMessageBox.confirm("确认删除选中的车辆信息吗?", "提示", {
    type: "warning",
  })
    .then(() => {
      const ids = selectedRows.value.map((item) => item.id);
      delVehicleInfo(ids).then(() => {
        ElMessage.success("删除成功");
        loadTableData();
      });
    })
    .catch(() => {});
}
 
// 打开审核弹窗
function openAuditDialog(row) {
  currentAuditRow.value = row;
  auditForm.status = row.reviewStatus || "pending";
  auditForm.comment = row.auditComment || "";
  auditDialogVisible.value = true;
}
 
function closeAuditDialog() {
  auditDialogVisible.value = false;
}
 
// 提交审核
function submitAudit() {
  if (!currentAuditRow.value) return;
 
  reviewVehicleInfo({
    id: currentAuditRow.value.id,
    reviewStatus: auditForm.status,
    auditComment: auditForm.comment,
  })
    .then(() => {
      ElMessage.success("审核完成");
      auditDialogVisible.value = false;
      loadTableData();
    })
    .catch(() => {});
}
 
// 初始化
loadTableData();
</script>
 
<style scoped lang="scss">
.table_list {
  margin-top: 20px;
}
</style>