<template>
	<view class="Box">
		<navseat :opacity='false' :title='"完善商户信息"' :titleshow='true' :namecolor='"#fff"' iconcolor='#fff'></navseat>
		<view class="Box_box_O">
			<view class="Box_box flex-between">
				<view>请填写公司名字</view>
				<view class="Box_box_input"><input type="text" :disabled="disabled" v-model="form.title"
						placeholder="请填写" data-key="mobile" /></view>
			</view>
			<view class="Box_box flex-between">
				<view>请填写法人姓名</view>
				<view class="Box_box_input"><input type="text" :disabled='disabled' v-model="form.legal_person_name"
						placeholder="请填写" data-key="mobile" /></view>
			</view>
			<view class="Box_box flex-between">
				<view>请填写法人手机号</view>
				<view class="Box_box_input"><input type="number" :disabled='disabled' v-model="form.phone"
						placeholder="请填写" data-key="mobile" /></view>
			</view>
		</view>
		<view class="Box_box_T">
			<view class="Box_box_T_o">请上传法人身份证图片</view>
			<view class="flex-colum" style="width: 100%;">
				<view class="Box_box_d" v-if="form.id_card_straight" @click="Upload(0)">
					<image :src="form.id_card_straight" mode=""></image>
				</view>
				<view v-else class="Box_box_Ts" @click="Upload(0)"></view>
			</view>
			<view class="Box_box_T_o">请上传法人国徽身份证图片</view>
			<view class="flex-colum" style="width: 100%;">
				<view class="Box_box_d" v-if="form.id_card_reverse" @click="Upload(1)">
					<image :src="form.id_card_reverse" mode=""></image>
				</view>
				<view v-else class="Box_box_Ts" @click="Upload(1)"></view>
			</view>
			<view class="Box_box_T_o">请拍摄并上传你的营业执照</view>
			<view class="flex-colum" style="width: 100%;">
				<view class="Box_box_d" v-if="form.business_license" @click="Upload(2)">
					<image :src="form.business_license" mode=""></image>
				</view>
				<view v-else class="Box_box_Ts" @click="Upload(2)"></view>
			</view>
		</view>
		<view class="preservation flex-colum">
			<view v-if="form.status == '2'" style="color: #FF2B2B; padding: 28rpx 0;">
				({{form.no|| '无'}})</view>
			<view v-if="disabled" class="preservation_boxs">审核中</view>
			<view v-else class="preservation_box" @tap="$u.throttle(saveMerchantBaseInfoV2, 1000)">提交</view>

		</view>
	</view>
</template>
<script>
	import uploadImage from "@/js_sdk/yushijie-ossutil/ossutil/uploadFile.js";
	import navseat from '@/components/navseat.vue'
	export default {
		components: {
			navseat
		},
		data() {
			return {
				disabled: true,
				Uploadurlnumber: '',
				namelang: '',
				merchantAuditStatus: '',
				form: {
					store_id: uni.getStorageSync('userId'),
					title: '',
					id_card_straight: '',
					id_card_reverse: '',
					business_license: '',
					phone: '',
					legal_person_name: '',
					no: ''
				}
			};
		},
		onLoad(e) {
			if (e.status == '0') {
				this.disabled = true
			} else {
				this.disabled = false
			}
			if (e.phone) {
				this.form.store_id = uni.getStorageSync('userId')
				this.form.title = e.title
				this.form.status = e.status
				this.form.id_card_straight = e.id_card_straight
				this.form.id_card_reverse = e.id_card_reverse
				this.form.business_license = e.business_license
				this.form.phone = e.phone
				this.form.legal_person_name = e.legal_person_name
				this.form.no = e.no
			}
		},
		onShow() {},
		methods: {
			Upload(i) {
				if (this.disabled) {
					return false;
				} else {
					uni.showLoading({
						title: '上传中',
						mask: true
					})
					this.Uploadurlnumber = i;
					uni.chooseImage({
						count: 1, //默认9
						sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album', 'camera'], //从相册选择，和摄像头功能，默认二者都有
						success: res => {
							var thisimgUrlcaca = res.tempFilePaths[0];
							uploadImage(thisimgUrlcaca, 'merchantinformation/',
								result => {
									//将上传后的图片以对象（官方要求的格式）的形式存入uni-file-picker的value值imageValue（imageValue值的结构为数组包对象）用于图片回显
									console.log(result)
									uni.showToast({
										title: '上传成功',
										icon: 'none',
										success: () => {

										}
									});
									if (this.Uploadurlnumber == 0) {
										this.form.id_card_straight = result
									} else if (this.Uploadurlnumber == 1) {
										this.form.id_card_reverse = result
									} else {
										this.form.business_license = result
									}
									uni.hideLoading()
								}, result => {
									uni.hideLoading()
									uni.showToast({
										title: result.message || result.msg,
										icon: 'none',
									});
								})


						}
					});
				}

			},
			async saveMerchantBaseInfoV2() {
				if (this.form.title == null || this.form.title == '') {
					uni.showToast({
						title: '请填写公司名字',
						icon: 'none'
					});
					return false;
				}
				if (this.form.phone == null || this.form.phone == '') {
					uni.showToast({
						title: '请填写法人手机号',
						icon: 'none'
					});
					return false;
				}
				if (this.form.legal_person_name == null || this.form.legal_person_name == '') {
					uni.showToast({
						title: '请填写法人姓名',
						icon: 'none'
					});
					return false;
				}
				if (this.form.id_card_straight == null || this.form.id_card_straight == '') {
					uni.showToast({
						title: '请上传身份证人像面',
						icon: 'none'
					});
					return false;
				}
				if (this.form.id_card_reverse == null || this.form.id_card_reverse == '') {
					uni.showToast({
						title: '请上传身份证国徽面',
						icon: 'none'
					});
					return false;
				}
				if (this.form.business_license == null || this.form.business_license == '') {
					uni.showToast({
						title: '请上传营业执照',
						icon: 'none'
					});
					return false;
				}
				// if (/[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/ig
				// 	.test(this.form.alias)) {
				// 	uni.showToast({
				// 		title: '请不要输入Emoji!!!',
				// 		icon: 'none'
				// 	});
				// 	return false;
				// }
				let res = await this.api.storestoreinfo(this.form)
				uni.showToast({
					title: res.message || res.msg,
					icon: 'none',
					success: () => {
						uni.hideLoading();
					}
				});
				if (res.code == 1) {
					setTimeout(() => {
						uni.navigateBack();
					}, 2000);
				}
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.Box {
		.Box_box_O {
			padding: 0 28rpx;

			.Box_box {
				text-align: right;
				padding: 24rpx;
				border-bottom: 1px solid #e5e5e5;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #333333;

				.Box_box_input {
					width: 60%;
				}
			}
		}

		.Box_box_T {
			padding: 0 28rpx;
			border-top: 16rpx solid #e5e5e5;

			.Box_box_T_o {
				padding: 28rpx 0;
				text-align: center;
			}

			.flex-colum {
				image {
					width: 396rpx;
					height: 240rpx;
				}

				padding-bottom: 16rpx;
				border-bottom: 1px solid #e5e5e5;

				.Box_box_Ts {
					width: 396rpx;
					height: 240rpx;
					background: #ffffff;
					border-radius: 8rpx;
					border: 2rpx dashed #707070;
					background: url(https://czg-invoicing.oss-cn-beijing.aliyuncs.com/static/my2.png) no-repeat;
					background-position: 50% 50%;
					background-size: 50%;
				}
			}
		}

		.preservation {
			width: 100%;
			padding-bottom: 50rpx;

			.preservation_box {
				width: 70%;
				height: 72rpx;
				background: #288efb;
				text-align: center;
				line-height: 72rpx;
				border-radius: 50rpx;
				font-size: 36rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #ffffff;
			}

			.preservation_boxs {
				width: 70%;
				height: 72rpx;
				background: #999999;
				text-align: center;
				line-height: 72rpx;
				border-radius: 50rpx;
				font-size: 36rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #ffffff;
			}
		}
	}
</style>