This commit is contained in:
dzc committed 2026-06-17 20:23:04 +08:00
commit 984718565e
7 files changed
+77 -49

No files matched your search

@@ -3,13 +3,16 @@
style="width: 100%"
v-model="state.selectId"
:placeholder="props.placeholder"
:disabled="props.disabled"
clearable
remote-show-suffix
filterable
remote
reserve-keyword
default-first-option
remote-show-suffix
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
@visible-change="handleVisibleChange"
@change="change"
>
<el-option v-for="item in state.options" :key="item.supplierId" :label="item.supplierName" :value="item.supplierId" />
@@ -18,65 +21,76 @@
<script setup lang="ts">
import { reactive, watch } from "vue"
import { fetchList } from "/@/api/supermarketerp/smErpSupplier"
import { getSupplierSimpleAll } from "/@/api/supermarketerp/smErpSupplier"
const emit = defineEmits(["change"])
const selectId = defineModel()
const selectId = defineModel<string | number>()
export type Props = {
placeholder?: string
disabled?: boolean
isDisplayName?: boolean
}
const props = withDefaults(defineProps<Props>(), {
placeholder: "输入货商搜索",
})
const queryForm = reactive<any>({
supplierName: "",
current: 1,
size: 10,
placeholder: "输入供货商名称搜索",
disabled: false,
isDisplayName: false,
})
const state = reactive<any>({
loading: true,
loading: false,
selectId: selectId,
options: [],
keyword: "",
})
let searchTimer: ReturnType<typeof setTimeout> | null = null
watch(
selectId,
(newVal, oldValue) => {
if (newVal == oldValue) return
state.selectId = newVal
getOptions()
loadOptions(state.keyword)
},
{ immediate: true },
)
async function getOptions() {
async function loadOptions(keyword = "") {
try {
state.loading = true
const _pa = {
supplierId: selectId.value,
...queryForm,
const params: Record<string, any> = {}
if (keyword) {
params.name = keyword
}
const { data } = await fetchList(_pa)
state.options = data.records ?? []
const { data } = await getSupplierSimpleAll(params)
let options = Array.isArray(data) ? data : []
if (selectId.value && !options.some((item: any) => item.supplierId == selectId.value)) {
const { data: selectedData } = await getSupplierSimpleAll({ supplierId: selectId.value })
const selected = Array.isArray(selectedData) ? selectedData : []
if (selected.length) {
options = [...selected, ...options.filter((item: any) => item.supplierId != selectId.value)]
}
}
state.options = options
} finally {
setTimeout(() => (state.loading = false), 500)
state.loading = false
}
}
function remoteSearch(params: string) {
if (params != queryForm.supplierName) {
queryForm.supplierName = params
getOptions()
function handleVisibleChange(visible: boolean) {
if (visible) {
loadOptions(state.keyword)
}
}
function clear() {
state.selectId = null
getOptions()
function remoteSearch(keyword: string) {
state.keyword = keyword
if (searchTimer) {
clearTimeout(searchTimer)
}
searchTimer = setTimeout(() => loadOptions(keyword), 300)
}
function change(v: any) {
@@ -368,35 +368,40 @@ const onUnitChange = (row: any) => {
row.selectedUnitObj.totalAmount = Number((row.quantity * Number(row.selectedUnitObj.realPrice || 0)).toFixed(2))
}
// 数量变动
// 数量变动:保持实际进价不变,按 数量×实际进价 重算总金额
const onQuantityChange = (row: any, $rowIndex: number) => {
row.selectedUnitObj.totalAmount = Number(displayPrice(row.quantity * Number(row.selectedUnitObj.purchasePrice || 0), ""))
row.selectedUnitObj.realPrice = (row.selectedUnitObj.totalAmount / row.quantity).toFixed(2)
const realPrice = Number(row.selectedUnitObj?.realPrice || 0)
const quantity = Number(row.quantity || 0)
row.selectedUnitObj.totalAmount = Number((quantity * realPrice).toFixed(2))
}
// 累计总金额变动
// 累计总金额变动:反算实际进价
const onTotalAmountChange = (row: any, $rowIndex: number) => {
row.selectedUnitObj.realPrice = (row.selectedUnitObj.totalAmount / row.quantity).toFixed(2)
const quantity = Number(row.quantity || 0)
if (quantity <= 0) return
row.selectedUnitObj.realPrice = Number((Number(row.selectedUnitObj.totalAmount || 0) / quantity).toFixed(2))
}
// 整理数据
const settledTableItems = computed(() => {
return vxeTableData.value.map((item: any) => {
// const unit = item.erpUnitVos.find((unitItem: any) => unitItem.id === item.unitId)
const selectedUnitObj = item.selectedUnitObj
return {
id: item.isNew ? "" : item.id,
const row: Record<string, any> = {
erpSpuId: item.erpSpuId,
quantity: item.quantity,
productNature: item.productNature,
unitPrice: selectedUnitObj.purchasePrice ? Number(selectedUnitObj?.purchasePrice) : 0,
realPrice: selectedUnitObj.realPrice ? storePrice(selectedUnitObj?.realPrice) : 0,
realPrice: storePrice(Number(selectedUnitObj?.realPrice || 0)),
retailPrice: selectedUnitObj.retailPrice ? storePrice(selectedUnitObj?.retailPrice) : 0,
totalAmount: storePrice(Number(selectedUnitObj?.totalAmount || 0)),
remark: item.remark,
unitId: selectedUnitObj.id,
orderType: baseDataForm.orderType,
}
if (!item.isNew && item.id) {
row.id = item.id
}
return row
})
})
@@ -15,8 +15,8 @@
value-format="YYYY-MM-DD"
/>
</el-form-item>
<el-form-item label="货商" prop="supplierId">
<SelectSupermarketSupplier v-model="state.queryForm.supplierId" style="width: 200px" />
<el-form-item label="供货商" prop="supplierId">
<SelectSupermarketSupplier v-model="state.queryForm.supplierId" placeholder="请选择供货商" style="width: 200px" />
</el-form-item>
<el-form-item>
<el-button icon="search" type="primary" @click="getDataList">查询</el-button>
@@ -111,6 +111,7 @@ const multiple = ref(true)
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {
inventoryType: "4",
supplierId: undefined,
},
pageList: fetchList,
})
@@ -373,34 +373,40 @@ const onUnitChange = (row: any) => {
row.selectedUnitObj.totalAmount = Number((row.quantity * Number(row.selectedUnitObj.realPrice || 0)).toFixed(2))
}
// 数量变动
// 数量变动:保持实际进价不变,按 数量×实际进价 重算总金额
const onQuantityChange = (row: any, $rowIndex: number) => {
row.selectedUnitObj.totalAmount = Number(displayPrice(row.quantity * Number(row.selectedUnitObj.purchasePrice || 0), ""))
row.selectedUnitObj.realPrice = (row.selectedUnitObj.totalAmount / row.quantity).toFixed(2)
const realPrice = Number(row.selectedUnitObj?.realPrice || 0)
const quantity = Number(row.quantity || 0)
row.selectedUnitObj.totalAmount = Number((quantity * realPrice).toFixed(2))
}
// 累计总金额变动
// 累计总金额变动:反算实际进价
const onTotalAmountChange = (row: any, $rowIndex: number) => {
row.selectedUnitObj.realPrice = (row.selectedUnitObj.totalAmount / row.quantity).toFixed(2)
const quantity = Number(row.quantity || 0)
if (quantity <= 0) return
row.selectedUnitObj.realPrice = Number((Number(row.selectedUnitObj.totalAmount || 0) / quantity).toFixed(2))
}
// 整理table数据
const settledTableItems = computed(() => {
return vxeTableData.value.map((item: any) => {
const selectedUnitObj = item.selectedUnitObj
return {
id: item.isNew ? "" : item.id,
const row: Record<string, any> = {
erpSpuId: item.erpSpuId,
quantity: item.quantity,
productNature: item.productNature,
unitPrice: selectedUnitObj.purchasePrice ? Number(selectedUnitObj?.purchasePrice) : 0,
realPrice: selectedUnitObj.realPrice ? storePrice(selectedUnitObj?.realPrice) : 0,
realPrice: storePrice(Number(selectedUnitObj?.realPrice || 0)),
retailPrice: selectedUnitObj.retailPrice ? storePrice(selectedUnitObj?.retailPrice) : 0,
totalAmount: storePrice(Number(selectedUnitObj?.totalAmount || 0)),
remark: item.remark,
unitId: selectedUnitObj.id,
orderType: baseDataForm.orderType,
}
if (!item.isNew && item.id) {
row.id = item.id
}
return row
})
})
@@ -15,8 +15,8 @@
value-format="YYYY-MM-DD"
/>
</el-form-item>
<el-form-item label="货商" prop="supplierId">
<SelectSupermarketSupplier v-model="state.queryForm.supplierId" style="width: 200px" />
<el-form-item label="供货商" prop="supplierId">
<SelectSupermarketSupplier v-model="state.queryForm.supplierId" placeholder="请选择供货商" style="width: 200px" />
</el-form-item>
<el-form-item>
<el-button icon="search" type="primary" @click="getDataList">查询</el-button>
@@ -114,6 +114,7 @@ const multiple = ref(true)
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {
inventoryType: "3",
supplierId: undefined,
},
pageList: fetchList,
})
@@ -23,6 +23,7 @@
<el-col :span="14" class="mb20">
<el-form-item label="分类排序" prop="sort">
<el-input-number v-model="form.sort" :min="1" :max="1000" :precision="0" />
<div class="text-xs text-gray-400 mt-1">数值越小越靠前显示</div>
</el-form-item>
</el-col>
@@ -61,7 +61,7 @@
<preview-image :src="scope.row.picUrl" />
</template>
</el-table-column>
<el-table-column prop="sort" label="分类排序" show-overflow-tooltip />
<el-table-column prop="sort" label="分类排序(越小越靠前)" show-overflow-tooltip min-width="160" />
<el-table-column prop="status" label="开启状态" show-overflow-tooltip>
<template #default="scope">
<dict-tag :options="status" :value="scope.row.status" />