<!-- Description: 厂商管理 Author: 李亚光 Date: 2023-09-13 --> <script lang="ts" setup name="ManufacturerManageList"> import { ElMessage, ElMessageBox } from 'element-plus' import editDialog from './editDialog.vue' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getManufacturerList, removeManufacturer } from '@/api/system/manufacturer' // const { proxy } = getCurrentInstance() as any // 默认查询条件 const defaultQuery = ref({ offset: 1, limit: 20, name: '', contact: '', tel: '', }) const total = ref(0) // 搜索重置 function reset() { defaultQuery.value = { offset: 1, limit: 20, name: '', contact: '', tel: '', } fetchData() } // 表格表头 const columns = ref<TableColumn[]>([ { text: '厂商名称', value: 'name', align: 'center' }, { text: '联系人', value: 'contact', align: 'center' }, { text: '联系方式', value: 'tel', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center' }, ]) // 数据列表 const list = ref<any[]>([]) const loading = ref(false) // 搜索按钮 function search() { fetchData() } // 查询数据 function fetchData() { loading.value = true getManufacturerList(defaultQuery.value).then((res: { data: { rows: []; total: number } }) => { list.value = res.data.rows total.value = res.data.total loading.value = false }).catch(() => { loading.value = false }) } // 删除行 function removeRow(row: any) { ElMessageBox.confirm( '确定要删除该数据吗?', '确认删除', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }, ).then(() => { removeManufacturer(row.id).then(() => { ElMessage.success('删除成功') fetchData() }) }) } // 编辑或者新建 const editRef = ref() const editRow = (type: string, row: any) => { editRef.value.initDialog(type, row) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 function changePage(val: { size: number; page: number }) { if (val && val.size) { defaultQuery.value.limit = val.size } if (val && val.page) { defaultQuery.value.offset = val.page } fetchData() } onMounted(() => { fetchData() }) const { proxy } = getCurrentInstance() as any </script> <template> <app-container> <edit-dialog ref="editRef" @refresh="fetchData" /> <search-area :need-clear="true" @search="fetchData" @clear="reset"> <search-item> <el-input v-model="defaultQuery.name" placeholder="厂商名称" clearable style="width: 162px;" /> </search-item> <search-item> <el-input v-model="defaultQuery.contact" placeholder="厂商联系人" clearable style="width: 162px;" /> </search-item> <search-item> <el-input v-model="defaultQuery.tel" placeholder="厂商电话" clearable style="width: 162px;"/> </search-item> </search-area> <table-container> <template #btns-right> <icon-button v-if="proxy.hasPerm('/sys/manufacturer/add')" icon="icon-add" title="新增" @click="editRow('add', {})" /> </template> <normal-table :query="defaultQuery" :list-loading="loading" :columns="columns" :data="list" :total="total" @change="changePage" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (defaultQuery.offset - 1) * defaultQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" width="140" align="center"> <template #default="scope"> <el-button v-if="proxy.hasPerm('/sys/manufacturer/update')" type="primary" link size="small" class="table-text-button" @click="editRow('edit', scope.row)"> 编辑 </el-button> <el-button v-if="proxy.hasPerm('/sys/manufacturer/delete')" type="danger" link size="small" class="table-text-button" @click="removeRow(scope.row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>