| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <div class="search_form"> |
| | | <div> |
| | | <span class="search_title ml10">车é´åç§°ï¼</span> |
| | | <el-input |
| | | v-model="searchForm.name" |
| | | style="width: 180px" |
| | | placeholder="请è¾å
¥è½¦é´åç§°" |
| | | clearable |
| | | @keyup.enter="handleQuery" |
| | | /> |
| | | <span class="search_title ml10">è´è´£äººï¼</span> |
| | | <el-input |
| | | v-model="searchForm.principal" |
| | | style="width: 160px" |
| | | placeholder="请è¾å
¥è´è´£äºº" |
| | | clearable |
| | | @keyup.enter="handleQuery" |
| | | /> |
| | | <el-button type="primary" @click="handleQuery" style="margin-left: 10px">æç´¢</el-button> |
| | | <el-button @click="handleReset">éç½®</el-button> |
| | | <el-button type="primary" @click="handleAdd" style="margin-left: 10px">æ°å¢è½¦é´</el-button> |
| | | </div> |
| | | </div> |
| | | <div class="table_list"> |
| | | <PIMTable |
| | | rowKey="id" |
| | | :column="tableColumn" |
| | | :tableData="tableData" |
| | | :page="page" |
| | | height="calc(100vh - 320px)" |
| | | :tableLoading="tableLoading" |
| | | :isSelection="false" |
| | | :isShowPagination="true" |
| | | @pagination="pagination" |
| | | /> |
| | | </div> |
| | | <el-dialog v-model="dialogVisible" :title="dialogTitle" width="520px" @close="onDialogClose"> |
| | | <el-form :model="formData" :rules="rules" ref="formRef" label-width="100px"> |
| | | <el-form-item label="车é´åç§°" prop="name"> |
| | | <el-input v-model="formData.name" placeholder="请è¾å
¥è½¦é´åç§°" maxlength="100" show-word-limit clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="è´è´£äºº" prop="principal"> |
| | | <el-input v-model="formData.principal" placeholder="请è¾å
¥è´è´£äºº" maxlength="100" clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="èç³»æ¹å¼" prop="contactPhone"> |
| | | <el-input v-model="formData.contactPhone" placeholder="请è¾å
¥èç³»æ¹å¼" maxlength="200" clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="夿³¨" prop="remark"> |
| | | <el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="请è¾å
¥å¤æ³¨" maxlength="500" show-word-limit /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button type="primary" @click="handleSubmit">ç¡®å®</el-button> |
| | | <el-button @click="dialogVisible = false">åæ¶</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { onMounted, reactive, ref } from "vue"; |
| | | import { ElMessage, ElMessageBox } from "element-plus"; |
| | | import PIMTable from "@/components/PIMTable/PIMTable.vue"; |
| | | import { workshopPage, workshopSave, workshopDeleteById } from "@/api/basicData/workshop.js"; |
| | | |
| | | const tableColumn = ref([ |
| | | { label: "车é´åç§°", prop: "name", minWidth: "140" }, |
| | | { label: "è´è´£äºº", prop: "principal", minWidth: "120" }, |
| | | { label: "èç³»æ¹å¼", prop: "contactPhone", minWidth: "160" }, |
| | | { label: "夿³¨", prop: "remark", minWidth: "160" }, |
| | | { |
| | | label: "æä½", |
| | | dataType: "action", |
| | | width: "150", |
| | | fixed: "right", |
| | | operation: [ |
| | | { |
| | | name: "ç¼è¾", |
| | | clickFun: row => handleEdit(row), |
| | | }, |
| | | { |
| | | name: "å é¤", |
| | | clickFun: row => handleDelete(row), |
| | | }, |
| | | ], |
| | | }, |
| | | ]); |
| | | |
| | | const tableData = ref([]); |
| | | const tableLoading = ref(false); |
| | | const page = reactive({ |
| | | current: 1, |
| | | size: 10, |
| | | total: 0, |
| | | }); |
| | | |
| | | const searchForm = reactive({ |
| | | name: "", |
| | | principal: "", |
| | | }); |
| | | |
| | | const dialogVisible = ref(false); |
| | | const dialogTitle = ref(""); |
| | | const formRef = ref(null); |
| | | const formData = reactive({ |
| | | id: null, |
| | | name: "", |
| | | principal: "", |
| | | contactPhone: "", |
| | | remark: "", |
| | | }); |
| | | |
| | | const rules = reactive({ |
| | | name: [{ required: true, message: "请è¾å
¥è½¦é´åç§°", trigger: "blur" }], |
| | | principal: [{ required: true, message: "请è¾å
¥è´è´£äºº", trigger: "blur" }], |
| | | contactPhone: [{ required: true, message: "请è¾å
¥èç³»æ¹å¼", trigger: "blur" }], |
| | | }); |
| | | |
| | | const isEdit = ref(false); |
| | | |
| | | function parsePagePayload(res) { |
| | | const payload = res?.data; |
| | | if (!payload) { |
| | | return { records: [], total: 0 }; |
| | | } |
| | | if (Array.isArray(payload)) { |
| | | return { records: payload, total: payload.length }; |
| | | } |
| | | const records = payload.records ?? payload.list ?? payload.rows ?? []; |
| | | const total = Number(payload.total ?? payload.totalCount ?? 0); |
| | | return { records: Array.isArray(records) ? records : [], total }; |
| | | } |
| | | |
| | | const getList = () => { |
| | | tableLoading.value = true; |
| | | workshopPage({ |
| | | name: searchForm.name?.trim() ?? "", |
| | | principal: searchForm.principal?.trim() ?? "", |
| | | contactPhone: "", |
| | | current: page.current, |
| | | size: page.size, |
| | | }) |
| | | .then(res => { |
| | | if (res.code === 200) { |
| | | const { records, total } = parsePagePayload(res); |
| | | tableData.value = records; |
| | | page.total = total; |
| | | } else { |
| | | ElMessage.error(res.msg || "æ¥è¯¢å¤±è´¥"); |
| | | } |
| | | }) |
| | | .catch(() => { |
| | | ElMessage.error("æ¥è¯¢å¤±è´¥"); |
| | | }) |
| | | .finally(() => { |
| | | tableLoading.value = false; |
| | | }); |
| | | }; |
| | | |
| | | const handleQuery = () => { |
| | | page.current = 1; |
| | | getList(); |
| | | }; |
| | | |
| | | const handleReset = () => { |
| | | searchForm.name = ""; |
| | | searchForm.principal = ""; |
| | | page.current = 1; |
| | | getList(); |
| | | }; |
| | | |
| | | const pagination = obj => { |
| | | page.current = obj.page; |
| | | page.size = obj.limit; |
| | | getList(); |
| | | }; |
| | | |
| | | const resetFormModel = () => { |
| | | formData.id = null; |
| | | formData.name = ""; |
| | | formData.principal = ""; |
| | | formData.contactPhone = ""; |
| | | formData.remark = ""; |
| | | }; |
| | | |
| | | const handleAdd = () => { |
| | | isEdit.value = false; |
| | | dialogTitle.value = "æ°å¢è½¦é´"; |
| | | resetFormModel(); |
| | | dialogVisible.value = true; |
| | | }; |
| | | |
| | | const handleEdit = row => { |
| | | isEdit.value = true; |
| | | dialogTitle.value = "ç¼è¾è½¦é´"; |
| | | formData.id = row.id; |
| | | formData.name = row.name ?? ""; |
| | | formData.principal = row.principal ?? ""; |
| | | formData.contactPhone = row.contactPhone ?? ""; |
| | | formData.remark = row.remark ?? ""; |
| | | dialogVisible.value = true; |
| | | }; |
| | | |
| | | const handleDelete = row => { |
| | | ElMessageBox.confirm("ç¡®å®è¦å é¤è¯¥è½¦é´åï¼", "æç¤º", { |
| | | confirmButtonText: "ç¡®å®", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning", |
| | | }) |
| | | .then(() => workshopDeleteById(row.id)) |
| | | .then(() => { |
| | | ElMessage.success("å 餿å"); |
| | | getList(); |
| | | }) |
| | | .catch(err => { |
| | | if (err === "cancel" || err === "close") return; |
| | | ElMessage.error("å é¤å¤±è´¥"); |
| | | }); |
| | | }; |
| | | |
| | | const onDialogClose = () => { |
| | | formRef.value?.resetFields?.(); |
| | | }; |
| | | |
| | | const handleSubmit = () => { |
| | | formRef.value?.validate(valid => { |
| | | if (!valid) return; |
| | | const payload = { |
| | | id: isEdit.value ? formData.id : null, |
| | | name: formData.name.trim(), |
| | | principal: formData.principal.trim(), |
| | | contactPhone: formData.contactPhone.trim(), |
| | | remark: (formData.remark || "").trim(), |
| | | }; |
| | | workshopSave(payload) |
| | | .then(res => { |
| | | if (res.code === 200) { |
| | | ElMessage.success(isEdit.value ? "ä¿®æ¹æå" : "æ°å¢æå"); |
| | | dialogVisible.value = false; |
| | | getList(); |
| | | } else { |
| | | ElMessage.error(res.msg || "ä¿å失败"); |
| | | } |
| | | }) |
| | | .catch(() => { |
| | | ElMessage.error("ä¿å失败"); |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | getList(); |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |
| | | .app-container { |
| | | padding: 24px; |
| | | background-color: #f0f2f5; |
| | | min-height: calc(100vh - 48px); |
| | | } |
| | | |
| | | .search_form { |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: center; |
| | | margin-bottom: 24px; |
| | | padding: 20px; |
| | | background-color: #ffffff; |
| | | border-radius: 6px; |
| | | box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05); |
| | | |
| | | .search_title { |
| | | color: #606266; |
| | | font-size: 14px; |
| | | font-weight: 500; |
| | | } |
| | | |
| | | .ml10 { |
| | | margin-left: 10px; |
| | | } |
| | | } |
| | | |
| | | .table_list { |
| | | background-color: #ffffff; |
| | | padding: 16px; |
| | | border-radius: 6px; |
| | | box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05); |
| | | } |
| | | </style> |