modal-price.vue
5.8 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<template>
<Modal v-model="visiable" sure-text="调整售价" cancel-text="取消" :loading="postLoading"
class="modal" :transfer="true" @on-sure="onSure" @on-cancel="onCancel"
>
<div class="change-price-modal">
<p class="modal-title">{{leastPriceMsg}}</p>
<InputUfo type="number" placeholder="定价需以9结尾 例如1999" :maxlength="8" class="ipt-number" v-model="chgPrice">
<span class="prepend" slot="prepend">¥</span>
</InputUfo>
<p class="tips" v-show="errorTip">{{errorTip}}</p>
<p class="price-line">
<span class="title">平台费用:</span>
<span class="price">{{platformFee}}</span>
</p>
<p class="price-line">
<span class="title">银行转账费用:</span>
<span class="price">{{bankTransferFee}}</span>
</p>
<p class="price-line total">
<span class="title">实际收入:</span>
<span class="price">{{income}}</span>
</p>
</div>
</Modal>
</template>
<script>
import Modal from './modal';
import InputUfo from './input-ufo';
import {debounce, get} from 'lodash';
import {createNamespacedHelpers} from 'vuex';
const {mapState, mapActions} = createNamespacedHelpers('order/priceChange');
export default {
name: 'modalPrice',
components: {Modal, InputUfo},
data() {
return {
visiable: false,
skc: {},
platformFee: '-¥0', // 平台费用
bankTransferFee: '-¥0', // 银行转账费用
income: '¥0', // 收入
errorTip: '',
chgPrice: '',
calced: false,
};
},
mounted() {
// debounce防抖动,输入数字后延迟500毫秒提交
this.inputChange = debounce(this.onChange.bind(this), 500);
},
watch: {
chgPrice(newVal) {
this.calced = false;
this.platformFee = '-¥0';
this.bankTransferFee = '-¥0';
this.income = '¥0';
this.inputChange(newVal);
}
},
computed: {
...mapState(['fetchingChangePrice']),
leastPriceMsg() {
if (this.skc.leastPrice) {
return `当前${this.skc.sizeName}码最低售价: ¥${this.skc.leastPrice}`;
} else if (this.skc.suggestMinPrice && this.skc.suggestMaxPrice) {
return `当前${this.skc.sizeName}码建议售价: ¥${this.skc.suggestMinPrice} - ¥${this.skc.suggestMaxPrice}`;
}
return `当前${this.skc.sizeName}码最低售价: ¥-`;
},
postLoading() {
console.log(this.fetchingChangePrice, this.calced);
return this.fetchingChangePrice || !this.calced;
}
},
methods: {
...mapActions(['postCalcPrice']),
resetPrices() {
this.prices = [];
},
show({skc, product}) {
this.chgPrice = '';
this.errorTip = '';
this.prices = [];
this.skc = skc;
this.product = product;
this.visiable = true;
this.calced = false;
},
hide() {
this.skc = {};
this.product = {};
this.visiable = false;
},
onChange(price) {
if (!this.visiable) {
return;
}
if (this.checkPrice(price)) {
this.calcPrice(price);
}
},
async calcPrice(price) {
const result = await this.postCalcPrice({
product_id: this.product.productId,
storage_id: this.skc.storageId,
new_price: price,
old_price: this.skc.price,
num: this.skc.storageNum,
skupType: this.skc.attributes
});
if (result && result.code === 200) {
this.platformFee = get(result, 'data.platformFee.amount', '');
this.bankTransferFee = get(result, 'data.bankTransferFee', '');
this.income = get(result, 'data.income', '');
this.calced = true;
} else {
if (result.message) {
this.errorTip = result.message;
}
this.$createToast({
txt: result.message,
type: 'warn',
}).show();
}
},
checkPrice(price) {
let valid = false;
if (!price) {
this.errorTip = '没有价格';
return false;
} else if (!/^\d+$/.test(price)) {
this.errorTip = '价格只能为正整数';
} else if (!/9$/.test(price)) {
this.errorTip = '出售价格必须以9结尾';
} else if (this.skc.minPrice && price < this.skc.minPrice) {
this.errorTip = '您的出价过低';
} else if (this.skc.maxPrice && price > this.skc.maxPrice) {
this.errorTip = '您的出价格过高';
} else if (+price === this.skc.price) {
this.errorTip = '前后价格没有变化';
} else if (this.skc.suggestMaxPrice && price > this.skc.suggestMaxPrice) {
this.errorTip = '超出建议价将被限制展示,建议下调至合理价格区间';
valid = true;
} else if (this.skc.leastPrice && price > this.skc.leastPrice) {
this.errorTip = '您的出价高于最低售价';
valid = true;
} else {
this.errorTip = '';
valid = true;
}
return valid;
},
onSure() {
if (!this.checkPrice(this.chgPrice)) {
this.$createToast({
txt: this.errorTip,
type: 'warn',
}).show();
} else {
this.$emit('on-change-price', {skc: this.skc, price: this.chgPrice});
}
},
onInput(val) {
this.$emit('input', val);
},
onCancel() {}
}
};
</script>
<style lang="scss" scoped>
.change-price-modal {
.tips {
color: #d0021b;
font-size: 24px;
margin-bottom: 20px;
}
.price-line {
margin-bottom: 20px;
color: #999;
font-size: 24px;
display: flex;
.title {
width: 50%;
}
.price {
width: 50%;
text-align: right;
}
&.total {
color: #000;
}
}
.ipt-number {
/deep/ .prepend {
width: 40px;
margin-left: 20px;
text-align: left;
}
}
.modal-title {
line-height: 100px;
text-align: center;
}
}
</style>