<template>
	<up-popup :show="popShow" @close="close" @open="open" mode="center" :round="9">
		<view class="u-p-32 box u-font-28">
			<view class="u-flex u-relative u-row-center">
				<view class="u-font-32">编辑</view>
				<view class="u-absolute close">
					<up-icon @click="close" :size="16" color="#000" name="close-circle-fill"></up-icon>
				</view>
			</view>
			<view class="u-m-t-36">
				<view>修改分组名称：</view>
				<view class="u-m-t-38">
					<view class="u-m-b-32">
						<view class="u-m-t-16">
							<up-input v-model="name">
							</up-input>
						</view>
					</view>

					<view class="u-m-t-60">
						<my-button type="primary" shape="circle" @tap="save">
							<view class="u-font-32">
								保存
							</view>
						</my-button>

					</view>
				</view>
			</view>
		</view>
	</up-popup>
</template>

<script setup>
	import { reactive, ref, watch } from 'vue';

	const props = defineProps({
		show: {
			type: Boolean,
			default: false
		},
		item: {
			type: Object,
			default: () => {
				name:''
			}
		}
	})

	const data = ref(props.item)
	const emits = defineEmits(['update:show', 'save'])
	
	let popShow = ref(props.show)
	let name=ref('')
	
	watch(()=>props.item.name,(newval)=>{
		name.value=newval
	})
	
	watch(() => props.show, (newval) => {
		popShow.value = newval
		if (newval) {
			data.value = props.item
		}
	})
	
	watch(() => popShow.value, (newval) => {
		emits('update:show', newval)
	})

	function close() {
		popShow.value = false
	}

	function open() {

	}

	function save() {
		console.log(data)
		emits('save', {
			...data.value,
			name:name.value
		})
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 556rpx;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
		box-sizing: border-box;
	}

	.close {
		position: absolute;
		right: 0;
	}

	.number {
		color: #EE4646;
	}
</style>