使用GPT开发食堂采购账单

2023-12-16 05:44

本文主要是介绍使用GPT开发食堂采购账单,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原始系统中,只有采购量和消耗量,需要添加“余”列,并自动计算的余量

 具体实现通过查询GPT获得:

提问:

使用antdesign vue的<a-table>组件做一个互动表,每行输入a和b两值,计算c=a+b,然后显示a、b、c

回答:

下面是使用 Ant Design Vue 的 <a-table> 组件创建一个互动表格,其中每行输入 a 和 b 的值,计算并显示 c = a + b

<template><a-table :dataSource="data" :columns="columns"><template v-slot:title>Interactive Table</template><template v-slot:expanded-row="{ record }">a: <a-input-number :value="record.a" @change="handleChange(record, 'a')" />b: <a-input-number :value="record.b" @change="handleChange(record, 'b')" />c: {{ record.c }}</template></a-table>
</template><script>
export default {data() {return {data: [{ key: 1, a: 0, b: 0, c: 0 },{ key: 2, a: 0, b: 0, c: 0 },{ key: 3, a: 0, b: 0, c: 0 }],columns: [{ title: 'Key', dataIndex: 'key' },{ title: 'A', dataIndex: 'a' },{ title: 'B', dataIndex: 'b' },{ title: 'C', dataIndex: 'c' }]};},methods: {handleChange(record, field) {record[field] = parseFloat(record[field]);record.c = record.a + record.b;}}
};
</script>

在上述示例中,我们使用了 <a-table> 组件来创建表格,并使用 :dataSource 和 :columns 属性将数据和列定义传递给表格组件。

在 <template v-slot:expanded-row> 中,我们定义了每行展开的内容。在展开的内容中,我们使用 <a-input-number> 组件来输入 a 和 b 的值。v-model 指令绑定了输入框的值到 record.a 和 record.b,使其与数据源中对应的值保持同步。

通过 @change 事件监听输入框值的变化,调用 handleChange 方法更新数据源中的值,并计算 c 的值。最后,我们通过插值表达式 {{ record.c }} 显示 c 的结果。

这样,每行输入 a 和 b 的值后,c 的值会自动计算并显示在表格中。、

提问:

限制<a-input-number>输入的数字保留小数点后两位

回答:

要限制 <a-input-number> 输入的数字保留小数点后两位,你可以使用 :precision 属性和 toFixed 方法。

下面是修改后的示例代码:

<template><a-table :dataSource="data" :columns="columns"><template v-slot:title>Interactive Table</template><template v-slot:expanded-row="{ record }">a: <a-input-number :value="record.a" @change="handleChange(record, 'a')" :precision="2" />b: <a-input-number :value="record.b" @change="handleChange(record, 'b')" :precision="2" />c: {{ record.c.toFixed(2) }}</template></a-table>
</template><script>
export default {data() {return {data: [{ key: 1, a: 0, b: 0, c: 0 },{ key: 2, a: 0, b: 0, c: 0 },{ key: 3, a: 0, b: 0, c: 0 }],columns: [{ title: 'Key', dataIndex: 'key' },{ title: 'A', dataIndex: 'a' },{ title: 'B', dataIndex: 'b' },{ title: 'C', dataIndex: 'c' }]};},methods: {handleChange(record, field) {record[field] = parseFloat(record[field]);record.c = record.a + record.b;}}
};
</script>

ps:

toFixed(2) 是js自带函数

成品代码:

<template><a-drawertitle="物品入库":maskClosable="false"placement="right":closable="false":visible="show":width="1200"@close="onClose"style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;"><a-form :form="form" layout="horizontal"><a-row :gutter="32"><a-col :span="12"><a-form-item label='保管人' v-bind="formItemLayout"><a-input v-decorator="['custodian',{ rules: [{ required: true, message: '请输入保管人!' }] }]"/></a-form-item></a-col><a-col :span="12"><a-form-item label='入库人' v-bind="formItemLayout"><a-input v-decorator="['putUser',{ rules: [{ required: true, message: '请输入入库人!' }] }]"/></a-form-item></a-col><a-col :span="24"><a-form-item label='备注消息' v-bind="formItemLayout"><a-textarea :rows="4" v-decorator="['content',{ rules: [{ required: true, message: '请输入名称!' }] }]"/></a-form-item></a-col><a-col :span="24"><a-table :columns="columns" :data-source="dataList"><template slot="nameShow" slot-scope="text, record"><a-input v-model="record.name"></a-input></template><template slot="typeShow" slot-scope="text, record"><a-input v-model="record.type"></a-input></template><template slot="typeIdShow" slot-scope="text, record"><a-select v-model="record.typeId" style="width: 100%"><a-select-option v-for="(item, index) in consumableType" :value="item.id" :key="index">{{ item.name }}</a-select-option></a-select></template><template slot="unitShow" slot-scope="text, record"><a-input v-model="record.unit"></a-input></template><template slot="amountShow" slot-scope="text, record"><a-input-number v-model="record.amount" :min="1" :step="1" :precision="2" @change="handleChange(record)"/></template><template slot="consumptionShow" slot-scope="text, record"><a-input-number v-model="record.consumption" :min="0" :max="record.amount" :step="1" :precision="2" @change="handleChange(record)"/></template><template slot="priceShow" slot-scope="text, record"><a-input-number v-model="record.price" :min="0"/></template></a-table><a-button @click="dataAdd" type="primary" ghost size="large" style="margin-top: 10px;width: 100%">新增物品</a-button></a-col></a-row></a-form><div class="drawer-bootom-button"><a-popconfirm title="确定放弃编辑?" @confirm="onClose" okText="确定" cancelText="取消"><a-button style="margin-right: .8rem">取消</a-button></a-popconfirm><a-button @click="handleSubmit" type="primary" :loading="loading">提交</a-button></div></a-drawer>
</template><script>
import {mapState} from 'vuex'
const formItemLayout = {labelCol: { span: 24 },wrapperCol: { span: 24 }
}
export default {name: 'stockAdd',props: {stockAddVisiable: {default: false}},computed: {...mapState({currentUser: state => state.account.user}),show: {get: function () {return this.stockAddVisiable},set: function () {}},columns () {return [{title: '序号',dataIndex: 'key'}, {title: '物品名称',dataIndex: 'name',scopedSlots: {customRender: 'nameShow'}}, {title: '所属类型',dataIndex: 'typeId',width: 200,scopedSlots: {customRender: 'typeIdShow'}}, {title: '型号',dataIndex: 'type',scopedSlots: {customRender: 'typeShow'}}, {title: '采购量',dataIndex: 'amount',scopedSlots: {customRender: 'amountShow'}}, {title: '消耗量',dataIndex: 'consumption',scopedSlots: {customRender: 'consumptionShow'}}, {title: '余',dataIndex: 'balance'}, {title: '单位',dataIndex: 'unit',scopedSlots: {customRender: 'unitShow'}}, {title: '单价',dataIndex: 'price',scopedSlots: {customRender: 'priceShow'}}]}},mounted () {this.getConsumableType()},data () {return {dataList: [],formItemLayout,form: this.$form.createForm(this),loading: false,consumableType: [],keynumber: 1}},methods: {getConsumableType () {this.$get('/cos/consumable-type/list').then((r) => {this.consumableType = r.data.data})},dataAdd () {this.dataList.push({key: this.keynumber++, name: '', type: '', typeId: '', unit: '', amount: 0, consumption: 0, balance: 0, price: 0})},reset () {this.loading = falsethis.form.resetFields()},onClose () {this.reset()this.$emit('close')},handleChange (record) {record.balance = (record.amount - record.consumption).toFixed(2)},handleSubmit () {let price = 0this.dataList.forEach(item => {price += item.price * item.amount})this.form.validateFields((err, values) => {values.price = pricevalues.goods = JSON.stringify(this.dataList)if (!err) {this.loading = truethis.$post('/cos/stock-info/put', {...values}).then((r) => {this.reset()this.$emit('success')}).catch(() => {this.loading = false})}})}}
}
</script><style scoped></style>

开始我犯了两个错误:

①把@change="handleChange(record)"加到了<template slot="consumptionShow" slot-scope="text, record">上,应该加到<a-input-number>上才对。

②data-source数据项没有加如key列,编译报错。看了提示信息,感觉到不加key,程序无法将单行record对应到数组中的具体项,无法绑定数组中的数据。有了key才能绑定,这与vue标签的v-for属性循环类似。

v-for通过 key 管理状态:列表渲染 | Vue.js

这篇关于使用GPT开发食堂采购账单的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

postgresql使用UUID函数的方法

《postgresql使用UUID函数的方法》本文给大家介绍postgresql使用UUID函数的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录PostgreSQL有两种生成uuid的方法。可以先通过sql查看是否已安装扩展函数,和可以安装的扩展函数

如何使用Lombok进行spring 注入

《如何使用Lombok进行spring注入》本文介绍如何用Lombok简化Spring注入,推荐优先使用setter注入,通过注解自动生成getter/setter及构造器,减少冗余代码,提升开发效... Lombok为了开发环境简化代码,好处不用多说。spring 注入方式为2种,构造器注入和setter

基于Python开发一个图像水印批量添加工具

《基于Python开发一个图像水印批量添加工具》在当今数字化内容爆炸式增长的时代,图像版权保护已成为创作者和企业的核心需求,本方案将详细介绍一个基于PythonPIL库的工业级图像水印解决方案,有需要... 目录一、系统架构设计1.1 整体处理流程1.2 类结构设计(扩展版本)二、核心算法深入解析2.1 自

MySQL中比较运算符的具体使用

《MySQL中比较运算符的具体使用》本文介绍了SQL中常用的符号类型和非符号类型运算符,符号类型运算符包括等于(=)、安全等于(=)、不等于(/!=)、大小比较(,=,,=)等,感兴趣的可以了解一下... 目录符号类型运算符1. 等于运算符=2. 安全等于运算符<=>3. 不等于运算符<>或!=4. 小于运

使用zip4j实现Java中的ZIP文件加密压缩的操作方法

《使用zip4j实现Java中的ZIP文件加密压缩的操作方法》本文介绍如何通过Maven集成zip4j1.3.2库创建带密码保护的ZIP文件,涵盖依赖配置、代码示例及加密原理,确保数据安全性,感兴趣的... 目录1. zip4j库介绍和版本1.1 zip4j库概述1.2 zip4j的版本演变1.3 zip4

Python 字典 (Dictionary)使用详解

《Python字典(Dictionary)使用详解》字典是python中最重要,最常用的数据结构之一,它提供了高效的键值对存储和查找能力,:本文主要介绍Python字典(Dictionary)... 目录字典1.基本特性2.创建字典3.访问元素4.修改字典5.删除元素6.字典遍历7.字典的高级特性默认字典

使用Python构建一个高效的日志处理系统

《使用Python构建一个高效的日志处理系统》这篇文章主要为大家详细讲解了如何使用Python开发一个专业的日志分析工具,能够自动化处理、分析和可视化各类日志文件,大幅提升运维效率,需要的可以了解下... 目录环境准备工具功能概述完整代码实现代码深度解析1. 类设计与初始化2. 日志解析核心逻辑3. 文件处

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断

C++中assign函数的使用

《C++中assign函数的使用》在C++标准模板库中,std::list等容器都提供了assign成员函数,它比操作符更灵活,支持多种初始化方式,下面就来介绍一下assign的用法,具有一定的参考价... 目录​1.assign的基本功能​​语法​2. 具体用法示例​​​(1) 填充n个相同值​​(2)

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命