fix: 修改耗材出入库计算逻辑,去除部分无用代码

This commit is contained in:
YeMingfei666 2025-03-21 11:29:05 +08:00
parent 812b01391b
commit fddbbf44cf
1 changed files with 92 additions and 309 deletions

View File

@ -11,8 +11,8 @@
<el-row> <el-row>
<el-form-item label="类型"> <el-form-item label="类型">
<el-radio-group :model-value="type"> <el-radio-group :model-value="type">
<el-radio-button label="in">入库</el-radio-button> <el-radio-button value="in">入库</el-radio-button>
<el-radio-button label="out">出库</el-radio-button> <el-radio-button value="out">出库</el-radio-button>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-row> </el-row>
@ -49,7 +49,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row v-if="shopTypes[shopTypesActive].value == 'purveyor'"> <el-row>
<el-col :span="8"> <el-col :span="8">
<el-form-item label="应付金额"> <el-form-item label="应付金额">
<el-input <el-input
@ -69,7 +69,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row v-if="shopTypes[shopTypesActive].value == 'purveyor'"> <el-row>
<el-col :span="8"> <el-col :span="8">
<el-form-item label="付款时间"> <el-form-item label="付款时间">
<el-date-picker <el-date-picker
@ -105,17 +105,13 @@
</el-row> </el-row>
<el-form-item label="选择耗材"> <el-form-item label="选择耗材">
<div></div> <div></div>
<el-button type="primary" @click="showHaocai" v-if="inTabValue == 'consumable'"> <el-button type="primary" @click="showHaocai">选择耗材</el-button>
选择耗材
</el-button>
<el-button type="primary" @click="$refs.shopList.show(tableData.list)" v-else>
选择商品
</el-button>
<el-autocomplete <el-autocomplete
v-model="autocompletename" v-model="autocompletename"
:fetch-suggestions="querySearchAsync" :fetch-suggestions="querySearchAsync"
:value-key="inTabValue == 'goods' ? 'name' : 'conName'" value-key="conName"
:placeholder="inTabValue == 'goods' ? '商品搜索' : '耗材搜索'" placeholder="耗材搜索"
@select="handleSelect" @select="handleSelect"
style="width: 200px; margin-left: 20px" style="width: 200px; margin-left: 20px"
></el-autocomplete> ></el-autocomplete>
@ -123,17 +119,13 @@
</el-form> </el-form>
</div> </div>
<div class="head-container"> <div class="head-container">
<el-button type="primary" plain v-if="inTabValue == 'consumable'"> <el-button type="primary" plain>
{{ tableData.list.length }}种耗材金额合计 {{ tableData.list.length }}种耗材金额合计
<span style="color: red">{{ queryForm.amountPayable }}</span> <span style="color: red">{{ amountPayable }}</span>
</el-button>
<el-button type="primary" plain v-else>
{{ tableData.list.length }}种商品金额合计
<span style="color: red">{{ queryForm.amountPayable }}</span>
</el-button> </el-button>
</div> </div>
<div class="head-container"> <div class="head-container">
<el-table :data="tableData.list" v-if="inTabValue == 'consumable'"> <el-table :data="tableData.list">
<el-table-column label="耗材名称" prop="conName"> <el-table-column label="耗材名称" prop="conName">
<template v-slot="scope"> <template v-slot="scope">
{{ scope.row.conName }} {{ scope.row.conName }}
@ -145,40 +137,22 @@
v-model="scope.row.price" v-model="scope.row.price"
:min="0" :min="0"
controls-position="right" controls-position="right"
@change="consCountTotal($event, scope.row, 'price')"
></el-input-number> ></el-input-number>
<div class="tips" style="font-size: 16px"> <div class="tips" style="font-size: 16px">
原价 原价
<!-- {{ scope.row.costPrice }}/{{ scope.row.conUnit }} -->
{{ {{ returnPrice(scope.row, scope.row.originPrice) }}
!scope.row.unit
? scope.row.defaultUnit
? scope.row.defaultUnit == scope.row.conUnitTwo
? (scope.row.costPrice * scope.row.conUnitTwoConvert).toFixed(2)
: scope.row.costPrice
: scope.row.costPrice
: scope.row.unit == scope.row.conUnitTwo
? (scope.row.costPrice * scope.row.conUnitTwoConvert).toFixed(2)
: scope.row.costPrice
}}
/ /
{{ {{ scope.row.unit }}
!scope.row.unit
? scope.row.defaultUnit
? scope.row.defaultUnit
: scope.row.conUnit
: scope.row.unit
}}
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="单位"> <el-table-column label="单位">
<template v-slot="scope"> <template v-slot="scope">
<el-select <el-select
@change="consCountTotal($event, scope.row, 'unit')"
v-model="scope.row.unit" v-model="scope.row.unit"
:placeholder="scope.row.defaultUnit ? scope.row.defaultUnit : scope.row.conUnit" :placeholder="scope.row.unit"
@change="changeUnit(scope.row)"
> >
<el-option :label="scope.row.conUnit" :value="scope.row.conUnit"></el-option> <el-option :label="scope.row.conUnit" :value="scope.row.conUnit"></el-option>
<el-option <el-option
@ -198,130 +172,24 @@
:step="1" :step="1"
step-strictly step-strictly
controls-position="right" controls-position="right"
@change="consCountTotal($event, scope.row, 'stockNumber')"
></el-input-number> ></el-input-number>
<div class="tips" style="font-size: 16px"> <div class="tips" style="font-size: 16px">
{{ type == "in" ? "入库" : "出库" }} {{ type == "in" ? "入库" : "出库" }}
{{ {{ returnStockNumber(scope.row, scope.row.number) }}
!scope.row.unit
? scope.row.defaultUnit
? scope.row.defaultUnit == scope.row.conUnitTwo
? scope.row.number / scope.row.conUnitTwoConvert
: scope.row.number
: scope.row.number
: scope.row.unit == scope.row.conUnitTwo
? scope.row.number / scope.row.conUnitTwoConvert
: scope.row.number
}}
{{ {{ scope.row.unit }}
!scope.row.unit
? scope.row.defaultUnit
? scope.row.defaultUnit
: scope.row.conUnit
: scope.row.unit
}}
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="小计"> <el-table-column label="小计">
<template v-slot="scope"> <template v-slot="scope">
<!-- <el-input-number v-model="scope.row.amountPayable" :min="0" scope.row.price , scope.row.stockNumber <el-input :value="xiaoji(scope.row)" readonly style="width: 100px" />
controls-position="right"></el-input-number> -->
<el-input :value="formatDecimal(testform(scope.row))" readonly style="width: 100px" />
</template> </template>
</el-table-column> </el-table-column>
<!-- <el-table-column label="变动后剩余库存">
<template v-slot="scope">
{{ scope.row.stockNumber + scope.row.number }}{{ scope.row.conUnit }}
</template>
</el-table-column> -->
<el-table-column label="操作" width="80"> <el-table-column label="操作" width="80">
<template v-slot="scope"> <template v-slot="scope">
<el-button link @click="tableData.list.splice(scope.$index, 1), spliceclick()"> <el-button link @click="tableData.list.splice(scope.$index, 1)">删除</el-button>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<el-table :data="tableData.list" v-else>
<el-table-column type="index" width="50"></el-table-column>
<el-table-column label="商品名称" prop="name">
<template v-slot="scope">
<div class="name_wrap">
<span class="name">{{ scope.row.name }}</span>
<span v-if="scope.row.specSnap">({{ scope.row.specSnap }})</span>
<!-- <el-tag type="info" v-if="scope.row.specSnap" size="mini">{{ scope.row.specSnap }}</el-tag> -->
</div>
</template>
</el-table-column>
<el-table-column label="进价">
<template v-slot="scope">
<el-input-number
v-model="scope.row.costPrice"
:min="0"
controls-position="right"
@change="modifyPrice($event, scope.row, 'costPrice')"
></el-input-number>
<div class="tips">成本价{{ scope.row.costPrice }}/{{ scope.row.unitName }}</div>
</template>
</el-table-column>
<el-table-column label="数量">
<template v-slot="scope">
<el-input-number
v-model="scope.row.number"
:min="0"
:step="1"
step-strictly
controls-position="right"
@change="modifyPrice($event, scope.row, 'number', 'amountPayable')"
></el-input-number>
<div class="tips" style="font-size: 16px">
入库前
{{
!scope.row.unit
? scope.row.defaultUnit
? scope.row.defaultUnit == scope.row.conUnitTwo
? scope.row.number / scope.row.conUnitTwoConvert
: scope.row.number
: scope.row.number
: scope.row.unit == scope.row.conUnitTwo
? scope.row.number / scope.row.conUnitTwoConvert
: scope.row.number
}}
{{
!scope.row.unit
? scope.row.defaultUnit
? scope.row.defaultUnit
: scope.row.conUnit
: scope.row.unit
}}
</div>
</template>
</el-table-column>
<el-table-column label="小计">
<template v-slot="scope">
<!-- <el-input-number v-model="scope.row.amountPayable" :min="0"
controls-position="right"></el-input-number> -->
<el-input
:value="scope.row.costPrice * scope.row.number"
readonly
style="width: 100px"
/>
</template>
</el-table-column>
<el-table-column label="变动后剩余库存">
<template v-slot="scope">
{{ scope.row.stockNumber + scope.row.number }}{{ scope.row.unitName }}
</template>
</el-table-column>
<el-table-column label="操作" width="80">
<template v-slot="scope">
<el-button type="text" @click="tableData.list.splice(scope.$index, 1), spliceclick()">
删除
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -329,8 +197,6 @@
<div> <div>
<el-button type="primary" @click="submitHandle" :loading="queryFormLoading">确定</el-button> <el-button type="primary" @click="submitHandle" :loading="queryFormLoading">确定</el-button>
</div> </div>
<!-- 选择商品 -->
<goods-list ref="shopList" @success="selectShop" />
<!-- 选择耗材 --> <!-- 选择耗材 -->
<ConsumableList ref="ConsumableList" @success="selectConsumable" /> <ConsumableList ref="ConsumableList" @success="selectConsumable" />
<el-dialog <el-dialog
@ -453,32 +319,60 @@ export default {
this.resetForm = { ...this.queryForm }; this.resetForm = { ...this.queryForm };
this.tbShopPurveyorGet(); this.tbShopPurveyorGet();
}, },
computed: {
amountPayable() {
if (!this.tableData.list.length) return 0;
const zong = this.tableData.list.reduce((prve, ele) => {
return (prve += ele.price * ele.stockNumber);
}, 0);
return zong.toFixed(2);
},
},
watch: {
amountPayable(newval) {
this.queryForm.amountPayable = newval;
},
},
methods: { methods: {
changeUnit(row) {
row.price = this.returnPrice(row, row.originPrice);
},
returnPrice(row, price = 0) {
if (!row.unit) {
return price;
}
if (row.unit && row.unit != row.defaultUnit) {
price = price / row.conUnitTwoConvert;
} else {
price = price;
}
return price;
},
returnStockNumber(row, number = 0) {
if (!row.unit) {
return number;
}
if (row.defaultUnit && row.unit != row.defaultUnit) {
return number * row.conUnitTwoConvert;
}
return number;
},
showHaocai() { showHaocai() {
this.$refs.ConsumableList.show(this.tableData.list); this.$refs.ConsumableList.show(this.tableData.list);
}, },
async querySearchAsync(queryString, cb) { async querySearchAsync(queryString, cb) {
// //
let res = null; let res = null;
if (this.inTabValue == "goods") {
res = await tbProductlist({ res = await consApi.getList({
page: 0, page: 0,
size: 20, size: 20,
name: queryString ? queryString : "", conName: queryString ? queryString : "",
shopId: localStorage.getItem("shopId"), });
sort: "id",
});
} else {
res = await consApi.getList({
page: 0,
size: 20,
conName: queryString ? queryString : "",
});
}
this.restaurants = res.records; this.restaurants = res.records;
if (res.records.length == 0) { if (res.records.length == 0) {
// //
ElMessage("无此商品"); ElMessage("无此耗材");
return false; return false;
} }
var uniqueArray = this.restaurants.filter( var uniqueArray = this.restaurants.filter(
@ -489,57 +383,16 @@ export default {
cb(uniqueArray); cb(uniqueArray);
}, 1000 * Math.random()); }, 1000 * Math.random());
}, },
testform(d) { xiaoji(row) {
let p = 1; const price = row.price * row.stockNumber;
if (d.unit && d.unit == d.conUnitTwo) { return price;
p = d.conUnitTwoConvert;
}
return d.price * d.stockNumber * p;
}, },
handleSelect(item) { handleSelect(item) {
// //
this.autocompletename = ""; this.autocompletename = "";
if (this.inTabValue == "goods") { this.selectConsumable([item]);
this.selectShop([item]);
} else {
this.selectConsumable([item]);
}
},
//
spliceclick() {
var zong = 0;
if (this.inTabValue == "goods") {
this.tableData.list.forEach((ele) => {
zong += ele.costPrice * ele.number;
});
} else {
this.tableData.list.forEach((ele) => {
let p = 1;
if (ele.unit && ele.conUnitTwo == ele.unit) {
p = ele.conUnitTwoConvert;
}
zong += ele.price * ele.stockNumber * p;
});
}
this.queryForm.amountPayable = formatDecimal(zong);
},
//
selectShop(res) {
let arr = [];
res.forEach((item) => {
item.skuList.forEach((i) => {
arr.push({
name: item.name,
unitName: item.unitName,
productId: item.id,
number: 0,
amountPayable: "",
...i,
});
});
});
this.tableData.list = [...this.tableData.list, ...arr];
}, },
// //
tabChange(value, type) { tabChange(value, type) {
this.shopTypesActive = type == "in" ? 0 : 1; this.shopTypesActive = type == "in" ? 0 : 1;
@ -568,101 +421,34 @@ export default {
this.shopTypesActive = 1; this.shopTypesActive = 1;
} }
}, },
//
consCountTotal(cvalue, row, key1, key2 = undefined) {
if (cvalue == undefined) {
setTimeout(() => {
row[key1] = 0;
let zong = 0;
this.tableData.list.forEach((ele) => {
zong += ele.price * ele.stockNumber;
});
this.queryForm.amountPayable = formatDecimal(zong);
}, 10);
} else {
row[key1] = cvalue;
let zong = 0;
this.tableData.list.forEach((ele) => {
let p = 1;
if (ele.unit && ele.conUnitTwo == ele.unit) {
p = ele.conUnitTwoConvert;
}
zong += ele.price * ele.stockNumber * p;
});
this.queryForm.amountPayable = formatDecimal(zong);
}
},
//
modifyPrice(cvalue, row, key1, key2 = undefined) {
if (cvalue == undefined) {
setTimeout(() => {
row[key1] = 0;
row[key2] = 0;
let zong = 0;
this.tableData.list.forEach((ele) => {
zong += ele.costPrice * ele.number;
});
this.queryForm.amountPayable = formatDecimal(zong);
}, 10);
} else {
row[key1] = cvalue;
row[key2] = cvalue;
let zong = 0;
this.tableData.list.forEach((ele) => {
zong += ele.costPrice * ele.number;
});
this.queryForm.amountPayable = formatDecimal(zong);
}
},
// //
submitHandle() { submitHandle() {
if (this.tableData.list.length == 0) { if (this.tableData.list.length == 0) {
switch (this.inTabValue) { ElMessage("请先选择耗材!");
case "goods": return;
ElMessage("请先选择商品!");
break;
case "consumable":
ElMessage("请先选择耗材!");
break;
default:
break;
}
return false;
} }
this.$refs.queryForm.validate(async (valid) => { this.$refs.queryForm.validate(async (valid) => {
if (valid) { if (valid) {
try { try {
this.queryFormLoading = true; this.queryFormLoading = true;
switch (this.inTabValue) { const bodyList = this.tableData.list.map((v) => {
case "goods": const inOutNumber =
this.queryForm.bodyList = this.tableData.list; v.defaultUnit && v.unit != v.defaultUnit
await tbProductStockOperateOutAndOn(this.queryForm); ? v.stockNumber / v.conUnitTwoConvert
break; : v.stockNumber;
case "consumable": return {
this.queryForm.accountsPayable = this.queryForm.amountPayable; conId: v.id,
this.queryForm.actualPayment = this.queryForm.actualPaymentAmount; conName: v.conName,
this.queryForm.paymentTime = this.queryForm.paymentDate; purchasePrice: v.price,
this.queryForm.supplierId = this.queryForm.vendorId; unitName: v.conUnit,
const bodyList = this.tableData.list.map((v) => { inOutNumber,
return { subTotal: this.xiaoji(v),
conId: v.id, };
conName: v.conName, });
purchasePrice: v.price, if (this.type == "in") {
unitName: v.conUnit, await stockApi.in({ ...this.queryForm, bodyList });
inOutNumber: v.stockNumber, } else {
subTotal: v.price * v.stockNumber, await stockApi.out({ ...this.queryForm, bodyList });
};
});
if (this.type == "in") {
await stockApi.in({ ...this.queryForm, bodyList });
} else {
await stockApi.out({ ...this.queryForm, bodyList });
}
break;
default:
break;
} }
this.queryFormLoading = false; this.queryFormLoading = false;
const title = this.type == "in" ? "入库" : "出库"; const title = this.type == "in" ? "入库" : "出库";
@ -689,6 +475,8 @@ export default {
item.stockNumber = 0; item.stockNumber = 0;
item.costPrice = item.price; item.costPrice = item.price;
item.conInfoId = item.id; item.conInfoId = item.id;
item.unit = item.defaultUnit;
item.originPrice = item.price;
return item; return item;
}); });
this.tableData.list = [...this.tableData.list, ...arr]; this.tableData.list = [...this.tableData.list, ...arr];
@ -698,14 +486,9 @@ export default {
resetHandle() { resetHandle() {
this.showResult = false; this.showResult = false;
this.queryForm = { ...this.resetForm }; this.queryForm = { ...this.resetForm };
if (this.inTabValue == "goods") { this.queryForm.type = this.inTabs.find((item) => item.value == this.inTabValue).type;
this.queryForm.type = "purveyor";
} else {
this.queryForm.type = this.inTabs.find((item) => item.value == this.inTabValue).type;
}
this.tableData.list = []; this.tableData.list = [];
this.$refs.queryForm.resetFields(); this.$refs.queryForm.resetFields();
this.$refs.queryForm.resetFields();
}, },
// //