<template>
	<view class="page">
		<view class="block">
			<view class="form-list edit-form">
				<view class="line with-arrow">
					<view class="name">LOGO</view>
					<image class="avatar" :src="logo" @click="uploadLogo"></image>
				</view>
				<view class="line with-arrow">
					<view class="name">幼儿园名称</view>
					<input type="text" placeholder="请输入幼儿园名称" />
					<uni-icons type="right" size="18" color="#ababab"></uni-icons>
				</view>
				<view class="line with-arrow">
					<view class="name">标签</view>
					<input type="text" placeholder="请输入标签" />
					<uni-icons type="right" size="18" color="#ababab"></uni-icons>
				</view>
				<view class="line textarea-line">
					<view class="name">幼儿园slogan</view>
					<textarea placeholder="请输入幼儿园slogan"></textarea>
				</view>
				<view class="line with-arrow">
					<view class="name">省份</view>
					<view class="inline">
						<text v-if="disabled" class="name">{{ provinceName }}</text>
						<uni-data-picker v-else class="picker-input" :clear-icon="false" :readonly="disabled" placeholder="请选择省份" popup-title="请选择省份" preload :localdata="provinces" :map="{text: 'provinceName', value: 'provinceId'}" v-model="provinceId" @change="getCity"></uni-data-picker>
					</view>
					<uni-icons type="right" size="18" color="#ababab"></uni-icons>
				</view>
				<view class="line textarea-line">
					<view class="name">地址</view>
					<textarea placeholder="请输入地址"></textarea>
				</view>
				<view class="line textarea-line no-bd">
					<view class="name">幼儿园简介</view>
					<textarea placeholder="请输入幼儿园简介"></textarea>
				</view>
				<view class="py">
					<uni-file-picker v-model="desPics" limit="3" title="最多选择3张图片" :auto-upload="false" @select="select" ></uni-file-picker>
				</view>
			</view>
		</view>
		
		
		<view class="block">
			<view class="form-list edit-form">
				<view class="line textarea-line">
					<view class="name">地址</view>
					<textarea placeholder="请输入地址"></textarea>
				</view>
				<view class="line with-arrow">
					<view class="name">联系电话</view>
					<input type="text" placeholder="请输入联系电话" />
					<uni-icons type="right" size="18" color="#ababab"></uni-icons>
				</view>
				<view class="py">
					<uni-file-picker v-model="desPics" limit="3" title="请上传二维码,最多选择3张图片" :auto-upload="false" @select="select" ></uni-file-picker>
				</view>
			</view>
		</view>
		
		<view class="btn-wrap">
			<view class="btn" @click="submit">保存</view>
		</view>
	</view>
</template>

<script>
	import { my } from '@/apis/modules/parner.js'
	import { queryProvince, queryCity, updateAvatars, getUserRolesPermissionMenu } from '@/apis/modules/user.js'
	import OSS from '@/libs/Oss/upload'
	export default {
		data() {
			return {
				logo: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
				disabled: true,
				provinces: [],
				cities: [],
				provinceId: '',
				cityId: '',
				provinceName: '',
				cityName: '',
				desPics: []
			}
		},
		onShow() {
			// this.getInfo()
			this.getProvince()
		},
		methods: {
			// 获取个人信息
			getInfo() {
				const { partnerId, teamId } = uni.getStorageSync('team')
				my({
					partnerId,
					teamId
				}).then(({ my }) => {
					this.info = my.info
				}).catch(e => {})
			},
			// 获取省份
			getProvince() {
				queryProvince().then(({ list }) => {
					if (this.disabled) {
						const { provinceId } = this
						if (provinceId) this.provinceName = list.find(e => e.provinceId == provinceId).provinceName
					} else {
						this.provinces = list
					}
				}).catch(res => {})
			},
			// 获取城市
			getCity(val) {
				if (this.provinceId) {
					queryCity({
						provinceId: this.provinceId
					}).then(({ list }) => {
						if (this.disabled) {
							const { cityId } = this
							if (cityId) this.cityName = list.find(e => e.cityId == cityId).cityName
						} else {
							this.cities = list
						}
					}).catch(res => {})
				} else {
					this.cities = []
				}
				if (val) this.cityId = ''
			},
			select(e){
				console.log('选择文件：',e)
				OSS(e.tempFilePaths[0], (res) => {
					this.desPics.push({
						name: res.name,
						extname: res.ext,
						url: res.url,
					})
				})
			},
			// 上传logo
			uploadLogo() {
				const that = this
				uni.chooseImage({
					success: (res) => {
						const file = res.tempFilePaths[0];
						OSS(file, ({ url }) => {
							that.logo = url
						})
					}
				});
			},
			onEditorReady() {
				uni.createSelectorQuery().select('#editor').context((res) => {
					this.editorCtx = res.context
				}).exec()
			},
			// 提交
			submit() {
				
			}
		}
	}
</script>

<style scoped lang="scss">
.page {
	padding-bottom: 170rpx;
	-webkit-overflow-scrolling: touch;
}
.avatar {
	width: 80rpx;
	height: 80rpx;
	border: 0;
	border-radius: 50%;
}
.info {
	position: relative;
	padding: 24rpx;
	.line {
		margin: 20rpx 0;
		font-size: 26rpx;
		color: #333;
	}
	.qrcode {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
		width: 120rpx;
		height: 120rpx;
	}
}
</style>
