|
@@ -27,7 +27,7 @@
|
|
|
</byTable>
|
|
|
</div>
|
|
|
<el-dialog
|
|
|
- :title="modalType == 'add' ? '产品组合' : '调仓接收'"
|
|
|
+ :title="modalType == 'add' ? '产品组合' : '组合详情'"
|
|
|
v-model="dialogVisible"
|
|
|
width="800"
|
|
|
v-loading="loading"
|
|
@@ -45,29 +45,40 @@
|
|
|
type="primary"
|
|
|
@click="openProduct = true"
|
|
|
style="margin-bottom: 10px"
|
|
|
+ v-if="modalType == 'add'"
|
|
|
>
|
|
|
添加产品
|
|
|
</el-button>
|
|
|
- <el-table :data="formData.data.stockWaitDetailsList">
|
|
|
- <el-table-column prop="name" label="产品名称" />
|
|
|
- <el-table-column prop="name" label="可组合数量" />
|
|
|
- <el-table-column prop="quantity" label="本次组合" min-width="150">
|
|
|
+ <el-table :data="formData.data.groupRecordDetailsList">
|
|
|
+ <el-table-column prop="productName" label="产品名称" />
|
|
|
+ <el-table-column
|
|
|
+ prop="canSum"
|
|
|
+ label="可组合数量"
|
|
|
+ v-if="modalType == 'add'"
|
|
|
+ />
|
|
|
+ <el-table-column prop="groupNum" label="组合数量" min-width="150">
|
|
|
<template #default="{ row, $index }">
|
|
|
<el-form-item
|
|
|
- :prop="'stockWaitDetailsList.' + $index + '.quantity'"
|
|
|
- :rules="rules.quantity"
|
|
|
+ :prop="'groupRecordDetailsList.' + $index + '.groupNum'"
|
|
|
+ :rules="rules.groupNum"
|
|
|
:inline-message="true"
|
|
|
>
|
|
|
<el-input-number
|
|
|
- v-model="row.quantity"
|
|
|
- :precision="4"
|
|
|
+ v-model="row.groupNum"
|
|
|
+ :precision="0"
|
|
|
:controls="false"
|
|
|
:min="0"
|
|
|
+ @change="() => changeCanSum(row, $index)"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column prop="zip" label="操作" width="100">
|
|
|
+ <el-table-column
|
|
|
+ prop="zip"
|
|
|
+ label="操作"
|
|
|
+ width="100"
|
|
|
+ v-if="modalType == 'add'"
|
|
|
+ >
|
|
|
<template #default="{ $index }">
|
|
|
<el-button type="primary" link @click="handleRemove($index)"
|
|
|
>删除</el-button
|
|
@@ -78,7 +89,7 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
</byForm>
|
|
|
- <template #footer>
|
|
|
+ <template #footer v-if="modalType == 'add'">
|
|
|
<el-button @click="dialogVisible = false" size="large">取 消</el-button>
|
|
|
<el-button
|
|
|
type="primary"
|
|
@@ -111,7 +122,7 @@
|
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
|
|
import byTable from "@/components/byTable/index";
|
|
|
import byForm from "@/components/byForm/index";
|
|
|
-import { computed, defineComponent, ref } from "vue";
|
|
|
+import { computed, defineComponent, ref, watch } from "vue";
|
|
|
import useUserStore from "@/store/modules/user";
|
|
|
import SelectProduct from "@/components/WDLY/product/SelectProduct";
|
|
|
|
|
@@ -123,6 +134,7 @@ const sourceList = ref({
|
|
|
total: 3,
|
|
|
pageNum: 1,
|
|
|
pageSize: 10,
|
|
|
+ type: "1",
|
|
|
},
|
|
|
});
|
|
|
let dialogVisible = ref(false);
|
|
@@ -131,8 +143,13 @@ let openProduct = ref(false);
|
|
|
let roomDialogVisible = ref(false);
|
|
|
let modalType = ref("add");
|
|
|
let rules = ref({
|
|
|
- code: [{ required: true, message: "请输入spu编码", trigger: "blur" }],
|
|
|
- name: [{ required: true, message: "请输入spu名称", trigger: "blur" }],
|
|
|
+ productWarehouseId: [
|
|
|
+ { required: true, message: "请选择半成品所在仓库", trigger: "change" },
|
|
|
+ ],
|
|
|
+ groupWarehouseId: [
|
|
|
+ { required: true, message: "请选择组合后放置仓库", trigger: "change" },
|
|
|
+ ],
|
|
|
+ groupNum: [{ required: true, message: "请输入分拆数量", trigger: "blur" }],
|
|
|
});
|
|
|
const { proxy } = getCurrentInstance();
|
|
|
const selectConfig = reactive([]);
|
|
@@ -141,57 +158,57 @@ const config = computed(() => {
|
|
|
return [
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "单号",
|
|
|
- prop: "code",
|
|
|
+ label: "组合编码",
|
|
|
+ prop: "productCode",
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "调出仓库",
|
|
|
- prop: "name",
|
|
|
+ label: "组合名称",
|
|
|
+ prop: "productName",
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "调出人",
|
|
|
- prop: "remark",
|
|
|
+ label: "规格型号",
|
|
|
+ prop: "productSpec",
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "调出时间",
|
|
|
- prop: "remark",
|
|
|
+ label: "半成品所在仓库",
|
|
|
+ prop: "productWarehouseName",
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "接收状态",
|
|
|
- prop: "remark",
|
|
|
+ label: "组合后放置仓库",
|
|
|
+ prop: "groupWarehouseName",
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "调入仓库",
|
|
|
- prop: "remark",
|
|
|
+ label: "组合数量",
|
|
|
+ prop: "groupNum",
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "接收人",
|
|
|
- prop: "remark",
|
|
|
+ label: "操作人",
|
|
|
+ prop: "createUserName",
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "接收时间",
|
|
|
- prop: "remark",
|
|
|
+ label: "操作时间",
|
|
|
+ prop: "createTime",
|
|
|
},
|
|
|
},
|
|
|
|
|
|
{
|
|
|
attrs: {
|
|
|
label: "操作",
|
|
|
- width: "200",
|
|
|
+ width: "100",
|
|
|
align: "right",
|
|
|
},
|
|
|
// 渲染 el-button,一般用在最后一列。
|
|
@@ -199,18 +216,7 @@ const config = computed(() => {
|
|
|
return [
|
|
|
{
|
|
|
attrs: {
|
|
|
- label: "接收",
|
|
|
- type: "primary",
|
|
|
- text: true,
|
|
|
- },
|
|
|
- el: "button",
|
|
|
- click() {
|
|
|
- getDtl(row);
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- attrs: {
|
|
|
- label: "打印",
|
|
|
+ label: "查看",
|
|
|
type: "primary",
|
|
|
text: true,
|
|
|
},
|
|
@@ -244,14 +250,14 @@ const formConfig = reactive([
|
|
|
},
|
|
|
{
|
|
|
type: "select",
|
|
|
- prop: "warehouseId",
|
|
|
+ prop: "productWarehouseId",
|
|
|
label: "半成品所在仓库",
|
|
|
itemWidth: 33,
|
|
|
data: [],
|
|
|
},
|
|
|
{
|
|
|
type: "select",
|
|
|
- prop: "warehouseId",
|
|
|
+ prop: "groupWarehouseId",
|
|
|
label: "组合后放置仓库",
|
|
|
itemWidth: 33,
|
|
|
data: [],
|
|
@@ -270,7 +276,7 @@ const getList = async (req) => {
|
|
|
sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
|
|
|
loading.value = true;
|
|
|
proxy
|
|
|
- .post("/productSpu/page", sourceList.value.pagination)
|
|
|
+ .post("/groupRecordDetails/page", sourceList.value.pagination)
|
|
|
.then((message) => {
|
|
|
console.log(message);
|
|
|
sourceList.value.data = message.rows;
|
|
@@ -283,16 +289,43 @@ const getList = async (req) => {
|
|
|
const openModal = () => {
|
|
|
dialogVisible.value = true;
|
|
|
modalType.value = "add";
|
|
|
+ formConfig[1].disabled = false;
|
|
|
+ formConfig[2].disabled = false;
|
|
|
formData.data = {
|
|
|
- stockWaitDetailsList: [],
|
|
|
+ type: "1",
|
|
|
+ groupRecordDetailsList: [],
|
|
|
};
|
|
|
};
|
|
|
|
|
|
const submitForm = () => {
|
|
|
- console.log(byform.value);
|
|
|
byform.value.handleSubmit((valid) => {
|
|
|
+ const list = formData.data.groupRecordDetailsList;
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ const e = list[i];
|
|
|
+ if (e.groupNum == 0) {
|
|
|
+ return ElMessage({
|
|
|
+ message: "组合数量不能为0!",
|
|
|
+ type: "info",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (e.groupNum > e.canSum) {
|
|
|
+ return ElMessage({
|
|
|
+ message: "组合数量不可大于可组合数量!",
|
|
|
+ type: "info",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
submitLoading.value = true;
|
|
|
- proxy.post("/productSpu/" + modalType.value, formData.data).then(
|
|
|
+ const data = {
|
|
|
+ type: formData.data.type,
|
|
|
+ productWarehouseId: formData.data.productWarehouseId,
|
|
|
+ groupWarehouseId: formData.data.groupWarehouseId,
|
|
|
+ groupRecordDetailsList: list.map((x) => ({
|
|
|
+ productId: x.productId,
|
|
|
+ groupNum: x.groupNum,
|
|
|
+ })),
|
|
|
+ };
|
|
|
+ proxy.post("/groupRecordDetails/" + modalType.value, data).then(
|
|
|
(res) => {
|
|
|
ElMessage({
|
|
|
message: modalType.value == "add" ? "添加成功" : "编辑成功",
|
|
@@ -309,11 +342,16 @@ const submitForm = () => {
|
|
|
|
|
|
const getDtl = (row) => {
|
|
|
modalType.value = "edit";
|
|
|
- proxy.post("/productSpu/detail", { id: row.id }).then((res) => {
|
|
|
- res.stockWaitDetailsList = res.productInfoList;
|
|
|
- formData.data = res;
|
|
|
- dialogVisible.value = true;
|
|
|
- });
|
|
|
+ proxy
|
|
|
+ .post("/groupRecordDetails/detail", { id: row.groupRecordId })
|
|
|
+ .then((res) => {
|
|
|
+ formConfig[1].disabled = true;
|
|
|
+ formConfig[2].disabled = true;
|
|
|
+ formData.data.productWarehouseId = row.productWarehouseId;
|
|
|
+ formData.data.groupWarehouseId = row.groupWarehouseId;
|
|
|
+ formData.data.groupRecordDetailsList = res;
|
|
|
+ dialogVisible.value = true;
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
const warehouseList = ref([]);
|
|
@@ -322,7 +360,7 @@ const warehouseListData = () => {
|
|
|
proxy
|
|
|
.post("/warehouse/page", {
|
|
|
pageNum: 1,
|
|
|
- pageSize: 10,
|
|
|
+ pageSize: 9999,
|
|
|
})
|
|
|
.then((message) => {
|
|
|
warehouseList.value = message.rows;
|
|
@@ -340,16 +378,20 @@ getList();
|
|
|
warehouseListData();
|
|
|
|
|
|
const handleSelect = (row) => {
|
|
|
- const flag = formData.data.stockWaitDetailsList.some((x) => x.id === row.id);
|
|
|
+ const flag = formData.data.groupRecordDetailsList.some(
|
|
|
+ (x) => x.productId === row.id
|
|
|
+ );
|
|
|
if (flag)
|
|
|
return ElMessage({
|
|
|
message: "该物品已选择",
|
|
|
type: "info",
|
|
|
});
|
|
|
- formData.data.stockWaitDetailsList.push({
|
|
|
- name: row.name,
|
|
|
- code: row.code,
|
|
|
- id: row.id,
|
|
|
+ formData.data.groupRecordDetailsList.push({
|
|
|
+ productName: row.name,
|
|
|
+ productCode: row.code,
|
|
|
+ productSpec: row.spec,
|
|
|
+ productId: row.id,
|
|
|
+ groupNum: 0,
|
|
|
});
|
|
|
return ElMessage({
|
|
|
message: "选择成功",
|
|
@@ -358,12 +400,137 @@ const handleSelect = (row) => {
|
|
|
};
|
|
|
|
|
|
const handleRemove = (index) => {
|
|
|
- formData.data.stockWaitDetailsList.splice(index, 1);
|
|
|
+ formData.data.groupRecordDetailsList.splice(index, 1);
|
|
|
return ElMessage({
|
|
|
message: "删除成功",
|
|
|
type: "success",
|
|
|
});
|
|
|
};
|
|
|
+const stockMapData = reactive({
|
|
|
+ data: {},
|
|
|
+});
|
|
|
+watchEffect(() => {
|
|
|
+ if (
|
|
|
+ formData.data.productWarehouseId &&
|
|
|
+ formData.data.groupRecordDetailsList.length > 0
|
|
|
+ ) {
|
|
|
+ proxy
|
|
|
+ .post("/groupRecordDetails/getCombinableQuantity", {
|
|
|
+ warehouseId: formData.data.productWarehouseId,
|
|
|
+ productIdList: formData.data.groupRecordDetailsList.map(
|
|
|
+ (x) => x.productId
|
|
|
+ ),
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ stockMapData.data = res.stockMap;
|
|
|
+ const stockMap = { ...stockMapData.data };
|
|
|
+ const list = formData.data.groupRecordDetailsList;
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ const e = list[i];
|
|
|
+ for (const key in res.combinableQuantity) {
|
|
|
+ if (e.productId === key) {
|
|
|
+ e.needProductIdMap = res.combinableQuantity[key]; //赋值需要的半成品id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ const e = list[i];
|
|
|
+ const canSumMap = {};
|
|
|
+ for (const needKey in e.needProductIdMap) {
|
|
|
+ if (stockMap.hasOwnProperty(needKey)) {
|
|
|
+ canSumMap[needKey] =
|
|
|
+ stockMap[needKey] / e.needProductIdMap[needKey];
|
|
|
+ } else {
|
|
|
+ canSumMap[needKey] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.canSumArr = Object.values(canSumMap);
|
|
|
+ e.canSum = Math.floor(Math.min(...e.canSumArr)); //取出最小值且向下取整
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const changeCanSum = (row, rowIndex) => {
|
|
|
+ const list = formData.data.groupRecordDetailsList;
|
|
|
+ const stockMap = { ...stockMapData.data };
|
|
|
+ if (rowIndex < list.length - 1) {
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ const e = list[i];
|
|
|
+ const canSumMap = {};
|
|
|
+ for (const key in e.needProductIdMap) {
|
|
|
+ if (stockMap.hasOwnProperty(key)) {
|
|
|
+ if (e.groupNum && e.groupNum > 0) {
|
|
|
+ stockMap[key] -= e.needProductIdMap[key] * e.groupNum;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ canSumMap[key] = 0;
|
|
|
+ }
|
|
|
+ // canSumMap[key] = stockMap[key] / e.needProductIdMap[key];
|
|
|
+ if (row.productId != e.productId) {
|
|
|
+ // console.log("aaa");
|
|
|
+ canSumMap[key] = stockMap[key] / e.needProductIdMap[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.canSumArr =
|
|
|
+ Object.values(canSumMap).length > 0
|
|
|
+ ? Object.values(canSumMap)
|
|
|
+ : [...e.canSumArr];
|
|
|
+ e.canSum = Math.floor(Math.min(...e.canSumArr)); //取出最小值且向下取整
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (let i = list.length - 1; i >= 0; i--) {
|
|
|
+ const e = list[i];
|
|
|
+ const canSumMap = {};
|
|
|
+ for (const key in e.needProductIdMap) {
|
|
|
+ if (stockMap.hasOwnProperty(key)) {
|
|
|
+ if (e.groupNum && e.groupNum > 0) {
|
|
|
+ stockMap[key] -= e.needProductIdMap[key] * e.groupNum;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ canSumMap[key] = 0;
|
|
|
+ }
|
|
|
+ // canSumMap[key] = stockMap[key] / e.needProductIdMap[key];
|
|
|
+ if (row.productId != e.productId) {
|
|
|
+ // console.log("aaa");
|
|
|
+ canSumMap[key] = stockMap[key] / e.needProductIdMap[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.canSumArr =
|
|
|
+ Object.values(canSumMap).length > 0
|
|
|
+ ? Object.values(canSumMap)
|
|
|
+ : [...e.canSumArr];
|
|
|
+ e.canSum = Math.floor(Math.min(...e.canSumArr)); //取出最小值且向下取整
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // for (let i = 0; i < list.length; i++) {
|
|
|
+ // const e = list[i];
|
|
|
+ // let canSumMap = {};
|
|
|
+ // for (const needKey in e.needProductIdMap) {
|
|
|
+ // if (stockMap.hasOwnProperty(needKey)) {
|
|
|
+ // if (e.groupNum && e.groupNum > 0) {
|
|
|
+ // stockMap[needKey] =
|
|
|
+ // stockMap[needKey] - e.needProductIdMap[needKey] * e.groupNum;
|
|
|
+ // } else {
|
|
|
+ // stockMap[needKey] =
|
|
|
+ // stockMap[needKey] - e.needProductIdMap[needKey] * -1;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (row.productId != e.productId) {
|
|
|
+ // canSumMap[needKey] = stockMap[needKey] / e.needProductIdMap[needKey];
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // canSumMap[needKey] = 0;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // e.canSumArr = Object.values(canSumMap).length
|
|
|
+ // ? Object.values(canSumMap)
|
|
|
+ // : [...e.canSumArr];
|
|
|
+ // e.canSum = Math.floor(Math.min(...e.canSumArr)); //取出最小值且向下取整
|
|
|
+ // // e.canSum = e.canSum - 1;
|
|
|
+ // }
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|