2026-06-24 18:14:36 +08:00

260 lines
7.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="order-sub-container" :style="{ height: containerHeight }">
<scan-box
ref="scanBox"
cache-key="stock-combo-goods"
width="250px"
:tree-props="{ children: 'children', label: 'label' }"
:auto-submit="false"
:preset-tree="presetTree"
:available-fields="availableFieldsRef"
@condition-change="handleConditionChange"
@reset="handleConditionReset"
@condition-clear="handleConditionClear"
@submit="handleSubmit"
/>
<div class="main-content">
<div class="toolbar">
<div class="toolbar-left">
<el-button size="small" type="primary" :loading="loading" @click="loadList">刷新</el-button>
<!-- <el-tag size="small" type="info">共 {{ pagination.total }} 条</el-tag> -->
</div>
<div class="toolbar-right">
<el-button size="small" type="primary" plain @click="searchDialogVisible = true">快速搜索</el-button>
<el-button type="success" size="small" @click="openCreate">新增组合商品</el-button>
</div>
</div>
<div class="upper-wrapper">
<upper-table
ref="upperTable"
title="组合商品列表"
table-id="stock-combo-goods"
:data="tableData"
:columns="columns"
:table-size="tableSize"
:pagination="pagination"
:show-index="true"
:show-selection="false"
:show-actions="true"
:loading="loading"
:query-time="queryTime"
row-key="id"
@page-change="handlePageChange"
@page-size-change="handlePageSizeChange"
@refresh="loadList"
>
<template #column-status="{ row }">
<el-tag :type="formatComboGoodsStatus(row.status).type" size="small">
{{ formatComboGoodsStatus(row.status).text }}
</el-tag>
</template>
<template #column-simpleNotation="{ row }">
{{ row.simpleNotation || '--' }}
</template>
<template #column-nameNotation="{ row }">
{{ row.nameNotation || '--' }}
</template>
<template #column-created_at="{ row }">
{{ formatComboGoodsDateTime(row.created_at) }}
</template>
<template #column-updated_at="{ row }">
{{ formatComboGoodsDateTime(row.updated_at) }}
</template>
<template #column-actions="{ row }">
<el-button link type="primary" size="small" @click.stop="openEdit(row)">编辑</el-button>
<el-button link type="danger" size="small" @click.stop="handleDelete(row)">删除</el-button>
</template>
<template #empty>
<div class="empty-tip">暂无组合商品,可调整左侧筛选条件或点击新增</div>
</template>
</upper-table>
</div>
</div>
<ComboGoodsFormDialog
v-model="formDialogVisible"
:mode="formDialogMode"
:record="editingRecord"
@success="loadList"
/>
<ComboGoodsSearchDialog v-model="searchDialogVisible" />
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import ScanBox from '@/components/ScanBox/index.vue'
import UpperTable from '@/components/UpperTable/index.vue'
import { comboGoodsDelete, comboGoodsList } from '@/api/combogoods/combogoods'
import { useSettingsStore } from '@/stores/modules/settings'
import ComboGoodsFormDialog from './component/ComboGoodsFormDialog.vue'
import ComboGoodsSearchDialog from './component/ComboGoodsSearchDialog.vue'
import {
buildComboGoodsListPayload,
comboGoodsColumns,
comboGoodsScanFields,
formatComboGoodsDateTime,
formatComboGoodsStatus,
isComboGoodsApiSuccess,
normalizeComboGoodsScanConditionToWhere,
parseComboGoodsListResponse,
type ComboGoodsRecord
} from './combo-stock-config'
const settingsStore = useSettingsStore()
const scanBox = ref<any>(null)
const presetTree = ref<any[]>([])
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(comboGoodsScanFields)))
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
const containerHeight = computed(() =>
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
)
const columns = comboGoodsColumns
const loading = ref(false)
const tableData = ref<ComboGoodsRecord[]>([])
const queryTime = ref(0)
const tableSize = ref<'small' | 'default' | 'large'>('small')
const currentConditionRaw = ref<any>(null)
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
const formDialogVisible = ref(false)
const formDialogMode = ref<'create' | 'edit'>('create')
const editingRecord = ref<ComboGoodsRecord | null>(null)
const searchDialogVisible = ref(false)
async function loadList() {
if (loading.value) return
loading.value = true
const start = Date.now()
try {
const where = normalizeComboGoodsScanConditionToWhere(currentConditionRaw.value)
const res: any = await comboGoodsList(
buildComboGoodsListPayload({
page: pagination.currentPage,
pageSize: pagination.pageSize,
where
})
)
if (!isComboGoodsApiSuccess(res)) {
ElMessage.error(res?.message || '获取组合商品列表失败')
tableData.value = []
pagination.total = 0
return
}
const data = parseComboGoodsListResponse(res)
tableData.value = data.list
pagination.total = data.total
if (data.page) pagination.currentPage = data.page
if (data.pageSize) pagination.pageSize = data.pageSize
} catch {
tableData.value = []
pagination.total = 0
ElMessage.error('获取组合商品列表失败')
} finally {
queryTime.value = Date.now() - start
loading.value = false
}
}
function handleConditionChange(condition: any) {
currentConditionRaw.value = condition
pagination.currentPage = 1
loadList()
}
function handleSubmit() {
pagination.currentPage = 1
loadList()
}
function handleConditionClear() {
currentConditionRaw.value = null
pagination.currentPage = 1
loadList()
}
function handleConditionReset() {
currentConditionRaw.value = null
pagination.currentPage = 1
if (scanBox.value?.reset) {
scanBox.value.reset()
} else if (scanBox.value?.clear) {
scanBox.value.clear()
}
loadList()
}
function handlePageChange(page: number) {
pagination.currentPage = page
loadList()
}
function handlePageSizeChange(size: number) {
pagination.pageSize = size
pagination.currentPage = 1
loadList()
}
function openCreate() {
formDialogMode.value = 'create'
editingRecord.value = null
formDialogVisible.value = true
}
function openEdit(row: ComboGoodsRecord) {
if (!row.id) return
formDialogMode.value = 'edit'
editingRecord.value = row
formDialogVisible.value = true
}
function handleDelete(row: ComboGoodsRecord) {
if (!row.id) return
const name = row.combo_name || row.combo_code || String(row.id)
ElMessageBox.confirm(`确认删除组合商品「${name}」吗?(软删除,状态置为停用)`, '提示', {
type: 'warning'
})
.then(async () => {
const res: any = await comboGoodsDelete({ id: row.id as number })
if (!isComboGoodsApiSuccess(res)) {
ElMessage.error(res?.message || '删除失败')
return
}
ElMessage.success('删除成功')
if (tableData.value.length === 1 && pagination.currentPage > 1) {
pagination.currentPage -= 1
}
loadList()
})
.catch(() => undefined)
}
onMounted(() => {
loadList()
})
</script>
<style lang="scss" scoped>
@use "../../order/orderManagement/styles/order-sub.scss";
.empty-tip {
text-align: center;
font-size: 13px;
color: #909399;
padding: 16px;
}
</style>