leaseAdd.vue 5.84 KB
<template>
	<view class="page">
		<view>
			<u-form labelPosition="left" :model="model1" ref="uForm" :labelWidth="250">
				<view class="add-list">
					<u-form-item label="经营者姓名" prop="name" borderBottom>
						<u-input v-model="model1.name"></u-input>
					</u-form-item>
			<!-- 		<u-form-item label="手机号" prop="phone" borderBottom>
						<u-input v-model="model1.phone"></u-input>
					</u-form-item> -->
		<!-- 			<u-form-item label="证件类型" prop="idCardType" borderBottom>
						<u-input v-model="model1.idCardType" type="select" @click="IdtypeShow = true"
							placeholder='请选择类型' />
					</u-form-item> -->
					<u-form-item label="身份证号码" prop="idCardNumber" borderBottom>
						<u-input v-model="model1.idCardNumber"></u-input>
					</u-form-item>
				</view>
				<view class="add-list">
					<view class="deom-box">
						<view class="img-deom">
							<u-upload :action="url" @on-choose-complete="onsuccess1" :auto-upload="false"
								:custom-btn="true" :max-count="1" ref="idPhotoFront">
								<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover"
									hover-stay-time="150">
									<u-image width="304rpx" height="182rpx" :src="$imgUrl('/uploadID1.png')"></u-image>
								</view>
							</u-upload>
							<text>点击上传证件人像面</text>
						</view>
						<view class="img-deom">
							<u-upload :action="url" @on-choose-complete="onsuccess2" :auto-upload="false" :custom-btn="true" :max-count="1"
								ref="idPhotoBack">
								<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover"
									hover-stay-time="150">
									<u-image width="304rpx" height="182rpx" :src="$imgUrl('/uploadID2.png')"></u-image>
								</view>
							</u-upload>
							<text>点击上传证件国徽面</text>
						</view>
					</view>
				</view>
				<view class="add-list">
					<view style="line-height: 60rpx;">上传示例</view>
					<view class="deom-box">
						<view class="img-deom">
							<u-image width="304rpx" height="182rpx" :src="$imgUrl('/front-icon.png')"></u-image>
							<text>人脸示例图</text>
						</view>
						<view class="img-deom">
							<u-image width="304rpx" height="182rpx" :src="$imgUrl('/back-icon.png')"></u-image>
							<text>国徽面示例图</text>
						</view>
					</view>
				</view>
				<text
					style="display: inline-block; font-size: 24rpx; line-height: 30px; margin: 24rpx 30rpx 0;">请拍摄证件原件,保证照片拍摄清晰,取图完整,不反光。</text>
			</u-form>
		</view>
		<u-select v-model="IdtypeShow" :list="idType" @confirm="IdtypeChange"></u-select>
		<!-- 保存按钮 -->
		<view class="page-footer">
			<u-button type="success" style="flex: 1; margin: 0 10px;" @click="go">提交申请</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: 'http://8.130.38.56:9003/file/upload',
				model1: {
					name: '',
					phone: '',
					idCardType: '身份证',
					idCardNumber: '',
					idCardFrontImage: '',
					idCardBackImage: '',
					checkState: '1',
					applyTime: ''
				},
				idType: [{
					value: 1,
					label: '身份证'
				}, ],
				IdtypeShow: false,
				fileList1: [],
				fileList2: [],
			};
		},
		onLoad() {

		},
		onShow() {


		},
		methods: {
			getCurrentTime() {
				const now = new Date();
				const year = now.getFullYear();
				const month = ('0' + (now.getMonth() + 1)).slice(-2);
				const day = ('0' + now.getDate()).slice(-2);
				const hours = ('0' + now.getHours()).slice(-2);
				const minutes = ('0' + now.getMinutes()).slice(-2);
				const seconds = ('0' + now.getSeconds()).slice(-2);

				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
			go() {
				if (!this.model1.idCardNumber) {
					uni.showToast({
						icon: 'none',
						title: '请输入身份证号码'
					});
					return false;
				}
	
				this.model1.applyTime = this.getCurrentTime()
				this.model1.idCardFrontImage = this.fileList1.join(',')
				this.model1.idCardBackImage = this.fileList2.join(',')
				if (!this.model1.idCardFrontImage) {
					uni.showToast({
						icon: 'none',
						title: '请上传身份证照片'
					});
					return false;
				}
				if (!this.model1.idCardBackImage) {
					uni.showToast({
						icon: 'none',
						title: '请上传身份证照片'
					});
					return false;
				}
				this.model1.username = this.model1.name
				this.model1.phone = uni.getStorageSync('user').phone
				console.error({
					...this.model1
				})
				// return
				this.$http.sendRequest('/cerePlatformMerchant/add', 'POST', this.model1, 2).then(res => {
					console.error(res)
					if (res.data.code) {
						uni.showToast({
							icon: 'none',
							title: '提交申请成功'
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1000);
					} else {
						uni.showToast({
							icon: 'none',
							title: '提交申请失败'
						})
					}
				})
			},
			onup(e,e1) {
				uni.uploadFile({
					url: this.$upload, // 仅为示例,请替换为您的服务器上传接口
					filePath: e,
					name: 'file', // 后端接收的文件参数名
					formData: {
						filePath: 'xcx', // 其他表单数据
					},
					success: (uploadFileRes) => {
						console.log('上传成功', uploadFileRes);
						uni.showToast({
							title: '上传成功',
							icon: 'success',
						});
						this[e1].push(JSON.parse(uploadFileRes.data).data)
					},
					fail: (err) => {
						console.error('上传失败', err);
						uni.showToast({
							title: '上传失败',
							icon: 'none',
						});
					},
				});
			},
			onsuccess1(e) {
				console.error(e)
				this.fileList1 = []
				this.onup(e[0].url,'fileList1')
			},
			onsuccess2(e) {
				console.error(e)
				this.fileList2 = []
				this.onup(e[0].url,'fileList2')
				
			},
			IdtypeChange(e) {
				this.model1.idCardType = e[0].label;
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'leaseAdd.scss';
</style>