|
|
@ -1,5 +1,7 @@ |
|
|
|
// subpages/goOut/goOut/goOut.js
|
|
|
|
var config = require('../../../utils/config') |
|
|
|
import { goOutSubmit,getgoOutInfo } from '../../../api/index' |
|
|
|
const app = getApp() |
|
|
|
Page({ |
|
|
|
|
|
|
|
/** |
|
|
@ -7,6 +9,7 @@ Page({ |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
reasonName: '', |
|
|
|
reasonId: '', |
|
|
|
currentDateStart: '', |
|
|
|
currentDateEnd: '', |
|
|
|
showReason: false, |
|
|
@ -18,15 +21,34 @@ Page({ |
|
|
|
endMinDate: null, // 结束时间最小日期
|
|
|
|
endMaxDate: null, // 结束时间最大日期
|
|
|
|
fileList: [], // 上传的文件列表
|
|
|
|
submitting: false, // 提交状态
|
|
|
|
showSuccessModal: true, // 显示成功弹框
|
|
|
|
showSuccessModal: false, // 显示成功弹框
|
|
|
|
info: false, // 是否是重新提交
|
|
|
|
id: '', // 外出申请id
|
|
|
|
nextFileNo: 1, // 文件编号自增,避免重名
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面加载 |
|
|
|
*/ |
|
|
|
onLoad(options) { |
|
|
|
|
|
|
|
if (options.id) { |
|
|
|
this.setData({ |
|
|
|
id: options.id, |
|
|
|
info: true |
|
|
|
}) |
|
|
|
getgoOutInfo({id: options.id}).then(res=>{ |
|
|
|
if (res.code === 200) { |
|
|
|
this.setData({ |
|
|
|
reasonName: this.data.options[res.data.reason], |
|
|
|
currentDateStart: res.data.startTime, |
|
|
|
currentDateEnd: res.data.endTime, |
|
|
|
fileList: res.data.imgs, |
|
|
|
reasonId: res.data.reason, |
|
|
|
nextFileNo: (res.data.imgs && res.data.imgs.length ? res.data.imgs.length : 0) + 1 |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
@ -78,6 +100,13 @@ Page({ |
|
|
|
|
|
|
|
}, |
|
|
|
handleReason() { |
|
|
|
if (this.data.info) { |
|
|
|
wx.showToast({ |
|
|
|
title: '无法修改原因', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
showReason: true |
|
|
|
}) |
|
|
@ -89,17 +118,28 @@ Page({ |
|
|
|
} = e.detail; |
|
|
|
console.log(index); |
|
|
|
this.setData({ |
|
|
|
reasonId: index, |
|
|
|
reasonName: value, |
|
|
|
showReason: false |
|
|
|
}) |
|
|
|
}, |
|
|
|
oncancel() { |
|
|
|
if (this.data.info) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
reasonName: '', |
|
|
|
showReason: false |
|
|
|
}) |
|
|
|
}, |
|
|
|
handleDateStart() { |
|
|
|
if (this.data.info) { |
|
|
|
wx.showToast({ |
|
|
|
title: '无法修改开始时间', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return |
|
|
|
} |
|
|
|
console.log('handleDateStart'); |
|
|
|
|
|
|
|
this.setData({ |
|
|
@ -107,6 +147,9 @@ Page({ |
|
|
|
}) |
|
|
|
}, |
|
|
|
oncancelStart() { |
|
|
|
if (this.data.info) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
currentDateStart: '', |
|
|
|
showDateStart: false |
|
|
@ -134,18 +177,31 @@ Page({ |
|
|
|
}) |
|
|
|
}, |
|
|
|
oncancelEnd() { |
|
|
|
if (this.data.info) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
currentDateEnd: '', |
|
|
|
showDateEnd: false |
|
|
|
}) |
|
|
|
}, |
|
|
|
onconfirmEnd(e) { |
|
|
|
if (this.data.info) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
showDateEnd: false, |
|
|
|
currentDateEnd: this.formatDate(e.detail) |
|
|
|
}) |
|
|
|
}, |
|
|
|
handleDateEnd() { |
|
|
|
if (this.data.info) { |
|
|
|
wx.showToast({ |
|
|
|
title: '无法修改结束时间', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
showDateEnd: true |
|
|
|
}) |
|
|
@ -159,13 +215,25 @@ Page({ |
|
|
|
sizeType: ['compressed'], |
|
|
|
sourceType: ['album', 'camera'], |
|
|
|
success: (res) => { |
|
|
|
console.log(res); |
|
|
|
const files = res.tempFiles || []; |
|
|
|
const oversize = files.some(f => typeof f.size === 'number' && f.size > 8 * 1024 * 1024); |
|
|
|
if (oversize) { |
|
|
|
wx.showToast({ |
|
|
|
title: '单张图片不能超过8MB', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
const startNo = this.data.nextFileNo; |
|
|
|
const tempFiles = res.tempFilePaths.map((path, index) => ({ |
|
|
|
url: path, |
|
|
|
name: `证明材料${this.data.fileList.length + index + 1}.jpg`, |
|
|
|
name: `证明材料${startNo + index}.jpg`, |
|
|
|
isImage: true |
|
|
|
})); |
|
|
|
this.setData({ |
|
|
|
fileList: [...this.data.fileList, ...tempFiles] |
|
|
|
fileList: [...this.data.fileList, ...tempFiles], |
|
|
|
nextFileNo: startNo + tempFiles.length |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
@ -173,10 +241,21 @@ Page({ |
|
|
|
|
|
|
|
afterRead(event) { |
|
|
|
const { file } = event.detail; |
|
|
|
const files = Array.isArray(file) ? file : [file]; |
|
|
|
const oversize = files.some(f => typeof f.size === 'number' && f.size > 8 * 1024 * 1024); |
|
|
|
if (oversize) { |
|
|
|
wx.showToast({ |
|
|
|
title: '单张图片不能超过8MB', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
const selected = Array.isArray(file) ? file[0] : file; |
|
|
|
const _this = this |
|
|
|
wx.showLoading({ title: '上传中...', mask: true }) |
|
|
|
wx.uploadFile({ |
|
|
|
url: `${config.BASEURL()}/common/upload`, // 仅为示例,非真实的接口地址
|
|
|
|
filePath: file.url, |
|
|
|
filePath: selected.url, |
|
|
|
name: 'file', |
|
|
|
header: { |
|
|
|
"Content-type": "multipart/form-data", |
|
|
@ -184,10 +263,21 @@ Page({ |
|
|
|
}, |
|
|
|
success(res) { |
|
|
|
const res1 = JSON.parse(res.data) |
|
|
|
const nextNo = _this.data.nextFileNo; |
|
|
|
_this.setData({ |
|
|
|
fileList: _this.data.fileList.concat([{ url: res1.url, name: `证明材料${_this.data.fileList.length + 1}.jpg` }]) |
|
|
|
fileList: _this.data.fileList.concat([{ url: res1.url, name: `证明材料${nextNo}.jpg` }]), |
|
|
|
nextFileNo: nextNo + 1 |
|
|
|
}); |
|
|
|
}, |
|
|
|
fail() { |
|
|
|
wx.showToast({ |
|
|
|
title: '上传失败,请重试', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
}, |
|
|
|
complete() { |
|
|
|
wx.hideLoading() |
|
|
|
} |
|
|
|
}); |
|
|
|
// 这里可以添加上传到服务器的逻辑
|
|
|
|
console.log('文件上传成功:', file); |
|
|
@ -200,50 +290,24 @@ Page({ |
|
|
|
fileList.splice(index, 1); |
|
|
|
this.setData({ fileList }); |
|
|
|
}, |
|
|
|
|
|
|
|
// 提交申请
|
|
|
|
submit() { |
|
|
|
// 表单验证
|
|
|
|
if (!this.data.reasonName) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择外出原因', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!this.data.currentDateStart) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择开始时间', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!this.data.currentDateEnd) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择结束时间', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (this.data.fileList.length === 0) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请上传证明材料', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
// 自定义文件名列表删除
|
|
|
|
removeFile(e) { |
|
|
|
const { index } = e.currentTarget.dataset; |
|
|
|
const fileList = [...this.data.fileList]; |
|
|
|
if (index >= 0 && index < fileList.length) { |
|
|
|
fileList.splice(index, 1); |
|
|
|
this.setData({ fileList }); |
|
|
|
} |
|
|
|
|
|
|
|
this.setData({ submitting: true }); |
|
|
|
|
|
|
|
// 模拟提交过程
|
|
|
|
setTimeout(() => { |
|
|
|
this.setData({ submitting: false }); |
|
|
|
wx.showToast({ |
|
|
|
title: '提交成功', |
|
|
|
icon: 'success' |
|
|
|
}); |
|
|
|
// 这里可以添加实际的提交逻辑
|
|
|
|
}, 2000); |
|
|
|
}, |
|
|
|
// 预览图片
|
|
|
|
previewFile(e){ |
|
|
|
const { index } = e.currentTarget.dataset; |
|
|
|
const urls = (this.data.fileList || []).map(i => i.url); |
|
|
|
if (!urls.length) return; |
|
|
|
wx.previewImage({ |
|
|
|
current: urls[index] || urls[0], |
|
|
|
urls |
|
|
|
}) |
|
|
|
}, |
|
|
|
submit() { |
|
|
|
if (!this.data.reasonName) { |
|
|
@ -275,19 +339,24 @@ Page({ |
|
|
|
return |
|
|
|
} |
|
|
|
let parms = { |
|
|
|
reasonName: this.data.reasonName, |
|
|
|
currentDateStart: this.data.currentDateStart, |
|
|
|
currentDateEnd: this.data.currentDateEnd, |
|
|
|
fileList: this.data.fileList |
|
|
|
reason: this.data.reasonId, |
|
|
|
startTime: this.data.currentDateStart, |
|
|
|
endTime: this.data.currentDateEnd, |
|
|
|
imgs: this.data.fileList, |
|
|
|
graduateId: app.globalData.userInfo.graduateId, |
|
|
|
} |
|
|
|
// goOutSubmit(parms).then(res => {
|
|
|
|
// if (res.code === 200) {
|
|
|
|
// wx.showToast({
|
|
|
|
// title: '提交成功',
|
|
|
|
// icon: 'success'
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
goOutSubmit(parms).then(res => { |
|
|
|
if (res.code === 200) { |
|
|
|
this.setData({ |
|
|
|
showSuccessModal: true |
|
|
|
}) |
|
|
|
} |
|
|
|
}).catch(err=>{ |
|
|
|
wx.showToast({ |
|
|
|
title: err.msg, |
|
|
|
icon:'none' |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
closeSuccessModal() { |
|
|
|
this.setData({ |
|
|
|