diff --git a/src/views/canteen/canteenInventoryRecords/form.vue b/src/views/canteen/canteenInventoryRecords/form.vue
index fb283ef..734b32d 100644
--- a/src/views/canteen/canteenInventoryRecords/form.vue
+++ b/src/views/canteen/canteenInventoryRecords/form.vue
@@ -1,42 +1,51 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
- 商品选择
- 删除选中
+ 商品选择
+
+ 删除选中
+
清空数据
+
+
+
-
-
- {{ row.name }}
-
-
+
+
+
@@ -102,26 +108,18 @@
- {{ disabled ? "返回" : "取消" }}
+ 返回
-
+
继续添加
-
+
保存
-
- 打印
+
+ 打印
-
-
-
@@ -133,56 +131,40 @@ import { getCanteenSequence } from "/@/api/canteen/common"
import { VxeTableEvents, VxeTablePropTypes, type VxeTableInstance } from "vxe-table"
import { formatDate } from "/@/utils/formatTime"
import { displayPrice, storePrice } from "/@/utils/formatMoney"
-import { tablePrint } from "../../supermarketerp/supermarketUtils"
-import { useSmProcessFormAction } from "/@/hooks/smProcessFormAction"
+import { useMessage } from "/@/hooks/message"
-const SelectDialog = defineAsyncComponent(() => import("/@/views/canteen/components/selectDialog.vue"))
+const SelectDialog = defineAsyncComponent(() => import("./select-dialog.vue"))
const props = withDefaults(
defineProps<{
formId?: string | undefined
- disabled?: boolean
}>(),
{
formId: undefined,
- disabled: false,
},
)
+
const emit = defineEmits(["close"])
-const loading = ref(false) // 采购计划加载
-const erpSpuSelectDialogRef = ref() // 商品选择对话框ref
-const baseDataFormRef = ref() // 基本数据表单ref
-const editableTableRef = ref>() // 可编辑表格ref
-// 基本信息表单数据
-const baseDataForm = reactive({
+const loading = ref(false)
+const baseFormRef = ref() // 基本表单ref
+const selectDialogRef = ref() // 对话框选择ref
+const itemTableFormRef = ref>() // 可编辑表格ref
+const baseForm = reactive({
id: "",
inventoryCode: "",
inventoryDate: formatDate(new Date(), "YYYY-mm-dd"),
handlerUserId: "",
- supplierId: "",
merchantId: "",
+ supplierId: "",
remark: "",
- inventoryType: "3",
+ inventoryType: "1",
orderType: "1",
})
-const state = reactive<{
- editableTableData: any[]
- erpSpuItemsMemo: any[]
- selectedRowsErpMaterialIds: string[]
- erpSpuSimpleAll: any
- linkCodeVisible: boolean
- erpSpuSelectDialogVisible: boolean
- linkCgPlanDialogVisible: boolean
-}>({
- editableTableData: [], // 可编辑表格数据
- erpSpuItemsMemo: [], // 请求到的可编辑表格商品数据的缓存
- selectedRowsErpMaterialIds: [], // 可编辑表格已选行的erpMaterialId
- erpSpuSimpleAll: [], // 简要商品列表
-
- linkCodeVisible: false, // 关联采购申请单对话框开关
- erpSpuSelectDialogVisible: false, // 商品选择对话框开关
- linkCgPlanDialogVisible: false, // 关联采购申请单对话框开关
+const state = reactive({
+ selectDialogVisible: false, // 对话框选择开关
+ itemTableForm: [], // 可编辑表格数据
+ selectedRowIds: [], // 可编辑表格已选行的id
})
// 基本信息表单校验规则
@@ -202,25 +184,24 @@ const validRules = ref>({
// 初始化数据
const getInitData = async () => {
- baseDataForm.id = undefined
+ baseForm.id = undefined
const id = props.formId
if (id) {
- loading.value = true
- // 获取清单数据
- const [cgPlanData] = await Promise.allSettled([getObj(id)])
- .then((results) => results.map((result) => (result.status === "fulfilled" ? result.value : null)))
- .finally(() => (loading.value = false))
-
- if (cgPlanData && cgPlanData.code === 0) {
- Object.assign(baseDataForm, cgPlanData.data)
- }
+ // loading.value = true
+ // // 获取清单数据
+ // const [cgPlanData] = await Promise.allSettled([getObj(id)])
+ // .then((results) => results.map((result) => (result.status === "fulfilled" ? result.value : null)))
+ // .finally(() => (loading.value = false))
+ // if (cgPlanData && cgPlanData.code === 0) {
+ // Object.assign(baseForm, cgPlanData.data)
+ // }
} else {
loading.value = true
// 获取采购入库编号
- const [planCode] = await Promise.allSettled([getCanteenSequence({ type: 1 })])
+ const [sequenceCode] = await Promise.allSettled([getCanteenSequence({ type: 1 })])
.then((results) => results.map((result) => (result.status === "fulfilled" ? result.value : null)))
.finally(() => (loading.value = false))
- planCode && planCode.code === 0 && (baseDataForm.inventoryCode = planCode.data)
+ sequenceCode && sequenceCode.code === 0 && (baseForm.inventoryCode = sequenceCode.data)
}
// loading.value = true
@@ -231,143 +212,136 @@ const getInitData = async () => {
// erpSpuSimpleAll && erpSpuSimpleAll.code === 0 && (state.erpSpuSimpleAll = erpSpuSimpleAll.data)
}
-// 点击关联采购申请编号
-// const handleClickLinkCode = () => linkCgPlanDialogRef.value.openLinkCodeDialog(2)
+// 点击商品选择
+const clickSelectDialog = () => selectDialogRef.value.openDialog()
-// 获取选择的采购申请
-// const getSelectedLinkCode = (selectionRows: any) => {
-// console.log("被选择的关联数据", selectionRows)
+// 获取被选择的商品行
+const getSelectedRows = (selectionRows: any) => {
+ console.log("被选择的商品行", selectionRows)
-// baseDataForm.linkCode = selectionRows.code
-// state.editableTableData = selectionRows.items.map((item: any) => ({
-// ...item,
-// unitObj: {},
-// realPrice: displayPrice(item.purchasePrice, ""),
-// }))
-// state.erpSpuItemsMemo = selectionRows.items.map((item: any) => ({
-// ...item,
-// unitObj: {},
-// realPrice: displayPrice(item.purchasePrice, ""),
-// }))
-// state.linkCgPlanDialogVisible = false
-// }
+ // 筛选新勾选的项并处理
+ const addedItems = selectionRows
+ .filter((selectionRowsItem: any) => !state.itemTableForm.some((item: any) => item.erpMaterialId === selectionRowsItem.erpMaterialId))
+ .map((addItem: any) => ({ ...addItem, price: displayPrice(addItem.price, ""), isNew: true }))
+
+ state.itemTableForm = [...state.itemTableForm, ...addedItems]
+
+ state.selectDialogVisible = false
+ console.log("state.itemTableForm", state.itemTableForm)
+}
+
+// 可编辑表格行勾选
+const selectChangeEvent: VxeTableEvents.CheckboxChange = ({ checked }) => {
+ const $table = itemTableFormRef.value
+ if ($table) {
+ const records = $table.getCheckboxRecords()
+ state.selectedRowIds = records.map((item) => item.erpMaterialId)
+ }
+}
// 删除选中的行
-const removeSelectRowEvent = () => {
- const $table = editableTableRef.value
+const removeSelectedRows = () => {
+ const $table = itemTableFormRef.value
if ($table) {
const selectRecords = $table.getCheckboxRecords()
if (selectRecords.length > 0) {
- state.editableTableData = state.editableTableData.filter(
- (item) => !selectRecords.some((row) => row.erpMaterialId === item.erpMaterialId),
+ state.itemTableForm = state.itemTableForm.filter(
+ (item: any) => !selectRecords.some((row) => row.erpMaterialId === item.erpMaterialId),
)
}
}
}
-// 可编辑表格行勾选
-const selectChangeEvent: VxeTableEvents.CheckboxChange = ({ checked }) => {
- const $table = editableTableRef.value
- if ($table) {
- const records = $table.getCheckboxRecords()
- console.log(checked ? "勾选事件" : "取消事件", records)
- state.selectedRowsErpMaterialIds = records.map((item) => item.erpMaterialId)
- }
-}
-
-// 点击商品选择
-const handleClickSpuSelect = () => erpSpuSelectDialogRef.value.openDialog()
-
-// 获取被选择的商品行
-const getSelectedSpuRows = (selectionRows: any) => {
- console.log("被选择的商品行", selectionRows)
-
- // 筛选新勾选的项
- const addedItems = selectionRows
- .filter(
- (item: any) => !state.editableTableData.some((editableTableItem: any) => editableTableItem.erpMaterialId === item.erpMaterialId),
- )
- .map((addItem: any) => {
- const index = state.erpSpuItemsMemo.findIndex((item: any) => item.erpMaterialId === addItem.erpMaterialId)
- if (index !== -1) return state.erpSpuItemsMemo[index]
- return { ...addItem, price: displayPrice(addItem.price, ""), isNew: true }
- })
- // 仅添加新勾选的项
- state.editableTableData = [...state.editableTableData, ...addedItems]
-
- // 筛选取消勾选的项
- const removedItems = state.editableTableData.filter(
- (item: any) => !selectionRows.some((selectedItem: any) => selectedItem.erpMaterialId === item.erpMaterialId),
- )
- // 仅移除取消勾选的项
- state.editableTableData = state.editableTableData.filter(
- (item: any) => !removedItems.some((removeItem: any) => removeItem.erpMaterialId === item.erpMaterialId),
- )
- // state.editableTableData.push(item)
- // nextTick(() => {
- // const $table = editableTableRef.value
- // if ($table) {
- // $table.setRow(item)
- // }
- // })
- state.erpSpuSelectDialogVisible = false
- console.log("state.editableTableData", state.editableTableData)
-}
-
// 整理数据
-const cgPlanSpuItems = computed(() => {
- return state.editableTableData.map((item: any) => {
- return {
- id: item.isNew ? undefined : item.id,
- erpMaterialId: item.erpMaterialId,
- quantity: item.quantity,
- unitPrice: item.price,
- realPrice: item.realPrice ? storePrice(item.realPrice) : 0,
- totalAmount: item?.realPrice && item.quantity ? storePrice(Number(item.realPrice) * Number(item.quantity)) : 0,
- stock: item.stock,
- remark: item.remark,
- }
- })
+const tableFormItems = state.itemTableForm.map((item: any) => {
+ return {
+ // id: item.isNew ? undefined : item.id,
+ erpMaterialId: item.erpMaterialId,
+ quantity: item.quantity,
+ unitPrice: item.price,
+ realPrice: item.realPrice ? storePrice(item.realPrice) : 0,
+ totalAmount: (Number(item.quantity || 0) * Number(item.realPrice || 0)).toFixed(2),
+ stock: item.stock,
+ remark: item.remark,
+ }
})
-const { formValidate, submitData } = useSmProcessFormAction()
-
// 点击继续添加
const onContinueAdd = async () => {
- console.log("baseDataForm", baseDataForm)
- console.log("state.editableTableData", state.editableTableData)
- ;(await formValidate(baseDataFormRef, editableTableRef, state.editableTableData)) &&
- (await submitData(baseDataForm, cgPlanSpuItems, loading, putObj, addObj)) &&
- clearData()
+ ;(await baseFormValidate()) && (await itemTableFormValidate()) && (await submitData()) && clearData()
}
// 点击保存
const onSave = async () => {
- console.log("baseDataForm", baseDataForm)
- console.log("state.editableTableData", state.editableTableData)
- ;(await formValidate(baseDataFormRef, editableTableRef, state.editableTableData)) &&
- (await submitData(baseDataForm, cgPlanSpuItems, loading, putObj, addObj)) &&
- clearData() &&
- emit("close")
+ ;(await baseFormValidate()) && (await itemTableFormValidate()) && (await submitData()) && clearData() && emit("close")
+}
+
+// 校验基本数据表单 成功返回 true 失败返回 undefined
+const baseFormValidate = async () => {
+ const valid = await baseFormRef.value.validate().catch(() => {})
+ return valid
+}
+
+// 校验可编辑表格 成功返回 true 失败返回 false
+const itemTableFormValidate = async () => {
+ if (state.itemTableForm.length <= 0) {
+ useMessage().warning("请选择商品")
+ return false
+ }
+
+ // 全量校验
+ const $table = itemTableFormRef.value
+ if ($table) {
+ const errMap = await $table.validate(true)
+ if (errMap) {
+ console.log("全量校验失败!")
+ return false
+ } else {
+ console.log("全量校验成功!")
+ return true
+ }
+ }
+}
+
+// 提交数据 成功返回 true 失败返回 false
+const submitData = async () => {
+ try {
+ loading.value = true
+
+ const _pa = {
+ ...baseForm,
+ items: tableFormItems(),
+ }
+
+ console.log("提交的数据:", _pa)
+
+ const res = baseForm.id ? await putObj(_pa) : await addObj(_pa)
+ if (res.code == 0) {
+ useMessage().success(baseForm.id ? "修改成功" : "添加成功")
+ return true
+ } else {
+ useMessage().error(res.msg)
+ return false
+ }
+ } catch (err: any) {
+ useMessage().error(err.msg)
+ return false
+ } finally {
+ loading.value = false
+ }
}
// 清空填写的数据 返回 true
const clearData = () => {
- for (const key in baseDataForm) {
+ for (const key in baseForm) {
if (key === "id" || key === "inventoryCode" || key === "inventoryDate" || key === "inventoryType" || key === "orderType") continue
- baseDataForm[key] = ""
+ baseForm[key] = ""
}
- state.editableTableData = []
- state.erpSpuItemsMemo = []
- state.selectedRowsErpMaterialIds = []
+ state.itemTableForm = []
+ state.selectedRowIds = []
return true
}
-// 点击打印
-const printEvent = () => {
- // tablePrint(editableTableRef.value, baseDataInfoRef.value, state.editableTableData, 23, "采购入库")
-}
-
onMounted(() => {
getInitData()
})
diff --git a/src/views/canteen/components/selectDialog.vue b/src/views/canteen/canteenInventoryRecords/select-dialog.vue
similarity index 88%
rename from src/views/canteen/components/selectDialog.vue
rename to src/views/canteen/canteenInventoryRecords/select-dialog.vue
index ef2f337..2a9e9a6 100644
--- a/src/views/canteen/components/selectDialog.vue
+++ b/src/views/canteen/canteenInventoryRecords/select-dialog.vue
@@ -44,20 +44,18 @@
\ No newline at end of file