Merge branch 'master' of http://gitea.zianxin.com/zianxin/biz-pc-cloud
This commit is contained in:
commit
52db784df2
4 files changed
+842
-5
No files matched your search
+4
-5
@@ -8,18 +8,17 @@ VITE_OPEN = true
|
||||
ENV = 'development'
|
||||
|
||||
# ADMIN 服务地址
|
||||
# VITE_ADMIN_PROXY_PATH = http://123.156.230.15:8089/api/ # 线上
|
||||
VITE_ADMIN_PROXY_PATH = http://123.156.230.15:8089/api/ # 线上
|
||||
# VITE_ADMIN_PROXY_PATH = http://pjcloud.center.takin.cc/
|
||||
# VITE_ADMIN_PROXY_PATH = http://localhost:9999/
|
||||
VITE_ADMIN_PROXY_PATH = http://192.168.101.50:9999/ # 邓-本地
|
||||
# VITE_ADMIN_PROXY_PATH = http://192.168.101.50:9999/ # 邓-本地
|
||||
# VITE_ADMIN_PROXY_PATH = http://59.202.170.152:81/api # 正式环境
|
||||
|
||||
|
||||
# 图片访问基础地址
|
||||
# VITE_IMAGE_BASE_PATH = http://123.156.230.15:8089/api # 线上
|
||||
VITE_IMAGE_BASE_PATH = http://123.156.230.15:8089/api # 线上
|
||||
# VITE_IMAGE_BASE_PATH = http://pjcloud.center.takin.cc
|
||||
# VITE_IMAGE_BASE_PATH = http://localhost:9999
|
||||
VITE_IMAGE_BASE_PATH = http://192.168.101.50:9999 # 邓-本地
|
||||
# VITE_IMAGE_BASE_PATH = http://192.168.101.50:9999 # 邓-本地
|
||||
# VITE_IMAGE_BASE_PATH = http://59.202.170.152:81/api/ # 正式环境
|
||||
|
||||
# 代码生成服务地址
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<template>
|
||||
<!-- 关联采购申请单对话框 -->
|
||||
<el-dialog v-model="linkCgCodeDialogVisible" title="选择采购单" width="70%" :close-on-click-modal="false" draggable @close="onClose">
|
||||
<vxe-table
|
||||
v-show="step === 0"
|
||||
ref="linkCgPlanTableRef"
|
||||
border
|
||||
v-loading="linkCodeLoading"
|
||||
:row-config="{ isCurrent: true, isHover: true }"
|
||||
:radio-config="{ labelField: '', trigger: 'row' }"
|
||||
:data="cgddPage"
|
||||
@radio-change="radioChangeEvent"
|
||||
>
|
||||
<vxe-column type="radio" width="60" align="center"></vxe-column>
|
||||
<vxe-column field="id" title="id" align="center" width="200"></vxe-column>
|
||||
<vxe-column field="planCode" title="编号" align="center" width="200"></vxe-column>
|
||||
<vxe-column field="planDate" title="单据日期" align="center" width="200"></vxe-column>
|
||||
<vxe-column field="handlerUserId" title="经办人" align="center" width="100"></vxe-column>
|
||||
<vxe-column field="checkStatus" title="审批状态" align="center" width="100"></vxe-column>
|
||||
<vxe-column field="remark" title="备注" show-overflow align="center" min-width="100"></vxe-column>
|
||||
</vxe-table>
|
||||
<!-- <pagination
|
||||
@size-change="sizeChangeHandle"
|
||||
@current-change="currentChangeHandle"
|
||||
v-model:current-page="foodQueryForm.current"
|
||||
v-model:page-size="foodQueryForm.size"
|
||||
:total="total"
|
||||
/> -->
|
||||
<vxe-table
|
||||
v-show="step === 1"
|
||||
ref="linkCgPlanSpuTableRef"
|
||||
border
|
||||
:row-config="{ isCurrent: true, isHover: true }"
|
||||
:checkbox-config="{ trigger: 'row' }"
|
||||
:data="currRadioRowItems"
|
||||
>
|
||||
<vxe-column type="checkbox" width="60" align="center"></vxe-column>
|
||||
<vxe-column field="erpSpuId" title="erpSpuId" align="center" width="200"></vxe-column>
|
||||
<vxe-column field="unit" title="包装单位" align="center" width="200"></vxe-column>
|
||||
<vxe-column field="quantity" title="数量" align="center" width="100"></vxe-column>
|
||||
<vxe-column field="purchasePrice" title="进价" align="center" width="100"></vxe-column>
|
||||
<vxe-column field="unitPrice" title="进价" align="center" width="100"></vxe-column>
|
||||
<vxe-column field="totalAmount" title="累计总金额" align="center" width="100"></vxe-column>
|
||||
<vxe-column field="remark" title="备注" show-overflow align="center" min-width="100"></vxe-column>
|
||||
</vxe-table>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="linkCgCodeDialogVisible = false">取消</el-button>
|
||||
<el-button v-show="step === 1" type="primary" @click="step--">上一步</el-button>
|
||||
<el-button v-show="step === 0" type="primary" @click="step++" :disabled="currRadioRowItems.length <= 0">下一步</el-button>
|
||||
<el-button v-show="step === 1" type="primary" @click="getSelectedRowData" :disabled="linkCodeLoading">确认</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="linkCgCodeDialog">
|
||||
import { ref } from "vue"
|
||||
import { getCgddPage } from "/@/api/supermarketerp/smErpInventoryRecords"
|
||||
import { VxeTableEvents } from "vxe-table"
|
||||
|
||||
const linkCgCodeDialogVisible = defineModel()
|
||||
const emit = defineEmits(["getSelectedCgPlan"])
|
||||
|
||||
const linkCodeLoading = ref(false) // 关联采购申请单对话框加载状态
|
||||
const linkCgPlanTableRef = ref() // 关联补货单对话框表格1ref
|
||||
const linkCgPlanSpuTableRef = ref() // 关联补货单对话框表格2ref
|
||||
const cgddPage = ref([]) // 采购申请列表数据
|
||||
const currRadioRowItems = ref([]) // 当前单选的表格行的items
|
||||
const step = ref(0) // 选择步骤
|
||||
|
||||
// 打开关联补货单对话框
|
||||
const openLinkCodeDialog = async () => {
|
||||
linkCgCodeDialogVisible.value = true
|
||||
step.value = 0
|
||||
linkCodeLoading.value = true
|
||||
try {
|
||||
const res = await getCgddPage().finally(() => (linkCodeLoading.value = false))
|
||||
if (res.code === 0) {
|
||||
cgddPage.value = res.data.records
|
||||
}
|
||||
} catch (error) {
|
||||
cgddPage.value = []
|
||||
linkCodeLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 单选时
|
||||
const radioChangeEvent: VxeTableEvents.RadioChange<any> = ({ row }) => (currRadioRowItems.value = row.items)
|
||||
|
||||
// 获取选择的关联补货单对话框表格行数据
|
||||
const getSelectedRowData = () => {
|
||||
const $table = linkCgPlanTableRef.value
|
||||
const $SpuTable = linkCgPlanSpuTableRef.value
|
||||
if ($table && $SpuTable) {
|
||||
const currRadioRow = $table.getRadioRecord()
|
||||
console.log("currRadioRow", currRadioRow)
|
||||
const currSpuRows = $SpuTable.getCheckboxRecords()
|
||||
console.log("currSpuRows", currSpuRows)
|
||||
|
||||
emit("getSelectedCgPlan", { ...currRadioRow, items: currSpuRows })
|
||||
}
|
||||
}
|
||||
|
||||
// 对话框关闭
|
||||
const onClose = () => {
|
||||
linkCgCodeDialogVisible.value = false
|
||||
currRadioRowItems.value = []
|
||||
cgddPage.value = []
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openLinkCodeDialog,
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,186 @@
|
||||
<template>
|
||||
<div class="layout-padding">
|
||||
<div class="layout-padding-auto layout-padding-view">
|
||||
<el-row v-show="showSearch">
|
||||
<el-form :model="state.queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList">
|
||||
<el-form-item label="单据编号" prop="inventoryCode">
|
||||
<el-input placeholder="请输入单据编号" v-model="state.queryForm.inventoryCode" />
|
||||
</el-form-item>
|
||||
<el-form-item label="单据日期" prop="inventoryDate">
|
||||
<el-date-picker
|
||||
type="date"
|
||||
placeholder="请输入单据日期"
|
||||
v-model="state.queryForm.inventoryDate"
|
||||
fomat="yyyy-MM-dd"
|
||||
value-format="yyyy-MM-dd"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="经办人" prop="handlerUserId">
|
||||
<el-select v-model="state.queryForm.handlerUserId" placeholder="请选择经办人id">
|
||||
<el-option label="请选择" value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="审批状态" prop="checkStatus">
|
||||
<el-select v-model="state.queryForm.checkStatus" placeholder="请选择审批状态">
|
||||
<el-option :label="item.label" :value="item.value" v-for="(item, index) in check_status" :key="index" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button icon="search" type="primary" @click="getDataList">查询</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<div class="mb8" style="width: 100%">
|
||||
<el-button
|
||||
icon="folder-add"
|
||||
type="primary"
|
||||
class="ml10"
|
||||
@click="handleClickCreateInventoryRecord()"
|
||||
v-auth="'supermarket_smErpInventoryRecords_add'"
|
||||
>
|
||||
新 增
|
||||
</el-button>
|
||||
<el-button
|
||||
plain
|
||||
:disabled="multiple"
|
||||
icon="Delete"
|
||||
type="primary"
|
||||
v-auth="'supermarket_smErpInventoryRecords_del'"
|
||||
@click="handleDelete(selectObjs)"
|
||||
>
|
||||
删 除
|
||||
</el-button>
|
||||
<right-toolbar
|
||||
v-model:showSearch="showSearch"
|
||||
:export="'supermarket_smErpInventoryRecords_export'"
|
||||
@exportExcel="exportExcel"
|
||||
class="ml10 mr20"
|
||||
style="float: right"
|
||||
@queryTable="getDataList"
|
||||
/>
|
||||
</div>
|
||||
</el-row>
|
||||
|
||||
<el-table
|
||||
:data="state.dataList"
|
||||
v-loading="state.loading"
|
||||
border
|
||||
:cell-style="tableStyle.cellStyle"
|
||||
:header-cell-style="tableStyle.headerCellStyle"
|
||||
@selection-change="selectionChangHandle"
|
||||
@sort-change="sortChangeHandle"
|
||||
>
|
||||
<el-table-column type="selection" width="40" align="center" />
|
||||
<el-table-column type="index" label="#" width="50" />
|
||||
<el-table-column prop="inventoryCode" label="单据编号" show-overflow-tooltip />
|
||||
<el-table-column prop="inventoryDate" label="单据日期" show-overflow-tooltip />
|
||||
<el-table-column prop="inventoryDate" label="入库商品" show-overflow-tooltip />
|
||||
<el-table-column prop="handlerUserId" label="经办人" show-overflow-tooltip />
|
||||
<el-table-column prop="checkStatus" label="审批状态" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<dict-tag :options="check_status" :value="scope.row.checkStatus"></dict-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="supplierId" label="货商" show-overflow-tooltip />
|
||||
<el-table-column prop="remark" label="备注" show-overflow-tooltip />
|
||||
<el-table-column prop="totalAmount" label="入库总金额" show-overflow-tooltip />
|
||||
<el-table-column label="操作" width="150">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
icon="edit-pen"
|
||||
text
|
||||
type="primary"
|
||||
v-auth="'supermarket_smErpInventoryRecords_edit'"
|
||||
@click="handleClickEditInventoryRecord(scope.row.id)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
icon="delete"
|
||||
text
|
||||
type="primary"
|
||||
v-auth="'supermarket_smErpInventoryRecords_del'"
|
||||
@click="handleDelete([scope.row.id])"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="systemSmErpInventoryRecords">
|
||||
import { useRouter } from "vue-router"
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table"
|
||||
import { fetchList, delObjs } from "/@/api/supermarketerp/smErpInventoryRecords"
|
||||
import { useMessage, useMessageBox } from "/@/hooks/message"
|
||||
import { useDict } from "/@/hooks/dict"
|
||||
|
||||
const router = useRouter()
|
||||
const { erp_order_type, inventory_type, check_status } = useDict("erp_order_type", "inventory_type", "check_status")
|
||||
// 搜索变量
|
||||
const queryRef = ref()
|
||||
const showSearch = ref(true)
|
||||
// 多选变量
|
||||
const selectObjs = ref([]) as any
|
||||
const multiple = ref(true)
|
||||
|
||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
queryForm: {},
|
||||
pageList: fetchList,
|
||||
})
|
||||
|
||||
// table hook
|
||||
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } = useTable(state)
|
||||
|
||||
// 清空搜索条件
|
||||
const resetQuery = () => {
|
||||
// 清空搜索条件
|
||||
queryRef.value?.resetFields()
|
||||
// 清空多选
|
||||
selectObjs.value = []
|
||||
getDataList()
|
||||
}
|
||||
|
||||
// 导出excel
|
||||
const exportExcel = () => {
|
||||
downBlobFile(
|
||||
"/supermarket/smErpInventoryRecords/export",
|
||||
Object.assign(state.queryForm, { ids: selectObjs }),
|
||||
"smErpInventoryRecords.xlsx",
|
||||
)
|
||||
}
|
||||
|
||||
// 多选事件
|
||||
const selectionChangHandle = (objs: { id: string }[]) => {
|
||||
selectObjs.value = objs.map(({ id }) => id)
|
||||
multiple.value = !objs.length
|
||||
}
|
||||
|
||||
// 点击创建出库入库记录表
|
||||
const handleClickCreateInventoryRecord = () => router.push({ path: "/supermarketerp/smErpCgBack/smErpCgBackOption" })
|
||||
// 点击编辑出库入库记录表
|
||||
const handleClickEditInventoryRecord = (id: string) => router.push({ path: "/supermarketerp/smErpCgBack/smErpCgBackOption", query: { id } })
|
||||
|
||||
// 删除操作
|
||||
const handleDelete = async (ids: string[]) => {
|
||||
try {
|
||||
await useMessageBox().confirm("此操作将永久删除")
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await delObjs(ids)
|
||||
getDataList()
|
||||
useMessage().success("删除成功")
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,538 @@
|
||||
<template>
|
||||
<div class="layout-padding">
|
||||
<div v-loading="loading" class="layout-padding-auto layout-padding-view" style="overflow: scroll">
|
||||
<el-form ref="baseDataFormRef" :model="baseDataForm" :rules="dataRules" formDialogRef label-width="100px">
|
||||
<div class="flex flex-wrap">
|
||||
<el-form-item label="单据编号" prop="inventoryCode">
|
||||
<el-input v-model.trim="baseDataForm.inventoryCode" readonly style="width: 200px" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="单据日期" prop="inventoryDate">
|
||||
<el-input v-model.trim="baseDataForm.inventoryDate" readonly style="width: 200px" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="关联采购订单" prop="linkCode">
|
||||
<el-input
|
||||
v-model="baseDataForm.linkCode"
|
||||
:suffix-icon="Search"
|
||||
@click="handleClickLinkCode"
|
||||
readonly
|
||||
placeholder="请选择采购订单"
|
||||
style="width: 200px"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="经办人" prop="handlerUserId">
|
||||
<SelectHandlerUser v-model.trim="baseDataForm.handlerUserId" placeholder="请选择经办人" style="width: 200px" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="审批状态" prop="checkStatus">
|
||||
<el-input v-model.trim="baseDataForm.checkStatus" placeholder="请输入审批状态" style="width: 200px" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="货商" prop="supplierId">
|
||||
<el-select v-model="baseDataForm.supplierId" placeholder="请选择货商" style="width: 200px">
|
||||
<el-option v-for="item in supplierTypeDict" :key="item?.id" :label="item?.typeName" :value="item?.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model.trim="baseDataForm.remark" placeholder="请输入备注" style="width: 200px" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
|
||||
<el-row class="my-3">
|
||||
<el-button @click="addEvent">新增(顶部)</el-button>
|
||||
<el-button @click="pushEvent">新增(尾部)</el-button>
|
||||
<el-button @click="insertEvent">
|
||||
在第
|
||||
<el-input-number
|
||||
@click.stop
|
||||
v-model="state.insertedRowNumber"
|
||||
:min="0"
|
||||
:max="state.editableTableData.length"
|
||||
:precision="0"
|
||||
size="small"
|
||||
controls-position="right"
|
||||
style="min-width: 50px; margin: 0 5px"
|
||||
/>
|
||||
行新增
|
||||
</el-button>
|
||||
<el-button @click="removeSelectRowEvent" :disabled="state.selectedRowsErpSpuIds.length <= 0">删除选中</el-button>
|
||||
<el-button @click="clearData">清空数据</el-button>
|
||||
<el-button @click="handleClickSpuSelect">商品选择</el-button>
|
||||
</el-row>
|
||||
|
||||
<vxe-table
|
||||
ref="editableTableRef"
|
||||
border
|
||||
:loading="loading"
|
||||
show-overflow
|
||||
max-height="400"
|
||||
:edit-config="{
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
beforeEditMethod({ row, column }:any) {
|
||||
// 禁止编辑
|
||||
if (column.property === '') {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
}"
|
||||
:column-config="{ resizable: true }"
|
||||
:row-config="{ isHover: true }"
|
||||
:resizable-config="{ dragMode: 'fixed' }"
|
||||
:data="state.editableTableData"
|
||||
:edit-rules="validRules"
|
||||
@checkbox-all="selectChangeEvent"
|
||||
@checkbox-change="selectChangeEvent"
|
||||
size="mini"
|
||||
align="center"
|
||||
>
|
||||
<vxe-column type="checkbox" width="40" fixed="left" />
|
||||
|
||||
<vxe-column type="seq" width="50" fixed="left" />
|
||||
|
||||
<vxe-column field="productName" title="库存商品">
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.productName">{{ row.productName }}</span>
|
||||
<span v-else>{{ row.erpSpuId && state.erpSpuSimpleAll.find((item: any) => item.id === row.erpSpuId)?.productName }}</span>
|
||||
</template>
|
||||
</vxe-column>
|
||||
|
||||
<vxe-column field="unitId" title="包装单位" :edit-render="{}">
|
||||
<template #edit="{ row }">
|
||||
<el-select v-model="row.unitId" placeholder="请选择包装单位">
|
||||
<el-option
|
||||
v-if="row.erpUnitVos?.length > 0"
|
||||
v-for="item in row.erpUnitVos"
|
||||
:key="item.id"
|
||||
:label="item.unit"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</template>
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.unitId">{{ row.unit ?? row.erpUnitVos?.find((item: any) => item.id == row.unitId)?.unit }}</span>
|
||||
<span v-else style="color: #c0c4cf">请选择</span>
|
||||
</template>
|
||||
</vxe-column>
|
||||
|
||||
<vxe-column field="quantity" title="数量" :edit-render="{ autoFocus: 'input', placeholder: '请输入' }">
|
||||
<template #edit="{ row }">
|
||||
<el-input v-model="row.quantity" />
|
||||
</template>
|
||||
</vxe-column>
|
||||
|
||||
<vxe-column field="unitPrice" title="进价">
|
||||
<template #default="{ row }">
|
||||
{{ row.purchasePrice ?? row.erpUnitVos?.find((item: any) => item.id == row.unitId)?.purchasePrice }}
|
||||
</template>
|
||||
</vxe-column>
|
||||
|
||||
<vxe-column field="totalAmount" title="累计总金额">
|
||||
<template #default="{ row }">
|
||||
{{
|
||||
row.unitId && row.quantity
|
||||
? Number(row.erpUnitVos?.find((item: any) => item.id == row.unitId)?.purchasePrice) * row.quantity
|
||||
: ""
|
||||
}}
|
||||
</template>
|
||||
</vxe-column>
|
||||
|
||||
<vxe-column field="remark" title="备注" :edit-render="{ autoFocus: 'input', placeholder: '请输入' }">
|
||||
<template #edit="{ row }">
|
||||
<el-input v-model="row.remark" />
|
||||
</template>
|
||||
</vxe-column>
|
||||
</vxe-table>
|
||||
|
||||
<el-row class="my-3">
|
||||
<el-tooltip effect="dark" content="返回列表页面" placement="top">
|
||||
<el-button type="primary" plain @click="router.back()">取消</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip v-if="!baseDataForm.id" effect="dark" content="保存并清空数据" placement="top">
|
||||
<el-button type="primary" plain @click="onContinueAdd">继续添加</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip effect="dark" content="保存并返回列表页面" placement="top">
|
||||
<el-button type="primary" plain @click="onSave">保存</el-button>
|
||||
</el-tooltip>
|
||||
</el-row>
|
||||
|
||||
<!-- 商品选择对话框 -->
|
||||
<erpSpuSelectDialog
|
||||
ref="erpSpuSelectDialogRef"
|
||||
v-model="state.erpSpuSelectDialogVisible"
|
||||
:selectedSpuRows="state.editableTableData"
|
||||
@getSelectedSpuRows="getSelectedSpuRows"
|
||||
/>
|
||||
|
||||
<!-- 关联采购申请单对话框 -->
|
||||
<linkCgCodeDialog ref="linkCgCodeDialogRef" v-model="state.linkCgCodeDialogVisible" @getSelectedCgPlan="getSelectedCgPlan" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="cgPlanOption">
|
||||
import { ref, reactive, computed, onMounted } from "vue"
|
||||
import { useRouter, useRoute } from "vue-router"
|
||||
import { useMessage } from "/@/hooks/message"
|
||||
import { getObj, addObj, putObj } from "/@/api/supermarketerp/smErpInventoryRecords"
|
||||
import { getPlanCode, getErpSpuSimpleAll } from "/@/api/supermarketerp/common"
|
||||
import { VxeTableEvents, VxeTablePropTypes, type VxeTableInstance } from "vxe-table"
|
||||
import { getSupplierTypeOptions } from "/@/api/supermarketerp/smErpSupplier"
|
||||
import { storePrice } from "/@/utils/formatMoney"
|
||||
import { formatDate } from "/@/utils/formatTime"
|
||||
import { Search } from "@element-plus/icons-vue"
|
||||
import erpSpuSelectDialog from "/@/views/supermarketerp/components/erpSpuSelectDialog.vue"
|
||||
import linkCgCodeDialog from "/@/views/supermarketerp/smErpCgDd/components/linkCgCodeDialog.vue"
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const loading = ref(false) // 采购计划加载
|
||||
const erpSpuSelectDialogRef = ref() // 商品选择对话框ref
|
||||
const linkCgCodeDialogRef = ref() // 关联采购申请单对话框ref
|
||||
const baseDataFormRef = ref() // 基本数据表单ref
|
||||
const editableTableRef = ref<VxeTableInstance<any>>() // 可编辑表格ref
|
||||
const supplierTypeDict = ref<any[]>([]) // 货商下拉选项
|
||||
// 基本信息表单数据
|
||||
const baseDataForm = reactive<any>({
|
||||
id: "",
|
||||
inventoryCode: "",
|
||||
inventoryDate: formatDate(new Date(), "YYYY-mm-dd"),
|
||||
inventoryType: "3",
|
||||
sourceId: "",
|
||||
warehouseId: "",
|
||||
handlerUserId: "",
|
||||
checkStatus: "",
|
||||
checkUserId: "",
|
||||
checkTime: "",
|
||||
merchantId: "",
|
||||
deptId: "",
|
||||
supplierId: "",
|
||||
remark: "",
|
||||
orderType: "1",
|
||||
totalAmount: "",
|
||||
})
|
||||
const state = reactive<{
|
||||
editableTableData: any[]
|
||||
erpSpuItemsMemo: any[]
|
||||
selectedRowsErpSpuIds: string[]
|
||||
insertedRowNumber: number
|
||||
erpSpuSimpleAll: any
|
||||
linkCodeVisible: boolean
|
||||
erpSpuSelectDialogVisible: boolean
|
||||
linkCgCodeDialogVisible: boolean
|
||||
}>({
|
||||
editableTableData: [], // 可编辑表格数据
|
||||
erpSpuItemsMemo: [], // 请求到的可编辑表格商品数据的缓存
|
||||
selectedRowsErpSpuIds: [], // 可编辑表格已选行的ErpSpuId
|
||||
insertedRowNumber: 0, // 可编辑表格插入行的行号
|
||||
erpSpuSimpleAll: [], // 简要商品列表
|
||||
|
||||
linkCodeVisible: false, // 关联采购申请单对话框开关
|
||||
erpSpuSelectDialogVisible: false, // 商品选择对话框开关
|
||||
linkCgCodeDialogVisible: false, // 关联采购申请单对话框开关
|
||||
})
|
||||
|
||||
// 基本信息表单校验规则
|
||||
const dataRules = ref({
|
||||
inventoryCode: [{ required: true, message: "出入库记录表编号不能为空", trigger: "blur" }],
|
||||
inventoryDate: [{ required: true, message: "出入库记录表单据日期不能为空", trigger: "blur" }],
|
||||
handlerUserId: [{ required: true, message: "经办人不能为空", trigger: "blur" }],
|
||||
supplierId: [{ required: true, message: "货商不能为空", trigger: "blur" }],
|
||||
})
|
||||
|
||||
// 可编辑表格校验规则
|
||||
const validRules = ref<VxeTablePropTypes.EditRules<any>>({
|
||||
unitId: [{ required: true, message: "必须选择" }],
|
||||
quantity: [{ required: true, type: "number", min: 1, max: 99, message: "数值范围1~99" }],
|
||||
})
|
||||
|
||||
// 初始化数据
|
||||
const getInitData = async () => {
|
||||
baseDataForm.id = undefined
|
||||
const id = route.query.id as string
|
||||
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)
|
||||
state.editableTableData = cgPlanData.data.items
|
||||
state.erpSpuItemsMemo = cgPlanData.data.items
|
||||
}
|
||||
}
|
||||
|
||||
// 获取货商选项 & 获取采购计划编号
|
||||
const [erpSpuSimpleAll, supplierTypeOptions, planCode] = await Promise.allSettled([
|
||||
getErpSpuSimpleAll(),
|
||||
getSupplierTypeOptions(),
|
||||
getPlanCode({ type: 3 }),
|
||||
]).then((results) => results.map((result) => (result.status === "fulfilled" ? result.value : null)))
|
||||
erpSpuSimpleAll && erpSpuSimpleAll.code === 0 && (state.erpSpuSimpleAll = erpSpuSimpleAll.data)
|
||||
supplierTypeOptions && supplierTypeOptions.code === 0 && (supplierTypeDict.value = supplierTypeOptions.data)
|
||||
planCode && planCode.code === 0 && (baseDataForm.inventoryCode = planCode.data)
|
||||
}
|
||||
|
||||
// 点击关联采购申请编号
|
||||
const handleClickLinkCode = () => linkCgCodeDialogRef.value.openLinkCodeDialog()
|
||||
|
||||
// 获取选择的采购申请
|
||||
const getSelectedCgPlan = (selectionRows: any) => {
|
||||
console.log("被选择的关联数据", selectionRows)
|
||||
|
||||
baseDataForm.linkCode = selectionRows.planCode
|
||||
state.editableTableData = selectionRows.items
|
||||
state.erpSpuItemsMemo = selectionRows.items
|
||||
state.linkCgCodeDialogVisible = false
|
||||
}
|
||||
|
||||
// 顶部表格行新增
|
||||
const addEvent = () => {
|
||||
const newRow: any = {
|
||||
id: "",
|
||||
erpSpuId: "",
|
||||
quantity: null,
|
||||
unitPrice: null,
|
||||
totalAmount: null,
|
||||
remark: "",
|
||||
unitId: "",
|
||||
}
|
||||
state.editableTableData.unshift(newRow)
|
||||
nextTick(() => {
|
||||
const $table = editableTableRef.value
|
||||
if ($table) {
|
||||
$table.setEditRow(newRow)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 底部表格行新增
|
||||
const pushEvent = () => {
|
||||
const newRow: any = {
|
||||
id: "",
|
||||
erpSpuId: "",
|
||||
quantity: null,
|
||||
unitPrice: null,
|
||||
totalAmount: null,
|
||||
remark: "",
|
||||
unitId: "",
|
||||
}
|
||||
state.editableTableData.push(newRow)
|
||||
nextTick(() => {
|
||||
const $table = editableTableRef.value
|
||||
if ($table) {
|
||||
$table.setEditRow(newRow)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 在指定行插入
|
||||
const insertEvent = () => {
|
||||
const newRow: any = {
|
||||
id: "",
|
||||
erpSpuId: "",
|
||||
quantity: null,
|
||||
unitPrice: null,
|
||||
totalAmount: null,
|
||||
remark: "",
|
||||
unitId: "",
|
||||
}
|
||||
state.editableTableData.splice(state.insertedRowNumber, 0, newRow)
|
||||
nextTick(() => {
|
||||
const $table = editableTableRef.value
|
||||
if ($table) {
|
||||
$table.setEditRow(newRow)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 删除选中的行
|
||||
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<any> = ({ 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 getSelectedSpuRows = (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 }
|
||||
}) // 为新增的数据项添加isNew标志,若该项原本已经存在,则不添加isNew标志
|
||||
// 仅添加新勾选的项
|
||||
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)
|
||||
// }
|
||||
// })
|
||||
state.erpSpuSelectDialogVisible = false
|
||||
console.log("state.editableTableData", state.editableTableData)
|
||||
}
|
||||
|
||||
// 整理数据
|
||||
const cgPlanSpuItems = computed(() => {
|
||||
return state.editableTableData.map((item: any) => {
|
||||
if (item.erpUnitVos) {
|
||||
const unit = item.erpUnitVos.find((unitItem: any) => unitItem.id === item.unitId)
|
||||
return {
|
||||
id: item.isNew ? undefined : item.id,
|
||||
erpSpuId: item.erpSpuId,
|
||||
quantity: item.quantity,
|
||||
unitPrice: unit.purchasePrice ? storePrice(unit?.purchasePrice) : 0,
|
||||
totalAmount: Number(unit?.purchasePrice || 0) * item.quantity,
|
||||
remark: item.remark,
|
||||
unitId: item.unitId,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
id: item.isNew ? undefined : item.id,
|
||||
erpSpuId: item.erpSpuId,
|
||||
quantity: item.quantity,
|
||||
unitPrice: item.unitPrice ? storePrice(item.unitPrice) : 0,
|
||||
totalAmount: Number(item.unitPrice || 0) * item.quantity,
|
||||
remark: item.remark,
|
||||
unitId: item.unitId,
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// 点击继续添加
|
||||
const onContinueAdd = async () => {
|
||||
console.log("baseDataForm", baseDataForm)
|
||||
console.log("state.editableTableData", state.editableTableData)
|
||||
;(await baseDataFormValidate()) && checkSelectSpu() && (await editableTableValidate()) && (await submitData()) && clearData()
|
||||
}
|
||||
|
||||
// 点击保存
|
||||
const onSave = async () => {
|
||||
console.log("baseDataForm", baseDataForm)
|
||||
console.log("state.editableTableData", state.editableTableData)
|
||||
;(await baseDataFormValidate()) &&
|
||||
checkSelectSpu() &&
|
||||
(await editableTableValidate()) &&
|
||||
(await submitData()) &&
|
||||
clearData() &&
|
||||
router.replace({ path: "/supermarketerp/smErpCgBack/index" })
|
||||
}
|
||||
|
||||
// 校验基本数据表单 成功返回 true 失败返回 undefined
|
||||
const baseDataFormValidate = async () => {
|
||||
const valid = await baseDataFormRef.value.validate().catch(() => {})
|
||||
return valid
|
||||
}
|
||||
|
||||
// 校验是否选择了商品 成功返回 true 失败返回 false
|
||||
const checkSelectSpu = () => {
|
||||
if (state.editableTableData.length <= 0) {
|
||||
useMessage().warning("请选择商品")
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// 校验可编辑表格 成功返回 true 失败返回 false
|
||||
const editableTableValidate = async () => {
|
||||
// 全量校验
|
||||
const $table = editableTableRef.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 = {
|
||||
...baseDataForm,
|
||||
items: cgPlanSpuItems.value,
|
||||
}
|
||||
|
||||
console.log("提交的数据:", _pa)
|
||||
|
||||
const res = baseDataForm.id
|
||||
? await putObj(_pa).finally(() => (loading.value = false))
|
||||
: await addObj(_pa).finally(() => (loading.value = false))
|
||||
if (res.code === 0) {
|
||||
useMessage().success(baseDataForm.id ? "修改成功" : "添加成功")
|
||||
return true
|
||||
} else {
|
||||
useMessage().error(res.msg)
|
||||
return false
|
||||
}
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg)
|
||||
loading.value = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 清空填写的数据 返回 true
|
||||
const clearData = () => {
|
||||
for (const key in baseDataForm) {
|
||||
if (key === "id" || key === "inventoryCode" || key === "inventoryDate") continue
|
||||
baseDataForm[key] = ""
|
||||
}
|
||||
state.insertedRowNumber = 0
|
||||
state.editableTableData = []
|
||||
state.erpSpuItemsMemo = []
|
||||
state.selectedRowsErpSpuIds = []
|
||||
return true
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getInitData()
|
||||
})
|
||||
</script>
|
||||
Reference in new issue
Block a user