exp.js
5.02 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
import areaList from '@common/area.js'
import {
Toast
} from 'vant';
export default {
data() {
return {
key: 'value',
fileList: [],
areaVisible: false,
areaList: [],
// 姓名、手机号、省市区、详细地址
editable: false,
formData: { // 奖品信息。抽奖后显示
"winCode": "",
"name": "",
"mobile": "",
"province": "",
"city": "",
"district": "",
"address": "",
"extData": "",
"prize": { // 奖品信息
"prizeName": "",
"prizePic": "",
"prizeThumb": "",
"prizeType": "", // 如果不中奖,奖品标识为lose
"outParams": "",
"extParams": "",
"outParamsVo": { // outParams参数格式化}
}
}
},
page: 1,
size: 10,
loading: false,
finished: false,
list: [],
}
},
components: {},
computed: {
areaStr() {
let result = "";
let {
province,
city,
district
} = this.formData;
if (province && city && district) {
result = `${province}-${city}-${district}`
}
return result;
}
},
methods: {
resetPage() {
this.loading = false;
this.page = 1;
this.total = 0;
this.list = [];
this.finished = false;
},
onLoad() {
if (this.finished) {
this.loading = false;
} else {
this.page++;
this.queryList();
}
},
queryList() {
app.get({
url: app.api.list,
data: {
page: this.page,
size: this.size
}
}).then((result) => {
this.list = this.list.concat(result.list);
this.finished = this.list.length >= result.total;
this.loading = false;
}).catch((err) => {
this.loading = false;
this.finished = true;
});
},
// 显示地区
onShowAreaSelect() {
if (!this.editable) return;
this.areaVisible = true;
},
// 确认省市区
onAreaConfirm(val) {
this.areaVisible = false;
if (val && val.length >= 3) {
this.formData.province = val[0].name || "";
this.formData.city = val[1].name || "";
this.formData.district = val[2].name || "";
this.formData.provinceCode = val[0].code || "";
this.formData.cityCode = val[1].code || "";
this.formData.districtCode = val[2].code || "";
}
},
beforeAvatarUpload(file) {
const size = 10 * 1024 * 1024;
if (file.size > size) {
Toast('上传图片大小不能超过10M');
return false;
}
return true;
},
afterRead(file) {
console.log("file:", file);
if (file.length == undefined) {
this.uploadFile(file);
} else {
for (let index = 0; index < file.length; index++) {
this.uploadFile(file[index]);
}
}
},
uploadFile(file) {
file.status = 'uploading';
file.message = '上传中...';
this.loading = true;
app.uploadFile({
url: app.api.upload,
// data: formData
data: {
file: file.file,
subPath: this.subPath
}
})
.then(res => {
file.status = 'done';
file.message = '';
file.url = res;
console.log("file:", file);
console.log("fileList:", this.fileList);
this.loading = false;
})
.catch(e => {
file.status = 'failed';
file.message = '上传失败';
this.loading = false;
this.refreshFileList();
Toast("上传失败,请上传体积小于10的文件")
});
},
refreshFileList() {
let fileList = this.fileList.filter(item => {
return item.url
});
this.fileList = fileList
},
initData() {
this.editable = true;
}
},
mounted() {
this.areaList = areaList;
this.initData();
},
created() {}
}