<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>
					{{$t('register.tips')}}
				</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"  @on-remove="licenseRemove" :show-tips="false" :reloadText="this.$t('register.reloadText')">
					<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;">
					{{$t('register.uplicense')}}
				</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;">
					{{$t('register.uppicture')}}
				</view>
			</view>
		</u-card>
		<view style="color: #787878;margin: 0 40rpx;">
			{{$t('register.tips2')}}
		</view>
		<view style="margin: 30rpx;">
			<u-button type="primary" @click="nextStep" v-if="showLicense&&showStore">{{$t('register.nextstep')}}</u-button>
			<!-- <u-button type="primary" @click="nextStep">下一步</u-button> -->
		</view>
		<u-modal v-model="modalShow" :title="this.$t('register.tipstitle')" :content="storecontent" :show-cancel-button="true"
		 :confirm-text="this.$t('register.tipsconfirmText')" :cancel-text="this.$t('register.tipscancelText')" @cancel="cancelModal"></u-modal>
	</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,
				modalShow: false,
				storecontent: this.$t('register.tipscontent'),
				Analyse: this.$t('register.Analyse'),
				appStoreBusinessLicenseDto: ''
			};
		},
		created() {
			uni.getSystemInfo({
				success: res => {
					this.SystemInfo = res
				}
			});
			if (this.SystemInfo.platform == 'ios') {
				uni.showModal({
					title: this.$t('register.tipstitle'),
					content: this.$t('register.tipscontent'),
					cancelText: this.$t('register.tipscancelText'),
					confirmText: this.$t('register.tipsconfirmText'),
					success: res => {
						if (res.cancel) {
							uni.navigateBack({})
						}
					}
				})
			} else {
				this.modalShow = true
			}
		},
		methods: {
			nextStep() {
				if (this.Analyse != "success") {
					this.$u.toast(this.Analyse);
					return
				}
				this.$u.route({
					url: 'pages/login/register_2',
				})
				if (this.licenseDate) {
					uni.$emit('licenseData', this.licenseDate)
				}
				this.appStoreBusinessLicenseDto = {
					"address": this.licenseDate.site.words,
					"businessLicense": this.licenseDate.business.words,
					"businessScope": this.licenseDate.business.words,
					"capital": this.licenseDate.registered.words,
					"composing": this.licenseDate.certificate.words,
					"createTime": "",
					"creditCode": this.licenseDate.credit.words,
					"identityNumber": this.licenseDate.credit.words,
					"indate": this.licenseDate.validity.words,
					"legalPerson": this.licenseDate.person.words,
					"nameStatus": "",
					"organization": this.licenseDate.company.words,
					"recognition": "",
					"registerDate": this.licenseDate.establishment.words,
					"status": "",
					"storeId": 0,
					"type": this.licenseDate.type.words
				}
				uni.$emit('dataUrl', {
					licenseUrl: this.licenseUrl,
					storeUrl: this.storeUrl,
					appStoreBusinessLicenseDto: this.appStoreBusinessLicenseDto
				})
			},
			getLicensedata(res, index, lists, name) {
				if (res.statusCode == 200) {
					this.$u.toast(this.$t('register.sucupload'));
					this.showLicense = true
					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.$t('register.sucAnalyse'));
							this.licenseDate = res.data.data.wordsResultQuery
							this.Analyse = res.data.msg
						}
						if (res.data.code == 500) {
							this.$u.toast(res.data.msg);
							this.Analyse = res.data.msg
						}
					}).catch(err => {
						this.$u.toast(this.$t('register.errAnalyse'));
						this.Analyse = this.$t('register.errAnalyse')
					}).finally(() => {})
				}
			},
			getStoredata(res, index, lists, name) {
				if (res.statusCode == 200) {
					this.$u.toast(this.$t('register.sucupload'));
					this.storeUrl = JSON.parse(res.data).data
					this.showStore = true
				}
			},
			cancelModal() {
				uni.navigateBack({})
			},
			licenseRemove() {
				this.$u.toast(this.$t('register.delupload'));
				this.showLicense = false
				this.Analyse = this.$t('register.Analyse')
			},
			storeRemove() {
				this.showStore = false
			}
		},
	}
</script>

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