<template>
	<view>
		<u-card :border="false" padding="30" box-shadow="0px 1px 10px rgba(0,0,0,0.2)" border-radius="20" :show-foot="false">
			<view slot="head">
				<view class="u-flex">
					<view style="width: 8rpx;height: 34rpx;background: #0292FD;margin-right:20rpx;"></view>
					请按照要求上传您的营业执照和门店照
				</view>
			</view>
			<view slot="body">
				<u-upload :custom-btn="true" max-count="1" class="u-flex u-row-center" :action="action" :form-data="licensepicType"
				 @on-change="getLicensedata">
					<view slot="addBtn" hover-class="slot-btn__hover" hover-stay-time="150">
						<u-image width="475rpx" height="303rpx" src="../../static/sailun/upload_preview.png"></u-image>
					</view>
				</u-upload>
				<view class="u-flex u-row-center" style="color: #787878;margin: 20rpx 0 60rpx 0;">
					点击上传营业执照
				</view>
				<u-upload :custom-btn="true" max-count="1" class="u-flex u-row-center" :action="action" :form-data="storepicType"
				 @on-change="getStoredata">
					<view slot="addBtn" hover-class="slot-btn__hover" hover-stay-time="150">
						<u-image width="475rpx" height="303rpx" src="../../static/sailun/upload_preview.png"></u-image>
					</view>
				</u-upload>
				<view class="u-flex u-row-center" style="color: #787878;margin: 20rpx 0;">
					点击上传门头照
				</view>
			</view>
		</u-card>
		<view style="color: #787878;margin-left: 40rpx;">
			注：上传完营业执照请确认和营业执照一致。
		</view>
		<view style="margin: 30rpx;">
			<!-- <u-button type="primary" @click="nextStep" v-if="showLicense&&showStore">下一步</u-button> -->
						<u-button type="primary" @click="nextStep">下一步</u-button>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '../../common/request/request'
	require("promise.prototype.finally").shim()
	export default {
		data() {
			return {
				action: "http://b2bcnapi.sailuntire.com/allstell/test/app/sailun/appStoreBasicInfo/storeupload",
				licensepicType: {
					"pictype": "license"
				},
				storepicType: {
					"pictype": "store"
				},
				showLicense:false,
				showStore:false,
			};
		},
		methods: {
			nextStep() {
				this.$u.route({
					url: 'pages/login/register_2',
				})
				if(this.licenseDate){
					uni.$emit('licenseData',this.licenseDate)
				}
				uni.$emit('dataUrl',{licenseUrl:this.licenseUrl,storeUrl:this.storeUrl})
			},
			getLicensedata(res, index, lists, name) {
				if (res.statusCode == 200) {
					this.$u.toast('上传成功');
					uni.hideLoading();
					this.licenseUrl = JSON.parse(res.data).data
					request({
						url: '/sailun/appStoreBasicInfo/licenseAnalyse',
						method: 'post',
						data: {
							"fileBox": this.licenseUrl,
						}
					}).then(res => {
						if (res.data.code == 0) {
							this.$u.toast('识别成功');
							this.licenseDate = res.data.data.wordsResultQuery
							this.showLicense=true
						}
						if (res.data.code == 500) {
							this.$refs.uToast.show({
								title: res.data.msg,
							})
						}
					}).catch(err => {
						this.$u.toast('识别失败');
					}).finally(() => {})
				}
			},
			getStoredata(res, index, lists, name) {
				if (res.statusCode == 200) {
					this.$u.toast('上传成功');
					this.storeUrl = JSON.parse(res.data).data
					this.showStore=true
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.slot-btn__hover {
		background-color: rgb(235, 236, 238);
	}
</style>
