seller-confirm.vue
5 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
<template>
<LayoutApp :show-back="true">
<div class="body">
<TitleComp txt="出售"></TitleComp>
<ProductInfo :data="productDetail" class="product-info"></ProductInfo>
<InputPrice @input="changePrice" :value="price" class="input-price" @on-blur="compute"></InputPrice>
<OrderMargin class="order-item order-margin" :data="fee"></OrderMargin>
<OrderFee class="order-item" :data="fee"></OrderFee>
<AddressInfo :data="address" class="order-item"></AddressInfo>
</div>
<div class="footer">
<OrderAgree :value="agree" @input="changeAgree" class="agree-wrapper" :desc="agreeDesc"></OrderAgree>
<YohoButton :txt="txt" @click="onClick" :disable="!agree"></YohoButton>
</div>
</LayoutApp>
</template>
<script>
import ProductInfo from './components/confirm/product';
import InputPrice from './components/confirm/input-price';
import AddressInfo from './components/confirm/address';
import TitleComp from './components/confirm/title';
import OrderMargin from './components/confirm/order-margin';
import OrderFee from './components/confirm/order-fee';
import OrderAgree from './components/confirm/agree';
import { Types, UserType } from 'store/order/order-confirm';
import { get } from 'lodash';
import { createNamespacedHelpers, mapState } from 'vuex';
const { mapState: mapOrderState, mapActions: mapOrderAction, mapMutations: mapOrderMutations } = createNamespacedHelpers('order/orderConfirm');
export default {
name: 'OrderConfirm',
props: ['productId', 'storageId'],
components: {
ProductInfo,
AddressInfo,
InputPrice,
TitleComp,
OrderMargin,
OrderFee,
OrderAgree
},
data() {
return {
txt: '提交',
error: false,
num: 1,
agreeDesc: '有货卖家协议'
};
},
mounted() {
this.fetchUserStatus();
this.fetchOrderAddress({ tabType: UserType.sell });
this.$store.dispatch('product/getSelectedTradeProduct', {
productId: this.productId,
storageId: this.storageId
});
},
computed: {
...mapOrderState(['address', 'fee', 'price', 'agree']),
...mapState({
productDetail: state => {
return {
goodImg: get(state.product.selectedProductInfo, 'product.goods_list[0].image_list[0].image_url', ''),
colorName: get(state.product.selectedProductInfo, 'product.goods_list[0].color_name', ''),
sizeName: get(state.product.selectedProductInfo, 'size.size_name', ''),
goodPrice: get(state.product.selectedProductInfo, 'size.least_price', ''),
};
}
})
},
methods: {
...mapOrderAction(['fetchOrderAddress', 'fetchUserStatus', 'fetchOrderPrice', 'submitOrder', 'fetchPayList']),
...mapOrderMutations([Types.CHANGE_PRICE, Types.CHANGE_AGREE]),
onClick() {
this.submit();
},
compute() {
return this.fetchOrderPrice({
address_id: this.address.address_id,
num: this.num,
price: this.price,
storage_id: this.storageId,
}).then(result => {
if (result.error) {
this.error = result.error;
this.$createToast({
time: 1500,
txt: result.error,
type: 'txt'
}).show();
}
this.error = false;
});
},
changePrice(val) {
this[Types.CHANGE_PRICE](val);
},
changeAgree(val) {
this[Types.CHANGE_AGREE](val);
},
async submit() {
const vm = this;
await this.compute();
if (this.error) {
return;
}
const orderResult = await this.submitOrder({
address_id: this.address.address_id,
num: 1,
price: this.price,
storage_id: this.storageId,
});
if (orderResult.code !== 200) {
this.$createToast({
time: 1500,
txt: '创建订单失败',
type: 'txt'
}).show();
return;
}
const { orderCode } = orderResult.data;
const payListResult = await this.fetchPayList({
order_code: orderCode
});
this.orderPay = this.$createOrderPayType({
data: payListResult.data,
price: this.fee.earnestMoneyStr,
desc: '保证金',
orderCode,
onCloseAction() {
vm.onClose();
vm.$router.push({
name: 'orderDetail',
params: {
owner: UserType.sell,
code: orderCode
}
});
},
onPayAction() {
vm.onPay();
}
}).show();
},
onClose() {
console.log('close');
},
onPay() {
console.log('pay');
}
}
};
</script>
<style lang="scss" scoped>
.footer {
position: absolute;
bottom: 0;
width: 100%;
z-index: 1;
}
.body {
height: 100%;
margin: 0 40px;
padding-bottom: 200px;
overflow-y: auto;
}
.order-item {
padding-top: 40px;
padding-bottom: 40px;
}
.order-item + .order-item {
border-top: 1px solid #eee;
}
.agree-wrapper {
height: 60px;
background-color: white;
border-top: 1px solid #eee;
padding: 0 40px;
line-height: 60px;
}
</style>