order.vue
6.89 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
<template>
<ul id="order-list" v-infinite-scroll="getOrderData()" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
<li class="order-item" v-for="(index, order) in orderList">
<div class="order-detail">
<div class="order-code">
<p>订单号:{{order.orderCode}}</p>
<p>{{order.status | convertOrderState}}</p>
</div>
<div class="order-goods" >
<div class="goods-info" v-for="goods in order.orderGoods">
<div class="img-box">
<img v-bind:src="goods.goodsImage | resize 49 65" alt="{{goods.productName}}">
</div>
<div class="goods-detail">
<p class="name">{{goods.productName}}</p>
<p class="size">
<span>颜色:{{goods.colorName}}</span>
<span>尺码:{{goods.sizeName}}</span>
</p>
</div>
<div class="goods-price">
<p>¥ {{goods.goodsPrice}}</p>
<p>×{{goods.buyNumber}}</p>
</div>
<a href="/home/order-detail?orderCode={{order.orderCode}}"></a>
</div>
</div>
<div class="order-option">
<div class="goods-total">合计: <b>¥{{order.amount}}</b></div>
<div class="options">
<button v-if="order.status === 0" @click="cancelOrder(order.orderCode)">取消订单</button>
<button v-if="order.status === 0 " class="countdown" @click="goBuy(order.orderCode)">去支付 <span v-count-down v-bind:left-time="order.payLefttime" v-bind:callback="autoCancel(order.orderCode)"></span></button>
<button v-if="order.status === 4 || order.status === 5 ">查看物流</button>
<button v-if="order.status === 4 || order.status === 5 " class="black" @click="confirmGoods(order.orderCode)">确认收货</button>
<button v-if="order.status === 6" @click="deleteOrder(order,index)">删除订单</button>
<button v-if="order.status === 6" class="normal">再次购买</button>
</div>
</div>
</div>
</li>
</ul>
</template>
<script>
'use strict';
const $ = require('yoho-jquery');
const tip = require('common/tip');
const Modal = require('common/modal');
const yohoAPI = require('yoho');
module.exports = {
data() {
return {
page: 0,
limit: 10,
pageTotal: 0,
type: this.$parent.$data.type,
orderList: [],
busy: false,
};
},
ready() {
this.getOrderData();
},
methods: {
getOrderData() {
let _that = this;
this.busy = true;
if (this.page > this.pageTotal) {
return;
}
$.ajax({
url: '/home/get-orders',
data: {
page: ++this.page,
limit: this.limit,
type: this.type
}
}).then(result => {
if (result.code === 200) {
_that.busy = false;
if (result.data.orderList.length > 0) {
this.$set('orderList', _that.orderList.concat(result.data.orderList));
_that.pageTotal = result.data.pageTotal;
}
}
}).fail(() => {
tip('网络错误');
});
},
autoCancel(code) {
let _that = this;
return () => {
_that.order().cancel(code, (result) => {
if (result.code === 200) {
location.reload();
}
});
};
},
order() {
return {
cancel(code, success, fail) {
$.ajax({
url: '/home/cancel-order',
type: 'post',
data: {
orderCode: code
}
}).then(success).fail(fail);
}
};
},
cancelOrder(code) {
let _that = this;
Modal.confirm('订单取消后不能恢复,确认取消订单吗?', '', function() {
_that.order().cancel(code, (result) => {
if (result.code === 200) {
location.reload();
} else {
tip(result.message);
}
}, () => {
tip('操作失敗');
});
});
},
deleteOrder(order, index) {
let that = this;
Modal.confirm('确认删除订单?', '', function() {
$.ajax({
url: '/home/delete-order',
type: 'post',
data: {
orderCode: order.orderCode
}
}).then(result => {
if (result.code === 200) {
that.$el.querySelectorAll('.order-item')[index].remove();
} else {
tip(result.message);
}
}).fail(() => {
tip('操作失敗');
});
});
},
confirmGoods(code) {
$.ajax({
url: '/home/confirm-order',
type: 'post',
data: {
orderCode: code
}
}).then(result => {
if (result.code === 200) {
location.reload();
} else {
tip(result.message);
}
}).fail(() => {
tip('操作失敗');
});
},
goBuy(code) {
yohoAPI.goPay({orderid: code});
},
seeExpress() {
location.href = '';
}
}
};
</script>
<style>
html,
body {
height: 100%;
}
@import "../../scss/home/_order.css";
</style>