<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='意见反馈' :titleStyle="{'color':'transparent'}" bgColor='transparent'></cus-header>
		<image class="topbg" src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/fe42b211-b00a-41d8-866c-0af96ff6fe35.png"></image>
		<div class="box" style="margin-top: 189rpx;">
			<div class="title adfac">选择问题类型<span>*</span></div>
			<div class="list adfacjb">
				<div class="pre adffcacjc" :class="{'active':tidx===1}" @tap="changeType(1)">
					<text>功能异常</text>
					<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/04b1514c-1024-4092-8be0-aa0af2e9b015.png" v-if="tidx===1"></image>
				</div>
				<div class="pre adffcacjc" :class="{'active':tidx===2}" @tap="changeType(2)">
					<text>新功能建议</text>
					<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/04b1514c-1024-4092-8be0-aa0af2e9b015.png" v-if="tidx===2"></image>
				</div>
				<div class="pre adffcacjc" :class="{'active':tidx===3}" @tap="changeType(3)">
					<text>其他</text>
					<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/04b1514c-1024-4092-8be0-aa0af2e9b015.png" v-if="tidx===3"></image>
				</div>
			</div>
		</div>
		<div class="box">
			<div class="title adfac">问题描述<span>*</span></div>
			<div class="desc">
				<u-textarea height="160rpx" v-model="dto.suggestion" placeholder="尽量详细描述您遇到的问题、具体位置及体现形式等" border="none"></u-textarea>
			</div>
		</div>
		<div class="box">
			<div class="title adfac">图片补充<span class="tip">上传问题截图可以让问题快速解决哦！</span></div>
			<div class="upload">
				<u-upload width="148rpx" height="148rpx"
					:fileList="fileList"
				    @afterRead="afterRead"
				    @delete="deletePic"
				    :maxCount="1"
				></u-upload>
			</div>
		</div>
		<div class="box lxfs adfacjb">
			<div class="title">联系方式</div>
			<div class="contact">
				<u-input v-model="dto.phone" placeholder="手机号/QQ号/微信号，方便与您联系" border="none"></u-input>
			</div>
		</div>
		<div class="zt_btn" @tap="submit">提交</div>
	</view>
</template>

<script>
	const baseApi = require('@/http/baseApi.js')
	export default {
		data(){
			return {
				tidx:1,
				dto:{
					type:1,
					suggestion:'',
					pics:'',
					phone:''
				},
				fileList:[],
			}
		},
		methods:{
			changeType(type){
				this.tidx = type;
				this.dto.type = type;
			},
			// 删除图片
			deletePic(event) {
				this.fileList.splice(event.index, 1);
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file);
				let fileListLen = this.fileList.length;
				lists.map((item) => {
				  this.fileList.push({
					...item,
					status: "uploading",
					message: "上传中",
				  });
				});
				for (let i = 0; i < lists.length; i++) {
				  const result = await this.uploadFilePromise(lists[i].url);
				  let item = this.fileList[fileListLen];
				  this.fileList.splice(
					fileListLen,
					1,
					Object.assign(item, {
					  status: "success",
					  message: "",
					  url: result,
					})
				  );
				  fileListLen++;
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
				  uni.uploadFile({
					url: baseApi.BaseApi + '/sys/oss/uploadFile',
					filePath: url,
					name: "file",
					header:{
						token: uni.getStorageSync('token')	
					},
					success: (res) => {
						let data = JSON.parse(res.data);
						if(data){
							if(data.code!==0) return
							setTimeout(() => {
								resolve(data.data);
							}, 1000);
						}
					}
				  });
				});
			},
			submit(){
				if(!this.dto.suggestion) return this.$showToast('请输入问题描述');
				if(this.fileList.length) this.dto.pics = this.fileList[0].url;
				this.$api.post('/sys/suggest/save',this.dto).then(res=>{
					if(res.data.code!==0) return this.$showToast(res.data.msg)
					this.$showToast('提交成功~');
					setTimeout(()=>{
						uni.reLaunch({
							url:'/pages/my'
						})
					},1500)
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	::v-deep .u-icon__icon{
		font-size: 48rpx !important;
	}
	::v-deep .u-upload__deletable{
		width: 48rpx !important;
		height: 48rpx !important;
	}
	::v-deep .u-upload__deletable__icon{
		transform: scale(2.7) !important;
		top: 14rpx !important;
		right: 14rpx !important;
	}
	::v-deep .u-upload__success{
		border-width:24rpx !important;
	}
	::v-deep .u-upload__success__icon{
		transform: scale(2.7) !important;
		bottom: -16rpx !important;
		right: -16rpx !important;
	}
	
	.page{
		background: #F7F6F9;
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
		
		.topbg{
			width: 100%;
			position: fixed;
			left: 0;
			top: 0;
		}
		
		.box{
			width: 100%;
			background: #FFFFFF;
			border-radius: 24rpx;
			margin-top: 20rpx;
			padding: 40rpx 24rpx;
			box-sizing: border-box;
			position: relative;
			
			.title{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #111111;
				line-height: 32rpx;
				span{
					color: #F31616;
					&.tip{
						font-weight: 400;
						font-size: 24rpx;
						color: #A6A6A6;
						margin-left: 10rpx;
					}
				}
			}
			
			&.lxfs{
				.title{
					width: 154rpx;
				}
				.contact{
					width: calc(100% - 154rpx);
				}
			}
		}
		
		.list{
			margin-top: 48rpx;
			.pre{
				width: calc(100% / 3 - 14rpx);
				height: 80rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				border: 1rpx solid #C7C7C7;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				line-height: 80rpx;
				text-align: center;
				position: relative;
				image{
					width: 48rpx;
					height: 48rpx;
					position: absolute;
					right: 0;
					bottom: 0;
				}
				&.active{
					background: #D9F159;
					border: 1rpx solid #D9F159;
					font-weight: bold;
					color: #111111;
				}
			}
		}
		
		.desc{
			margin-top: 40rpx;
		}
		
		.upload{
			margin-top: 54rpx;
			width: 148rpx;
			height: 148rpx;
			background: url('https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/ee77704d-8cda-4cfb-a4d8-23a95040e8ad.png') no-repeat;
			background-size: 100% 100%;
		}
		
		.zt_btn{
			margin-top: 30rpx;
		}
	}
</style>