<template>
	<view class="page">
		<view class="content">
			<view style="padding: 30rpx 0;">
				<text>请选择您要反馈的问题类型：</text>
			</view>

			<radio-group  class="block" @change="RadioChange">
				<view class="radioBox">
					<view class="radioItem" :class="data.feedbackType==item.feedbackType?'checkBorder':'defalutBorder'" v-for="(item,index) in typeList" :key="index">
						<label class="flex" >
							<view class="">
								<radio  style="transform: scale(.7);"  class="round blue" :class="data.feedbackType===item.feedbackType?'checked':''" :checked="data.feedbackType==item.feedbackType?true:false"
								 :value="item.feedbackType"></radio>
							</view>
							<view class="text-left padding-left-20 flex" style="flex-direction: column;justify-content: center;">
								{{item.title}}
							</view>
						</label>
					</view>
				</view>
			</radio-group>
			<view class="area">
				<view >
					<textarea @input="input" :value="data.content"  maxlength="120"  placeholder="请描述您的问题,以便我们尽快为您处理"></textarea>
					<view  class="text-right text-df text-gray padding-bottom-10">
						{{data.content.length}} / 120
					</view>
				</view>
				<view class="imgArea">
					<view class="padding-bottom-20">
						<text class="">请提供相关问题的截图或照片（最多四张）</text>
					</view>
					<view class="cu-form-group" style="padding: 20rpx 0 0 0;">
						<view class="grid col-4 grid-square flex-sub">
							<view class="bg-img" v-for="(item,index) in imgList" :key="index" @click="viewImage(index)" >
							 <image :src="imgList[index]" mode="aspectFill"></image>
								<view class="cu-tag bg-red" style="padding: 6rpx;" @click.stop="DelImg(index)" >
									<text class='cuIcon-close' ></text>
								</view>
							</view>
							<view class="solids" @click="chooseImage" v-if="imgList.length<4">
								<text class='cuIcon-add ' style="font-size: 60rpx;color: #c9c9c9;"></text>
							</view>
						</view>
					</view>
					<!-- <u-upload @on-choose-complete="chooseImage" :auto-upload="false" width="194" height="194" :action="action" max-count="4" :file-list="fileList" ></u-upload> -->
				</view>
				
			</view>
			<view class="bg-white" style="height: 150rpx;">
				
			</view>
		</view>
		<view @click="submit"  class=" footer-fixed cu-btn  base-bg-color flex " style="padding: 45rpx;" :style="{marginBottom:safeAreaBottom}">
			提交反馈
		</view>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				//图片回显
				imgList:[],
				data:{
					name:'',
					
					content:'',
					images:'',
					feedbackType:"0",
				},
				//选择项列表
				typeList:[
					{
						title:'功能异常：功能故障或不可用',
						feedbackType:'0'
					},
					{
						title:'产品建议：用的不爽，我有建议',
						feedbackType:'1'
					},
					{
						title:'安全密码：密码，故障等',
						feedbackType:'2'
					},
					{
						title:'其他问题',
						feedbackType:'3'
					},
				],
			}
		},
		computed: {
		  //ios底部安全区域
		  safeAreaBottom() {
		    let info = uni.getSystemInfoSync()
		    let safe = 20
		    if (
		      info &&
		      ['devtools', 'ios'].includes(info.platform) &&
		      info.statusBarHeight > safe
		    ) {
		      return info.statusBarHeight - safe+'px'
		    }
		    return 0
		  }
		},
		methods: {
			//选择反馈类型
			RadioChange(e){
				this.data.feedbackType=e.detail.value
			},
			/**输入问题描述
			 * @param {Object} e
			 */
			input(e){
				this.data.content=e.detail.value
			},
			submit(){
				this.data.agnecyId=this.$cache.get('agencyId')
				if (this.$cache.get('loginType')==this.$loginType.STAFF) {
					let userInfo=getApp().globalData.userInfo
					this.data.openId=userInfo.openId
					this.data.name=userInfo.realName
					this.data.phone=userInfo.phone
				}else if(this.$cache.get('loginType')==this.$loginType.ENTERPRISE){
					this.data.name=this.$cache.get('enterpriseName')
				}
				this.data.images=this.imgList.join(',')
				if (this.$isEmpty(this.data.content)) {
					uni.showToast({
						title:"问题描述不能为空",
						icon:"none"
					})
					return
				}
				if (this.data.content.length<3) {
					uni.showToast({
						title:"问题描述不能少于三个字",
						icon:"none"
					})
					return
				}
				if (this.$isEmpty(this.data.images)) {
					uni.showToast({
						title:"请提供相关截图",
						icon:"none"
					})
					return
				}
				this.$api.feedback.submit(this.data).then(res=>{
					if (res.success) {
						this.$showModel('提交成功，感谢您的反馈!',false).then(res=>{
							uni.navigateBack({
								delta:1
							})
						})
					}
				})
			},
			/**
			 * 上传问题截图
			 */
			chooseImage() {
				let that=this
				uni.chooseImage({
					count: 4-this.imgList.length, 
					sizeType: ['original', 'compressed'], 
					sourceType: ['album'],
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						for (let index in tempFilePaths) {
							that.$api.uploadFile.submit(tempFilePaths[index]).then(res=>{
								that.imgList.push(res.data.link)
							})
						}
					}
				});
			},
			/*预览图片*/
			viewImage(index) {
				uni.previewImage({
					urls: this.imgList,
					current: index
				});
			},
			/*删除图片*/
			DelImg(index) {
				uni.showModal({
					title: '提示',
					content: '确定要删除这张照片吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(index, 1)
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.page{
		background-color: #FFFFFF;
		min-height: 100vh;
	}
	view{
		box-sizing: border-box;
	}
	
	.commit{
		color: #fff;
		font-size: 28upx;
		text-align: center;
		line-height: 88upx;
		margin: 0 20upx;
		width: 690upx;
		height:88upx;
		background:$base-color;
		border-radius:25px;
		margin-bottom: 50upx;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		
	}
	.content{
		margin: 0 26rpx;
		.radioBox{
			padding-top: 10rpx;
			.radioItem{
				padding: 18rpx;
				margin-bottom: 15rpx;
				border-radius: 10rpx;
			}
			.defalutBorder{
				border: 1rpx solid #d1d1d1;
			}
			.checkBorder{
				border: 1rpx solid $base-color;
				color: $base-color;
			}
			
		}
		.area{
			margin-top: 20rpx;
			padding: 20rpx;
			border-radius: 12rpx;
			border: 1rpx solid #d1d1d1;
			
			textarea{
				width: 100%;
				line-height: 50rpx;
			}
			.imgArea{
				border-top: 1rpx solid #d1d1d1;
				padding-top: 30rpx;
			}
			
		}
	}
	
</style>
