|
@@ -1,13 +1,15 @@
|
|
|
import { enrollRecord } from '../../api/other';
|
|
|
-
|
|
|
+import { uploadImage } from '../../utils/upload.js';
|
|
|
Page({
|
|
|
data: {
|
|
|
cardList: [],
|
|
|
page: 1,
|
|
|
- pageSize: 2,
|
|
|
+ pageSize: 10,
|
|
|
loadingMore: false,
|
|
|
noMore: false,
|
|
|
- refreshing: false
|
|
|
+ refreshing: false,
|
|
|
+ filePath: '', // 上传成功的文件路径
|
|
|
+ fileType: '', // image / pdf
|
|
|
},
|
|
|
|
|
|
onLoad() {
|
|
@@ -31,8 +33,7 @@ Page({
|
|
|
let allList = isRefresh ? newList : [...this.data.cardList, ...newList];
|
|
|
allList = allList.map(item => ({
|
|
|
...item,
|
|
|
- img: statusImgMap[item.status],
|
|
|
- genderText: item.gender == 0 ? '女' : '男'
|
|
|
+ img: statusImgMap[item.status]
|
|
|
}));
|
|
|
|
|
|
this.setData({
|
|
@@ -63,5 +64,79 @@ Page({
|
|
|
if (this.data.refreshing) return;
|
|
|
this.setData({ refreshing: true, noMore: false, page: 1 });
|
|
|
this.loadData(true);
|
|
|
- }
|
|
|
+ },
|
|
|
+ // 点击上传区域
|
|
|
+ chooseFile() {
|
|
|
+ wx.showActionSheet({
|
|
|
+ itemList: ['图片', 'PDF'],
|
|
|
+ success: res => {
|
|
|
+ if (res.tapIndex === 0) {
|
|
|
+ this.chooseImage();
|
|
|
+ } else {
|
|
|
+ this.choosePdf();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 选择图片
|
|
|
+ chooseImage() {
|
|
|
+ wx.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['original', 'compressed'],
|
|
|
+ sourceType: ['album', 'camera'],
|
|
|
+ success: res => {
|
|
|
+ const path = res.tempFilePaths[0];
|
|
|
+ this.uploadFile(path, 'image');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 选择 PDF
|
|
|
+ choosePdf() {
|
|
|
+ wx.chooseMessageFile({
|
|
|
+ count: 1,
|
|
|
+ type: 'file',
|
|
|
+ success: res => {
|
|
|
+ const file = res.tempFiles[0];
|
|
|
+ if (file.name.endsWith('.pdf')) {
|
|
|
+ this.uploadFile(file.path, 'pdf');
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: '请选择 PDF 文件', icon: 'none' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 上传文件
|
|
|
+ async uploadFile(path, type) {
|
|
|
+ if (!path) {
|
|
|
+ wx.showToast({ title: '文件路径错误', icon: 'none' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const res = await uploadImage(path);
|
|
|
+ console.log('上传成功:', res);
|
|
|
+ this.setData({
|
|
|
+ filePath: res.url,
|
|
|
+ fileType: type,
|
|
|
+ "formData.competition_image": res.path
|
|
|
+ });
|
|
|
+ } catch (err) {
|
|
|
+ console.error('上传失败:', err);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 删除文件
|
|
|
+ removeFile() {
|
|
|
+ this.setData({
|
|
|
+ filePath: '',
|
|
|
+ fileType: '',
|
|
|
+ "formData.competition_image": ''
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //预览图片
|
|
|
+ previewImage(e){
|
|
|
+ const current = e.currentTarget.dataset.src;
|
|
|
+ wx.previewImage({
|
|
|
+ current,
|
|
|
+ urls: [current]
|
|
|
+ });
|
|
|
+ },
|
|
|
});
|