Files
2023-08-04 13:14:48 +08:00

286 lines
7.2 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="container">
<view class="form">
<u--form :model="form" ref="uForm" label-width="200rpx">
<u-gap height="10" bgColor="#f3f3f3"></u-gap>
<view class="block">
<u-form-item label="学历" prop="education" borderBottom @click="showEducation">
<u-input v-model="form.education" :disabled="true" :customStyle="{backgroundColor: '#ffffff'}" placeholder="选择学历" class="u-input" maxlength="20" />
</u-form-item>
<u-form-item label="认证方式" prop="authType" borderBottom @click="showAuthType">
<u-input v-model="form.authType" :disabled="true" :customStyle="{backgroundColor: '#ffffff'}" placeholder="选择认证方式" class="u-input" maxlength="20" />
</u-form-item>
<u-form-item label="毕业院校" prop="college">
<u-input v-model="form.college" :disabled="isEdit" placeholder="毕业院校" class="u-input" maxlength="20" />
</u-form-item>
</view>
<u-gap height="10" bgColor="#f3f3f3"></u-gap>
<view class="block">
<view class="upload">
<u-upload :fileList="fileList1" :maxSize="3145728" width="250" height="150"
@afterRead="afterRead" @delete="deletePic" :disabled="isEdit" name="1" multiple :maxCount="1">
<view class="id-card-upload">
<image class="photograph" src="../../../static/icon/photograph.png" mode="widthFix">
</image>
<text>上传学历认证照片</text>
</view>
</u-upload>
</view>
</view>
<u-gap height="10" bgColor="#f3f3f3"></u-gap>
<view class="block">
<u-form-item label="去学信网截图" prop="authType">
<!-- <u-input v-model="form.authType" class="u-input" maxlength="20" /> -->
</u-form-item>
<view class="desc"><text>登录学信网->在线验证报告截图后返回上传即可</text></view>
<view class="photo">
<image src="https://file.wsdns.cn/20230619/e259164339364fb1b2bc43fc50b21c50.png"
style="width: 700rpx;" mode="widthFix"></image>
</view>
</view>
</u--form>
</view>
<view class="btn-wrapper">
<u-button :text="submitText" color="linear-gradient(to bottom, #010002, #681752)" :disabled="isEdit"
shape="circle" @click="handleSubmit()"></u-button>
</view>
<!-- 地址选择器 -->
<liu-customize-sel ref="area" @change="chooseSuccess"></liu-customize-sel>
</view>
</template>
<script>
import * as UploadApi from '@/api/upload'
import * as CertificateApi from '@/api/love-certificate.js'
const userId = uni.getStorageSync('userId')
export default {
data() {
return {
form: {
certificateType: 'education',
userId,
education: '',
authType: ''
},
educationColumns: [''],
fileList1: [],
disabled: false,
// 临时图片 (用于上传)
tempFile: null,
isEdit: false,
submitText: '提交认证信息'
}
},
onLoad() {
this.getData()
},
methods: {
getData() {
const app = this
const {
form
} = this
CertificateApi.listCertificate({
userId,
certificateType: 'education',
}).then(res => {
if (res.data && res.data.length > 0) {
app.form = res.data[0]
app.fileList1 = JSON.parse(res.data[0].files)
if(app.form.status == 10){
app.submitText = '认证中'
app.isEdit = true
}
if(app.form.status == 20){
app.submitText = '提交认证信息'
app.isEdit = false
}
if(app.form.status == 30){
app.submitText = '已通过'
app.isEdit = true
}
}
})
},
showEducation() {
if(this.isEdit == true){
return false;
}
const itemList = ['专科以下','专科','本科','硕士研究生','博士研究生'];
uni.showActionSheet({
itemList,
success: ({tapIndex}) => {
this.form.education = itemList[tapIndex]
}
})
},
showAuthType() {
if(this.isEdit == true){
return false;
}
const itemList = ['学信网截图','毕业证/学位证','在校(学生证/在读证明)'];
uni.showActionSheet({
itemList,
success: ({tapIndex}) => {
this.form.authType = itemList[tapIndex]
}
})
},
onArea() {
if(this.isEdit == true){
return false;
}
this.$refs.area.open()
},
//地址选择成功
chooseSuccess(e) {
const data = e.value
this.form.city = data[1].label
},
// 新增图片
async afterRead(event) {
console.log("event: ", event);
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file)
let fileListLen = this[`fileList${event.name}`].length
lists.map((item) => {
this[`fileList${event.name}`].push({
...item,
status: 'uploading',
message: '上传中'
})
})
for (let i = 0; i < lists.length; i++) {
const result = await this.uploadFilePromise(lists[i].url)
console.log('result: ',result);
let item = this[`fileList${event.name}`][fileListLen]
this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
status: 'success',
message: '',
url: result.url,
thumb: result.thumbUrl
}))
fileListLen++
}
},
uploadFilePromise(url) {
return new Promise((resolve, reject) => {
UploadApi.uploadFile({
filePath: url,
fileType: 'image',
name: 'file',
header: {
Authorization: uni.getStorageSync('AccessToken')
},
}).then(result => {
setTimeout(() => {
resolve(result.data)
}, 1000)
}).catch(err => {
console.log("err: ", err);
})
})
},
// 删除图片
deletePic(event) {
if(this.isEdit == true){
return false;
}
this[`fileList${event.name}`].splice(event.index, 1)
},
// 确认修改
async handleSubmit() {
const app = this
if(app.fileList1.findIndex(item => item.status != 'success') >= 0){
return
}
if (app.disabled === true) return
app.form.files = JSON.stringify(app.fileList1)
const saveCertificate = app.isEdit ? CertificateApi.updateCertificate : CertificateApi.addCertificate
saveCertificate(app.form).then(result => {
app.$success('提交成功')
this.getData()
}).catch(err => {
app.$error(err.message)
})
}
}
}
</script>
<style lang="scss" scoped>
page {
background-color: #f3f3f3;
}
.container {
.form {
background-color: #ffffff;
}
.block {
margin: auto;
width: 700rpx;
font-size: 28rpx;
.u-input {
background-color: #ffffff !important;
}
.upload {
width: 360rpx;
margin: 0 auto;
padding: 20rpx 0;
justify-content: center;
.id-card-upload {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
margin: 10rpx auto;
color: #cccccc;
border: 5rpx dashed #d9d9d9;
border-radius: 20rpx;
width: 360rpx;
height: 220rpx;
.photograph {
width: 60rpx;
}
}
}
.desc-title {
line-height: 3rem;
}
.desc {
color: #cccccc;
text {
color: #7f006f;
}
}
}
}
.btn-wrapper {
background: none;
width: 360rpx;
margin: 50rpx auto;
// display: flex;
// align-items: center;
padding: 0 20rpx;
}
</style>