<template>
	<view class="page">
		<view class="tips color-ffb size-22">
			注意:这段内容将会在您的喂养员个人主页，做为"服务案例”展示，并开放给其他铲屎官查看，请认真编辑哟！
		</view>
		<view class="li bg-fff">
			<view class="title">
				服务类型
				<text class="size-22 color-999 ml10">可多选</text>
			</view>
			<up-checkbox-group v-model="state.petType" @change="checkboxChange">
				<view class="flex-between mt40" style="width: 100%;">
					<up-checkbox shape="circle" class="mr10" :customStyle="{marginBottom: '8px'}"
						v-for="(item, index) in petTypeOptions" :key="index" :label="item.name" :name="item.name">
					</up-checkbox>
				</view>
			</up-checkbox-group>
		</view>

		<view class="li bg-fff">
			<view class="title">
				服务时间
			</view>
			<view class="flex-between mt16">
				<text class="size-28 color-999">选择服务时间</text>
				<view class="flex-rowr" @click="openTimePicker">
					<view class="t-r size-28 mr10" :class="[state.serveTime ? 'highlight' : '']">{{ serveTimeDesc }}</view>
					<up-icon name="arrow-right" color="#999999" size="27rpx"></up-icon>
				</view>
			</view>
			<up-datetime-picker
				v-model="state.serveTime"
				:show="showTimePicker"
				mode="date"
				:closeOnClickOverlay="true"
				@close="closeTimePicker"
				@cancel="closeTimePicker"
				@confirm="closeTimePicker"
			></up-datetime-picker>
		</view>

		<view class="li bg-fff">
			<view class="title">
				服务地点
			</view>
			<view class="flex-between mt16">
				<text class="size-28 color-999">选择服务地点</text>
				<view class="flex-rowr" @click="jumpToSeletAddress">
					<view class="t-r size-28 mr10" :class="[selectedAddress.address ? 'highlight' : '']">{{ selectedAddress.address || '请选择' }}</view>
					<up-icon name="arrow-right" color="#999999" size="27rpx"></up-icon>
				</view>
			</view>
		</view>

		<view class="li bg-fff">
			<view class="title">
				文字记录
			</view>
			<textarea class="text" placeholder="请输入文字记录，可简单描述服务过程中发生的趣事，或夸奖一下服务宠物吧，10-100字"></textarea>
		</view>

		<view class="li bg-fff">
			<view class="title">
				图片记录
			</view>
			<view class="size-28 color-999 mt16">
				请选择具有代表性的2-3张服务宠物图片，服务过程图片或视频截图，让铲屎官感受到您对毛孩子的爱吧
			</view>
		</view>

		<view class="footer-btn">
			<view class="btn">
				立即上传
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, reactive, computed } from 'vue';
	import { onShow } from '@dcloudio/uni-app'
	import dayjs from 'dayjs'

	const state = reactive({
		petType: [],
		serveTime: null,
	})
	const petTypeOptions = [{
			name: '猫咪喂养',
		},
		{
			name: '狗狗喂养',
		},
		{
			name: '异宠喂养',
		},
	]

	const checkboxChange = () => {}

	const showTimePicker = ref(false)
	const openTimePicker = () => {
		showTimePicker.value = true
	}
	const closeTimePicker = () => {
		showTimePicker.value = false
	}
	const serveTimeDesc = computed(() => {
		if (!state.serveTime) {
			return '请选择'
		}

		return dayjs(state.serveTime).format('YYYY/MM/DD')
	})

	const selectedAddress = ref({})
	const jumpToSeletAddress = () => {
		// todo: check select from map or address book ?
		
		uni.navigateTo({
			url: "/otherPages/authentication/connectAddress/index"
		})
	}

	onShow(() => {
		selectedAddress.value = uni.getStorageSync('serveAddress')
	})
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		padding-bottom: 144rpx;
	}

	.text {
		padding: 16rpx;
		background-color: #F3F3F3;
		font-size: 28rpx;
		margin-top: 16rpx;
		border-radius: 20rpx;
	}

	.tips {
		padding: 8rpx 16rpx;
		background-color: rgb(255, 250, 242);
	}

	.li {
		margin: 20rpx;
		border-radius: 20rpx;
		padding: 24rpx 36rpx;
	}

	.title {
		font-size: 30rpx;
		font-weight: 700;
		display: flex;
		align-items: center;

		&:before {
			display: block;
			content: "";
			width: 10rpx;
			border-radius: 10rpx;
			height: 34rpx;
			background-color: #FFBF60;
			margin-right: 15rpx;
		}
	}

	.highlight {
		color: #FFBF60;
	}
</style>