<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="@/static/feedback_bg.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="@/static/selected_dh.png" v-if="tidx===1"></image>
				</div>
				<div class="pre adffcacjc" :class="{'active':tidx===2}" @tap="changeType(2)">
					<text>新功能建议</text>
					<image src="@/static/selected_dh.png" v-if="tidx===2"></image>
				</div>
				<div class="pre adffcacjc" :class="{'active':tidx===3}" @tap="changeType(3)">
					<text>其他</text>
					<image src="@/static/selected_dh.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.desc" 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.contact" 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,
					desc:'',
					photo:'',
					contact:''
				},
				fileList:[],
			}
		},
		methods:{
			changeType(type){
				this.tidx = 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) => {
				  let a = uni.uploadFile({
					url: baseApi.BaseApi + '/uploadFile',
					filePath: url,
					name: "file",
					success: (res) => {
						let data = JSON.parse(res.data);
						if(data){
							if(data.code!==0) return
							setTimeout(() => {
								resolve(data.data);
							}, 1000);
						}
					},
				  });
				});
			},
			submit(){
				if(!this.dto.desc) return this.$showToast('请输入问题描述')
			}
		}
	}
</script>

<style scoped lang="less">
	.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('@/static/upload.png') no-repeat;
			background-size: 100% 100%;
		}
		
		.zt_btn{
			margin-top: 30rpx;
		}
	}
</style>