orderaction.js
2.74 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
// src/components/order/orderaction.js
import { formatTimeByMin } from '../../utils/index.js';
import { showDialog } from './orderActionUtil.js';
import { prePay } from '../../pages/order/wxpay.js'
import router from '../../router/index.js'
const BUY_AGAIN = 'buy_again';
const NOW_BUY = 'now_buy';
const SHOW_DETAIL = 'show_detail';
const SHOW_EXPRESS = 'show_express';
import event from '../../utils/event';
Component({
/**
* 组件的属性列表
*/
properties: {
buttons: Array,
//默认值:-1(不显示),0:订单列表,1:订单详情
// fromPage: Number,
timer: String,
realPrice: String,
orderCode:String,
productId:String,
isStore:{
type:Boolean,
value: false
}
},
/**
* 组件的初始数据
*/
data: {
lefttime:"",
lastIndex: 0,
interval:Object,
},
lifetimes: {
},
attached: function () {
let that = this;
if (that.data.buttons){
let lastIndex = that.data.buttons.length - 1;
that.setData({ lastIndex: lastIndex });
}
if (that.data.timer) {
let leftTime = that.data.lefttime;
let timer = that.data.timer;
if (timer > 0){
this.data.interval && clearInterval(this.data.interval);
this.data.interval = setInterval(() => {
timer = timer - 1;
leftTime = formatTimeByMin(timer, 'm:s');
if (timer <= 0) {
leftTime = '00:00';
setTimeout(() => {
event.emit('refresh-order');
}, 2000);
clearInterval(this.data.interval);
}
that.setData({
lefttime: leftTime,
timer: timer
});
}, 1000);
}
}
},
detached: function () {
if (this.data.interval){
clearInterval(this.data.interval);
}
},
/**
* 组件的方法列表
*/
methods: {
onButtonClick: function(e){
let actionCode = e.currentTarget.dataset.buttonCode;
let orderCode = e.currentTarget.dataset.orderCode;
let productId = e.currentTarget.dataset.productId;
if (actionCode == BUY_AGAIN) {
let params = {
id: productId
}
router.go('productDetail', params);
} else if (actionCode == NOW_BUY){
prePay(productId, orderCode, 1 ,this.properties.isStore);
} else if (actionCode == SHOW_DETAIL) {
let params = {
orderCode
}
router.go('orderDetail', params);
} else if (actionCode == SHOW_EXPRESS){
let params = {
orderCode
}
router.go('logistics', params);
} else {
if (actionCode === 'cancel_order' && !this.data.isStore) {
return this.triggerEvent('cancelorder', {
orderCode
});
}
showDialog(orderCode, actionCode, 0);
}
},
}
})