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项目中包和包之间的联系

《深度解析Java项目中包和包之间的联系》文章浏览阅读850次,点赞13次,收藏8次。本文详细介绍了Java分层架构中的几个关键包:DTO、Controller、Service和Mapper。_jav... 目录前言一、各大包1.DTO1.1、DTO的核心用途1.2. DTO与实体类(Entity)的区别1

Python中re模块结合正则表达式的实际应用案例

《Python中re模块结合正则表达式的实际应用案例》Python中的re模块是用于处理正则表达式的强大工具,正则表达式是一种用来匹配字符串的模式,它可以在文本中搜索和匹配特定的字符串模式,这篇文章主... 目录前言re模块常用函数一、查看文本中是否包含 A 或 B 字符串二、替换多个关键词为统一格式三、提

如何在Spring Boot项目中集成MQTT协议

《如何在SpringBoot项目中集成MQTT协议》本文介绍在SpringBoot中集成MQTT的步骤,包括安装Broker、添加EclipsePaho依赖、配置连接参数、实现消息发布订阅、测试接口... 目录1. 准备工作2. 引入依赖3. 配置MQTT连接4. 创建MQTT配置类5. 实现消息发布与订阅

springboot项目打jar制作成镜像并指定配置文件位置方式

《springboot项目打jar制作成镜像并指定配置文件位置方式》:本文主要介绍springboot项目打jar制作成镜像并指定配置文件位置方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录一、上传jar到服务器二、编写dockerfile三、新建对应配置文件所存放的数据卷目录四、将配置文

怎么用idea创建一个SpringBoot项目

《怎么用idea创建一个SpringBoot项目》本文介绍了在IDEA中创建SpringBoot项目的步骤,包括环境准备(JDK1.8+、Maven3.2.5+)、使用SpringInitializr... 目录如何在idea中创建一个SpringBoot项目环境准备1.1打开IDEA,点击New新建一个项

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再

一文深入详解Python的secrets模块

《一文深入详解Python的secrets模块》在构建涉及用户身份认证、权限管理、加密通信等系统时,开发者最不能忽视的一个问题就是“安全性”,Python在3.6版本中引入了专门面向安全用途的secr... 目录引言一、背景与动机:为什么需要 secrets 模块?二、secrets 模块的核心功能1. 基

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关