提交
This commit is contained in:
@@ -5,36 +5,36 @@
|
||||
<view class="mt15">
|
||||
<!-- <u-upload width="165" height="165" :file-list=" fileList1" multiple :max-count="1" @afterRead="afterRead" @delete="deletePic" /> -->
|
||||
<!-- <u-upload ref="uUpload" class="mt25" :size-type="['compressed']" :file-list="fileList1" deletable :multiple="false" :max-count="1" width="165rpx" height="165rpx" @afterRead="afterRead" @delete="deletePic" /> -->
|
||||
<view style="width: 320rpx;height:300rpx;background-color: rgb(247, 255, 255);border-radius: 20rpx;">
|
||||
<view style="width: 320rpx;height:240rpx;" class="flex jc-c ai-c">
|
||||
<image v-if="fileList1&&fileList1.length" style="width: 240rpx;height: 240rpx;" :src="fileList1[0].url">
|
||||
</image>
|
||||
<u-avatar v-else class="br-p50 overflow-h" :size="64" mp-avatar shape="circle"></u-avatar>
|
||||
</view>
|
||||
<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" multiple :maxCount="1" width="150"
|
||||
height="150">
|
||||
<view style="width: 320rpx;height:300rpx;background-color: rgb(247, 255, 255);border-radius: 20rpx;">
|
||||
<view style="width: 320rpx;height:240rpx;" class="flex jc-c ai-c">
|
||||
<image v-if="fileList&&fileList.length" style="width: 240rpx;height: 240rpx;" :src="fileList[0].url">
|
||||
</image>
|
||||
<u-avatar v-else class="br-p50 overflow-h" :size="64" mp-avatar shape="circle"></u-avatar>
|
||||
</view>
|
||||
<u-upload :fileList="fileList1" :maxSize="500 * 1024" @oversize="oversize" @afterRead="afterRead"
|
||||
@delete="deletePic" multiple :maxCount="1" width="150" height="150">
|
||||
<view
|
||||
style="width: 320rpx;height:60rpx;line-height:60rpx;background-color: #3C9CFF;border-radius: 0 0 20rpx 20rpx;"
|
||||
style="width: 320rpx;height:60rpx;line-height:60rpx;background-color: #05C341;border-radius: 0 0 20rpx 20rpx;"
|
||||
class="text-center cor-fff">
|
||||
点击
|
||||
</view>
|
||||
</u-upload>
|
||||
</view>
|
||||
</u-upload>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mt20">
|
||||
<view class="title fontColor">第二步 核实后再提交</view>
|
||||
<u--form labelPosition="left" labelWidth="80" :model="form" :rules="rules" ref="form1">
|
||||
<u-form-item label="姓名" :required="true" prop="name" borderBottom ref="item1">
|
||||
<u--input v-model="form.name" border="none"></u--input>
|
||||
<u-form-item label="姓名" :required="true" prop="idCardName" borderBottom ref="item1">
|
||||
<u--input v-model="form.idCardName" border="none"></u--input>
|
||||
</u-form-item>
|
||||
<u-form-item label="身份证号" :required="true" prop="idNum" borderBottom ref="item2">
|
||||
<u--input v-model="form.idNum" border="none"></u--input>
|
||||
<u-form-item label="身份证号" :required="true" prop="sfzmhm" borderBottom ref="item2">
|
||||
<u--input v-model="form.sfzmhm" border="none"></u--input>
|
||||
</u-form-item>
|
||||
</u--form>
|
||||
</view>
|
||||
<view style="margin-top: 20px;">
|
||||
<u-button type="primary" :style="{width: '100%',borderRadius:'40rpx'}" :disabled="saving" text="提交"
|
||||
@click="submit" />
|
||||
<u-button type="primary" :style="{width: '100%',borderRadius:'40rpx',backgroundColor:'#05C341'}"
|
||||
:disabled="saving" text="提交" @click="submit" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -42,6 +42,9 @@
|
||||
|
||||
<script>
|
||||
import storage from '@/jtools/storage';
|
||||
import {
|
||||
addInfo,
|
||||
} from '@/jtools/api/index';
|
||||
export default {
|
||||
data() {
|
||||
const shenfenzhen = (rule, value, callback) => {
|
||||
@@ -50,23 +53,25 @@
|
||||
}
|
||||
return {
|
||||
form: {
|
||||
name: '',
|
||||
idNum: ''
|
||||
idCardName: '',
|
||||
sfzmhm: storage.get('sfzNum') || ''
|
||||
},
|
||||
driverLicenseImg: '',
|
||||
fileList: [],
|
||||
fileList1: [],
|
||||
uploadList: [],
|
||||
saving: false,
|
||||
rules: {
|
||||
name: [{
|
||||
idCardName: [{
|
||||
required: true,
|
||||
message: '请输入姓名',
|
||||
trigger: ['blur', 'change']
|
||||
}],
|
||||
idNum: [{
|
||||
sfzmhm: [{
|
||||
required: true,
|
||||
message: '请输入身份证号',
|
||||
trigger: ['blur', 'change']
|
||||
},{
|
||||
}, {
|
||||
// 自定义验证函数,见上说明
|
||||
validator: shenfenzhen,
|
||||
message: '身份证号码不正确',
|
||||
@@ -77,17 +82,17 @@
|
||||
};
|
||||
},
|
||||
onReady() {
|
||||
console.log(storage.get('photoForm'));
|
||||
if(storage.get('photoForm')){
|
||||
this.fileList1=storage.get('photoForm').file
|
||||
this.form={
|
||||
name: storage.get('photoForm').name,
|
||||
idNum: storage.get('photoForm').idNum
|
||||
}
|
||||
}
|
||||
this.$refs.form1.setRules(this.rules);
|
||||
},
|
||||
methods: {
|
||||
|
||||
// 文件超出大小限制
|
||||
oversize() {
|
||||
uni.showToast({
|
||||
title: "图片最大不能超过500k",
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
// 删除图片
|
||||
deletePic(event) {
|
||||
this.fileList1.splice(event.index, 1);
|
||||
@@ -95,95 +100,94 @@
|
||||
},
|
||||
// 新增图片
|
||||
async afterRead(event) {
|
||||
// this.compressImage(event.file);
|
||||
let imageInfoObj = await uni.getImageInfo({
|
||||
src: event.file[0].url
|
||||
})
|
||||
console.log(imageInfoObj);
|
||||
if (imageInfoObj.width != 260 && imageInfoObj.height != 378) {
|
||||
uni.showToast({
|
||||
icon: 'error',
|
||||
title: '证件照尺寸有误'
|
||||
})
|
||||
this.fileList = []
|
||||
return false
|
||||
}
|
||||
this.driverLicenseImg = await this.urlTobase64(event.file[0].url)
|
||||
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
|
||||
const lists = [].concat(event.file);
|
||||
this.fileList1 = lists;
|
||||
this.fileList = lists
|
||||
this.fileList1 = [];
|
||||
uni.showToast({
|
||||
title:'上传成功!'
|
||||
title: '上传成功!'
|
||||
})
|
||||
},
|
||||
uploadFilePromise(url) {
|
||||
this.saving = true;
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: process.env.VUE_APP_BASE_API + 'mongodb/uploadFile', // 仅为示例,非真实的接口地址
|
||||
filePath: url,
|
||||
name: 'file',
|
||||
success: (res) => {
|
||||
// setTimeout(() => {
|
||||
resolve(JSON.parse(res.data).data);
|
||||
// }, 100);
|
||||
this.saving = false;
|
||||
},
|
||||
fail: () => {
|
||||
resolve(null);
|
||||
this.saving = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
// 提交
|
||||
submit() {
|
||||
this.$refs.form1.validate().then((valid) => {
|
||||
if (valid) {
|
||||
const param={
|
||||
file:this.fileList1,
|
||||
...this.form
|
||||
const param = {
|
||||
driverLicenseImg: this.driverLicenseImg,
|
||||
...this.form,
|
||||
schoolOrgCode: '340103000700',
|
||||
operater: '1d08daf852cf4ee28f67cb583f538cbf'
|
||||
}
|
||||
storage.set('photoForm',param)
|
||||
uni.showToast({
|
||||
title:"提交成功!",
|
||||
duration:2000,
|
||||
})
|
||||
setTimeout(()=>{
|
||||
uni.navigateBack()
|
||||
},1000)
|
||||
storage.set('sfzNum', this.form.sfzmhm)
|
||||
uni.request({
|
||||
url: 'https://www.hfcgs.cn:20223/driver/addInfo',
|
||||
method: 'POST',
|
||||
data: param,
|
||||
success: res => {
|
||||
console.log(res);
|
||||
uni.showToast({
|
||||
title: "提交成功!",
|
||||
duration: 2000,
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1000)
|
||||
},
|
||||
fail: () => {},
|
||||
|
||||
});
|
||||
// addInfo(param).then(resp=>{
|
||||
// if(resp.code==='0000'){
|
||||
// uni.showToast({
|
||||
// title:"提交成功!",
|
||||
// duration:2000,
|
||||
// })
|
||||
// setTimeout(()=>{
|
||||
// uni.navigateBack()
|
||||
// },1000)
|
||||
// }
|
||||
// })
|
||||
} else {
|
||||
console.log('验证失败');
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
async compressImage(image) {
|
||||
const img = new Image();
|
||||
img.src = image.url;
|
||||
|
||||
img.onload = async () => {
|
||||
const canvas = document.createElement('canvas'); // 创建Canvas对象(画布)
|
||||
const context = canvas.getContext('2d');
|
||||
// 默认按比例压缩
|
||||
const cw = img.width;
|
||||
const ch = img.height;
|
||||
let w = img.width;
|
||||
let h = img.height;
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
if (cw > 400 && cw > ch) {
|
||||
w = 400;
|
||||
h = (400 * ch) / cw;
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
}
|
||||
if (ch > 400 && ch > cw) {
|
||||
h = 400;
|
||||
w = (400 * cw) / ch;
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
}
|
||||
// 生成canvas
|
||||
let base64;
|
||||
// 创建属性节点
|
||||
context.clearRect(0, 0, 0, w, h);
|
||||
context.drawImage(img, 0, 0, w, h);
|
||||
if (image.size > 2000000) {
|
||||
// 如果图片超过2m,则进行压缩
|
||||
base64 = canvas.toDataURL(image['type'], 0.5);
|
||||
}
|
||||
const result = await this.uploadFilePromise(base64 || image.url);
|
||||
this.uploadList.push(result);
|
||||
};
|
||||
urlTobase64(url) {
|
||||
let base64 = ''
|
||||
console.log(url);
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getFileSystemManager().readFile({
|
||||
filePath: url, //选择图片返回的相对路径
|
||||
encoding: 'base64', //编码格式
|
||||
success: res => { //成功的回调
|
||||
console.log(res);
|
||||
base64 = 'data:image/jpeg;base64,' + res.data //不加上这串字符,在页面无法显示的哦
|
||||
resolve(base64);
|
||||
},
|
||||
fail: (e) => {
|
||||
console.log("图片转换失败");
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -214,4 +218,9 @@
|
||||
::v-deep .u-button--square {
|
||||
border-radius: 40rpx !important;
|
||||
}
|
||||
|
||||
::v-deep .u-button--primary {
|
||||
background-color: #05C341 !important;
|
||||
border-color: #05C341 !important;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user