<template>
	<view class='base-info'>
		<view class="blank-info"></view>
		<!-- 反馈类型 -->
		<view class='my-feed' v-if="isAdd" @click="linkToIndex()">
			<view class="my-feed-info">
				<u-icon name="chat" size="16" color="#2979ff" style="margin-right: 5px;"></u-icon>
				<view>我的反馈记录</view>
			</view>
			<view>
				<u-icon name="arrow-right" size="16"></u-icon>
			</view>
		</view>
		<view class='label-info'>新建反馈</view>
		<u--textarea v-model="model.INFO" :disabled="!isAdd" placeholder="请输入反馈意见" border="none" height="150"></u--textarea>
		<view class="upload-title">附件</view>
		<full-upload v-model="model.Nav_Files" :isShowBtn='isAdd' :listProp='listProp'
			:listPropVal='listPropVal'></full-upload>

		<view class='label-info'>回复</view>
		<view>
			<u--textarea v-model="model.BACKINFO" :disabled="!isAdd" placeholder="请输入反馈意见"
				border="none" height="150"></u--textarea>
		</view>

		<button @click="formSubmit" type="primary" v-if="isAdd" class='save-btn'>提交</button>

	</view>
</template>

<script>
	import {
		feedBack,
		feedBackGet
	} from '../../../services/common'
	import {
		guid,
		initFilter,
		extendRule,
		extendInclude
	} from '../../../utils/common'

	export default {
		data() {
			return {
				listProp: [],
				listPropVal: [],
				isAdd: true,
				model: {
					ID: '',
					INFO: '',
					USER_ID: '',
					DEPARTMENT_ID: '',
					STATUS: 0,
					Nav_Files: []
				},
				rules: {
					INFO: [{
						type: 'string',
						required: true,
						message: '反馈意见不能为空',
						trigger: ['blur', 'change']
					}, {
						max: 400,
						message: '反馈意见最多400字',
						trigger: ['blur', 'change']
					}]
				},
			}
		},
		onLoad(option) {
			if (option.isAdd) {
				if (option.isAdd === 'false')
					this.isAdd = false
			}
			if (this.isAdd == false) {
				this.model.ID = option.ID //数据加载
				this.loadData()
			} else {
				this.listProp.push('FDDEBACK_ID')
				this.model.ID = guid()
				this.listPropVal.push(this.model.ID)
			}
		},
		methods: {
			formSubmit() {
				this.$refs.form.validate().then(res => {
					const appInfoData = uni.getStorageSync('appInfo')
					if (appInfoData.User == undefined) {
						uni.$showErrorInfo('获取人员信息失败')
						return false
					} else if (appInfoData.User.DEPARTMENT_ID == undefined) {
						uni.$showErrorInfo('获取人员部门失败')
						return false
					}

					this.model.ORG_ID = uni.getStorageSync('orgId')
					this.model.USER_ID = appInfoData.User.ID
					this.model.DEPARTMENT_ID = appInfoData.User.DEPARTMENT_ID
					this.model.STATUS = 10
					feedBack(this.model).then(res => {
						if (res.IsSuccessful) {
							uni.$showMsgFunc('反馈成功!', () => {
								uni.navigateBack()
							}, 'success', 1000)
						} else {
							uni.$showErrorInfo('操作失败')
						}
					})

				}).catch((error) => {
					uni.$showErrorInfo(error)
				})
			},
			linkToIndex() {
				uni.navigateTo({
					url: 'feedBackIndex'
				})
			},
			loadData() {
				this.pageIndex++
				const orgId = uni.getStorageSync('orgId')
				let json = initFilter(orgId, "", "CREATE_TIME", 1, this.pageIndex);
				extendRule(json, 'ID', 1, this.model.ID)
				extendInclude(json, "Nav_Files.Nav_ImgFile")
				feedBackGet(json).then(res => {
					this.model = res
				})
			},
		}
	}
</script>

<style scoped>
	.base-info {
		/* padding: 16px; */
		width: 100%;
		height: 100vh;
		position: relative;
		box-sizing: border-box;
		background-color: #F1F2F8;
		font-size: 16px;
	}

	.blank-info {
		padding: 10px;
	}

	.my-feed {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		background-color: #ffffff;
		padding: 10px;
	}

	.my-feed-info {
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.label-info {
		margin: 20px 0px 20px 10px;
	}

	.info-form {}

	.save-btn {
		margin-top: 20px;
	}

	.upload-title {
		color: #303133;
		font-size: 15px;
		line-height: 22px;
		padding: 20px 10px;
	}
</style>