<template>
	<view class="publishPost">
		<navbar 
		leftClick
		@leftClick="$utils.navigateBack"
		title="发布帖子"/>
		
		<view class="images box">
			<uv-upload 
			:fileList="fileList" 
			:maxCount="5" 
			multiple 
			width="150rpx" 
			height="150rpx"
			@delete="deleteImage"
			@afterRead="afterRead"
			:previewFullImage="true"></uv-upload>
		</view>
		
		<view class="title-input box">
			<input type="text" placeholder="添加标题"/>
		</view>
		
		<view class="content-input">
			<uv-textarea 
			v-model="form.content" 
			:maxlength="200" 
			autoHeight
			count
			placeholder="添加正文"></uv-textarea>
		</view>
		
		<view class="upTop">
			<view class="title">
				<uv-icon name="pushpin-fill"></uv-icon>
				是否置顶
			</view>
			<uv-radio-group v-model="form.upTop">
				<view class="list">
					<view class="item"
					v-for="(item, index) in upTopList"
					:key="index">
						<view class="left">
							{{ item.info }}
						</view>
						<view class="right">
							<uv-radio
							size="35rpx"
							icon-size="35rpx"
							:name="item.id">
							</uv-radio>
						</view>
					</view>
				</view>
			</uv-radio-group>
		</view>
		
		<submit
		@submit="submit"
		@preview="preview"
		@draft="draft"
		submitTitle="发布帖子"
		/>
	</view>
</template>

<script>
	import submit from '@/components/content/submit.vue'
	import uvUpload from '@/uni_modules/uv-upload/components/uv-upload/uv-upload.vue'
	export default {
		components : {
			submit,
			uvUpload,
		},
		data() {
			return {
				upTopList : [
					{
						info : '置顶1天3元',
						id : 1,
					},
					{
						info : '置顶2天3元',
						id : 4,
					},
					{
						info : '置顶3天3元',
						id : 3,
					},
					{
						info : '置顶4天3元',
						id : 2,
					},
				],
				form : {
					image : [],
					content : '',
					upTop : '',
				},
				fileList: [
					{
						url: 'https://cdn.uviewui.com/uview/swiper/2.jpg'
					},
				],
			};
		},
		methods : {
			//上传图片
			uploadImage(){
				let self = this
				this.$Oss.ossUploadImage({
					success(res){
						self.form.images.push(res)
					}
				})
			},
			deleteImage(e){
				this.fileList.splice(e.index, 1)
			},
			afterRead(e){
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.fileList.push({
							url
						})
					})
				})
			},
			submit(){},
			preview(){},
			draft(){},
		}
	}
</script>

<style lang="scss" scoped>
.publishPost{
	background-color: #fff;
	min-height: 100vh;
	font-size: 28rpx;
	/deep/ .uv-textarea{
		background-color: transparent;
		border: none;
	}
	/deep/ .uv-textarea__count{
		background-color: transparent !important;
	}
	.box{
		padding: 0 20rpx;
	}
	.images{
		display: flex;
		flex-wrap: wrap;
		padding: 20rpx;
	}
	.title-input{
		border-bottom: 1px solid #00000015;
		padding-bottom: 25rpx;
		margin-bottom: 15rpx;
	}
	.content-input{
		min-height: 400rpx;
	}
	.upTop{
		.title{
			padding-top: 20rpx;
			padding-left: 30rpx;
			border-top: 1px solid #00000015;
			display: flex;
			align-items: center;
		}
		.list{
			padding-top: 30rpx;
			width: 100%;
			.item{
				display: flex;
				padding: 20rpx;
				padding-left: 80rpx;
				justify-content: space-between;
				width: 600rpx;
				border-bottom: 1px solid #00000015;
				align-items: center;
			}
		}
	}
}
</style>
