index.js
4.84 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
import Taro, {Component} from '@tarojs/taro';
import {View, Text, Button} from '@tarojs/components';
import { connect } from '@tarojs/redux';
import {productDetail as productDetailModel} from '../../models';
import { showSizeBox } from '../../actions/productDetail'
import './index.scss';
@connect(({ productDetail }) => ({
productDetail
}), (dispatch) => ({
showSizeBox (isShow) {
dispatch(showSizeBox(isShow))
}
}))
export default class SelectSize extends Component {
constructor(props) {
super(props);
this.state = {
curSelect: '',
selectedskup: 0,
canBuy: false,
curPrice: '',
hide: false
};
}
static defaultProps = {
sizeList: []
}
onChangeSize(item) {
this.setState({
curSelect: item.size_id,
selectedskup: item.skup,
curPrice: item.least_price,
canBuy: item.skup > 0
});
}
onClickMask() {
let {showSizeBox} = this.props;
showSizeBox(false);
}
onClickBuy(canBuy) {
if (!canBuy) {
return;
}
productDetailModel.createPaymentinfo(this.state.selectedskup).then(data => {
if (data && data.code === 200) {
let {product_id, onConfirmSelect} = this.props;
onConfirmSelect && onConfirmSelect(this.state.selectedskup);
this.state.canBuy && Taro.navigateTo({
url: `/pages/order/orderConfirm/orderConfirm?skup=${this.state.selectedskup}&&product_id=${product_id}`,
})
} else {
Taro.showToast({
title: data.message,
icon: 'none'
})
}
}).catch(error => {
Taro.showToast({
title: error.message,
icon: 'none'
})
})
}
onTouchMove() {
}
render() {
let {sizeList} = this.props;
let curSelect = this.state.curSelect;
let sizeLength = sizeList.length;
let sizeStyle = 'size-item';
if (sizeLength <= 5) {
sizeStyle = 'size-item top-border';
}
return (
<View className= "size-area" catchtouchmove = {this.onTouchMove.bind(this)}>
<View className="mask" onClick={this.onClickMask}></View>
<View className="select-size">
<Text className="title">选择尺码</Text>
{
sizeLength > 0 &&
<View className="size-list">
{
sizeList.map((item, index) => {
let price;
if (item.skup > 0) {
price = `¥${item.least_price}`;
} else {
price = '-';
}
let rightStyle = ''
let topStyle = ''
if (index < 5) {
topStyle = 'top-border'
}
if (index !== 0 && (index + 1) % 5 === 0) {
rightStyle = 'right-border'
} else if (index === sizeLength - 1) {
rightStyle = 'right-border'
}
return (
<View key={item.size_id} className={curSelect === item.size_id ? `actived ${sizeStyle}` : `${sizeStyle} ${topStyle} ${rightStyle}`} onClick={this.onChangeSize.bind(this, item)}>
<View className={item.storage_num > 0 ? 'size' : 'size gray'}>{item.size_name}</View>
{
curSelect !== item.size_id &&
<View className={item.storage_num > 0 ? 'price' : 'price gray'}>{price}</View>
}
</View>
)
})
}
</View>
}
<Button className={this.state.canBuy ? 'buy-btn' : 'buy-btn disabled'} hover-class='none' onClick={this.onClickBuy.bind(this, this.state.canBuy)} data-can-buy={this.state.canBu}>
购买
{
this.state.canBuy && this.state.curPrice &&
<Text className="price">¥{this.state.curPrice}</Text>
}
</Button>
</View>
</View>
)
}
}