erp项目采购模块新增商品,商品价格计算demo

2024-03-01 17:20

本文主要是介绍erp项目采购模块新增商品,商品价格计算demo,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1:因为此前erp项目中的采购模块添加商品,实时计算单个商品预估价格及全部商品总额折磨了我很久,所以今天闲来无事优化一下,使用另一种思维来做一个类似demo,作为此前总结反思

2:原来项目模块是这样的

3:开始写demo,使用hbuilderx创建一个uniapp3项目,项目结构如下

4:父组件index.vue文件

<template><view class="content"><hzy-inputStep v-for="(item, index) in goodsList" :key="item.id" style="margin-bottom: 20rpx;" :index="index":item="item" v-model:goodsItem="goodsList[index]" v-model:goodsList="goodsList" /><view>商品总额:<text style="color: red;font-weight: 700;">{{ total }}</text></view><view><u-button type="primary" @click="addGoods">新增商品</u-button></view></view>
</template><script setup>
import { ref, watch } from 'vue'
let goodsList = ref([])
let num = ref(0)
let total = ref(0)
const addGoods = () => {goodsList.value.push({id: num.value++,goodsName: '苹果',qty: 1,planTotal: ''})
}
watch(() => goodsList.value, (newValue, oldValue) => {total.value = newValue.reduce((acc, item) => acc + (item.planTotal || 0), 0);
}, {deep: true
})
</script><style lang="less"></style>

子组件hzy-inputStep.vue文件

<template><view><view class="inputStep"><view style="background-color: beige;margin-bottom: 20rpx;" @click="deleteItem">删除</view><view class="title"><view><text>商品名称:</text><text>苹果</text></view><view><u-number-box v-model="goodsNum" @change="goodsNumChange"></u-number-box></view></view><view class="inputPrice"><view>建议单价:</view><u-input placeholder="请输入商品建议单价" border="surround" v-model="goodsPlanPrice"@change="goodsPlanPriceChange"></u-input></view><view class="total" v-show="goodsPlanPrice"><view>预估总额:</view><view style="color: red;">{{item.planTotal}}</view></view></view></view>
</template><script setup>import {ref} from 'vue'let emits = defineEmits(['update:goodsItem', 'update:goodsList'])let props = defineProps(['index', 'item', 'goodsItem', 'goodsList'])// 单个商品总价let total = ref();// 删除商品const deleteItem = () => {let index = props.goodsList.findIndex(item => item.id === props.item.id);if (index !== -1) {props.goodsList.splice(index, 1);emits('update:goodsList', props.goodsList);}}// 更新商品const updateGoods = () => {total.value = (goodsNum.value * 1) * goodsPlanPrice.valueemits('update:goodsItem', {id: props.item.id,goodsName: props.item.goodsName,qty: goodsNum.value,planTotal: total.value})}// 单个商品数量let goodsNum = ref(1)// 商品数量改变const goodsNumChange = (e) => {goodsNum.value = e.valueupdateGoods()}// 单个商品建议单价let goodsPlanPrice = ref()// 商品建议单价改变const goodsPlanPriceChange = (e) => {goodsPlanPrice.value = eupdateGoods()}
</script><style lang="less">.inputStep {border: 1px solid green;.title,.inputPrice {display: flex;justify-content: space-between;}.total {display: flex;justify-self: start;}}
</style>

极大的删减了原有的代码量,功能保持不变,主要是用了v-model:updateValue组件双向绑定的功能,最后展示一下demo案例

如有任何疑问,欢迎在评论区提出,谢谢阅读

这篇关于erp项目采购模块新增商品,商品价格计算demo的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/763224

相关文章

JAVA项目swing转javafx语法规则以及示例代码

《JAVA项目swing转javafx语法规则以及示例代码》:本文主要介绍JAVA项目swing转javafx语法规则以及示例代码的相关资料,文中详细讲解了主类继承、窗口创建、布局管理、控件替换、... 目录最常用的“一行换一行”速查表(直接全局替换)实际转换示例(JFramejs → JavaFX)迁移建

JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)

《JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)》:本文主要介绍如何在IntelliJIDEA2020.1中创建和部署一个JavaWeb项目,包括创建项目、配置Tomcat服务... 目录简介:一、创建项目二、tomcat部署1、将tomcat解压在一个自己找得到路径2、在idea中添加

解决idea启动项目报错java: OutOfMemoryError: insufficient memory

《解决idea启动项目报错java:OutOfMemoryError:insufficientmemory》:本文主要介绍解决idea启动项目报错java:OutOfMemoryError... 目录原因:解决:总结 原因:在Java中遇到OutOfMemoryError: insufficient me

python项目环境切换的几种实现方式

《python项目环境切换的几种实现方式》本文主要介绍了python项目环境切换的几种实现方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 如何在不同python项目中,安装不同的依赖2. 如何切换到不同项目的工作空间3.创建项目

SpringBoot项目整合Netty启动失败的常见错误总结

《SpringBoot项目整合Netty启动失败的常见错误总结》本文总结了SpringBoot集成Netty时常见的8类问题及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参... 目录一、端口冲突问题1. Tomcat与Netty端口冲突二、主线程被阻塞问题1. Netty启动阻

python项目打包成docker容器镜像的两种方法实现

《python项目打包成docker容器镜像的两种方法实现》本文介绍两种将Python项目打包为Docker镜像的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目录简单版:(一次成功,后续下载对应的软件依赖)第一步:肯定是构建dockerfile,如下:第二步

Python + Streamlit项目部署方案超详细教程(非Docker版)

《Python+Streamlit项目部署方案超详细教程(非Docker版)》Streamlit是一款强大的Python框架,专为机器学习及数据可视化打造,:本文主要介绍Python+St... 目录一、针对 Alibaba Cloud linux/Centos 系统的完整部署方案1. 服务器基础配置(阿里

在SpringBoot+MyBatis项目中实现MySQL读写分离的实战指南

《在SpringBoot+MyBatis项目中实现MySQL读写分离的实战指南》在SpringBoot和MyBatis项目中实现MySQL读写分离,主要有两种思路:一种是在应用层通过代码和配置手动控制... 目录如何选择实现方案核心实现:应用层手动分离实施中的关键问题与解决方案总结在Spring Boot和

Python AST 模块实战演示

《PythonAST模块实战演示》Python的ast模块提供了一种处理Python代码的强大工具,通过解析代码生成抽象语法树(AST),可以进行代码分析、修改和生成,接下来通过本文给大家介绍Py... 目录 什么是抽象语法树(AST)️ ast 模块的核心用法1. 解析代码生成 AST2. 查看 AST

gitlab项目实现添加新成员

《gitlab项目实现添加新成员》:本文主要介绍gitlab项目实现添加新成员方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录gitlabhttp://www.chinasem.cn项目添加新成员1、进入项目2、手动输入要添加成员的账号或者搜索总结gitlab项