orderaction.js
2.37 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
// 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';
Component({
/**
* 组件的属性列表
*/
properties: {
buttons: Array,
//默认值:-1(不显示),0:订单列表,1:订单详情
// fromPage: Number,
timer: String,
realPrice: String,
orderCode:String,
productId:String,
},
/**
* 组件的初始数据
*/
data: {
lefttime:"",
lastIndex: 0,
interval:Object,
},
lifetimes: {
},
attached: function () {
let that = this;
if (that.data.buttons){
let lastIndex = that.data.buttons.length - 1;
console.log("lastIndex===" + lastIndex);
that.setData({ lastIndex: lastIndex });
}
if (that.data.timer) {
let leftTime = that.data.lefttime;
let timer = that.data.timer;
if(timer > 0){
let interval = setInterval(() => {
timer = timer - 1;
leftTime = formatTimeByMin(timer, '00:00');
that.setData({
lefttime: leftTime,
timer: timer
});
}, 1000);
that.setData({ interval: interval});
}
}
},
detached: function () {
let interval = this.interval;
if (interval){
clearInterval(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){
console.log("== 去支付页面===")
prePay(productId, orderCode, 1);
} 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 {
showDialog(orderCode, actionCode, 0);
}
},
}
})