-
+
单据编号:
@@ -11,17 +11,13 @@
单据日期:
{{ baseDataForm.inventoryDate }}
-
- 经办人:
- {{ baseDataForm.handlerUserId }}
-
备注:
{{ baseDataForm.remark }}
-
+
@@ -29,14 +25,14 @@
-
+
@@ -45,13 +41,12 @@
商品选择
- 删除选中
+ 删除选中
清空数据
-
-
+
{{ row.productName }}
- {{ row.erpSpuId && state.erpSpuSimpleAll.find((item: any) => item.id === row.erpSpuId)?.productName }}
+ {{ row.erpSpuId && erpSpuSimpleAll.find((item: any) => item.id === row.erpSpuId)?.productName }}
-
+
- 单位:{{ item.unit }} 装数:{{ item.packageNum }}
+
+ 单位:{{ item.unit }} 装数:{{ item.packageNum }} 进价:{{ displayPrice(item.purchasePrice, "元") }}
+ 规格:{{ item.spec }}
+
+
@@ -108,6 +108,16 @@
+
+
+ {{
+ displayPrice(
+ row.erpUnitVos.reduce((pre: any, cur: any) => pre + cur.purchasePrice * Number(cur.accountNumber), 0),
+ "",
+ )
+ }}
+
+
-
-
- {{
- displayPrice(
- row.erpUnitVos.reduce((pre: any, cur: any) => pre + cur.purchasePrice * Number(cur.accountNumber), 0),
- "",
- )
- }}
-
-
-
-
-
-
-
-
+
{{ row.erpUnitVos.reduce((pre: any, cur: any) => pre + Number(cur.realNumber) * cur.packageNum, 0) || 0 }}
-
+
+
+
+
+
+
{{
(
- parseFloat(row.pdPrice || 0) *
+ Number(row.pdPrice || 0) *
(row.erpUnitVos.reduce((pre: any, cur: any) => pre + Number(cur.realNumber) * cur.packageNum, 0) || 0)
).toFixed(2) || 0
}}
@@ -183,15 +183,10 @@
保存
-
- 打印
-
-
-
@@ -200,9 +195,8 @@
import { ref, reactive, computed, onMounted } from "vue"
import { getPlanCode, getErpSpuSimpleAll } from "/@/api/supermarketerp/common"
import { getStockTakingDeatil, addObj, putObj } from "/@/api/supermarketerp/stockTaking"
-import { VxeTableEvents, VxeTablePropTypes, type VxeTableInstance } from "vxe-table"
+import { VxeTablePropTypes, type VxeTableInstance } from "vxe-table"
import { formatDate } from "/@/utils/formatTime"
-import barCodeEnter from "./barCodeEnter.vue"
import { displayPrice } from "/@/utils/formatMoney"
import { tablePrint } from "../supermarketUtils"
import { useSmProcessFormAction } from "/@/hooks/smProcessFormAction"
@@ -211,89 +205,105 @@ const SelectDialog = defineAsyncComponent(() => import("/@/views/supermarketerp/
const props = withDefaults(
defineProps<{
- formId: string | undefined
+ formId: string
disabled: boolean
}>(),
{
- formId: undefined,
- disabled: true,
+ formId: "",
+ disabled: false,
},
)
const emit = defineEmits(["close"])
-const loading = ref(false) // 采购计划加载
+const loading = ref(false)
const disabled = ref(false)
const erpSpuSelectDialogRef = ref() // 商品选择对话框ref
-const barCodeEnterRef = ref() // 条码录入对话框ref
-const baseDataFormRef = ref() // 基本数据表单ref
-const editableTableRef = ref
>() // 可编辑表格ref
-const baseDataInfoRef = ref() // 基本信息ref
-// 基本信息表单数据
+const baseFormRef = ref() // 基本表单ref
+const vxeTableRef = ref>() // 可编辑表格ref
+const baseInfoRef = ref() // 基本信息ref
const baseDataForm = reactive({
id: "",
inventoryCode: "",
inventoryDate: formatDate(new Date(), "YYYY-mm-dd"),
- handlerUserId: "",
remark: "",
inventoryType: "7",
orderType: "",
})
-const state = reactive<{
- editableTableData: any[]
- erpSpuItemsMemo: any[]
- selectedRowsErpSpuIds: string[]
- erpSpuSimpleAll: any
-}>({
- editableTableData: [], // 可编辑表格数据
- erpSpuItemsMemo: [], // 请求到的可编辑表格商品数据的缓存
- selectedRowsErpSpuIds: [], // 可编辑表格已选行的ErpSpuId
- erpSpuSimpleAll: [], // 简要商品列表
-})
+const vxeTableData = ref([])
+const erpSpuSimpleAll = ref([])
-// 基本信息表单校验规则
const dataRules = ref({
inventoryCode: [{ required: true, message: "单据编号不能为空", trigger: "blur" }],
inventoryDate: [{ required: true, message: "单据日期不能为空", trigger: "blur" }],
- handlerUserId: [{ required: true, message: "经办人不能为空", trigger: "blur" }],
})
-
-// 可编辑表格校验规则
const validRules = ref>({
pdPrice: [{ required: true, message: "请输入" }],
})
+onMounted(() => {
+ getInitData()
+})
+
// 初始化数据
const getInitData = async () => {
- baseDataForm.id = undefined
+ baseDataForm.id = ""
const id = props.formId
disabled.value = props.disabled
if (id) {
loading.value = true
// 获取清单数据
- const [cgPlanData] = await Promise.allSettled([getStockTakingDeatil({ id })])
- .then((results) => results.map((result) => (result.status === "fulfilled" ? result.value : null)))
- .finally(() => (loading.value = false))
+ const [cgPlanData] = await Promise.allSettled([getStockTakingDeatil({ id })]).then((results) =>
+ results.map((result) => (result.status === "fulfilled" ? result.value : null)),
+ )
if (cgPlanData && cgPlanData.code === 0) {
Object.assign(baseDataForm, cgPlanData.data)
- state.editableTableData = cgPlanData.data.items
- state.erpSpuItemsMemo = cgPlanData.data.items
+ vxeTableData.value = cgPlanData.data.items
}
} else {
// 获取采购入库编号
- const [planCode] = await Promise.allSettled([getPlanCode({ type: 7 })])
- .then((results) => results.map((result) => (result.status === "fulfilled" ? result.value : null)))
- .finally(() => (loading.value = false))
-
+ const [planCode] = await Promise.allSettled([getPlanCode({ type: 7 })]).then((results) =>
+ results.map((result) => (result.status === "fulfilled" ? result.value : null)),
+ )
planCode && planCode.code === 0 && (baseDataForm.inventoryCode = planCode.data)
}
// 获取简要商品列表
- loading.value = true
- const [erpSpuSimpleAll] = await Promise.allSettled([getErpSpuSimpleAll()])
+ const [erpSpuSimpleAllData] = await Promise.allSettled([getErpSpuSimpleAll()])
.then((results) => results.map((result) => (result.status === "fulfilled" ? result.value : null)))
.finally(() => (loading.value = false))
- erpSpuSimpleAll && erpSpuSimpleAll.code === 0 && (state.erpSpuSimpleAll = erpSpuSimpleAll.data)
+ erpSpuSimpleAllData && erpSpuSimpleAllData.code === 0 && (erpSpuSimpleAll.value = erpSpuSimpleAllData.data)
+}
+
+// 点击商品选择
+const handleClickSpuSelect = () => erpSpuSelectDialogRef.value.openDialog()
+
+// 获取被选择的商品行
+const getSelectedRows = (selectionRows: any) => {
+ console.log("被选择的商品行", selectionRows)
+
+ // 筛选新勾选的项
+ const addedItems = selectionRows
+ .filter((item: any) => !vxeTableData.value.some((vxeTableItem: any) => vxeTableItem.erpSpuId === item.erpSpuId))
+ .map((addItem: any) => {
+ // const index = vxeTableDataMemo.value.findIndex((item: any) => item.erpSpuId === addItem.erpSpuId)
+ // if (index !== -1) return vxeTableDataMemo.value[index]
+ return { ...addItem, isNew: true }
+ })
+ vxeTableData.value.push(...addedItems)
+
+ console.log("vxeTableData.value", vxeTableData.value)
+}
+
+// 删除选中的行
+const removeRow = () => {
+ const $table = vxeTableRef.value
+ if ($table) {
+ const selectRecords = $table.getCheckboxRecords()
+ if (selectRecords.length > 0) {
+ vxeTableData.value = vxeTableData.value.filter((item: any) => !selectRecords.some((row) => row.erpSpuId === item.erpSpuId))
+ }
+ }
}
// 计算账面数量
@@ -333,7 +343,7 @@ const computeProfit = (row: any) => {
row._cachedProfit = diff > 0 ? diff : 0
}
- return row._cachedProfit
+ return row._cachedProfit.toFixed(2)
}
// 计算亏
const computeLoss = (row: any) => {
@@ -348,7 +358,7 @@ const computeLoss = (row: any) => {
row._cachedLoss = diff > 0 ? diff : 0
}
- return row._cachedLoss
+ return row._cachedLoss.toFixed(2)
}
// 当编辑实际数量时清除缓存使其重新计算
@@ -357,131 +367,6 @@ const handleRealNumberChange = (row: any) => {
row._cachedLoss = null
}
-// 删除选中的行
-const removeSelectRowEvent = () => {
- const $table = editableTableRef.value
- if ($table) {
- const selectRecords = $table.getCheckboxRecords()
- if (selectRecords.length > 0) {
- state.editableTableData = state.editableTableData.filter((item) => !selectRecords.some((row) => row.erpSpuId === item.erpSpuId))
- }
- }
-}
-
-// 可编辑表格行勾选
-const selectChangeEvent: VxeTableEvents.CheckboxChange = ({ checked }) => {
- const $table = editableTableRef.value
- if ($table) {
- const records = $table.getCheckboxRecords()
- console.log(checked ? "勾选事件" : "取消事件", records)
- state.selectedRowsErpSpuIds = records.map((item) => item.erpSpuId)
- }
-}
-
-// 点击商品选择
-const handleClickSpuSelect = () => erpSpuSelectDialogRef.value.openDialog()
-
-// 点击条码录入
-const handleClickBarCodeEnter = () => barCodeEnterRef.value.openDialog()
-
-// 获取被选择的商品行
-const getSelectedRows = (selectionRows: any) => {
- console.log("被选择的商品行", selectionRows)
-
- // 筛选新勾选的项
- const addedItems = selectionRows
- .filter((item: any) => !state.editableTableData.some((editableTableItem: any) => editableTableItem.erpSpuId === item.erpSpuId))
- .map((addItem: any) => {
- const index = state.erpSpuItemsMemo.findIndex((item: any) => item.erpSpuId === addItem.erpSpuId)
- if (index !== -1) return state.erpSpuItemsMemo[index]
- return { ...addItem, isNew: true }
- })
- // 仅添加新勾选的项
- state.editableTableData = [...state.editableTableData, ...addedItems]
-
- // 筛选取消勾选的项
- const removedItems = state.editableTableData.filter(
- (item: any) => !selectionRows.some((selectedItem: any) => selectedItem.erpSpuId === item.erpSpuId),
- )
- // 仅移除取消勾选的项
- state.editableTableData = state.editableTableData.filter(
- (item: any) => !removedItems.some((removeItem: any) => removeItem.erpSpuId === item.erpSpuId),
- )
- // state.editableTableData.push(item)
- // nextTick(() => {
- // const $table = editableTableRef.value
- // if ($table) {
- // $table.setRow(item)
- // }
- // })
- console.log("state.editableTableData", state.editableTableData)
-}
-
-// 整理数据
-const pdPlanItems = computed(() => {
- return state.editableTableData.map((item: any) => {
- return {
- ...item,
- unitPrice: Number(
- displayPrice(
- item.erpUnitVos.reduce((pre: any, cur: any) => pre + cur.purchasePrice * Number(cur.accountNumber), 0),
- "",
- ),
- ),
- realPrice: Number(
- displayPrice(
- item.erpUnitVos.reduce((pre: any, cur: any) => pre + cur.purchasePrice * Number(cur.realNumber), 0),
- "",
- ),
- ),
- profit: item._cachedProfit,
- loss: item._cachedLoss,
- totalNumber: item.erpUnitVos.reduce((pre: any, cur: any) => pre + Number(cur.realNumber) * cur.packageNum, 0) || 0,
- totalAmount: Number(
- (
- parseFloat(item.pdPrice || 0) *
- (item.erpUnitVos.reduce((pre: any, cur: any) => pre + Number(cur.realNumber) * cur.packageNum, 0) || 0)
- ).toFixed(2) || 0,
- ),
- // 盘盈就是1,盘亏就是2
- orderType: item._cachedProfit === item._cachedLoss ? "0" : item._cachedProfit > item._cachedLoss ? "1" : "2",
- }
- })
-})
-
-const { formValidate, submitData } = useSmProcessFormAction()
-
-// 点击继续添加
-const onContinueAdd = async () => {
- console.log("baseDataForm", baseDataForm)
- console.log("state.editableTableData", state.editableTableData)
- ;(await formValidate(baseDataFormRef, editableTableRef, state.editableTableData.length)) &&
- (await submitData(baseDataForm, pdPlanItems, loading, putObj, addObj)) &&
- clearData()
-}
-
-// 点击保存
-const onSave = async () => {
- console.log("baseDataForm", baseDataForm)
- console.log("state.editableTableData", state.editableTableData)
- ;(await formValidate(baseDataFormRef, editableTableRef, state.editableTableData.length)) &&
- (await submitData(baseDataForm, pdPlanItems, loading, putObj, addObj)) &&
- clearData() &&
- emit("close")
-}
-
-// 清空填写的数据 返回 true
-const clearData = () => {
- for (const key in baseDataForm) {
- if (key === "id" || key === "inventoryCode" || key === "inventoryDate" || key === "inventoryType" || key === "orderType") continue
- baseDataForm[key] = ""
- }
- state.editableTableData = []
- state.erpSpuItemsMemo = []
- state.selectedRowsErpSpuIds = []
- return true
-}
-
// 计算行数据
// const computeRowData = (row: any) => {
// // 计算盘点总数
@@ -493,7 +378,7 @@ const clearData = () => {
// const loss = diff < 0 ? Math.abs(diff) : 0
// // 计算总金额
-// const pdTotalAmount = parseFloat(row.pdPrice) * pdTotalNum
+// const pdTotalAmount = Number(row.pdPrice) * pdTotalNum
// return {
// pdTotalNum,
@@ -511,22 +396,86 @@ const handleEditChange = ({ row, column }: any) => {
// row._cachedLoss = null
// // 更新盘点总数和总金额
// row.pdTotalNum = row.erpUnitVos.reduce((pre: any, cur: any) => pre + Number(cur.realNumber) * cur.packageNum, 0)
- // row.pdTotalAmount = parseFloat(row.pdPrice) * row.pdTotalNum
+ // row.pdTotalAmount = Number(row.pdPrice) * row.pdTotalNum
// }
// if (column.field === "pdPrice") {
// // 更新盘点总金额
- // row.pdTotalAmount = parseFloat(row.pdPrice) * row.pdTotalNum
+ // row.pdTotalAmount = Number(row.pdPrice) * row.pdTotalNum
// }
}
-// 点击打印
-const printEvent = () => {
- tablePrint(editableTableRef.value, baseDataInfoRef.value, state.editableTableData, 23, "库存盘点")
+// 整理数据
+const settledTableItems = computed(() => {
+ return vxeTableData.value.map((item: any) => {
+ return {
+ ...item,
+ erpSpuId: item.erpSpuId,
+ profit: item._cachedProfit,
+ loss: item._cachedLoss,
+ // 盘盈就是1,盘亏就是2
+ orderType: item._cachedProfit === item._cachedLoss ? "0" : item._cachedProfit > item._cachedLoss ? "1" : "2",
+ accountNumber: item.stock,
+ realNumber: item.erpUnitVos.reduce((prev: number, curr: any) => prev + Number(curr.realNumber), 0),
+ unitPrice: Number(
+ displayPrice(
+ item.erpUnitVos.reduce((pre: any, cur: any) => pre + cur.purchasePrice * Number(cur.accountNumber), 0),
+ "",
+ ),
+ ),
+ realPrice: item.pdPrice,
+ // realPrice: Number(
+ // displayPrice(
+ // item.erpUnitVos.reduce((pre: any, cur: any) => pre + cur.purchasePrice * Number(cur.realNumber), 0),
+ // "",
+ // ),
+ // ),
+ totalNumber: item.erpUnitVos.reduce((pre: any, cur: any) => pre + Number(cur.realNumber) * cur.packageNum, 0) || 0,
+ totalAmount: Number(
+ (
+ Number(item.pdPrice || 0) *
+ (item.erpUnitVos.reduce((pre: any, cur: any) => pre + Number(cur.realNumber) * cur.packageNum, 0) || 0)
+ ).toFixed(2) || 0,
+ ),
+ }
+ })
+})
+
+const { formValidate, submitData } = useSmProcessFormAction()
+
+// 点击继续添加
+const onContinueAdd = async () => {
+ console.log("baseDataForm", baseDataForm)
+ console.log("vxeTableData", vxeTableData.value)
+ ;(await formValidate(baseFormRef, vxeTableRef, vxeTableData.value.length)) &&
+ (await submitData(baseDataForm, settledTableItems.value, loading, putObj, addObj)) &&
+ clearData()
}
-onMounted(() => {
- getInitData()
-})
+// 点击保存
+const onSave = async () => {
+ console.log("baseDataForm", baseDataForm)
+ console.log("vxeTableData", vxeTableData.value)
+ console.log("settledTableItems", settledTableItems.value)
+ ;(await formValidate(baseFormRef, vxeTableRef, vxeTableData.value.length)) &&
+ (await submitData(baseDataForm, settledTableItems.value, loading, putObj, addObj)) &&
+ clearData() &&
+ emit("close")
+}
+
+// 清空填写的数据
+const clearData = () => {
+ for (const key in baseDataForm) {
+ if (["id", "inventoryCode", "inventoryDate", "inventoryType", "orderType"].includes(key)) continue
+ baseDataForm[key] = ""
+ }
+ vxeTableData.value = []
+ return true
+}
+
+// 点击打印
+// const printEvent = () => {
+// tablePrint(vxeTableRef.value, baseInfoRef.value, vxeTableData.value, 23, "库存盘点")
+// }