新增仓储模块页面与 API、店铺授权/店铺订单页面及路由权限目录; 扩展菜单管理同步能力支持二级子菜单与三级按钮;优化公告、仓库地址、下单等页面。 Co-authored-by: Cursor <cursoragent@cursor.com>
227 lines
8.1 KiB
Vue
227 lines
8.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, reactive, ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { Modal } from '@arco-design/web-vue'
|
|
import HandsontablePro from '@/components/HandsontablePro/index.vue'
|
|
import PaginationPro from '@/components/PaginationPro/index.vue'
|
|
import ModalPro from '@/components/ModalPro/index.vue'
|
|
import useModal from '@/components/ModalPro/useModal'
|
|
import FormPro from '@/components/FormPro/index.vue'
|
|
import { useTableContainerHeight } from '@/composables/useTableContainerHeight'
|
|
import { deleteWarehouseParcel, getWarehouseParcelList, saveWarehouseParcel } from '@/api/warehouse'
|
|
import { getWarehouseList } from '@/api/system/warehouse'
|
|
import { $baseMessage } from '@/utils'
|
|
import { hasPermission } from '@/utils/rbac-permission'
|
|
|
|
defineOptions({ name: 'WarehouseParcel' })
|
|
|
|
const { t } = useI18n()
|
|
const { tableContainerRef, tableHeight } = useTableContainerHeight()
|
|
|
|
const lifecycleStatus = ref<string>()
|
|
const keyword = ref('')
|
|
const warehouseId = ref<number>()
|
|
const warehouseOptions = ref<Array<{ label: string; value: number }>>([])
|
|
const listLoading = ref(false)
|
|
const tableRows = ref<any[]>([])
|
|
const currentPage = ref(1)
|
|
const pageSize = ref(30)
|
|
const totalCount = ref(0)
|
|
|
|
const statusTabs = [
|
|
{ value: undefined, labelKey: 'warehouse.parcel.status.all' },
|
|
{ value: 'inTransit', labelKey: 'warehouse.parcel.status.inTransit' },
|
|
{ value: 'arrived', labelKey: 'warehouse.parcel.status.arrived' },
|
|
{ value: 'stored', labelKey: 'warehouse.parcel.status.stored' },
|
|
]
|
|
|
|
const { visible: modalVisible, open: openModal, close: closeModal } = useModal()
|
|
const saving = ref(false)
|
|
const formModel = reactive({
|
|
id: 0,
|
|
warehouseId: undefined as number | undefined,
|
|
trackingNo: '',
|
|
carrierName: '',
|
|
lifecycleStatus: 'inTransit',
|
|
remark: '',
|
|
items: [{ productName: '', quantity: 1 }],
|
|
})
|
|
|
|
const hotColumns = computed(() => [
|
|
{ key: 'trackingNo', label: t('warehouse.parcel.table.trackingNo'), width: 160 },
|
|
{ key: 'carrierName', label: t('warehouse.parcel.table.carrierName'), width: 120 },
|
|
{ key: 'lifecycleStatus', label: t('warehouse.parcel.table.lifecycleStatus'), width: 100 },
|
|
{ key: 'warehouseId', label: t('warehouse.parcel.table.warehouseId'), width: 90 },
|
|
{ key: 'remark', label: t('warehouse.parcel.table.remark'), width: 160 },
|
|
])
|
|
|
|
async function loadWarehouses() {
|
|
try {
|
|
const { items } = await getWarehouseList({ page: 1, pageSize: 200 })
|
|
warehouseOptions.value = (items || []).map((w: any) => ({
|
|
label: w.warehouseName || w.WarehouseName || `#${w.id}`,
|
|
value: Number(w.id),
|
|
}))
|
|
} catch {
|
|
warehouseOptions.value = []
|
|
}
|
|
}
|
|
|
|
async function loadList() {
|
|
listLoading.value = true
|
|
try {
|
|
const { items, total } = await getWarehouseParcelList({
|
|
page: currentPage.value,
|
|
pageSize: pageSize.value,
|
|
lifecycleStatus: lifecycleStatus.value,
|
|
keyword: keyword.value || undefined,
|
|
warehouseId: warehouseId.value,
|
|
})
|
|
tableRows.value = (items || []).map((r: any) => ({
|
|
...r,
|
|
lifecycleStatus: t(`warehouse.parcel.status.${r.lifecycleStatus}`, r.lifecycleStatus),
|
|
_raw: r,
|
|
}))
|
|
totalCount.value = Number(total || 0)
|
|
} catch (e: any) {
|
|
$baseMessage(e?.message || t('warehouse.parcel.message.loadFailed'), 'error')
|
|
tableRows.value = []
|
|
totalCount.value = 0
|
|
} finally {
|
|
listLoading.value = false
|
|
}
|
|
}
|
|
|
|
function handleAdd() {
|
|
if (!hasPermission('Warehouse.Parcel.Save')) return
|
|
formModel.id = 0
|
|
formModel.warehouseId = warehouseId.value
|
|
formModel.trackingNo = ''
|
|
formModel.carrierName = ''
|
|
formModel.lifecycleStatus = 'inTransit'
|
|
formModel.remark = ''
|
|
formModel.items = [{ productName: '', quantity: 1 }]
|
|
openModal()
|
|
}
|
|
|
|
async function handleSave() {
|
|
if (!formModel.warehouseId || !formModel.trackingNo.trim()) {
|
|
$baseMessage(t('warehouse.parcel.message.required'), 'warning')
|
|
return
|
|
}
|
|
saving.value = true
|
|
try {
|
|
await saveWarehouseParcel({ ...formModel })
|
|
$baseMessage(t('warehouse.parcel.message.saveSuccess'), 'success')
|
|
closeModal()
|
|
await loadList()
|
|
} catch (e: any) {
|
|
$baseMessage(e?.message || t('warehouse.parcel.message.saveFailed'), 'error')
|
|
} finally {
|
|
saving.value = false
|
|
}
|
|
}
|
|
|
|
function handleDelete(row: any) {
|
|
if (!hasPermission('Warehouse.Parcel.Delete')) return
|
|
Modal.confirm({
|
|
title: t('warehouse.parcel.actions.delete'),
|
|
content: row._raw?.trackingNo || row.trackingNo,
|
|
onOk: async () => {
|
|
await deleteWarehouseParcel(row._raw?.id || row.id)
|
|
$baseMessage(t('warehouse.parcel.message.deleteSuccess'), 'success')
|
|
await loadList()
|
|
},
|
|
})
|
|
}
|
|
|
|
function actionRenderer() {
|
|
const parts: string[] = []
|
|
if (hasPermission('Warehouse.Parcel.Delete')) {
|
|
parts.push(`<button type="button" class="hot-action-btn" data-action="delete">${t('warehouse.common.delete')}</button>`)
|
|
}
|
|
return parts.join('')
|
|
}
|
|
|
|
function handleActionClick(row: any, _i: number, action?: string) {
|
|
if (action === 'delete') handleDelete(row)
|
|
}
|
|
|
|
onMounted(async () => {
|
|
await loadWarehouses()
|
|
await loadList()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="warehouse-parcel-container">
|
|
<div class="page-card">
|
|
<a-tabs v-model:active-key="lifecycleStatus" @change="() => { currentPage = 1; loadList() }">
|
|
<a-tab-pane v-for="tab in statusTabs" :key="tab.value ?? 'all'" :title="t(tab.labelKey)" />
|
|
</a-tabs>
|
|
<div class="table-toolbar">
|
|
<div class="toolbar-left">
|
|
<a-space wrap :size="8">
|
|
<a-select v-model="warehouseId" allow-clear :placeholder="t('warehouse.common.warehouse')" :options="warehouseOptions" style="width: 200px" />
|
|
<a-input v-model="keyword" allow-clear :placeholder="t('warehouse.parcel.search.trackingNo')" style="width: 200px" />
|
|
<a-button type="primary" @click="() => { currentPage = 1; loadList() }">{{ t('warehouse.common.search') }}</a-button>
|
|
<a-button v-if="hasPermission('Warehouse.Parcel.Save')" type="primary" @click="handleAdd">{{ t('warehouse.common.add') }}</a-button>
|
|
</a-space>
|
|
</div>
|
|
</div>
|
|
<div ref="tableContainerRef" class="list-wrap">
|
|
<HandsontablePro :columns="hotColumns" :data="tableRows" :height="tableHeight" :loading="listLoading" show-action-column :action-renderer="actionRenderer" @action-click="handleActionClick" />
|
|
</div>
|
|
<PaginationPro v-model:current="currentPage" v-model:page-size="pageSize" :total="totalCount" @change="loadList" @page-size-change="() => { currentPage = 1; loadList() }" />
|
|
</div>
|
|
|
|
<ModalPro v-model:visible="modalVisible" :title="t('warehouse.parcel.modal.add')" :width="640" @cancel="closeModal">
|
|
<FormPro :model="formModel" layout="horizontal" :row-gutter="20" :default-span="12">
|
|
<a-form-item :label="t('warehouse.common.warehouse')" required>
|
|
<a-select v-model="formModel.warehouseId" :options="warehouseOptions" />
|
|
</a-form-item>
|
|
<a-form-item :label="t('warehouse.parcel.form.trackingNo')" required>
|
|
<a-input v-model="formModel.trackingNo" />
|
|
</a-form-item>
|
|
<a-form-item :label="t('warehouse.parcel.form.carrierName')">
|
|
<a-input v-model="formModel.carrierName" />
|
|
</a-form-item>
|
|
<a-form-item :label="t('warehouse.parcel.form.productName')">
|
|
<a-input v-model="formModel.items[0].productName" />
|
|
</a-form-item>
|
|
<a-form-item :label="t('warehouse.parcel.form.quantity')">
|
|
<a-input-number v-model="formModel.items[0].quantity" :min="1" style="width: 100%" />
|
|
</a-form-item>
|
|
</FormPro>
|
|
<template #footer>
|
|
<a-button @click="closeModal">{{ t('warehouse.common.cancel') }}</a-button>
|
|
<a-button type="primary" :loading="saving" @click="handleSave">{{ t('warehouse.common.save') }}</a-button>
|
|
</template>
|
|
</ModalPro>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped lang="less">
|
|
.warehouse-parcel-container {
|
|
padding: 16px;
|
|
background: #f0f3f4;
|
|
min-height: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.page-card {
|
|
background: #fff;
|
|
padding: 16px;
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 0;
|
|
border-radius: 4px;
|
|
}
|
|
.list-wrap {
|
|
flex: 1;
|
|
min-height: 0;
|
|
margin-top: 12px;
|
|
}
|
|
</style>
|