-
+
单据编号:
@@ -11,17 +11,13 @@
单据日期:
{{ baseDataForm.inventoryDate }}
-
- 经办人:
- {{ baseDataForm.handlerUserId }}
-
备注:
{{ baseDataForm.remark }}
-
+
@@ -29,14 +25,14 @@
-
+
@@ -45,15 +41,15 @@
商品选择
- 删除选中
+ 删除选中
清空数据
-
-
+
{{ 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 }}
@@ -183,15 +180,10 @@
保存
-
- 打印
-
-
-
@@ -200,9 +192,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 +202,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))
+ }
+ }
}
// 计算账面数量
@@ -357,69 +364,9 @@ 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) => {
+const settledTableItems = computed(() => {
+ return vxeTableData.value.map((item: any) => {
return {
...item,
unitPrice: Number(
@@ -454,31 +401,29 @@ 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)) &&
+ console.log("vxeTableData", vxeTableData.value)
+ ;(await formValidate(baseFormRef, vxeTableRef, vxeTableData.value.length)) &&
+ (await submitData(baseDataForm, settledTableItems.value, 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)) &&
+ console.log("vxeTableData", vxeTableData.value)
+ ;(await formValidate(baseFormRef, vxeTableRef, vxeTableData.value.length)) &&
+ (await submitData(baseDataForm, settledTableItems.value, 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
+ if (["id", "inventoryCode", "inventoryDate", "inventoryType", "orderType"].includes(key)) continue
baseDataForm[key] = ""
}
- state.editableTableData = []
- state.erpSpuItemsMemo = []
- state.selectedRowsErpSpuIds = []
+ vxeTableData.value = []
return true
}
@@ -520,13 +465,9 @@ const handleEditChange = ({ row, column }: any) => {
}
// 点击打印
-const printEvent = () => {
- tablePrint(editableTableRef.value, baseDataInfoRef.value, state.editableTableData, 23, "库存盘点")
-}
-
-onMounted(() => {
- getInitData()
-})
+// const printEvent = () => {
+// tablePrint(vxeTableRef.value, baseInfoRef.value, vxeTableData.value, 23, "库存盘点")
+// }