<template>
	<view class="suggest-content">
		<navigation-bar-vue title="评价" style="width: 100%;" background-color="#ffffff"
			title-color="#000000"></navigation-bar-vue>
		<view class="card-detail">
			<view class="item-field">
				<view class="item-lable is-required">
					写下你的建议
				</view>
				<view class="item-value">
          <uni-easyinput type="textarea" v-model="dataObj.content" placeholder="请输入" />
				</view>
			</view>
			<view class="item-field">
				<view class="item-lable is-required">
					上传材料
				</view>
				<view class="item-value">
					<uni-file-picker :value="fileList" :sizeType="sizeType" @select="afterRead" @delete="deleteFile"
						limit="9"></uni-file-picker>
				</view>
			</view>
			<view class="item-field" style="align-items: center;">
				<view class="submit-box" @click="submitForm">提交</view>
			</view>
			<view class="item-field" style="align-items: center;">
				<view class="my-suggest-dom" @click="goMySuggest()">
					<text>我的反馈</text>
					<uni-icons type="right" color="#623109" size="12"></uni-icons>
				</view>

			</view>
		</view>

	</view>
</template>

<script>
	import navigationBarVue from '@/components/navigation/navigationBar.vue';
  import upload from '@/utils/upload'
  import {toast} from '@/utils/common.js'
  import config from '@/config';
  import {uniAddFeedBack} from '@/api/business/notice.js'
	export default {
		components: {
			navigationBarVue
		},
		data() {
			return {
        uploadUrl: config.baseUrl,
				dataObj: {
					content: ""
				},
				sizeType: ['compressed'],
				//图片数组
				fileList: [],
        userType:"",
			}
		},
    onLoad(option){
		  this.userType = option.userType
    },
		methods: {
			afterRead(file) {
				for (let i = 0; i < file.tempFilePaths.length; i++) {
					upload({
						url: '',
						filePath: file.tempFilePaths[i]
					}).then((res) => {
						console.log(res, '215')
						this.fileList.push({
							url: res.url
						})
					})
				}
			},
			deleteFile(file, index) {
				console.log('删除文件');
				this.fileList.splice(index, 1);
			},
			/**提交*/
			submitForm() {
			  //凭证图片
        if (this.fileList.length > 0) {
          this.dataObj.images = this.fileList
              .map(item => item.url.replace(this.uploadUrl, ''))
              .join(',');
        }
        this.dataObj.userType = this.userType
        uniAddFeedBack(this.dataObj).then(res => {
          if (res.code == 200){
            uni.showToast({
              icon: 'success',
              duration: 2000,
              title: '举报成功'
            });
            uni.navigateBack()
          }
        }).catch((e)=>{
          toast(e)
        })
      },
			/**
			 * 去我的建议列表
			 */
			goMySuggest() {
				this.$tab.navigateTo('/pages/mine/set/my-suggest')
			}
		}
	}
</script>

<style lang="scss">
	.suggest-content {
		padding-top: calc(90rpx + var(--status-bar-height));
		background-color: white;
		width: 100%;
		color: #363636;
		font-size: 32rpx;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: self-start;
		justify-content: center;
		position: relative;

		.card-detail {
			border-top: 1rpx solid #F2F2F2;
			width: 100%;
			padding: 20rpx 30rpx;
			background-color: white;
			border-radius: 20rpx;
			display: flex;
			flex-direction: column;
			align-items: self-start;
			justify-content: center;
			position: relative;

			.item-field {
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: self-start;
				justify-content: center;

				.item-lable {
					padding: 15rpx 0;
					display: flex;
					align-items: center;
					justify-content: center;

				}

				.item-value {
					width: 100%;

					input {
						padding-left: 20rpx;
						line-height: 1;
						height: 70rpx;
						border: 1rpx solid #dcdfe6;
						border-radius: 8rpx;
					}

					.choose-add {
						color: #686868;
						padding: 10rpx 0 10rpx 20rpx;
						display: flex;
						align-items: center;
						justify-content: flex-start;
						border: 1rpx solid #dcdfe6;
						border-radius: 8rpx;
					}


				}

				.submit-box {
					padding: 15rpx 0;
					background-color: #FC1F3E;
					color: white;
					width: 70%;
					border-radius: 10rpx;
					margin-top: 80rpx;
					text-align: center;
				}

				.my-suggest-dom {
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 22rpx;
					margin-top: 20rpx;
				}
			}
		}
	}
</style>