<template>
	<view class="content">
		<view class="content">
			
			<view class="inner">
				<view class="bg">
					<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/74645f3b57bc45b08b35e2449fdf90c7.jpg"></image>
					<view class="title">商家入驻</view>
				</view>
				<view class="my-form"  >
					<u-form :rules="rules" :model="form" ref="uForm" labelPosition="top" errorType="toast">
						<u-form-item required labelWidth="auto" label="企业LOGO" prop="logoUrl">
							<u-upload
								:fileList="fileList1"
								@afterRead="afterRead"
								@delete="deletePic"
								name="1"
								:maxCount="1"
							></u-upload>
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="店铺名称" prop="storeName">
							<u-input border="none" placeholder="连锁店/企业简称+店铺名称；单独店铺/企业简称" v-model="form.storeName" maxlength="60" />
						</u-form-item>
						<u-form-item required labelWidth="auto" borderBottom label="企业全称" prop="fullName">
							<u-input border="none" placeholder="请输入企业全称" v-model="form.fullName"  maxlength="60" />
						</u-form-item>
						<u-form-item required labelWidth="auto" borderBottom label="负责人联系电话" prop="phone">
							<u-input  border="none"  placeholder="请输入负责人联系电话;" v-model="form.phone"  maxlength="20" />
						</u-form-item>
						<u-form-item required labelWidth="auto" borderBottom label="所在城市" prop="cityIds" @click="cityShow=true">
							<!-- <u-input border="none" placeholder="请输入所在城市" v-model="form.cityIds" /> -->
							<u-input
								v-model="form.address"
								disabled
								disabledColor="#ffffff"
								placeholder="请选择所在城市"
								border="none"
							></u-input>
							<template #right>
								<u-icon
									name="arrow-right"
								></u-icon>
							</template>
						</u-form-item>
						<u-form-item required labelWidth="auto" borderBottom label="企业地址" prop="enterpriseAddress">
							<u-input border="none" placeholder="请输入企业地址" v-model="form.enterpriseAddress"  maxlength="100" />
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="法人姓名" prop="legalPersonName">
							<u-input border="none" placeholder="请输入法人姓名" v-model="form.legalPersonName"  maxlength="20" />
						</u-form-item>
						<!-- <u-form-item required labelWidth="auto" borderBottom label="统一社会信用代码" prop="unifiedSocialCreditCode">
							<u-input border="none" placeholder="请输入统一社会信用代码" v-model="form.unifiedSocialCreditCode"  maxlength="60" />
						</u-form-item> -->
						<u-form-item required labelWidth="auto"  borderBottom label="营业执照" prop="businessLicense">
							<view style="color: red;">{{errMsg}}</view>
							<u-upload
								:fileList="fileList2"
								@afterRead="afterRead"
								@delete="deletePic"
								name="2"
								:maxCount="1"
							></u-upload>
						</u-form-item>
						<u-form-item required labelWidth="auto" borderBottom label="统一社会信用代码" prop="businessCode">
							<u-input border="none" placeholder="请输入统一社会信用代码" v-model="form.businessCode"  maxlength="100" />
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="营业执照是否长期有效" prop="isBusinessLicensePermanent">
							<u-radio-group placement="row" v-model="form.isBusinessLicensePermanent" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="是" :name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="0" label="否" :name="0" > </u-radio>
							 </u-radio-group>
						</u-form-item>
						<template v-if="form.isBusinessLicensePermanent==0">
							<!-- <u-form-item required labelWidth="auto"  borderBottom label="营业执照有效期" prop="businessLicenseExpireStart" @click="openCalendar(1)">
								<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择营业执照有效期" v-model="businessLicenseExpire" />
								<template #right> <u-icon name="arrow-right"></u-icon> </template>
							</u-form-item> -->
							<u-form-item :required="form.isBusinessLicensePermanent==0" labelWidth="auto" borderBottom label="营业执照有效期开始时间" prop="businessLicenseExpireStart">
								<picker :value="form.businessLicenseExpireStart" mode="date" fields="day" @change="pickerChange($event,'businessLicenseExpireStart')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择开始时间" v-model="form.businessLicenseExpireStart" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
							<u-form-item :required="form.isBusinessLicensePermanent==0" labelWidth="auto" borderBottom label="营业执照有效期结束时间" prop="businessLicenseExpireEnd">
								<picker :value="form.businessLicenseExpireEnd" mode="date" fields="day" @change="pickerChange($event,'businessLicenseExpireEnd')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择结束时间" v-model="form.businessLicenseExpireEnd" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
						</template>
						<u-form-item required labelWidth="auto" borderBottom label="经营范围" prop="businessScope">
							<u--textarea v-model="form.businessScope" placeholder="请输入经营范围" maxlength="2000"></u--textarea>
							<!-- <u-input border="none" placeholder="请输入经营范围" v-model="form.businessScope"  maxlength="1000" /> -->
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="药品经营许可证" prop="drugLicense">
							<u-upload
								:fileList="fileList3"
								@afterRead="afterRead"
								@delete="deletePic"
								name="3"
								:maxCount="2"
							></u-upload>
						</u-form-item>
						<u-form-item required labelWidth="auto" borderBottom label="药品经营许可证编码" prop="drugCode">
							<u-input border="none" placeholder="请输入药品经营许可证编码" v-model="form.drugCode"  maxlength="100" />
						</u-form-item>
					<!-- 	<u-form-item required labelWidth="auto"  borderBottom label="药品经营许可证是否长期有效" prop="isDrugLicensePermanent">
							<u-radio-group placement="row" v-model="form.isDrugLicensePermanent" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="是" :name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="0" label="否" :name="0" > </u-radio>
							 </u-radio-group>
						</u-form-item> -->
						<template v-if="form.isDrugLicensePermanent==0">
							<u-form-item :required="form.isDrugLicensePermanent==0" labelWidth="auto"  borderBottom label="药品经营许可证编号有效期开始时间">
								<!-- <u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择药品经营许可证编号有效期" v-model="drugLicenseExpiry" />
								<template #right> <u-icon name="arrow-right"></u-icon> </template> -->
								<picker :value="form.drugLicenseExpiryStart" mode="date" fields="day" @change="pickerChange($event,'drugLicenseExpiryStart')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择开始时间" v-model="form.drugLicenseExpiryStart" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
							<u-form-item :required="form.isDrugLicensePermanent==0" labelWidth="auto"  borderBottom label="药品经营许可证编号有效期结束时间" prop="drugLicenseExpiryEnd">
								<picker :value="form.drugLicenseExpiryStart" mode="date" fields="day" @change="pickerChange($event,'drugLicenseExpiryEnd')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择结束时间" v-model="form.drugLicenseExpiryEnd" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
						</template>
						<u-form-item required labelWidth="auto" borderBottom label="药品经营许可证经营范围" prop="drugLicenseBusinessScope">
							<u--textarea v-model="form.drugLicenseBusinessScope" placeholder="请输入药品经营许可证经营范围" maxlength="2000"></u--textarea>
						</u-form-item>
					<!-- 	<u-form-item required labelWidth="auto"  borderBottom label="药品经营许可证范围是否包含" prop="drugScopeHasFrozen">
							<u-radio-group placement="row" v-model="form.drugScopeHasFrozen" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '16px'}" key="0" label="否 " name="0" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '16px'}" key="1" label="冷冻" name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '16px'}" key="2" label="冷藏" name="2" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '16px'}" key="3" label="冷冻、冷藏" name="3" > </u-radio>
							 </u-radio-group>
						</u-form-item> -->
						<u-form-item  labelWidth="auto"  borderBottom label="2类器械经营备案" prop="medicalDevice2">
							<u-upload
								:fileList="fileList4"
								@afterRead="afterRead"
								@delete="deletePic"
								name="4"
								:maxCount="1"
							></u-upload>
						</u-form-item>
						<u-form-item  labelWidth="auto" borderBottom label="2类器械经营备案编码" prop="medicalDevice2Code">
							<u-input border="none" placeholder="请输入2类器械经营备案编码" v-model="form.medicalDevice2Code"  maxlength="100" />
						</u-form-item>
						<!-- <u-form-item  labelWidth="auto"  borderBottom label="2类器械经营备案是否长期有效" prop="isMedicalDevice2ExpiryPermanent">
							<u-radio-group placement="row" v-model="form.isMedicalDevice2ExpiryPermanent" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="是" :name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="0" label="否" :name="0" > </u-radio>
							 </u-radio-group>
						</u-form-item> -->
						<template v-if="form.isMedicalDevice2ExpiryPermanent==0">
							<u-form-item labelWidth="auto"  borderBottom label="2类器械经营备案有效期开始时间">
								<picker :value="form.medicalDevice2ExpiryStart" mode="date" fields="day" @change="pickerChange($event,'medicalDevice2ExpiryStart')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择开始时间" v-model="form.medicalDevice2ExpiryStart" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
							<u-form-item labelWidth="auto"  borderBottom label="2类器械经营备案有效期结束时间" prop="medicalDevice2ExpiryEnd">
								<picker :value="form.medicalDevice2ExpiryEnd" mode="date" fields="day" @change="pickerChange($event,'medicalDevice2ExpiryEnd')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择结束时间" v-model="form.medicalDevice2ExpiryEnd" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
						</template>
						<u-form-item labelWidth="auto" borderBottom label="2类医疗器械经营许可证营业范围" prop="medicalDevice2BusinessScope">
							<u--textarea v-model="form.medicalDevice2BusinessScope" placeholder="请输入2类医疗器械经营许可证营业范围" maxlength="2000"></u--textarea>
						</u-form-item>
						<!-- <u-form-item labelWidth="auto"  borderBottom label="1类器械生产备案" prop="medicalDevice1">
							<u-upload
								:fileList="fileList5"
								@afterRead="afterRead"
								@delete="deletePic"
								name="5"
								:maxCount="1"
							></u-upload>
						</u-form-item>
						<u-form-item labelWidth="auto" borderBottom label="1类器械生产备案编码" prop="medicalDevice1Code">
							<u-input border="none" placeholder="请输入1类器械生产备案编码" v-model="form.medicalDevice1Code"  maxlength="100" />
						</u-form-item>
						<u-form-item labelWidth="auto"  borderBottom label="1类器械生产备案是否长期有效" prop="isMedicalDevice1ExpiryPermanent">
							<u-radio-group placement="row" v-model="form.isMedicalDevice1ExpiryPermanent" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="是" :name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="0" label="否" :name="0" > </u-radio>
							 </u-radio-group>
						</u-form-item>
						<template v-if="form.isMedicalDevice1ExpiryPermanent==0">
							<u-form-item labelWidth="auto"  borderBottom label="1类器械生产备案有效期开始时间" prop="medicalDevice1ExpiryStart">
								<picker :value="form.medicalDevice1ExpiryStart" mode="date" fields="day" @change="pickerChange($event,'medicalDevice1ExpiryStart')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择开始时间" v-model="form.medicalDevice1ExpiryStart" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
							<u-form-item labelWidth="auto"  borderBottom label="1类器械生产备案有效期结束时间" prop="medicalDevice1ExpiryEnd">
								<picker :value="form.medicalDevice1ExpiryEnd" mode="date" fields="day" @change="pickerChange($event,'medicalDevice1ExpiryEnd')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择结束时间" v-model="form.medicalDevice1ExpiryEnd" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
						</template> -->
						<u-form-item labelWidth="auto"  borderBottom label="3类器械经营许可证" prop="medicalDevice3">
							<u-upload
								:fileList="fileList6"
								@afterRead="afterRead"
								@delete="deletePic"
								name="6"
								:maxCount="1"
							></u-upload>
						</u-form-item>
						<u-form-item labelWidth="auto" borderBottom label="3类器械生产备案编码" prop="medicalDevice3Code">
							<u-input border="none" placeholder="请输入3类器械生产备案编码" v-model="form.medicalDevice3Code"  maxlength="100" />
						</u-form-item>
						<!-- <u-form-item labelWidth="auto"  borderBottom label="3类器械经营许可证是否长期有效" prop="isMedicalDevice3ExpiryPermanent">
							<u-radio-group placement="row" v-model="form.isMedicalDevice3ExpiryPermanent" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="是" :name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="0" label="否" :name="0" > </u-radio>
							 </u-radio-group>
						</u-form-item> -->
						<template v-if="form.isMedicalDevice3ExpiryPermanent==0">
							<u-form-item labelWidth="auto"  borderBottom label="3类器械经营许可证有效期开始时间" prop="medicalDevice3ExpiryStart">
								<picker :value="form.medicalDevice3ExpiryStart" mode="date" fields="day" @change="pickerChange($event,'medicalDevice3ExpiryStart')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择开始时间" v-model="form.medicalDevice3ExpiryStart" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
							<u-form-item labelWidth="auto"  borderBottom label="3类器械经营许可证有效期结束时间" prop="medicalDevice3ExpiryEnd">
								<picker :value="form.medicalDevice3ExpiryEnd" mode="date" fields="day" @change="pickerChange($event,'medicalDevice3ExpiryEnd')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择结束时间" v-model="form.medicalDevice3ExpiryEnd" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
						</template>
						<u-form-item labelWidth="auto" borderBottom label="3类医疗器械经营许可证营业范围" prop="medicalDevice3BusinessScope">
							<u--textarea v-model="form.medicalDevice3BusinessScope" placeholder="请输入3类医疗器械经营许可证营业范围" maxlength="2000"></u--textarea>
						</u-form-item>
						<u-form-item labelWidth="auto"  borderBottom label="食品经营许可证/备案凭证" prop="foodLicense">
							<u-upload
								:fileList="fileList7"
								@afterRead="afterRead"
								@delete="deletePic"
								name="7"
								:maxCount="3"
							></u-upload>
						</u-form-item>
						<u-form-item labelWidth="auto" borderBottom label="食品经营许可证/备案凭证编码" prop="foodCode">
							<u-input border="none" placeholder="请输入食品经营许可证/备案凭证编码" v-model="form.foodCode"  maxlength="100" />
						</u-form-item>
						<u-form-item labelWidth="auto"  borderBottom label="食品经营许可证/备案凭证是否长期有效" prop="isFoodLicenseExpiryPermanent">
							<u-radio-group placement="row" v-model="form.isFoodLicenseExpiryPermanent" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="是" :name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="0" label="否" :name="0" > </u-radio>
							 </u-radio-group>
						</u-form-item>
						<template v-if="form.isFoodLicenseExpiryPermanent==0">
							<u-form-item labelWidth="auto"  borderBottom label="食品经营许可证/备案凭证有效期开始时间" prop="foodLicenseExpiryStart">
								<picker :value="form.foodLicenseExpiryStart" mode="date" fields="day" @change="pickerChange($event,'foodLicenseExpiryStart')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择开始时间" v-model="form.foodLicenseExpiryStart" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
							<u-form-item labelWidth="auto"  borderBottom label="食品经营许可证/备案凭证有效期结束时间" prop="foodLicenseExpiryEnd">
								<picker :value="form.foodLicenseExpiryEnd" mode="date" fields="day" @change="pickerChange($event,'foodLicenseExpiryEnd')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择结束时间" v-model="form.foodLicenseExpiryEnd" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
						</template>
						<u-form-item labelWidth="auto" borderBottom label="食品经营范围" prop="foodLicenseBusinessScope">
							<u--textarea v-model="form.foodLicenseBusinessScope" placeholder="请输入食品经营范围" maxlength="2000"></u--textarea>
						</u-form-item>
						<!-- <u-form-item labelWidth="auto"  borderBottom label="医疗机构执业许可证" prop="medicalLicense">
							<u-upload
								:fileList="fileList8"
								@afterRead="afterRead"
								@delete="deletePic"
								name="8"
								:maxCount="1"
							></u-upload>
						</u-form-item>
						<u-form-item labelWidth="auto" borderBottom label="医疗机构执业许可证编码" prop="medicalCode">
							<u-input border="none" placeholder="请输入医疗机构执业许可证编码" v-model="form.medicalCode"  maxlength="100" />
						</u-form-item>
						<u-form-item labelWidth="auto"  borderBottom label="医疗机构执业许可证是否长期有效" prop="isMedicalLicenseExpiryPermanent">
							<u-radio-group placement="row" v-model="form.isMedicalLicenseExpiryPermanent" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="是" :name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="0" label="否" :name="0" > </u-radio>
							 </u-radio-group>
						</u-form-item>
						<template v-if="form.isMedicalLicenseExpiryPermanent==0">
							<u-form-item labelWidth="auto"  borderBottom label="医疗机构执业许可证有效期开始时间">
								<picker :value="form.medicalLicenseExpiryStart" mode="date" fields="day" @change="pickerChange($event,'medicalLicenseExpiryStart')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选开始时间" v-model="form.medicalLicenseExpiryStart" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
							<u-form-item labelWidth="auto"  borderBottom label="医疗机构执业许可证有效期择结束时间" prop="medicalLicenseExpiryEnd">
								<picker :value="form.medicalLicenseExpiryEnd" mode="date" fields="day" @change="pickerChange($event,'medicalLicenseExpiryEnd')">
									<view class="x-f" style="justify-content: space-between;">
										<u-input disabled disabledColor="#ffffff" border="none" placeholder="请选择结束时间" v-model="form.medicalLicenseExpiryEnd" />
										<u-icon name="arrow-right"></u-icon>
									</view>
								</picker>
							</u-form-item>
						</template> -->
						<u-form-item required labelWidth="auto"  borderBottom label="发货联系电话" prop="sendPhone">
							<u-input border="none" placeholder="请输入发货联系电话" v-model="form.sendPhone"  maxlength="20" />
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="配送方式" prop="shippingType">
							<u-radio-group placement="row" v-model="form.shippingType" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="配送" name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="2" label="到店自提" name="2" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="3" label="配送、自提" name="3" > </u-radio>
							 </u-radio-group>
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="退货联系人" prop="refundConsignee">
							<u-input border="none" placeholder="请输入退货联系人" v-model="form.refundConsignee"  maxlength="20" />
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="退货联系电话" prop="refundPhone">
							<u-input border="none" placeholder="请输入退货联系电话" v-model="form.refundPhone"  maxlength="20" />
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="退货地址" prop="refundAddress">
							<u-input border="none" placeholder="请输入退货地址" v-model="form.refundAddress"  maxlength="100" />
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="佣金类型" prop="brokerageType">
							<u-radio-group placement="row" v-model="form.brokerageType" >
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="1" label="每盒" name="1" > </u-radio>
								<u-radio activeColor="#2583EB" :customStyle="{marginRight: '8px'}" key="2" label="总价" name="2" > </u-radio>
							 </u-radio-group>
						</u-form-item>
						<u-form-item required labelWidth="auto"  borderBottom label="登录帐号" prop="account">
							<u-input border="none" placeholder="请输入登录帐号" v-model="form.account"  maxlength="50" />
						</u-form-item>
					</u-form>
				</view>
				<u-picker ref="cityPicker" @cancel="cityShow = false"  keyName="n" @confirm="citySelect" @change="cityChangeHandler"  :show="cityShow" :columns="citys"></u-picker>
				<u-picker ref="deptPicker" @cancel="deptShow = false"  keyName="deptName" @confirm="deptSelect"   :show="deptShow" :columns="depts"></u-picker>
				<u-picker  @cancel="hospitalShow = false"  keyName="hospitalName" @confirm="hospitalSelect"    :show="hospitalShow" :columns="hospitals"></u-picker>
				<u-picker ref="positionPicker" @cancel="positionShow = false"  keyName="dictLabel" @confirm="positionSelect"   :show="positionShow" :columns="positions"></u-picker>
				<uni-calendar ref="calendar" :range="true" :insert="false" @confirm="confirmCalendar" />	
			</view>
			<view class="btn-box">
				<view class="sub-btn" @click="submit()">提交</view>
			</view>
		</view>
		
	</view>
</template>

<script>
import {getDictByKey,getHospitalList,getDepartmentList,sendSmsCode,uploadOSS,getCitys} from '@/api/common.js'
import {storeAdd,businessLicenseCheck} from './api/shopping.js'

export default {
 	data() {
 		return {
			cityIndex1:0,
			cityIndex2:0,
			allCitys:[],
			citys:[[],[],[]],
			cityShow:false,
			depts:[[]],
			deptShow:false,
			hospitals:[[]],
			hospitalShow:false,
			positions:[[]],
			positionShow:false,
			fileList1:[],
			fileList2:[],
			fileList3:[],
			fileList4:[],
			fileList5:[],
			fileList6:[],
			fileList7:[],
			fileList8:[],
			checked:0,
			form:{
				isBusinessLicensePermanent: 1,
				isDrugLicensePermanent: 0,
				isMedicalDevice1ExpiryPermanent: 1,
				isMedicalDevice2ExpiryPermanent: 1,
				isMedicalDevice3ExpiryPermanent: 0,
				isFoodLicenseExpiryPermanent: 1,
				isMedicalLicenseExpiryPermanent: 1,
				storeName:'',
				fullName:'',
				phone:'',
				cityIds:'',
				enterpriseAddress:'',
				legalPersonName:'',
				unifiedSocialCreditCode:'',
				logoUrl:'',
				businessLicense:'',
				businessLicenseExpireStart:'',
				businessLicenseExpireEnd:'',
				drugLicense:'',
				drugLicenseExpiryStart:'',
				drugLicenseExpiryEnd:'',
				medicalDevice1:'',
				medicalDevice1ExpiryStart:'',
				medicalDevice1ExpiryEnd:'',
				medicalDevice2:'',
				medicalDevice2ExpiryStart:'',
				medicalDevice2ExpiryEnd:'',
				medicalDevice3:'',
				medicalDevice3ExpiryStart:'',
				medicalDevice3ExpiryEnd:'',
				foodLicense:'',
				foodLicenseExpiryStart:'',
				foodLicenseExpiryEnd:'',
				medicalLicense:'',
				medicalLicenseExpiryStart:'',
				medicalLicenseExpiryEnd:'',
				businessScope:'',
				address:'',
				refundPhone:'',
				refundAddress:'',
				refundConsignee:'',
				brokerageType: undefined,
				account:'',
				sendPhone:'',
				shippingType: undefined,
				medicalCode: '',
				foodCode: '',
				medicalDevice3Code: '',
				medicalDevice2Code: '',
				medicalDevice1Code: '',
				drugCode: '',
				businessCode: '',
				medicalDevice2BusinessScope: '',
				medicalDevice3BusinessScope:'',
				drugLicenseBusinessScope: '',
				drugScopeHasFrozen: 3,
				foodLicenseBusinessScope:''
			},
			rules: {
				logoUrl: [{required: true, message: '请上传企业LOGO'}],
				storeName: [{required: true, message: '请输入店铺名称'}],
				fullName: [{required: true, message: '请输入企业全称'}],
				phone: [{required: true, message: '请输入负责人联系电话'}],
				cityIds: [{required: true, message: '请选择所在城市'}],
				enterpriseAddress: [{required: true, message: '请输入企业地址'}],
				legalPersonName: [{required: true, message: '请输入法人姓名'}],
				// unifiedSocialCreditCode: [{required: true, message: '请输入统一社会信用代码'}],
				businessLicense: [{required: true, message: '请上传营业执照'}],
				businessCode: [{required: true, message: '请输入统一社会信用代码'}],
				businessLicenseExpireStart: [],
				businessLicenseExpireEnd: [],
				drugLicense: [{required: true, message: '请上传药品经营许可证'}],
				drugLicenseBusinessScope: [{required: true, message: '请输入药品经营许可证经营范围'}],
				drugCode: [{required: true, message: '请输入药品经营许可证编码'}],
				// drugScopeHasFrozen: [{required: true, message: '药品经营许可证范围是否包含'}],
				// drugLicenseExpiryStart: [{required: true, message: '请选择药品经营许可证编号有效期'}],
				// medicalDevice2: [{required: true, message: '请上传2类医疗器械备案'}],
				// medicalDevice2Code: [{required: true, message: '请输入2类医疗器械备案编码'}],
				// medicalDevice2ExpiryStart: [{required: true, message: '请选择2类医疗器械备案有效期'}],
				// medicalLicense: [{required: true, message: '请上传医疗机构执业许可证'}],
				// medicalCode: [{required: true, message: '请输入医疗机构执业许可证编码'}],
				// medicalLicenseExpiryStart: [{required: true, message: '请选择医疗机构执业许可证有效期'}],
				sendPhone: [{required: true, message: '请输入发货联系电话'}],
				refundPhone: [{required: true, message: '请输入退货联系电话'}],
				businessScope: [{required: true, message: '请输入经营范围'}],
				refundAddress: [{required: true, message: '请输入退货地址'}],
				refundConsignee: [{required: true, message: '请输入退货联系人'}],
				brokerageType: [{required: true, message: '请选择佣金类型'}],
				account: [{required: true, message: '请输入登录帐号'}],
				shippingType: [{required: true, message: '请选择配送方式'}],
				isBusinessLicensePermanent: [{required: true, message: '请选择营业执照是否长期有效'}],
				isDrugLicensePermanent: [{required: true, message: '请选择药品经营许可证是否长期有效'}],
				// isMedicalDevice2ExpiryPermanent: [{required: true, message: '请选择2类器械经营备案是否长期有效'}],
				// isMedicalLicenseExpiryPermanent: [{required: true, message: '请选择医疗机构执业许可证是否长期有效'}],
			},
			calendarType: 0,
			businessLicenseExpire:'',
			drugLicenseExpiry:'',
			medicalDevice2Expiry:'',
			medicalDevice1Expiry:'',
			medicalDevice3Expiry:'',
			foodLicenseExpiry:'',
			medicalLicenseExpiry:'',
			errMsg:'',
 		}
 	},
	onLoad(options) {
		this.form.doctorType=options.type;
		this.getCitys()
		// this.getHospitalList();
		// this.getDepartmentList();
		// this.getDictByKey("sys_doc_position");
	},
	onShow() {
		
		
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
		
	},
 	methods: {
		pickerChange(e,type) {
			this.form[type] = e.detail.value
		},
		openCalendar(calendarType){
			this.calendarType=calendarType
			this.$refs.calendar.open();
		},
		confirmCalendar(e) {
			if(!e.range.before||!e.range.after) {
				uni.showToast({
					title: '请选择正确的时间范围',
					icon: 'none'
				})
				return
			}
			if(this.calendarType==1) {
				this.form.businessLicenseExpireStart = e.range.before;
				this.form.businessLicenseExpireEnd = e.range.after;
				this.businessLicenseExpire = this.form.businessLicenseExpireStart+'至'+this.form.businessLicenseExpireEnd
			}else if(this.calendarType==2) {
				this.form.drugLicenseExpiryStart = e.range.before;
				this.form.drugLicenseExpiryEnd = e.range.after;
				this.drugLicenseExpiry = this.form.drugLicenseExpiryStart+'至'+this.form.drugLicenseExpiryEnd
			}else if(this.calendarType==3) {
				this.form.medicalDevice2ExpiryStart = e.range.before;
				this.form.medicalDevice2ExpiryEnd = e.range.after;
				this.medicalDevice2Expiry = this.form.medicalDevice2ExpiryStart+'至'+this.form.medicalDevice2ExpiryEnd
			}else if(this.calendarType==4) {
				this.form.medicalDevice1ExpiryStart = e.range.before;
				this.form.medicalDevice1ExpiryEnd = e.range.after;
				this.medicalDevice1Expiry = this.form.medicalDevice1ExpiryStart+'至'+this.form.medicalDevice1ExpiryEnd
			}else if(this.calendarType==5) {
				this.form.medicalDevice3ExpiryStart = e.range.before;
				this.form.medicalDevice3ExpiryEnd = e.range.after;
				this.medicalDevice3Expiry = this.form.medicalDevice3ExpiryStart+'至'+this.form.medicalDevice3ExpiryEnd
			}else if(this.calendarType==6) {
				this.form.foodLicenseExpiryStart = e.range.before;
				this.form.foodLicenseExpiryEnd = e.range.after;
				this.foodLicenseExpiry = this.form.foodLicenseExpiryStart+'至'+this.form.foodLicenseExpiryEnd
			}else if(this.calendarType==7) {
				this.form.medicalLicenseExpiryStart = e.range.before;
				this.form.medicalLicenseExpiryEnd = e.range.after;
				this.medicalLicenseExpiry = this.form.medicalLicenseExpiryStart+'至'+this.form.medicalLicenseExpiryEnd
			}
			console.log(e);
		},
		hospitalSelect(e){
			this.form.hospitalId=this.hospitals[0][e.indexs[0]].hospitalId;
			this.form.hospitalName=this.hospitals[0][e.indexs[0]].hospitalName;
			this.hospitalShow=false;
		},
		deptSelect(e){
			console.log(e)
			this.form.deptId=this.depts[0][e.indexs[0]].deptId;
			this.form.deptName=this.depts[0][e.indexs[0]].deptName;
			this.deptShow=false;
		},
		positionSelect(e){
			console.log(e)
			this.form.position=this.positions[0][e.indexs[0]].dictLabel;
			this.positionShow=false;
		},
		getDictByKey(key){
			var data={key:key}
			getDictByKey(data).then(
				res => {
					if(res.code==200){
						this.positions[0]=res.data;
					}
				},
				err => {
				}
			);
			
		},
		openContent(type){
			uni.navigateTo({
				url:"agreement?type="+type
			})
		},
		cityChangeHandler(e) {
			const {
				columnIndex,
				index,
				// 微信小程序无法将picker实例传出来，只能通过ref操作
				picker = this.$refs.cityPicker
			} = e
			if(columnIndex==0){
				this.cityIndex1=index
				console.log(this.cityIndex1)
				//获取第二列数据
				var citys1 = this.allCitys[this.cityIndex1].c;
				console.log(citys1)
				picker.setColumnValues(1,citys1)
				this.cityIndex2=0
				var citys2 = this.allCitys[this.cityIndex1].c[this.cityIndex2].c;
				picker.setColumnValues(2,citys2)
			}
			if(columnIndex==1){
				this.cityIndex2=index
				//获取第三列数据
				var citys = this.allCitys[this.cityIndex1].c[this.cityIndex2].c;
				console.log(citys)
				picker.setColumnValues(2,citys)
			}
			
		},
		citySelect(e){
			console.log(e)
			this.form.address=e.value[0].n+""+e.value[1].n+""+e.value[2].n
			this.form.cityIds=e.value[0].v+","+e.value[1].v+","+e.value[2].v;
			this.cityShow=false;
		},
	 
		getCitys(){
			var that=this;
			var data={}
			getCitys(data).then(
				res => {
					if(res.code==200){
						that.allCitys=res.data;
						that.citys=[[],[],[]];
						that.citys[0]=that.allCitys;
						that.citys[1]=that.allCitys[0].c;
						that.citys[2]=that.allCitys[0].c[0].c;
						console.log(that.citys)
					}
				},
				err => {
					 
				}
			);
		},
		getHospitalList(){
			var that=this;
			var data={}
			getHospitalList(data).then(
				res => {
					if(res.code==200){
						that.hospitals[0]=res.data;
						console.log(111)
						console.log(that.hospitals)
						
					}
				},
				err => {
					 
				}
			);
		},
		getDepartmentList(){
			var that=this;
			var data={}
			getDepartmentList(data).then(
				res => {
					if(res.code==200){
						that.depts[0]=res.data;
					}
				},
				err => {
					 
				}
			);
		},
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1)
		},
		async afterRead(event) {
			// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file)
			let fileListLen = this[`fileList${event.name}`].length
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				})
			})
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url)
				let item = this[`fileList${event.name}`][fileListLen]
				this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
					status: result.status,
					message: result.status == 'failed' ? '上传失败' : '',
					url: result.url
				}))
				fileListLen++
				if(event.name==2&&result.status=='success') {
					this.form.businessLicense = this.fileList2[0].url
					this.businessLicenseCheck()
				}
			}
		},
		getSuccessUrls(list) {
		  if (!list || list.length === 0) return '';
		
		  const hasUploading = list.some(v => v.status === 'uploading');
		  const hasFailed = list.some(v => v.status === 'failed');
		
		  if (hasUploading) {
		    uni.showToast({ title: '请等待图片上传完成', icon: 'none' });
		    return 'failed';
		  }
		  if (hasFailed) {
		    uni.showToast({ title: '请检查是否有图片上传失败', icon: 'none' });
		    return 'failed';
		  }
		
		  return list.filter(v => v.status === 'success').map(v => v.url).join(',');
		},
		uploadFilePromise(url) {
			return new Promise((resolve, reject) => {
				let a = uni.uploadFile({
					url: uni.getStorageSync('requestPath') +'/app/common/uploadOSS', // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					success: (res) => {
						if(res.statusCode == 200&&JSON.parse(res.data).code == 200) {
							resolve({
								url:JSON.parse(res.data).url,
								status: 'success'
							})
						} else {
							resolve({
								url:url,
								status: 'failed'
							})
						}
					},
					fail: (res) => {
						resolve({
							url:url,
							status: 'failed'
						})
					}
				});
			})
		},
		register(){
			storeAdd(this.form).then(
				res => {
					console.log(res)
					if(res.code==200){
						 uni.showToast({
						 	icon:'none',
						 	title:res.msg,
						 });
						 setTimeout(function() {
							 uni.navigateBack({
								 delta: 1
							 })
						 }, 2000);
					}else{
						uni.showToast({
							icon:'none',
							title: res.msg,
						});
					}
				},
				rej => {
					console.log(rej)
				}
			);
		},
 		submit(){
 			var that=this;

			const logoUrl = this.getSuccessUrls(this.fileList1);
			if (logoUrl === 'failed') return;
			this.form.logoUrl = logoUrl;
			
			const businessLicense = this.getSuccessUrls(this.fileList2);
			if (businessLicense === 'failed') return;
			this.form.businessLicense = businessLicense;
			
			const drugLicense = this.getSuccessUrls(this.fileList3);
			if (drugLicense === 'failed') return;
			this.form.drugLicense = drugLicense;
			
			const medicalDevice2 = this.getSuccessUrls(this.fileList4);
			if (medicalDevice2 === 'failed') return;
			this.form.medicalDevice2 = medicalDevice2;
			
			const medicalDevice1 = this.getSuccessUrls(this.fileList5);
			if (medicalDevice1 === 'failed') return;
			this.form.medicalDevice1 = medicalDevice1;

			const medicalDevice3 = this.getSuccessUrls(this.fileList6);
			if (medicalDevice3 === 'failed') return;
			this.form.medicalDevice3 = medicalDevice3;

			const foodLicense = this.getSuccessUrls(this.fileList7);
			if (foodLicense === 'failed') return;
			this.form.foodLicense = foodLicense;
			
			const medicalLicense = this.getSuccessUrls(this.fileList8);
			if (medicalLicense === 'failed') return;
			this.form.medicalLicense = medicalLicense;

			console.log(this.form)
			if(this.form.isBusinessLicensePermanent == 0&&!this.form.businessLicenseExpireStart) {
				uni.showToast({
					title: '请选择营业执照有效期开始时间',
					icon: 'none'
				})
				return
			}
			if(this.form.isBusinessLicensePermanent == 0&&!this.form.businessLicenseExpireEnd) {
				uni.showToast({
					title: '请选择营业执照有效期结束时间',
					icon: 'none'
				})
				return
			}
			if(this.form.isDrugLicensePermanent == 0&&!this.form.drugLicenseExpiryStart) {
				uni.showToast({
					title: '请选择药品经营许可证编号有效期开始时间',
					icon: 'none'
				})
				return
			}
			if(this.form.isDrugLicensePermanent == 0&&!this.form.drugLicenseExpiryEnd) {
				uni.showToast({
					title: '请选择药品经营许可证编号有效期结束时间',
					icon: 'none'
				})
				return
			}
			if(this.form.isMedicalDevice2ExpiryPermanent == 0&&!this.form.medicalDevice2ExpiryStart) {
				uni.showToast({
					title: '请选择2类器械经营备案有效期开始时间',
					icon: 'none'
				})
				return
			}
			if(this.form.isMedicalDevice2ExpiryPermanent == 0&&!this.form.medicalDevice2ExpiryEnd) {
				uni.showToast({
					title: '请选择2类器械经营备案有效期结束时间',
					icon: 'none'
				})
				return
			}
			if(this.form.isFoodLicenseExpiryPermanent == 0&&!this.form.foodLicenseExpiryStart) {
				uni.showToast({
					title: '请选择食品经营许可证/备案凭证有效期开始时间',
					icon: 'none'
				})
				return
			}
			if(this.form.isFoodLicenseExpiryPermanent == 0&&!this.form.foodLicenseExpiryEnd) {
				uni.showToast({
					title: '请选择食品经营许可证/备案凭证有效期结束时间',
					icon: 'none'
				})
				return
			}
			const err = this.checkDateRanges([
				{
					start: this.form.businessLicenseExpireStart,
					end: this.form.businessLicenseExpireEnd,
					msg: '营业执照有效期' ,
					require: this.form.isBusinessLicensePermanent == 0,
				},
				{ 
					start: this.form.drugLicenseExpiryStart,
					end: this.form.drugLicenseExpiryEnd,
					msg: '药品经营许可证编号有效期' ,
					require: this.form.isDrugLicensePermanent == 0,
				},
				{
					start: this.form.medicalDevice2ExpiryStart,
					end: this.form.medicalDevice2ExpiryEnd,
					msg: '2类器械经营备案有效期',
					require: this.form.isMedicalDevice2ExpiryPermanent == 0,
				},{
					start: this.form.medicalDevice3ExpiryStart,
					end: this.form.medicalDevice3ExpiryEnd,
					msg: '3类器械经营许可证有效期' ,
					require: false,
				},
				{
					start: this.form.foodLicenseExpiryStart,
					end: this.form.foodLicenseExpiryEnd,
					msg: '食品经营许可证/备案凭证有效期' ,
					require: this.form.isFoodLicenseExpiryPermanent == 0,
				}
			]);
			
			if (err) {
			  uni.showToast({ title: err, icon: 'none' });
			  return;
			}
			// if(this.form.isMedicalLicenseExpiryPermanent == 0&&!this.form.medicalLicenseExpiryStart) {
			// 	uni.showToast({
			// 		title: '请选择医疗机构执业许可证有效期开始时间',
			// 		icon: 'none'
			// 	})
			// 	return
			// }
			// if(this.form.isMedicalLicenseExpiryPermanent == 0&&!this.form.medicalLicenseExpiryEnd) {
			// 	uni.showToast({
			// 		title: '请选择医疗机构执业许可证有效期结束时间',
			// 		icon: 'none'
			// 	})
			// 	return
			// }
			this.form.unifiedSocialCreditCode = this.form.businessCode
			this.$refs.uForm.validate().then(res => {
				if(res) {
					this.register()
				}
			})
 		},
		checkDateRanges(list = []) {
			for (const { start, end, msg = '有效期', require = true, afterToday = true } of list) {
				// 1. require=false 且任一为空 → 跳过
				if (!require && (!start || !end)) continue;
			
				// 2. require=true 时缺值 → 报错
				if (!start || !end) return `${msg} 请选择完整时间`;
			
				// 3. 常规区间校验
				if (start > end) return `${msg} 开始时间不能大于结束时间`;
			
				if (afterToday) {
				  // 今天 00:00:00.000
				  const todayZero = new Date();
				  todayZero.setHours(0, 0, 0, 0);
				
				  // 明天 00:00:00.000
				  const tomorrowZero = new Date(todayZero);
				  tomorrowZero.setDate(todayZero.getDate() + 1);
				
				  // 结束日期 00:00:00.000
				  const endZero = new Date(end);
				  endZero.setHours(0, 0, 0, 0);
				
				  // 结束日期 < 明天零点 → 不合法
				  if (endZero < tomorrowZero) return `${msg} 结束时间必须大于今天`;
				}
			}
			return '';
		},
		businessLicenseCheck() {
			businessLicenseCheck({imageUrl:this.form.businessLicense}).then(res=>{
				if(res.code==200) {
					if(res.data.flag) {
						this.errMsg = ''
						this.form.enterpriseAddress = res.data.address;
						this.form.legalPersonName = res.data.person;
						this.form.businessScope = res.data.businessStr;
						this.form.businessCode = res.data.regNum;
					} else {
						this.fileList2 = ''
						this.form.businessLicense = ''
						this.errMsg = '请上传正确且清晰的营业执照'
						uni.showToast({
							title: '请上传正确且清晰的营业执照',
							icon: 'none'
						})
					}
				} else {
					this.errMsg = ''
					this.fileList2 = ''
					this.form.businessLicense = ''
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			}).catch((err)=>{
				this.errMsg = ''
				this.fileList2 = ''
				this.form.businessLicense = ''
				uni.showToast({
					title: err,
					icon: 'none'
				})
			})
		}
 	}
}
 
 
</script>


<style scoped lang="scss">
	.es-ml-14 {
		margin-right: 14rpx;
	}
	.content{
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		
		.inner{
			padding: 20upx 20rpx 120rpx;
			.bg{
				width: 100%;
				height: 300rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: flex-start;
				image{
					position: absolute;
					border-radius: 30rpx 30rpx 0rpx 0rpx;
					width: 100%;
					height: 100%;
				}
				.title{
					z-index: 999;
					padding: 0rpx 30rpx;
					font-size: 40upx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #FFFFFF;
				}
				.desc{
					z-index: 999;
					padding: 0rpx 30rpx;
					margin-top: 20rpx;
					font-size: 28upx;
					opacity: 0.5;
					font-family: PingFang SC;
					color: #FFFFFF;
				}
			}
			.my-form{
				z-index: 1;
				background-color: #FFFFFF;
				padding: 0 30upx;
				input{
					text-align: right;
				}
			}
			 
		}
		.agree{
			padding: 10rpx 20rpx;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			.label{
				font-size: 24rpx;
			}
			.text{
				margin-left: 10rpx;
				color: royalblue;
				font-size: 24rpx;
			}
		}
		.btn-box{
			z-index: 90;
			width: 100%;
			position: fixed;
			bottom: 0;
			height: 120upx;
			padding: 0 30upx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: #FFFFFF;
			.sub-btn{
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #2583EB;
				border-radius: 44upx;
			}
		}
	}
	 

</style>
