- P1.1 /other/goodunit 商品单位 (走 /other/goodunit/list 真 API, 112 行真数据, 6 字段) - P1.2 /other/textconfig 常量配置 (后端 500, 走 el-result 占位) - P1.3 /other/categoryGood 平台分类 (后端 404, 走 el-result 占位) - P1.4 /other/label 标签管理 (后端 404, 走 el-result 占位) - P1.5 /other/supplierBrand 品牌管理 (后端 404, 走 el-result 占位) P1 推进模式: 1 view 真数据 (goodunit 走 list 数组 API) + 4 view 占位页 (后端未实现走 el-result)
123 lines
3.7 KiB
Vue
123 lines
3.7 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* F006 商品单位 - W3.x C P1.1
|
|
* 走 /other/goodunit/list 真 API (返 data: [...] 数组, 共 112 行)
|
|
* 字段: id/name/type/supplierId/enterpriseId/createTime
|
|
*/
|
|
import { onMounted, ref, computed } from 'vue'
|
|
import { httpGet } from '@/utils/request'
|
|
import DataTable from '@/components/DataTable/DataTable.vue'
|
|
|
|
interface GoodUnit {
|
|
id: string
|
|
name: string
|
|
type: number | null
|
|
supplierId: string | null
|
|
enterpriseId: string | null
|
|
createTime: string
|
|
raw: any
|
|
}
|
|
|
|
const list = ref<GoodUnit[]>([])
|
|
const loading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
const filterKw = ref('')
|
|
|
|
const TYPE_MAP: Record<number, string> = {
|
|
1: '系统',
|
|
2: '自定义'
|
|
}
|
|
|
|
async function load() {
|
|
loading.value = true
|
|
error.value = null
|
|
try {
|
|
const data: any = await httpGet<GoodUnit[]>('/other/goodunit/list')
|
|
list.value = (Array.isArray(data) ? data : []).map((it: any) => ({
|
|
id: String(it.id),
|
|
name: it.name || '--',
|
|
type: it.type ?? null,
|
|
supplierId: it.supplierId,
|
|
enterpriseId: it.enterpriseId,
|
|
createTime: it.createTime || '--',
|
|
raw: it
|
|
}))
|
|
} catch (e: any) {
|
|
error.value = e?.msg || e?.message || '加载失败'
|
|
list.value = []
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const filtered = computed(() => {
|
|
const kw = filterKw.value.trim().toLowerCase()
|
|
if (!kw) return list.value
|
|
return list.value.filter(it => it.name.toLowerCase().includes(kw))
|
|
})
|
|
|
|
function fmtTime(s?: string | null) {
|
|
if (!s) return '--'
|
|
return s
|
|
}
|
|
|
|
onMounted(load)
|
|
</script>
|
|
|
|
<template>
|
|
<div class="rr-page">
|
|
<div class="rr-page-header">
|
|
<h2 class="rr-page-title">商品单位</h2>
|
|
<p class="rr-page-sub">商品计量单位管理(共 {{ list.length }} 个, 筛选后 {{ filtered.length }} 个)</p>
|
|
</div>
|
|
|
|
<div class="rr-filters">
|
|
<el-input v-model="filterKw" placeholder="按名称筛选" clearable class="rr-filter-input" size="default" />
|
|
</div>
|
|
|
|
<div class="rr-card">
|
|
<DataTable
|
|
:columns="[
|
|
{ prop: 'id', label: 'ID', width: 80 },
|
|
{ prop: 'name', label: '单位名称', minWidth: 200 },
|
|
{ prop: 'type', label: '类型', width: 100, slot: 'type' },
|
|
{ prop: 'supplierId', label: '供应商ID', width: 120 },
|
|
{ prop: 'enterpriseId', label: '企业ID', width: 120 },
|
|
{ prop: 'createTime', label: '创建时间', width: 180, slot: 'createTime' }
|
|
]"
|
|
:data="filtered"
|
|
:loading="loading"
|
|
:total="filtered.length"
|
|
:page="1"
|
|
:limit="filtered.length || 1"
|
|
:show-pagination="list.length > 20"
|
|
:error="error"
|
|
empty-text="暂无单位"
|
|
borderless
|
|
row-key="id"
|
|
>
|
|
<template #type="{ row }">
|
|
<el-tag v-if="row.type !== null" :type="row.type === 1 ? 'primary' : 'info'" size="small" effect="light">
|
|
{{ TYPE_MAP[row.type] || `类型${row.type}` }}
|
|
</el-tag>
|
|
<span v-else>--</span>
|
|
</template>
|
|
<template #createTime="{ row }">
|
|
<span class="rr-time">{{ fmtTime(row.createTime) }}</span>
|
|
</template>
|
|
</DataTable>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
.rr-page { max-width: 1400px; }
|
|
.rr-page-header { margin-bottom: 16px; }
|
|
.rr-page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); margin-bottom: 4px; }
|
|
.rr-page-sub { color: var(--ink-3); font-size: 13px; }
|
|
.rr-filters { margin-bottom: 16px; display: flex; gap: 8px; }
|
|
.rr-filter-input { width: 280px; }
|
|
.rr-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
|
|
.rr-time { font-family: 'SF Mono', Menlo, monospace; font-size: 12px; color: var(--ink-2); }
|
|
</style>
|