<template>
	<view class="content">
		<view class="cell-li">
			<view class="cell-tit">
				反馈类型
			</view>
			<view class="" style="display: flex;margin: 20rpx 0;">
				<view class="types">
					注册
				</view>
				<view class="types">
					注册
				</view>
			</view>
			<view class="type-detail" @click="showTypeDetail=true">
				<text>未收到短信</text>
				<up-icon name="arrow-down"></up-icon>
			</view>
			<up-picker confirmColor='#20B128' @confirm='confirm' @cancel='showTypeDetail=false' :show="showTypeDetail"
				:columns="columns"></up-picker>

		</view>

		<view class="cell-li">
			<view class="cell-tit" style="margin-bottom: 20rpx;">
				反馈内容
			</view>
			<up-textarea v-model="cont" style="background-color: #F5F5F5;" placeholder="请输入内容" count></up-textarea>
		</view>

		<view class="cell-li">
			<view class="cell-tit" style="margin-bottom: 20rpx;">
				图片上传
			</view>
			<up-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
				:maxCount="10"></up-upload>
		</view>

		<view class="cell-li">
			<view class="cell-tit" style="margin-bottom: 20rpx;">
				联系方式
			</view>
			<up-input placeholder="请填写您的姓名" style="background-color: #F5F5F5;margin-bottom: 20rpx;" border="surround"
				v-model="formData.name"></up-input>
			<up-input placeholder="请输入您的电话或者邮箱" style="background-color: #F5F5F5;" border="surround"
				v-model="formData.phone"></up-input>
		</view>
		<view class="btn">
			<up-button text="提交反馈" shape='circle' color="#20B128"></up-button>
			<view style="display: flex;align-items: center;margin-top: 20rpx;">
				<view style="margin: 0 auto; display: flex;" @click="navgo('/pageQuota/feedBack/list')">
					反馈记录 <up-icon name="arrow-right"></up-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from "vue"
	const showTypeDetail = ref(false)
	const columns = reactive([
		['中国', '美国', '日本']
	]);
	const confirm = (e) => {
		console.log(e)
		showTypeDetail.value = false
	}
	const cont = ref('')

	const formData = reactive({
		name: "",
		phone: ''

	})

	const navgo = (url) => {
		uni.navigateTo({
			url
		})
	}


	// 上传
	const fileList1 = ref([]);

	// 删除图片
	const deletePic = (event) => {
		fileList1.value.splice(event.index, 1);
	};

	// 新增图片
	const afterRead = async (event) => {
		// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
		let lists = [].concat(event.file);
		let fileListLen = fileList1.value.length;
		lists.map((item) => {
			fileList1.value.push({
				...item,
				status: 'uploading',
				message: '上传中',
			});
		});
		for (let i = 0; i < lists.length; i++) {
			const result = await uploadFilePromise(lists[i].url);
			let item = fileList1.value[fileListLen];
			fileList1.value.splice(fileListLen, 1, {
				...item,
				status: 'success',
				message: '',
				url: result,
			});
			fileListLen++;
		}
	};

	const uploadFilePromise = (url) => {
		return new Promise((resolve, reject) => {
			let a = uni.uploadFile({
				url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
				filePath: url,
				name: 'file',
				formData: {
					user: 'test',
				},
				success: (res) => {
					setTimeout(() => {
						resolve(res.data.data);
					}, 1000);
				},
			});
		});
	};
</script>

<style lang="scss">
	.content {
		padding: 20rpx;
		min-height: 100vh;
		background-color: white;

		.cell-li {
			margin-bottom: 50rpx;
		}

		.cell-tit {
			position: relative;

		}

		.cell-tit::after {
			content: '';
			width: 5rpx;
			height: 20rpx;
			border-radius: 20rpx;
			background-color: #20B128;
			position: absolute;
			left: -10rpx;
			top: 5rpx;

		}

		.types {
			width: 150rpx;
			height: 70rpx;
			background-color: #20B128;
			color: white;
			text-align: center;
			line-height: 70rpx;
			border-radius: 50rpx;
			margin-right: 20rpx;
		}

		.type-detail {
			background-color: #F5F5F5;
			padding: 20rpx;
			display: flex;
			justify-content: space-between;


		}
	}
</style>