CartIndex.vue
6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<template>
<div class="catindex">
<div :style="'margin-bottom:'+margin_top">
<div class="card-root-c" v-for="(item, idx) in goods_list" :key="idx">
<van-swipe-cell :right-width="65" :data-id="item.goods_id" :data-goods_sku_id="item.goods_sku_id" :on-close="onCloseItem">
<div v-if="item.show_error != 0" class="goods_err_div">{{item.show_error_text}}</div>
<van-card :class="item.show_error == 0 ? '' : 'error_goods'"
:price="item.goods_price" :thumb-link="'#/cartindex/goods?id='+item.goods_id"
:title="item.goods_name"
:desc="item.goods_sku.goods_attr ? item.goods_sku.goods_attr :'默认规格'"
:centered="true" :lazy-load="true" :thumb="item.goods_sku.spec_image==''? item.image:item.goods_sku.img_show">
<div slot="footer" v-if="item.show_error == 0">
<van-stepper disable-input async-change
class="van-stepper-c" :value="item.total_num" integer :min="1" :max="999"
@plus="onplus(idx,item.goods_sku_id)"
@minus="onsub(idx,item.goods_sku_id)" />
</div>
</van-card>
<div slot="right" class='delb'><span>删除</span></div>
</van-swipe-cell>
</div>
</div>
<div v-if="!goods_list.length" class="liteshop-notcont" style="margin-top:130px;">
<div class="img">
<img src="@/assets/no-data.png"/>
</div>
<span class="cont">购物车空空如也</span>
</div>
<van-submit-bar
:price="order_total_price*100"
button-text="开始结算"
@submit="onSubmit"
/>
<BottomTabbar :curactive="2"></BottomTabbar>
<cube-view></cube-view>
</div>
</template>
<script>
import CubeView from '@/components/TP/cube-view'
import BottomTabbar from '@/components/TP/BottomTabbar'
import * as util from '@/utils/network'
import { Dialog } from 'vant';
import { Toast } from 'vant';
export default {
components: {
CubeView,
BottomTabbar
},
data() {
return {
goods_list: [], // 商品列表
order_total_num: 0,
order_total_price: 0,
margin_top:"108px",
};
},
created: function () {
this.getCartList()
},
watch:{
$route(to,from) {
console.log(to)
if(to.path=="/CartIndex/cartcheck"||to.path=="/cartindex/goods"){
this.margin_top = '0px'
}
if(to.path=="/CartIndex"){
this.margin_top = '108px'
}
},
},
methods: {
onSubmit(){
if (this.goods_list.length==0){
Toast.fail('请添置您的购物车。');
return;
}
this.$router.push({path: 'CartIndex/cartcheck', query: {type: 'cart'}})
},
/** 购物车列表 */
getCartList: function () {
let that = this;
var url = "/addons/litestore/api.cart/getlists"
util.get(url,{},
function (result) {
that.goods_list = result.data.goods_list
that.order_total_num = result.data.order_total_num
that.order_total_price = result.data.order_total_price
},
);
},
onCloseItem(clickPosition, instance) {
let that = this;
switch (clickPosition) {
case 'left':
case 'cell':
case 'outside':
instance.close();
break;
case 'right':
Dialog.confirm({
message: '确定删除吗?'
}).then(() => {
instance.close();
var url = "/addons/litestore/api.cart/delete"
util.get(url,{
goods_id: instance.$attrs['data-id'],
goods_sku_id: instance.$attrs['data-goods_sku_id'],
},
function (result) {
console.log(result)
//that.goods_list.splice(instance.$attrs['idx'],1);
that.getCartList()
},
);
}).catch(() => {});
break;
}
},
onplus: function (index,goodsSkuId) {
let that = this;
let goods = that.goods_list[index],
order_total_price = that.order_total_price;
var url = "/addons/litestore/api.cart/add"
util.get(url,{
goods_id: goods.goods_id,
goods_num: 1,
goods_sku_id: goodsSkuId,
},
function (result) {
goods.total_num++;
that.goods_list[index]=goods
that.order_total_price=that.mathadd(order_total_price, goods.goods_price)
},
);
},
mathadd: function (arg1, arg2) {
return (Number(arg1) + Number(arg2)).toFixed(2);
},
onsub: function (index,goodsSkuId) {
let that = this;
let goods = that.goods_list[index],
order_total_price = that.order_total_price;
var url = "/addons/litestore/api.cart/sub"
util.get(url,{
goods_id: goods.goods_id,
goods_sku_id: goodsSkuId,
},
function (result) {
goods.total_num--;
if(goods.total_num > 0) {
that.goods_list[index]=goods
that.order_total_price=that.mathsub(order_total_price, goods.goods_price)
}
},
);
},
mathsub: function (arg1, arg2) {
return (Number(arg1) - Number(arg2)).toFixed(2);
},
togoods: function(id){
this.$router.push({path: 'cartindex/goods', query: {id: id}})
},
}
}
</script>
<style>
.catindex .error_goods{
background-color:#fff;filter:Alpha(Opacity=30);opacity:0.3;
}
.catindex .card-root-c{
padding-top: 10px;
}
.catindex .delb {
height:100%;
width:65px;
text-align:center;
font-size:1.2em;
background-color:#6d189e;
color:white;
font-weight:bold;
display:flex;
justify-content:center;
align-items:Center;
}
.catindex .van-stepper__input[disabled] {
color:white!important;
background-color:#6d189e!important;
}
.catindex .goods_err_div{
position:absolute;
z-index:9;
font-size:2em;
line-height:100px;
text-align:center;
width:100%;
color: #6d189e;
letter-spacing:1.2em;
font-weight:bolder;
text-indent : 3em;
}
.catindex .van-submit-bar{
bottom: 49px;
z-index: 8;
}
.catindex .van-card__footer{
position: absolute;
bottom: 10px;
right: 6px;
}
.liteshop-notcont {
margin:130px 100px;
}
.liteshop-notcont .img {
width: 180px;
height: 120px;
margin: 0 auto;
}
.liteshop-notcont .img image {
width: 100%;
height: 100%;
}
.liteshop-notcont .cont {
display: block;
text-align: center;
font-size: 16px;
color: #6d189e;
margin-top: 60px;
}
</style>