<template>
	<view class='content'>
		<u--form  ref="uForm">
			
				<u-form-item label="主体">
					<u-radio-group v-model="form.radio">
						<u-radio  name="商铺" >商铺</u-radio>
						<u-radio  name="个人" >个人</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="店铺名称"><u-input placeholder='输入店铺名称' v-model="form.name" /></u-form-item>
				<u-form-item label="封面图片">
					<u-upload :fileList="fileList1" @afterRead="afterRead($event,0)" @delete="deletePic" name="1" multiple
						:maxCount="1"></u-upload>
				</u-form-item>
				<u-form-item @click='placeSelect(),hideKeyboard()' label="店铺位置"></u-form-item>
				<u-form-item label="详细地址">
					<u-input placeholder='输入详细地址,不超过15个字' v-model="form.intro" />
				</u-form-item>
				<u-form-item label="业务描述">
					<u--textarea v-model="value1" autoHeight placeholder="输入业务描述,0-200个字" ></u--textarea> 
				</u-form-item>
				<view>以下信息为选填信息</view>
				<u-form-item label="联系人(仅平台可见)"><u-input v-model="form.sex" type="select" /></u-form-item>
				<u-form-item label="昵称(所有人可见)"><u-input v-model="form.sex" type="select" /></u-form-item>
				<u-form-item label="联系人(所有人可见)"><u-input v-model="form.sex" type="select" /></u-form-item>
				<u-form-item label="营业执照">
					<u-upload :fileList="fileList3" @afterRead="afterRead($event,1)" @delete="deletePic" name="2" multiple
						:maxCount="1"></u-upload>
				</u-form-item>
				<view>注：如提供风险类服务，请上传身份证信息</view>
				<u-form-item label="身份证头像面">
					<u-upload :fileList="fileList5" @afterRead="afterRead($event,1)" @delete="deletePic" name="4" multiple
						:maxCount="1"></u-upload>
				</u-form-item>
				<u-form-item label="身份证国徽面">
					<u-upload :fileList="fileList7" @afterRead="afterRead($event,1)" @delete="deletePic" name="6" multiple
						:maxCount="1"></u-upload>
				</u-form-item>
				<u-form-item label="身份证号码">
					<u-input placeholder='请输入身份证号码' v-model="form.intro" />
				</u-form-item>
			</u--form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{},
				// 封面
				fileList:[],
				fileList1:[],
				// 营业执照
				fileList2:[],
				fileList3:[],
				// 头像面
				fileList4:[],
				fileList5:[],
				// 国徽面
				fileList6:[],
				fileList7:[],
			}
		},
		methods: {
			placeSelect() {
				uni.chooseLocation({
					success: function(res) {
						console.log(res);
						that.cardInfo.location = res.latitude + ',' + res.longitude
						let _address = that.$helper.formatLocation(res.address)
						that.cardInfo.province = _address.Province
						that.cardInfo.city = _address.City
						that.cardInfo.area = _address.Country
						that.cardInfo.detailedAddress = _address.Village
					}
				});
			},
			hideKeyboard() {
				uni.hideKeyboard()
			},
			// 删除图片
			deletePic(event,status) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event,status) {
				// 当设置 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,status)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(res,status) {
				return new Promise((resolve, reject) => {
					uploadImage(res, 'cardImages/',
						result => {
							
							that.cardInfo.headSculpture = result
							resolve(res)
						}
					)
				})
			},
		}
	}
</script>

<style>

</style>
