form.vue
4.3 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
<template>
<div class="form-body">
<div class="title">新的好物</div>
<Form ref="form">
<FormItem>
<CInput label="品牌" :max-length="50" :show-required="true" :required="true" place-holder="例如:Nike, Adidas" v-model="form.brand"></CInput>
</FormItem>
<FormItem>
<CInput label="商品名称" :max-length="50" :show-required="true" :required="true" place-holder="例如:Yeezy 350 v2 纯白" v-model="form.product_name"></CInput>
</FormItem>
<FormItem>
<CInput label="发售价" :max-length="9" type="number" :show-required="true" :required="false" place-holder="请输入官方售价" v-model="form.price"></CInput>
</FormItem>
<FormItem>
<CSingleDataPick label="发售时间" :show-required="true" :required="false" place-holder="请选择发售时间" v-model="form.sale_time"></CSingleDataPick>
</FormItem>
<FormItem>
<CInput :max-length="50" label="货号" :show-required="true" :required="true" place-holder="例如:CP9366,参见合格证" v-model="form.product_code"></CInput>
</FormItem>
<FormItem>
<CUpload label="商品图片" @file-change="fileChange" :show-required="true" :required="true" :max="9" v-model="form.imageList"></CUpload>
</FormItem>
</Form>
<div :class="submitClass" @click="onSubmit">确认提交</div>
</div>
</template>
<script>
import CUpload from '../../license/components/upload';
import FormItem from '../../license/components/form-item';
import Form from '../../license/components/form';
import CInput from '../../license/components/input';
import CSingleDataPick from '../components/single-data-pick';
import { createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers(
'license/form'
);
export default {
name: 'UfoFormPage',
data() {
return {
form: {
brand: '',
product_name: '',
price: '',
sale_time: '',
product_code: '',
imageList: [],
forceRecomputeCounter: 1
}
};
},
components: {
Form,
FormItem,
CUpload,
CInput,
CSingleDataPick
},
methods: {
async onSubmit() {
if (!this.validate()) {
return;
}
if (!this.isNotEmpty) {
return;
}
this.toast = this.$createToast({
type: 'loading',
txt: '正在提交中',
mask: true
}).show();
const result = await this.createUfoProduct(this.form);
await this.sleep(1000);
this.toast && this.toast.hide();
if (result && result.code === 200) {
this.$createToast({
type: 'text',
txt: '您的好货信息已提交,审核通过会第一时间通知您',
mask: true,
time: 3000,
$events: {
timeout: this.finishPage
}
}).show();
} else {
this.$createToast({
type: 'error',
txt: result.message,
mask: true
}).show();
}
},
...mapActions(['fetchToken', 'createUfoProduct']),
validate() {
return this.$refs.form && this.$refs.form.validate();
},
fileChange() {
this.form.forceRecomputeCounter += 1;
},
sleep(n) {
return new Promise((resolve) => {
setTimeout(resolve, n);
});
},
finishPage() {
this.$yoho.finishPage();
}
},
computed: {
submitClass() {
return [
'footer',
{
active: this.isNotEmpty
}
];
},
isNotEmpty() {
return this.form.forceRecomputeCounter && this.form.brand && this.form.product_name && this.form.product_code &&
this.form.imageList.length >= 1 &&
this.form.imageList[0] && this.form.imageList[0].response && this.form.imageList[0].response.data;
},
},
mounted() {
this.fetchToken();
}
};
</script>
<style lang="scss" scoped>
.form-body {
height: 100%;
overflow: scroll;
-webkit-overflow-scrolling: touch;
padding-top: 12px;
padding-left: 40px;
padding-right: 40px;
}
.title {
font-weight: bold;
font-size: 68px;
margin-bottom: 42px;
}
.footer {
width: 100%;
height: 120px;
text-align: center;
line-height: 120px;
font-size: 28px;
margin: 40px 0;
color: white;
background-color: #ccc;
&.active {
background-color: #002b47;
}
}
</style>