<template>
	<view class="applyLaundryStore">
		<navbar title="申请水洗店" leftClick @leftClick="$utils.navigateBack" />


		<view class="frame">
			<view class="title">
				<span
					style="width: 10rpx;height: 40rpx;background-color: #f78142;border-radius: 10rpx;overflow: hidden;"></span>
				<span>店铺信息</span>
			</view>
			<view class="shopName">
				<view>店铺照片</view>
				<view>
					<uv-upload :fileList="fileList" multiple :maxCount="1" width="180rpx"
						height="180rpx" multiple @afterRead="afterRead" @delete="deleteImage">
						<image src="../static/help/uploading.png" mode="aspectFill"
							style="width: 180rpx;height: 180rpx;" />
					</uv-upload>
				</view>
			</view>
			<view class="shopName">
				<view>店铺名称</view>
				<view>
					<input v-model="form.name" placeholder="请输入店铺名称" clearable></input>
				</view>
			</view>
			<view class="shopName">
				<view>您的姓名</view>
				<view>
					<input v-model="form.userName" placeholder="请输入您的姓名" clearable></input>
				</view>
			</view>
			<view class="shopName">
				<view>联系方式</view>
				<view>
					<input v-model="form.phone" type="number" placeholder="请输入联系方式" clearable></input>
				</view>
			</view>
			<view class="shopName">
				<view>设置密码</view>
				<view>
					<input v-model="form.password" type="password" placeholder="请输入密码" clearable></input>
				</view>
			</view>

			<view class="currentRegion">
				<view>所在地区</view>
				<view @click.stop="selectAddr">
					<input class="input"
					disabled
					v-model="form.currentRegion" placeholder="请选择所在地区"></input>
					<view class="orientation">
						<!-- 定位 -->
						<image src="/static/image/address/selectIcon.png"
							style="width:30rpx;height: 30rpx;margin:5rpx 5rpx 5rpx 5rpx;"></image>
					</view>
				</view>
			</view>
			<view class="shopName">
				<view>详细地址</view>
				<view>
					<input v-model="form.address" placeholder="详细地址" clearable></input>
				</view>
			</view>
		</view>


		<!-- 底部按钮 -->
		<bottomBtn @confirm='submitApplication()' :color='bottomBtnStyle.color'
			:backgroundColor='bottomBtnStyle.backgroundColor' :fontSize='bottomBtnStyle.fontSize'
			:text='bottomBtnStyle.text' :width="bottomBtnStyle.width" :height="bottomBtnStyle.height"
			:borderRadius='bottomBtnStyle.borderRadius' :bottom='bottomBtnStyle.bottom'>
		</bottomBtn>


	</view>
</template>

<script>
	import Position from '@/utils/position.js'
	import bottomBtn from "../../components/bottom/bottomBtn.vue"
	export default {
		components: {
			bottomBtn,
		},
		data() {
			return {
				form: {
					userName: '',
					name: '',
					phone: '',
					currentRegion: '',
					address: '',
					latitude: '',
					longitude: '',
					password : '',
				},

				bottomBtnStyle: {
					color: '#FFF',
					backgroundColor: '#fd5100',
					fontSize: '34rpx',
					text: '提交',
					width: '400rpx',
					height: '80rpx',
					borderRadius: '100rpx',
					bottom: '40rpx'
				},
				fileList: [],
			}
		},
		computed: {

		},
		onShow() {

		},
		methods: {
			deleteImage(e){
				this.fileList.splice(e.index, 1)
			},
			afterRead(e){
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.fileList.push({
							url
						})
					})
				})
			},
			// 提交按钮
			submitApplication() {
				this.form.pic = this.fileList.map((item) => item.url).join(",")
				
				if (this.$utils.verificationAll(this.form, {
						pic: '请上传店铺照片',
						name: '请输入店铺名称',
						userName: '请输入您的姓名',
						phone: '请输入联系方式',
						currentRegion: '请选择所在地区',
						address: '请输入详细地址',
						password : '请设置密码',
					})) {
					return
				}
				
				this.form.address = this.form.currentRegion + this.form.address
				this.$api('applyShopHotel', this.form, res => {
					if (res.code == 200) {
						uni.showToast({
							title: '申请成功待审核', // 提示的内容
							icon: 'success', // 图标，可选值有 'success', 'loading', 'none'
							duration: 1500 // 提示的持续时间，默认是1500毫秒
						});
						setTimeout(uni.navigateBack, 1500, -1)
					}
				})
			},

			//地图上选择地址
			selectAddr() {
				Position.getLocation(res => {
					Position.selectAddress(res.longitude, res.latitude, success => {
						this.setAddress(success)
					})
				})
				Position.getLocationDetail(res => {
					console.log(res);
					// this.form.address = res
				})
			},

			//提取用户选择的地址信息复制给表单数据
			setAddress(res) {
				//经纬度信息
				this.form.latitude = res.latitude
				this.form.longitude = res.longitude

				if (!res.address && res.name) { //用户直接选择城市的逻辑
					return this.form.currentRegion = res.name

				}
				if (res.address || res.name) {
					return this.form.currentRegion = res.address + res.name
				}
				this.form.currentRegion = '' //用户啥都没选就点击勾选
			},



		}
	}
</script>

<style lang="scss" scoped>
	* {
		box-sizing: border-box;
	}

	.applyLaundryStore {
		padding: 0 20rpx 0 20rpx;
		background-color: #f5f5f5;

		.frame {
			display: flex;
			flex-direction: column;
			gap: 20rpx;
			background-color: #FFF;
			margin-top: 20rpx;
			padding: 20rpx;

			.title {
				display: flex;
				// padding-top: 40rpx;
				font-size: 34rpx;
				font-weight: 700;
				padding: 0 0 0 20rpx;

				>span:nth-of-type(1) {
					margin: 4rpx 0 0 8rpx;
					background-color: #FFF;
				}

				>span:nth-of-type(2) {
					margin: 0 0 0 8rpx;
					background-color: #FFF;
				}
			}

			.shopName {
				display: flex;
				align-items: center;
				background-color: #FFF;
				// margin: 10rpx 0 0 0;
				padding: 10rpx 0 0 20rpx;

				>view:nth-of-type(1) {
					width: 30%;
					// font-weight: 700;
				}

				>view:nth-of-type(2) {
					width: 70%;
					// padding: 0 20rpx 0 0;
					border-radius: 10rpx;
					overflow: hidden;

					input {
						background-color: #f5f5f5;
						// color: #a4a4a4;
						font-size: 28rpx;
						padding: 8rpx 8rpx 8rpx 15rpx;
					}
				}
			}

			.name {
				display: flex;
				align-items: center;
				background-color: #FFF;
				height: 80rpx;
				// margin: 10rpx 0 0 0;
				padding: 10rpx 0 0 20rpx;

				>view:nth-of-type(1) {
					width: 30%;
					font-weight: 700;
				}

				>view:nth-of-type(2) {
					width: 70%;
					padding: 0 20rpx 0 0;
				}
			}

			.phone {
				display: flex;
				align-items: center;
				background-color: #FFF;
				height: 80rpx;
				// margin: 10rpx 0 0 0;
				padding: 10rpx 0 0 20rpx;

				>view:nth-of-type(1) {
					width: 30%;
					font-weight: 700;
				}

				>view:nth-of-type(2) {
					width: 70%;
					padding: 0 20rpx 0 0;
				}
			}

			.currentRegion {
				display: flex;
				align-items: center;
				background-color: #FFF;
				height: 80rpx;
				// margin: 10rpx 0 0 0;
				padding: 10rpx 0 0 20rpx;

				>view:nth-of-type(1) {
					width: 30%;
					// font-weight: 700;
				}

				>view:nth-of-type(2) {
					width: 70%;
					padding: 0 20rpx 0 0;
					display: flex;

					.input {
						background-color: #f5f5f5;
						// color: #a4a4a4;
						font-size: 28rpx;
						padding: 8rpx 8rpx 8rpx 15rpx;
						width: 350rpx;
					}

					.orientation {
						display: flex;
						padding: 10rpx 10rpx 10rpx 20rpx;
						font-size: 30rpx;
						color: #FBAB32;
						flex-direction: column;
						justify-content: center;
						align-items: center;
					}



				}
			}

			.detailedAddress {
				display: flex;
				align-items: center;
				background-color: #FFF;
				height: 80rpx;
				// margin: 10rpx 0 0 0;
				padding: 10rpx 0 0 20rpx;

				>view:nth-of-type(1) {
					width: 30%;
					font-weight: 700;
				}

				>view:nth-of-type(2) {
					width: 70%;
					padding: 0 20rpx 0 0;
				}
			}



		}
	}
</style>