modal-price.vue
4.56 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
<template>
<Modal
class="ufo-font"
v-model="visiable"
sure-text="调整售价"
cancel-text="取消"
:loading="fetchingChangePrice"
:transfer="true"
@on-sure="onSure">
<div class="change-price-modal">
<p class="modal-title">当前{{skc.sizeName}}码最低售价:¥{{skc.leastPrice}}</p>
<InputUfo type="number" :maxlength="8" class="input-number" v-model="chgPrice">
<span class="prepend" slot="prepend">¥</span>
</InputUfo>
<p class="tips" v-show="errorTip">{{errorTip}}</p>
<p class="price-line" v-for="(price, inx) in prices" :key="inx" :class="{total: price.total}">
<span class="title">{{price.label}}</span>
<span class="price">{{price.money}}</span>
</p>
</div>
</Modal>
</template>
<script>
import {debounce, get} from 'lodash';
import InputUfo from '../../components/input-ufo';
import Modal from '../../components/modal.vue';
import {createNamespacedHelpers} from 'vuex';
const {mapState, mapActions} = createNamespacedHelpers('ufo/order');
export default {
name: 'ModalPrice',
data() {
return {
visiable: false,
skc: {},
prices: [],
errorTip: '',
chgPrice: '',
};
},
mounted() {
this.inputChange = debounce(this.onChange.bind(this), 500);
},
watch: {
chgPrice(newVal) {
this.inputChange(newVal);
}
},
computed: {
...mapState(['fetchingChangePrice'])
},
methods: {
...mapActions(['postCalcPrice']),
show({skc, product}) {
this.chgPrice = '';
this.errorTip = '';
this.prices = [];
this.skc = skc;
this.product = product;
this.visiable = true;
},
hide() {
this.skc = {};
this.product = {};
this.visiable = false;
},
onChange(price) {
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
});
if (result && result.code === 200) {
this.prices = [{
label: '平台费用:',
money: get(result, 'data.platformFee.amount', '')
}, {
label: '银行转账费用:',
money: get(result, 'data.bankTransferFee', '')
}, {
label: '实际收入:',
money: get(result, 'data.income', ''),
total: 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 {
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);
}
},
components: {Modal, InputUfo}
};
</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;
}
}
.input-number {
/deep/ .prepend {
width: 40px;
margin-left: 20px;
text-align: left;
}
}
.modal-title {
line-height: 100px;
text-align: center;
}
}
</style>