<template>
</template>

<script>
</script>

<style>
</style><template>
	<view class="page">
		<view class="steps-box">
			<u-steps :list="numList" :current="active"></u-steps>
		</view>
		<view>
			<view class="add-list" v-show="active == 0">
				<u-form labelPosition="left" :model="model1" :rules="rules" ref="uForm" :labelWidth="250">
					<u-form-item label="租用开始时间" prop="rentalPeriodStartTime" borderBottom>
						
				<u-input v-model="model1.rentalPeriodStartTime" type="select" @click="TimeStratshow = true" placeholder="请选择"/>
				<u-picker mode="time" v-model="TimeStratshow" :params="params" @confirm="startTimeChange"></u-picker>			
					</u-form-item>
					<u-form-item label="租用结束时间" prop="rentalPeriodEndTime" borderBottom>	
					<u-input v-model="model1.rentalPeriodEndTime" type="select" @click="TimeEndshow = true" placeholder="请选择"/>
					<u-picker mode="time" v-model="TimeEndshow" :params="params" @confirm="EndTimeChange"></u-picker>			

					</u-form-item>
					<u-form-item label="租期" prop="leaseTerm" borderBottom>
						<u-input v-model="model1.leaseTerm" placeholder="请输入/年或/月或/日" ></u-input>
					</u-form-item>
					<u-form-item label="意向经营类型" prop="intentionalBusinessType" borderBottom>
						<u-input v-model="model1.intentionalBusinessType" type="select" @click="leiXpopup = true" placeholder="请选择"/>
					</u-form-item>
					<u-form-item label="意向区域（如有）" prop="intendedArea" borderBottom>
						<u-input v-model="model1.intendedArea" ></u-input>
					</u-form-item>
					<u-form-item label="意向商铺位置（如有）" prop="intentionalStoreLocation" borderBottom>
						<u-input v-model="model1.intentionalStoreLocation" ></u-input>
					</u-form-item>
					<u-form-item label="意向商铺名称（如有）" prop="intentionalStoreName" borderBottom>
						<u-input v-model="model1.intentionalStoreName" ></u-input>
					</u-form-item>
				</u-form>
			</view>
			
			<view class="add-list" v-show='active == 1'>
				<u-form labelPosition="left" :model="model1" :rules="rules" ref="uForm" :labelWidth="250">
					<u-form-item label="主体名称" prop="subjectName" borderBottom>
						<u-input v-model="model1.subjectName" ></u-input>
					</u-form-item>
					<u-form-item label="统一社会信用代码" prop="unifiedSocialCreditCode" borderBottom>
						<u-input v-model="model1.unifiedSocialCreditCode" ></u-input>
					</u-form-item>
					<u-form-item label="类型" prop="type" borderBottom>
						<u-input v-model="model1.type" type="select" @click="typeShow = true" placeholder='请选择类型'/>
					</u-form-item>
					<u-form-item label="法定代表人" prop="legalRepresentative" borderBottom>
						<u-input v-model="model1.legalRepresentative" ></u-input>
					</u-form-item>
					<u-form-item label="经营范围" prop="businessScope" borderBottom>
						<u-input v-model="model1.businessScope" ></u-input>
					</u-form-item>
					<u-form-item label="注册资本" prop="registeredCapital" borderBottom>
						<u-input v-model="model1.registeredCapital" ></u-input>
					</u-form-item>
					<u-form-item label="成立日期" prop="establishmentDate" borderBottom>
						<u-input v-model="model1.establishmentDate" ></u-input>
					</u-form-item>
					<u-form-item label="住所" prop="address" borderBottom>
						<u-input v-model="model1.address" ></u-input>
					</u-form-item>
					<u-form-item label="邮箱地址" prop="emailAddress" borderBottom>
						<u-input v-model="model1.emailAddress" ></u-input>
					</u-form-item>
					<u-form-item label="经营开始时间" prop="businessStartTime" borderBottom>
						<u-input v-model="model1.businessStartTime" type="select" @click="busStartshow = true" placeholder="请选择"/>
						<u-picker mode="time" v-model="busStartshow" :params="params" @confirm="busStTimeChange"></u-picker>	
					</u-form-item>
					<u-form-item label="经营结束时间" prop="businessEndTime" borderBottom>
						<u-input v-model="model1.businessEndTime" type="select" @click="busEndtshow = true" placeholder="请选择"/>
						<u-picker mode="time" v-model="busEndtshow" :params="params" @confirm="busEndTimeChange"></u-picker>	
					</u-form-item>
					
					<u-form-item label="营业执照" prop="businessLicense" borderBottom labelPosition="top">
						<u-upload :action="$upload"  :auto-upload="true"  ref="businessLicense" :max-count="1" ></u-upload>
					</u-form-item>
				</u-form>
			</view>
			<view v-show='active == 2'>
				<u-form labelPosition="left" :model="model1" :rules="rules" ref="uForm" :labelWidth="250">
					<view class="add-list">
						<u-form-item label="经营者姓名" prop="intentCustomerName" borderBottom>
							<u-input v-model="model1.intentCustomerName" ></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>
						
						<u-form-item label="身份证有效开始时间" prop="idCardValidStart" borderBottom>
							<u-input v-model="model1.idCardValidStart" type="select" @click="idCardStartshow = true" placeholder="请选择"/>
							<u-picker mode="time" v-model="idCardStartshow" :params="params1" @confirm="idCardStTimeChange"></u-picker>	
						</u-form-item>
						<u-form-item label="身份证有效结束时间" prop="idCardValidEnd" borderBottom>
							<u-input v-model="model1.idCardValidEnd" type="select" @click="idCardEndtshow = true" placeholder="请选择"/>
							<u-picker mode="time" v-model="idCardEndtshow" :params="params1" @confirm="idCardEndTimeChange"></u-picker>	
						</u-form-item>
					</view>
					<view class="add-list">
						<view class="deom-box">
							<view class="img-deom">
								<u-upload :action="$upload"  :custom-btn="true" :max-count="1" ref="idCardzhen">
									<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="$upload"  :custom-btn="true" :max-count="1"  ref="idCardFan">
									<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>
					<view class="add-list" labelPosition="left" :model="model1" :rules="rules" ref="uForm" :labelWidth="250">
						<u-form-item label="是否为法人" prop="isLegalPerson" borderBottom>
							<u-radio-group v-model="model1.isLegalPerson">
								<u-radio :name="1">是</u-radio>
								<u-radio :name="0">否</u-radio>
							</u-radio-group>
						</u-form-item>
						<u-form-item label="企业授权书" prop="enter" borderBottom labelPosition="top">
							<u-upload :action="$upload"  :auto-upload="true"  ref="enter" :max-count="1" ></u-upload>
						</u-form-item>
					</view>
				</u-form>
			</view>
		</view>
		<u-toast ref="uToast" />
		<u-select v-model="leiXpopup" mode="mutil-column-auto" :list="leiXinglist" @confirm="leiXpops" label-name="label" value-name="value"></u-select>
		<u-select v-model="typeShow" :list="activesType" @confirm="typeChange"></u-select>
		<u-select v-model="IdtypeShow" :list="idType" @confirm="IdtypeChange"></u-select>
		
		<!-- 保存按钮 -->
		<view class="page-footer">
			<u-button style="background-color: #DFE0E4; flex: 1; margin: 0 10px;" @click="toBefor" v-if="active != 0">上一步</u-button>
			<u-button type="success" style="flex: 1; margin: 0 10px;" @click="toNext" v-if="active != 2">下一步</u-button>
			<u-button type="success" style="flex: 1; margin: 0 10px;" @click="go" v-if="active == 2">提交申请</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active: 0,
				numList: [{name: '意向申请'}, {name: '主体信息'}, {name: '经营者信息'}],
				// model1: {
				// 	name: '',
				// 	type: '',
				// 	typeShow: false,
				// 	fileList: [], // 文件列表
				// },
				model1: {
				  intentCustomerName: '', //意向客户名称
				  contactPhone: '', //联系电话
				  entityType: '', //主体类型
				  customerLevel: '', //客户级别
				  isLegalPerson: '', //是否为法人(0:否,1:是)
				  enterpriseAuthorization: '', //企业授权书
				  idCardNumber: '', //身份证号
				  idCardType: '', //证件类型
				  idCardValidStart: '', //身份证有效开始时间
				  idCardValidEnd: '', //身份证有效结束时间
				  idCardPhotoFront: '', //身份证照片(正面)
				  idCardPhotoBack: '', //身份证照片(反面)
				  subjectName: '', //主体名称
				  unifiedSocialCreditCode: '', //统一社会信用代码
				  type: '', //类型(可能是企业类型等)
				  legalRepresentative: '', //法定代表人
				  businessScope: '', //经营范围
				  registeredCapital: '', //注册资本
				  establishmentDate: '', //成立日期
				  address: '', //住所
				  emailAddress: '', //邮箱地址
				  businessStartTime: '', //营业开始时间(如果为全天，则可为NULL或指定默认时
				  businessEndTime: '', //营业结束时间(如果为全天，则可为NULL或指定默认时
				  businessLicense: '', //营业执照(存储路径或URL)
				  intendedResources: '', //意向资源
				  auditStatus:'1',
				  rentalPeriodStartTime:'',
				  rentalPeriodEndTime:'',
				  leaseTerm:'',
				  rent:'',
				  intentionalBusinessType:'',
				  intendedArea:'',
				  intentionalStoreLocation:'',
				  intentionalStoreName:''
				},
				TimeStratshow:false,
				TimeEndshow:false,
				rules: {},
				// 类型
				showType: false,
				activesType: [
					{value:1 , label: '个人'},
					{value:2 , label: '企业'},
				],
				idType: [
					{value:1 , label: '身份证'},
				],
				
				// 上传文件
				active: '', // 地址
				ziyuanId:'',
				params: {
					year: true,
					month: true,
					day: true,
				},
				params1: {
					year: true,
					month: true,
					day: true
				},
				leiXinglist: [{
						value: '商铺',
						label: '商铺'
					},
					{
						value: '场地',
						label: '场地'
					},
					{
						value: '广告位',
						label: '广告位'
					}
				],
				leiXpopup :false,
				typeShow:false,
				IdtypeShow:false,
				busStartshow:false,
				busEndtshow:false,
				idCardStartshow:false,
				
				idCardEndtshow:false,
				
			}
		},
		onLoad(option) {
			this.ziyuanId = option.ids
		},
		onShow() {
		let shopId = {
			shopId:uni.getStorageSync('shopId') || ''
		}
		  const isLogin = uni.getStorageSync('token');
		  if (isLogin =='') { 
		    // 如果未登录，跳转到登录页面
		        	uni.navigateTo({
		        	  url: '/pages/login/login'
		        	})
		  }else{
			  let page={
				condition:2
			  }
			 this.$http.sendRequest('/shop/getById', 'POST',shopId).then(res => {
				 if(res.data.code !="20004"){
					 this.shopMsg = res.data.data
					 this.Islogin= false
					 this.$http.sendRequest('/index/index', 'POST',page).then(res => {
					 	//成功回调
					 	this.tongji = res.data.data
					 })
				 }else{
					 uni.navigateTo({
					   url: '/pages/login/login'
					 })
				 }
			 })
		  }		
		
		},
		methods:{
			startTimeChange(val) {
				this.model1.rentalPeriodStartTime = this.timeChange(val)
				this.model1.rentalPeriodEndTime = ''
			},
			EndTimeChange(val){
				const time = this.timeChange(val);
				if(new Date(time).getTime() > new Date(this.model1.rentalPeriodStartTime).getTime()) {
					this.model1.rentalPeriodEndTime= time
				} else {
					this.$refs.uToast.show({
						title: '结束时间不能小于开始时间',
						type: 'error',
					})
				}
			},
			timeChange(val) {
				const { year, month, day} = val;
				return `${year}-${month}-${day}`;	
			},
			timeChange1(val) {
				const { year, month, day } = val;
				return `${year}-${month}-${day}`;
			},
			typeChange(e) {
				this.model1.type = e[0].label;
			},
			IdtypeChange(e) {
				this.model1.idCardType = e[0].label;
			},
			go(){
				let  busfiles = []
				let idfilesz = []
				let idfilesf= []
				let enterper= []
				// 通过filter，筛选出上传进度为100的文件(因为某些上传失败的文件，进度值不为100，这个是可选的操作)
				busfiles = this.$refs.businessLicense.lists.filter(val => {
					return val.progress == 100;
				})
				idfilesz = this.$refs.idCardzhen.lists.filter(val => {
					return val.progress == 100;
				})
				idfilesf = this.$refs.idCardFan.lists.filter(val => {
					return val.progress == 100;
				})
				enterper = this.$refs.enter.lists.filter(val => {
					return val.progress == 100;
				})
				
				busfiles.map(item=>{
					this.model1.businessLicense  = item.response.data.url
				})
				idfilesz.map(item=>{
					this.model1.idCardPhotoFront  = item.response.data.url
				})
				idfilesf.map(item=>{
					this.model1.idCardPhotoBack  = item.response.data.url
				})
				enterper.map(item=>{
					this.model1.enterpriseAuthorization  = item.response.data.url
				})
				   this.model1.intendedResources  =  this.ziyuanId
				 this.model1.createUser =  uni.getStorageSync('shopId')
				this.$http.sendRequest('/cereCustomerInfo/add', 'POST',this.model1,1).then(res => {
				     uni.switchTab({
				     	url: '/pages/home/home'
				     })
				})
				// uni.navigateTo({
				// 	url: '/pages/record/record'
				// })
			},
			// 上一步
			toBefor() {
				this.active = +this.active - 1;
			},
			// 下一步
			toNext() {
				this.active = +this.active + 1;
			},
			leiXpops(val){	
				this.model1.intentionalBusinessType =  val[0].label
			},
			busStTimeChange(val){
				this.model1.businessStartTime = this.timeChange(val)
				this.model1.businessEndTime = ''
			},
			busEndTimeChange(val){
				const time = this.timeChange(val);
				
				if(new Date(time).getTime() > new Date(this.model1.businessStartTime).getTime()) {
					this.model1.businessEndTime= time
				} else {
					this.$refs.uToast.show({
						title: '结束时间不能小于开始时间',
						type: 'error',
					})
				}
			},
			idCardStTimeChange(val){
				this.model1.idCardValidStart = this.timeChange1(val)
				this.model1.idCardValidEnd = ''
			},
			idCardEndTimeChange(val){
			const time = this.timeChange1(val);
			
			if(new Date(time).getTime() > new Date(this.model1.idCardValidStart).getTime()) {
				this.model1.idCardValidEnd= time
			} else {
				this.$refs.uToast.show({
					title: '结束时间不能小于开始时间',
					type: 'error',
				})
			}	
			},
			
		}
	}
</script>

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