vue实现结账单基本方法
<script>
import axios from 'axios';
export default {
name: 'Pos',
mounted: function () {
var orderHeight = document.body.clientHeight;
document.getElementById("order-list").style.height = orderHeight + 'px';
},
created() {
//读取常用商品列表
axios.get('http://jspang.com/DemoApi/oftenGoods.php')
.then(response => {
//console.log(response);
this.oftenGoods = response.data;
})
.catch(error => {
console.log(error);
alert('网络错误,不能访问');
})
//读取分类商品列表
axios.get('http://jspang.com/DemoApi/typeGoods.php')
.then(response => {
//console.log(response);
//this.oftenGoods=response.data;
this.type0Goods = response.data[0];
this.type1Goods = response.data[1];
this.type2Goods = response.data[2];
this.type3Goods = response.data[3]; })
.catch(error => {
console.log(error);
alert('网络错误,不能访问');
})
},
data() {
return {
tableData: [], //订单列表的值
oftenGoods: [],
type0Goods: [],
type1Goods: [],
type2Goods: [],
type3Goods: [],
totalMoney: 0, //订单总价格
totalCount: 0 //订单商品总数量 }
},
methods: {
//添加订单列表的方法
addOrderList(goods) {
//console.log(goods);
this.totalCount = 0; //汇总数量清0
this.totalMoney = 0;
let isHave = false;
//判断是否这个商品已经存在于订单列表
for (let i = 0; i < this.tableData.length; i++) {
console.log(this.tableData[i].goodsId);
if (this.tableData[i].goodsId == goods.goodsId) { isHave = true; //存在 }
}
//根据isHave的值判断订单列表中是否已经有此商品
if (isHave) {
//存在就进行数量添加
let arr = this.tableData.filter(o => o.goodsId == goods.goodsId);
arr[0].count++;
//console.log(arr);
} else {
//不存在就推入数组
let newGoods = { goodsId: goods.goodsId, goodsName: goods.goodsName, price: goods.price, count: 1 };
this.tableData.push(newGoods); } this.getAllMoney();
},
//删除单个商品
delSingleGoods(goods) {
console.log(goods);
this.tableData = this.tableData.filter(o => o.goodsId != goods.goodsId);
this.getAllMoney(); },
//删除所有商品
delAllGoods() {
this.tableData = [];
this.totalCount = 0;
this.totalMoney = 0;
},
//汇总数量和金额
getAllMoney() {
this.totalCount = 0;
this.totalMoney = 0;
if (this.tableData) {
this.tableData.forEach((element) => {
this.totalCount += element.count;
this.totalMoney = this.totalMoney + (element.price * element.count);
});
}
},
//结账方法模拟
checkout() {
if (this.totalCount!=0) {
this.tableData = [];
this.totalCount = 0;
this.totalMoney = 0;
this.$message({
message: '结账成功,感谢你又为店里出了一份力!',
type: 'success'
}); }else{
this.$message.error('不能空结。老板了解你急切的心情!'); } } }
}
</script>
vue实现结账单基本方法的更多相关文章
- pubwin 客户端会员无法自助结账的排查方法
客户端会员无法自助结账按以下方法排查:1,看客户端能不能打开web https 后台,打不开的话,在服务端打上2048证书补丁(按下面帖子操作)http://bbs.pubwin.com.cn/for ...
- Vue2.x源码学习笔记-Vue实例的属性和方法整理
还是先从浏览器直观的感受下实例属性和方法. 实例属性: 对应解释如下: vm._uid // 自增的id vm._isVue // 标示是vue对象,避免被observe vm._renderProx ...
- Vue(十二)vue实例的属性和方法
vue实例的属性和方法 1. 属性 vm.$el vm.$data vm.$options vm.$refs <!DOCTYPE html> <html lang="en& ...
- 在Vue中关闭Eslint 的方法
在vue项目中关闭ESLint方法:找到 webpack.base.conf.js 将这些代码注释掉, { test: /\.(js|vue)$/, loader: 'eslint-loader', ...
- vue解决遮罩层滚动方法
vue 遮罩层阻止默认滚动事件 在写移动端页面的时候,弹出遮罩层后,我们仍然可以滚动页面. vue中提供 @touchmove.prevent 方法可以完美解决这个问题 <div class=& ...
- vue实例的属性和方法
vue实例的属性和方法 1. 属性 vm.$el #指定要绑定的元素 vm.$data #Vue 实例的数据对象 vm.$options #获取自定义属性的值 new Vue({ customOpti ...
- Vue把父组件的方法传递给子组件调用(评论列表例子)
Vue把父组件的方法传递给子组件调用(评论列表例子) 效果展示: 相关Html: <!DOCTYPE html> <html lang="en"> < ...
- vue中添加util公共方法&&ES6之import、export
vue中添加util公共方法&&ES6之import.export https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Re ...
- vue中methods中的方法闭包缓存问题
vue中methods中的方法闭包缓存问题 问题背景 需求描述 在路由的导航栏中需要, 判断是否为第一次点击 需要一个标志位来记录是否点击过 现状: 这个标志位只在一个函数中用过.不希望存放全局 希望 ...
随机推荐
- [Markdown]纯文本标记语言MarkdowPad2--MD语法知识
##1.标题 代码 注:# 后面保持空格 # h1 ## h2 ### h3 #### h4 ##### h5 ###### h6 ####### h7 // 错误代码 ######## h8 // ...
- Problem Y: 零起点学算法21——摄氏温度转换
#include<stdio.h> int main() { float f,c; while(scanf("%f",&f)!=EOF) c=*(f-); pr ...
- java读写文件及保留指定位小数
1)先上代码: public static void main(String[] args)throws IOException{ double[][] B=new double[1043][2102 ...
- <摘录>Linux下动态共享库加载时的搜索路径详解
对动态库的实际应用还不太熟悉的读者可能曾经遇到过类似“error while loading shared libraries”这样的错误,这是典型的因为需要的动态库不在动态链接器ld.so的搜索路径 ...
- CRC代码实现
CRC代码实现1: #include <stdio.h> #include <string.h> unsigned int cfgCrc32(const unsigned ch ...
- Shell实现多级菜单系统安装维护脚本实例分享
Shell实现多级菜单系统安装维护脚本实例分享 这篇文章主要介绍了Shell实现多级菜单系统安装维护脚本实例分享,本文脚本用多级菜单实现管理WEB服务器.Mysql服务器.Nginx服器等,需要的朋友 ...
- (如何理解gamma校准)GAMMA测试方法及分析
http://wenku.baidu.com/link?url=Wz5oXJsFQ-TVe3qxm9Zd4pp207cQ4jmjuBnwmWAvD1ibgoI2U8y7KCFhaR9xWtu9cGLE ...
- 【angularJS】前后台分离,angularJS使用Token认证
参考资料: [AngularJS系列(4)] 那伤不起的provider们啊~ (Provider, Value, Constant, Service, Factory, Decorator):htt ...
- Kubernetes用户指南(一)--快速开始、使用k8s配置文件
一.快速开始 1.启动一个简单的容器. 一旦在container中打包好应用并将其commit为image之后,你就可以将其部署在k8s集群上. 一个简单的nginx服务器例子: 先决条件:你需要拥有 ...
- spring常用的一些注解以及注解注入总结
常用的spring注解有如下几种: @Controller@Service@Autowired@RequestMapping@RequestParam@ModelAttribute@Cacheable ...