| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <div class="search_form"> |
| | | <div> |
| | | <span class="search_title">èµäº§åç§°ï¼</span> |
| | | <el-input v-model="searchForm.name" |
| | | style="width: 240px" |
| | | placeholder="请è¾å
¥" |
| | | @change="handleQuery" |
| | | clearable |
| | | prefix-icon="Search" /> |
| | | <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"> |
| | | <el-table :data="tableData" |
| | | border |
| | | v-loading="tableLoading" |
| | | @selection-change="handleSelectionChange" |
| | | style="width: 100%" |
| | | height="calc(100vh - 18.5em)"> |
| | | <el-table-column align="center" |
| | | type="selection" |
| | | width="55" /> |
| | | <el-table-column align="center" |
| | | label="åºå·" |
| | | type="index" |
| | | width="60" /> |
| | | <el-table-column label="èµäº§åç§°" |
| | | prop="name" |
| | | show-overflow-tooltip /> |
| | | <el-table-column label="åå·" |
| | | prop="model" |
| | | show-overflow-tooltip /> |
| | | <el-table-column label="ä»·æ ¼" |
| | | prop="price" |
| | | show-overflow-tooltip> |
| | | <template #default="{ row }"> |
| | | ¥{{ row.price ? row.price.toFixed(2) : '0.00' }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="ä½ç½®" |
| | | prop="address" |
| | | show-overflow-tooltip /> |
| | | <el-table-column label="å建æ¶é´" |
| | | prop="createTime" |
| | | show-overflow-tooltip> |
| | | <template #default="{ row }"> |
| | | {{ row.createTime ? dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') : '-' }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column fixed="right" |
| | | label="æä½" |
| | | min-width="100" |
| | | align="center"> |
| | | <template #default="scope"> |
| | | <el-button link |
| | | type="primary" |
| | | size="small" |
| | | @click="openForm('edit', scope.row);">ç¼è¾</el-button> |
| | | <el-button link |
| | | type="danger" |
| | | size="small" |
| | | @click="handleDeleteSolo(scope.row)">å é¤</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <pagination v-show="total > 0" |
| | | :total="total" |
| | | layout="total, sizes, prev, pager, next, jumper" |
| | | :page="page.current" |
| | | :limit="page.size" |
| | | @pagination="paginationChange" /> |
| | | </div> |
| | | <el-dialog v-model="dialogFormVisible" |
| | | :title="operationType === 'add' ? 'æ°å¢åºå®èµäº§' : 'ç¼è¾åºå®èµäº§'" |
| | | width="600px" |
| | | @close="closeDia"> |
| | | <el-form :model="form" |
| | | label-width="100px" |
| | | :rules="rules" |
| | | ref="formRef"> |
| | | <el-form-item label="èµäº§åç§°" |
| | | prop="name"> |
| | | <el-input v-model="form.name" |
| | | placeholder="请è¾å
¥èµäº§åç§°" |
| | | clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="åå·" |
| | | prop="model"> |
| | | <el-input v-model="form.model" |
| | | placeholder="请è¾å
¥åå·" |
| | | clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="ä»·æ ¼" |
| | | prop="price"> |
| | | <el-input-number v-model="form.price" |
| | | :min="0" |
| | | :precision="2" |
| | | :step="0.01" |
| | | style="width: 100%" |
| | | placeholder="请è¾å
¥ä»·æ ¼" /> |
| | | </el-form-item> |
| | | <el-form-item label="ä½ç½®" |
| | | prop="address"> |
| | | <el-input v-model="form.address" |
| | | type="textarea" |
| | | :rows="3" |
| | | placeholder="请è¾å
¥ä½ç½®" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button type="primary" |
| | | @click="submitForm">确认</el-button> |
| | | <el-button @click="closeDia">åæ¶</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import pagination from "@/components/PIMTable/Pagination.vue"; |
| | | import { ref, reactive, toRefs, onMounted, getCurrentInstance } from "vue"; |
| | | import { ElMessageBox } from "element-plus"; |
| | | import useUserStore from "@/store/modules/user"; |
| | | import { |
| | | listPage, |
| | | add, |
| | | update, |
| | | delFixedAssets, |
| | | } from "@/api/financialManagement/fixedAssets.js"; |
| | | import dayjs from "dayjs"; |
| | | |
| | | const userStore = useUserStore(); |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | | const tableData = ref([]); |
| | | const selectedRows = ref([]); |
| | | const tableLoading = ref(false); |
| | | const loading = ref(false); |
| | | |
| | | const page = reactive({ |
| | | current: 1, |
| | | size: 100, |
| | | }); |
| | | const total = ref(0); |
| | | |
| | | const operationType = ref(""); |
| | | const dialogFormVisible = ref(false); |
| | | const data = reactive({ |
| | | searchForm: { |
| | | name: "", |
| | | }, |
| | | form: { |
| | | id: null, |
| | | name: "", |
| | | model: "", |
| | | price: 0, |
| | | address: "", |
| | | }, |
| | | rules: { |
| | | name: [{ required: true, message: "请è¾å
¥èµäº§åç§°", trigger: "blur" }], |
| | | model: [{ required: true, message: "请è¾å
¥åå·", trigger: "blur" }], |
| | | price: [{ required: true, message: "请è¾å
¥ä»·æ ¼", trigger: "blur" }], |
| | | address: [{ required: true, message: "请è¾å
¥ä½ç½®", trigger: "blur" }], |
| | | }, |
| | | }); |
| | | const { searchForm, form, rules } = toRefs(data); |
| | | |
| | | const handleQuery = () => { |
| | | page.current = 1; |
| | | getList(); |
| | | }; |
| | | |
| | | const paginationChange = obj => { |
| | | page.current = obj.page; |
| | | page.size = obj.limit; |
| | | getList(); |
| | | }; |
| | | |
| | | const getList = () => { |
| | | tableLoading.value = true; |
| | | listPage({ ...searchForm.value, ...page }) |
| | | .then(res => { |
| | | tableLoading.value = false; |
| | | tableData.value = res.data.records; |
| | | total.value = res.data.total; |
| | | }) |
| | | .catch(() => { |
| | | tableLoading.value = false; |
| | | }); |
| | | }; |
| | | |
| | | const handleSelectionChange = selection => { |
| | | selectedRows.value = selection; |
| | | }; |
| | | |
| | | const openForm = async (type, row) => { |
| | | operationType.value = type; |
| | | dialogFormVisible.value = true; |
| | | |
| | | if (type === "add") { |
| | | form.value = { |
| | | id: null, |
| | | name: "", |
| | | model: "", |
| | | price: 0, |
| | | address: "", |
| | | }; |
| | | } else { |
| | | form.value = { |
| | | id: row.id, |
| | | name: row.name, |
| | | model: row.model, |
| | | price: row.price, |
| | | address: row.address, |
| | | }; |
| | | } |
| | | }; |
| | | |
| | | const submitForm = async () => { |
| | | try { |
| | | await proxy.$refs.formRef.validate(); |
| | | loading.value = true; |
| | | |
| | | if (operationType.value === "add") { |
| | | await add(form.value); |
| | | proxy.$modal.msgSuccess("æ°å¢èµäº§æå"); |
| | | } else { |
| | | await update(form.value); |
| | | proxy.$modal.msgSuccess("ä¿®æ¹èµäº§æå"); |
| | | } |
| | | closeDia(); |
| | | getList(); |
| | | } catch (error) { |
| | | console.error("æäº¤å¤±è´¥:", error); |
| | | if (!error.errors) { |
| | | proxy.$modal.msgError("æä½å¤±è´¥ï¼è¯·éè¯"); |
| | | } |
| | | } finally { |
| | | loading.value = false; |
| | | } |
| | | }; |
| | | |
| | | const closeDia = () => { |
| | | proxy.$refs.formRef.resetFields(); |
| | | dialogFormVisible.value = false; |
| | | }; |
| | | const handleDeleteSolo = row => { |
| | | ElMessageBox.confirm("该èµäº§å°è¢«å é¤ï¼æ¯å¦ç¡®è®¤å é¤ï¼", "å é¤æç¤º", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning", |
| | | }) |
| | | .then(() => { |
| | | const ids = [row.id]; |
| | | delFixedAssets(ids) |
| | | .then(res => { |
| | | proxy.$modal.msgSuccess("å 餿å"); |
| | | getList(); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msgError("å é¤å¤±è´¥"); |
| | | }); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msg("已忶"); |
| | | }); |
| | | }; |
| | | |
| | | const handleDelete = () => { |
| | | if (selectedRows.value.length === 0) { |
| | | proxy.$modal.msgWarning("è¯·éæ©è¦å é¤çæ°æ®"); |
| | | return; |
| | | } |
| | | ElMessageBox.confirm("éä¸çå
容å°è¢«å é¤ï¼æ¯å¦ç¡®è®¤å é¤ï¼", "å é¤æç¤º", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning", |
| | | }) |
| | | .then(() => { |
| | | const ids = selectedRows.value.map(item => item.id); |
| | | delFixedAssets(ids) |
| | | .then(res => { |
| | | proxy.$modal.msgSuccess("å 餿å"); |
| | | getList(); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msgError("å é¤å¤±è´¥"); |
| | | }); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msg("已忶"); |
| | | }); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | getList(); |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped lang="scss"></style> |