<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实现结账单基本方法的更多相关文章

  1. pubwin 客户端会员无法自助结账的排查方法

    客户端会员无法自助结账按以下方法排查:1,看客户端能不能打开web https 后台,打不开的话,在服务端打上2048证书补丁(按下面帖子操作)http://bbs.pubwin.com.cn/for ...

  2. Vue2.x源码学习笔记-Vue实例的属性和方法整理

    还是先从浏览器直观的感受下实例属性和方法. 实例属性: 对应解释如下: vm._uid // 自增的id vm._isVue // 标示是vue对象,避免被observe vm._renderProx ...

  3. Vue(十二)vue实例的属性和方法

    vue实例的属性和方法 1. 属性 vm.$el vm.$data vm.$options vm.$refs <!DOCTYPE html> <html lang="en& ...

  4. 在Vue中关闭Eslint 的方法

    在vue项目中关闭ESLint方法:找到 webpack.base.conf.js 将这些代码注释掉, { test: /\.(js|vue)$/, loader: 'eslint-loader', ...

  5. vue解决遮罩层滚动方法

    vue 遮罩层阻止默认滚动事件 在写移动端页面的时候,弹出遮罩层后,我们仍然可以滚动页面. vue中提供 @touchmove.prevent 方法可以完美解决这个问题 <div class=& ...

  6. vue实例的属性和方法

    vue实例的属性和方法 1. 属性 vm.$el #指定要绑定的元素 vm.$data #Vue 实例的数据对象 vm.$options #获取自定义属性的值 new Vue({ customOpti ...

  7. Vue把父组件的方法传递给子组件调用(评论列表例子)

    Vue把父组件的方法传递给子组件调用(评论列表例子) 效果展示: 相关Html: <!DOCTYPE html> <html lang="en"> < ...

  8. vue中添加util公共方法&&ES6之import、export

    vue中添加util公共方法&&ES6之import.export https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Re ...

  9. vue中methods中的方法闭包缓存问题

    vue中methods中的方法闭包缓存问题 问题背景 需求描述 在路由的导航栏中需要, 判断是否为第一次点击 需要一个标志位来记录是否点击过 现状: 这个标志位只在一个函数中用过.不希望存放全局 希望 ...

随机推荐

  1. 【计算几何】【辛普森积分法】UVALive - 7076 - Highway

    春节前后想了好久才在队友的讲解下想明白…… 太难讲了,我就不讲了,大概就是考虑直着走到高速上还是斜着走到高速上,然后平移直线和大圆相切,把生成的最大的“桥”和大圆并一下就行了. #include< ...

  2. 【费马小定理】HDU4704-Sum

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  3. PHP empty()函数:Can't use method return value in write context

    <?php if (!empty (get_gpc('userId'))) { $userId = get_gpc('userId'); } else { $error = "ID d ...

  4. Remote procedure call (RPC)

    Remote procedure call (RPC) (using the .NET client) Prerequisites This tutorial assumes RabbitMQ isi ...

  5. Editplus格式化代码

    Editplus格式化代码插件(CSS,JS)今天在BlueIdea看到有人发了一篇名 为“让Editplus自动格式化css和js”的文章,看完后觉得写的很好,我也突然来了灵感,为什么不把前端开发常 ...

  6. webpack配置:css文件打包、JS压缩打包和HTML文件发布

    一.CSS文件打包 1.在src下新建css文件,在css文件下新建index.css文件,输入以下代码 body{ color:red; font-size:20px; } 2.css建立好后,需要 ...

  7. http://blog.csdn.net/rosten/article/details/17068285

    http://blog.csdn.net/rosten/article/details/17068285

  8. ExtJs 4中 Ext.Ajax.request提交实现waitMsg等待提示效果

    //submitForm为form表单 var myMask = new Ext.LoadMask(Ext.getBody(),{msg:"请稍等,正在导入..."}); myMa ...

  9. 【RabbitMQ 参考资料】

    RabbitMQ从入门到精通:http://blog.csdn.net/column/details/rabbitmq.html RabbitMQ消息队列(一): Detailed Introduct ...

  10. 【招聘App】—— React/Nodejs/MongoDB全栈项目:个人中心&退出登录

    前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...