fix: 修改耗材出入库计算逻辑,去除部分无用代码
This commit is contained in:
parent
812b01391b
commit
fddbbf44cf
|
|
@ -11,8 +11,8 @@
|
|||
<el-row>
|
||||
<el-form-item label="类型">
|
||||
<el-radio-group :model-value="type">
|
||||
<el-radio-button label="in">入库</el-radio-button>
|
||||
<el-radio-button label="out">出库</el-radio-button>
|
||||
<el-radio-button value="in">入库</el-radio-button>
|
||||
<el-radio-button value="out">出库</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-row>
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row v-if="shopTypes[shopTypesActive].value == 'purveyor'">
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="应付金额">
|
||||
<el-input
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row v-if="shopTypes[shopTypesActive].value == 'purveyor'">
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="付款时间">
|
||||
<el-date-picker
|
||||
|
|
@ -105,17 +105,13 @@
|
|||
</el-row>
|
||||
<el-form-item label="选择耗材">
|
||||
<div></div>
|
||||
<el-button type="primary" @click="showHaocai" v-if="inTabValue == 'consumable'">
|
||||
选择耗材
|
||||
</el-button>
|
||||
<el-button type="primary" @click="$refs.shopList.show(tableData.list)" v-else>
|
||||
选择商品
|
||||
</el-button>
|
||||
<el-button type="primary" @click="showHaocai">选择耗材</el-button>
|
||||
|
||||
<el-autocomplete
|
||||
v-model="autocompletename"
|
||||
:fetch-suggestions="querySearchAsync"
|
||||
:value-key="inTabValue == 'goods' ? 'name' : 'conName'"
|
||||
:placeholder="inTabValue == 'goods' ? '商品搜索' : '耗材搜索'"
|
||||
value-key="conName"
|
||||
placeholder="耗材搜索"
|
||||
@select="handleSelect"
|
||||
style="width: 200px; margin-left: 20px"
|
||||
></el-autocomplete>
|
||||
|
|
@ -123,17 +119,13 @@
|
|||
</el-form>
|
||||
</div>
|
||||
<div class="head-container">
|
||||
<el-button type="primary" plain v-if="inTabValue == 'consumable'">
|
||||
<el-button type="primary" plain>
|
||||
共{{ tableData.list.length }}种耗材,金额合计
|
||||
<span style="color: red">¥{{ queryForm.amountPayable }}</span>
|
||||
</el-button>
|
||||
<el-button type="primary" plain v-else>
|
||||
共{{ tableData.list.length }}种商品,金额合计
|
||||
<span style="color: red">¥{{ queryForm.amountPayable }}</span>
|
||||
<span style="color: red">¥{{ amountPayable }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="head-container">
|
||||
<el-table :data="tableData.list" v-if="inTabValue == 'consumable'">
|
||||
<el-table :data="tableData.list">
|
||||
<el-table-column label="耗材名称" prop="conName">
|
||||
<template v-slot="scope">
|
||||
{{ scope.row.conName }}
|
||||
|
|
@ -145,40 +137,22 @@
|
|||
v-model="scope.row.price"
|
||||
:min="0"
|
||||
controls-position="right"
|
||||
@change="consCountTotal($event, scope.row, 'price')"
|
||||
></el-input-number>
|
||||
<div class="tips" style="font-size: 16px">
|
||||
原价¥
|
||||
<!-- {{ scope.row.costPrice }}/{{ scope.row.conUnit }} -->
|
||||
|
||||
{{
|
||||
!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
|
||||
}}
|
||||
{{ returnPrice(scope.row, scope.row.originPrice) }}
|
||||
/
|
||||
{{
|
||||
!scope.row.unit
|
||||
? scope.row.defaultUnit
|
||||
? scope.row.defaultUnit
|
||||
: scope.row.conUnit
|
||||
: scope.row.unit
|
||||
}}
|
||||
{{ scope.row.unit }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单位">
|
||||
<template v-slot="scope">
|
||||
<el-select
|
||||
@change="consCountTotal($event, 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
|
||||
|
|
@ -198,130 +172,24 @@
|
|||
:step="1"
|
||||
step-strictly
|
||||
controls-position="right"
|
||||
@change="consCountTotal($event, scope.row, 'stockNumber')"
|
||||
></el-input-number>
|
||||
<div class="tips" style="font-size: 16px">
|
||||
{{ type == "in" ? "入库" : "出库" }}前:
|
||||
{{
|
||||
!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
|
||||
}}
|
||||
{{ returnStockNumber(scope.row, scope.row.number) }}
|
||||
|
||||
{{
|
||||
!scope.row.unit
|
||||
? scope.row.defaultUnit
|
||||
? scope.row.defaultUnit
|
||||
: scope.row.conUnit
|
||||
: scope.row.unit
|
||||
}}
|
||||
{{ 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" scope.row.price , scope.row.stockNumber
|
||||
controls-position="right"></el-input-number> -->
|
||||
<el-input :value="formatDecimal(testform(scope.row))" readonly style="width: 100px" />
|
||||
<el-input :value="xiaoji(scope.row)" readonly style="width: 100px" />
|
||||
</template>
|
||||
</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">
|
||||
<template v-slot="scope">
|
||||
<el-button link @click="tableData.list.splice(scope.$index, 1), spliceclick()">
|
||||
删除
|
||||
</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>
|
||||
<el-button link @click="tableData.list.splice(scope.$index, 1)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
|
@ -329,8 +197,6 @@
|
|||
<div>
|
||||
<el-button type="primary" @click="submitHandle" :loading="queryFormLoading">确定</el-button>
|
||||
</div>
|
||||
<!-- 选择商品 -->
|
||||
<goods-list ref="shopList" @success="selectShop" />
|
||||
<!-- 选择耗材 -->
|
||||
<ConsumableList ref="ConsumableList" @success="selectConsumable" />
|
||||
<el-dialog
|
||||
|
|
@ -453,32 +319,60 @@ export default {
|
|||
this.resetForm = { ...this.queryForm };
|
||||
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: {
|
||||
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() {
|
||||
this.$refs.ConsumableList.show(this.tableData.list);
|
||||
},
|
||||
async querySearchAsync(queryString, cb) {
|
||||
//快捷搜索
|
||||
let res = null;
|
||||
if (this.inTabValue == "goods") {
|
||||
res = await tbProductlist({
|
||||
page: 0,
|
||||
size: 20,
|
||||
name: queryString ? queryString : "",
|
||||
shopId: localStorage.getItem("shopId"),
|
||||
sort: "id",
|
||||
});
|
||||
} else {
|
||||
res = await consApi.getList({
|
||||
page: 0,
|
||||
size: 20,
|
||||
conName: queryString ? queryString : "",
|
||||
});
|
||||
}
|
||||
|
||||
res = await consApi.getList({
|
||||
page: 0,
|
||||
size: 20,
|
||||
conName: queryString ? queryString : "",
|
||||
});
|
||||
this.restaurants = res.records;
|
||||
if (res.records.length == 0) {
|
||||
//给个提示没有搜到
|
||||
ElMessage("无此商品");
|
||||
ElMessage("无此耗材");
|
||||
return false;
|
||||
}
|
||||
var uniqueArray = this.restaurants.filter(
|
||||
|
|
@ -489,57 +383,16 @@ export default {
|
|||
cb(uniqueArray);
|
||||
}, 1000 * Math.random());
|
||||
},
|
||||
testform(d) {
|
||||
let p = 1;
|
||||
if (d.unit && d.unit == d.conUnitTwo) {
|
||||
p = d.conUnitTwoConvert;
|
||||
}
|
||||
return d.price * d.stockNumber * p;
|
||||
xiaoji(row) {
|
||||
const price = row.price * row.stockNumber;
|
||||
return price;
|
||||
},
|
||||
handleSelect(item) {
|
||||
//选定后清空
|
||||
this.autocompletename = "";
|
||||
if (this.inTabValue == "goods") {
|
||||
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];
|
||||
this.selectConsumable([item]);
|
||||
},
|
||||
|
||||
// 切换入库内容
|
||||
tabChange(value, type) {
|
||||
this.shopTypesActive = type == "in" ? 0 : 1;
|
||||
|
|
@ -568,101 +421,34 @@ export default {
|
|||
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() {
|
||||
if (this.tableData.list.length == 0) {
|
||||
switch (this.inTabValue) {
|
||||
case "goods":
|
||||
ElMessage("请先选择商品!");
|
||||
break;
|
||||
case "consumable":
|
||||
ElMessage("请先选择耗材!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
ElMessage("请先选择耗材!");
|
||||
return;
|
||||
}
|
||||
this.$refs.queryForm.validate(async (valid) => {
|
||||
if (valid) {
|
||||
try {
|
||||
this.queryFormLoading = true;
|
||||
switch (this.inTabValue) {
|
||||
case "goods":
|
||||
this.queryForm.bodyList = this.tableData.list;
|
||||
await tbProductStockOperateOutAndOn(this.queryForm);
|
||||
break;
|
||||
case "consumable":
|
||||
this.queryForm.accountsPayable = this.queryForm.amountPayable;
|
||||
this.queryForm.actualPayment = this.queryForm.actualPaymentAmount;
|
||||
this.queryForm.paymentTime = this.queryForm.paymentDate;
|
||||
this.queryForm.supplierId = this.queryForm.vendorId;
|
||||
const bodyList = this.tableData.list.map((v) => {
|
||||
return {
|
||||
conId: v.id,
|
||||
conName: v.conName,
|
||||
purchasePrice: v.price,
|
||||
unitName: v.conUnit,
|
||||
inOutNumber: v.stockNumber,
|
||||
subTotal: v.price * v.stockNumber,
|
||||
};
|
||||
});
|
||||
if (this.type == "in") {
|
||||
await stockApi.in({ ...this.queryForm, bodyList });
|
||||
} else {
|
||||
await stockApi.out({ ...this.queryForm, bodyList });
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
const bodyList = this.tableData.list.map((v) => {
|
||||
const inOutNumber =
|
||||
v.defaultUnit && v.unit != v.defaultUnit
|
||||
? v.stockNumber / v.conUnitTwoConvert
|
||||
: v.stockNumber;
|
||||
return {
|
||||
conId: v.id,
|
||||
conName: v.conName,
|
||||
purchasePrice: v.price,
|
||||
unitName: v.conUnit,
|
||||
inOutNumber,
|
||||
subTotal: this.xiaoji(v),
|
||||
};
|
||||
});
|
||||
if (this.type == "in") {
|
||||
await stockApi.in({ ...this.queryForm, bodyList });
|
||||
} else {
|
||||
await stockApi.out({ ...this.queryForm, bodyList });
|
||||
}
|
||||
this.queryFormLoading = false;
|
||||
const title = this.type == "in" ? "入库" : "出库";
|
||||
|
|
@ -689,6 +475,8 @@ export default {
|
|||
item.stockNumber = 0;
|
||||
item.costPrice = item.price;
|
||||
item.conInfoId = item.id;
|
||||
item.unit = item.defaultUnit;
|
||||
item.originPrice = item.price;
|
||||
return item;
|
||||
});
|
||||
this.tableData.list = [...this.tableData.list, ...arr];
|
||||
|
|
@ -698,14 +486,9 @@ export default {
|
|||
resetHandle() {
|
||||
this.showResult = false;
|
||||
this.queryForm = { ...this.resetForm };
|
||||
if (this.inTabValue == "goods") {
|
||||
this.queryForm.type = "purveyor";
|
||||
} else {
|
||||
this.queryForm.type = this.inTabs.find((item) => item.value == this.inTabValue).type;
|
||||
}
|
||||
this.queryForm.type = this.inTabs.find((item) => item.value == this.inTabValue).type;
|
||||
this.tableData.list = [];
|
||||
this.$refs.queryForm.resetFields();
|
||||
this.$refs.queryForm.resetFields();
|
||||
},
|
||||
|
||||
// 获取供应商列表
|
||||
|
|
|
|||
Loading…
Reference in New Issue