<template>
	<view class="content">
		<view class="headbox">
			<text class="headtitle">供货商注册</text>
			<view class="logobox">
				<image src="../../static/img/logo.png" mode="aspectFill"></image>
			</view>
		</view>
		<view class="acountbox">
			<view class="inacount">
				<text class="acoutitle">供货商</text>
				<input type="text" v-model="form.name" class="checkword" placeholder="请输入供货商名称"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">统一社会信用代码</text>
				<input type="text" v-model="form.socialCode" class="checkword" placeholder="请输入统一社会信用代码"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">法人姓名</text>
				<input type="text" v-model="form.legalPerson" class="checkword" placeholder="请输入法人姓名"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">联系人</text>
				<input type="text" v-model="form.contacts" class="checkword" placeholder="请输入联系人"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">联系电话</text>
				<input type="number" v-model="form.contactsMobile" class="checkword" placeholder="请输入联系电话"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view>
				<view class="inacount" style="flex-direction: column;align-items: center;background-color: #fff;">
					<text class="acoutitle" style="flex: 1;width: 100%;">认证照片</text>
					<view class="upmsg">

						<view class="uppic" style="padding-top: 80rpx;font-weight:600 ;" @click="upImages(1)"
							v-if="form.identifyPics.length==0">
							<text>点击上传照片</text>
						</view>
						<image :src="form.identifyPics" mode="aspectFill" v-if="form.identifyPics.length>0" @click="upImages(1)"></image>
					</view>
					<text style="font-size: 24rpx;color: #D05C39;padding-top: 20rpx;">*注意上传法人手持身份证半身照</text>
				</view>
			</view>
			<view>
				<view class="inacount"
					style="flex-direction: column;align-items: center;background-color: #fff;margin-top:0 ;">
					<text class="acoutitle" style="flex: 1;width: 100%;">授权委托书</text>
					<view class="upmsg">

						<view class="uppic" style="padding-top: 80rpx;font-weight:600 ;" @click="upImages(2)" v-if="form.proxyFile.length==0">
							<text>点击上传照片</text>
						</view>
						<image :src="form.proxyFile" mode="aspectFill" v-if="form.proxyFile.length>0" @click="upImages(1)"></image>
					</view>
					<text style="font-size: 24rpx;color: #D05C39;padding-top: 20rpx;">*注意上传法人签署的授权委托书</text>
				</view>
			</view>
		</view>
		<view class="logininbtn" @click="acountRegister">
			<text>下一步</text>
		</view>
		<view class="safebt"></view>

	</view>
</template>

<script>
	import {
		mainUrl
	} from '@/http/baseUrl.js';
	let that
	export default {
		data() {
			return {
				checked: 1,
				form: {
					name: '',
					socialCode: '',
					legalPerson: '',
					password: '',
					contacts: '',
					contactsMobile: '',
					identifyPics: [],
					proxyFile: []
				},
			}
		},
		onLoad(o) {
			that = this
			if (o.checked) {
				this.checked = o.checked
			}
		},
		methods: {
			acountRegister() {
				
				let form=this.form
				if(form.name.length==0){
					this.$toast("请输入供货商名称")
					return
				}
				if(form.socialCode.length==0){
					this.$toast("请输入统一社会信用代码")
					return
				}
				if(form.legalPerson.length==0){
					this.$toast("请输入法人姓名")
					return
				}
				if(form.contacts.length==0){
					this.$toast("请输入联系人")
					return
				}
				if(form.contactsMobile.length==0){
					this.$toast("请输入联系电话")
					return
				}
				if(form.identifyPics.length==0){
					this.$toast("请上传认证照片")
					return
				}
				if(form.proxyFile.length==0){
					this.$toast("请上传授权委托书")
					return
				}
				form.checked=1
				console.log(form)
				uni.navigateTo({
					url: "/pages/bsinessadmin/register?form="+JSON.stringify(form)
				})
			},

			upImages(e) {
				if (e == 1) {
					this.chooseImage(1)

				} else if (e == 2) {
					this.chooseImage(2)
				}
			},
			chooseImage(u) {
				uni.chooseImage({
					count: 1,
					success: function(e) {
						for (let i in e.tempFilePaths) {
							let ui = that.upText(e.tempFilePaths[i], u)
						}

					},
					complete: function(e) {
						// 触发事件 tabEvent
						return []
					}
				})

			},
			upText(e, i) {
				var list = []
				uni.showLoading({
					
				})
				uni.uploadFile({
					url: mainUrl + '/api/File',
					filePath: e,
					name: 'File',
					fileType: 'image',
					header: {
						"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)"
					},
					formData: {
						File: JSON.stringify(e),
						// file_name: fileName,
					},
					success(re) {
						uni.hideLoading()
						let res = JSON.parse(re.data)
						if (res.code == 200) {
							if (i == 1) {
								that.form.identifyPics.push(res.data.file)
							} else if (i == 2) {
								that.form.proxyFile.push(res.data.file)
							}

						} else {
							uni.showModal({
								title: '',
								content: res.msg,
								showCancel: false,
							});
						}
					},
					fail(e) {
						if (e && e.msg) {
							uni.showModal({
								title: '错误',
								content: e.msg,
								showCancel: false,
							});
						}
					},
				});

			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {

		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.headbox {
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
	}

	.headtitle {
		font-size: 60rpx;
		font-weight: 600;
		padding-bottom: 36rpx;
	}

	.logobox {
		width: 269rpx;
		height: 191rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.acountbox {
		.upmsg {
			margin-top: 20rpx;
			background-color: #F6F6F6;
			width: 690rpx;
			height: 399rpx;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			overflow:hidden;
			image {
				width: 100%;
				height: 100%;
				
			}
		}

		.uppic {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 500rpx;
			height: 250rpx;
			background-image: url("@/static/img/upuer.png");
			background-size: 100%;
		}

		.inacount {
			flex: 1;
			display: flex;
			padding: 35rpx 20rpx;
			box-sizing: border-box;
			// width: 606rpx;
			margin-top: 40rpx;
			background-color: #F6F6F6;
			border-radius: 20rpx;
			font-size: 30rpx;
			color: #1F242A;

			input {
				width: 360rpx;
			}
		}

		.acoutitle {
			font-weight: 600;
		}

		.checkword {
			padding-left: 20rpx;
			color: #1F242A;
			font-size: 30rpx;
		}
	}

	.logininbtn {
		box-sizing: border-box;
		margin-top: 140rpx;
		// width: 606rpx;
		flex: 1;
		border-radius: 20rpx;
		border: 1rpx solid #BEBDBB;
		height: 100rpx;
		text-align: center;
		color: #BEBDBB;
		line-height: 100rpx;
		margin-bottom: 100rpx;
	}

	.acountall {
		display: flex;
		justify-content: flex-end;
		margin-top: 30rpx;
		font-size: 24rpx;
	}

	.checkag {
		margin-top: 200rpx;
		font-size: 28rpx;
		margin-bottom: 150rpx;
	}
</style>
