<template>
	<view class="content">
		<view class="row1">
			<u-input placeholder="这一刻得想法..." focus :border="false" v-model="formData.content"></u-input>
		</view>
		<view class="row2">
			<cl-upload v-model="fileList" @onSuccess="onSuccess" @showType='getShowType($event)'></cl-upload>
		</view>
		<view class="row3 flex flex-between" @click="selectPlace">
			<view class="left flex">
				<u-icon name="map-fill" color="#112253" size="18"></u-icon>
				<text style="margin:0 20rpx;">{{formData.location?formData.location:'所在位置'}}</text>
			</view>
			<view class="right">
				<u-icon name="arrow-right" color="#112253" size="20"></u-icon>
			</view>
		</view>
		<view class="row4 flex flex-between">
			<view class="left flex">
				<u-icon name="pushpin" color="#112253" size="18"></u-icon>
				<text style="margin:0 20rpx;">开启评论</text>
				<u-switch v-model="switchStatus" activeColor="#112253" @change="change($event,1)" size="20"></u-switch>
			</view>
			<view class="right">
				<u-icon name="arrow-right" color="#112253" size="20"></u-icon>
			</view>
		</view>
		<view @click="submit" class="submit">提交</view>
	</view>
</template>

<script>
	var that;
	import uploadImage from '@/components/ossutil/uploadFile.js';
	export default {
		data() {
			return {
				userInfo: {},
				switchStatus: true,
				fileList: [],
				formData: {
					commonId: '',
					head: '',
					nickname: '',
					content: '',
					image: '',
					location: '',
					commentFlag: '',
					positioning:'',
					circleId:'',
					mediaType:''
					
				}
			};
		},
		onShow() {
			this.userInfo = uni.getStorageSync("userInfo")
			
		},
		onLoad(options) {
			that = this
			this.formData.circleId = options.id
		},
		methods: {
			getShowType(type){debugger
			console.log("文件类型",type)
				this.mediaType = type
			},
			onSuccess(reslut) {
				// 把服务端返回的图片地址添加到list中与组件数据同步
				this.fileList.push(reslut)
			},
			submit() {debugger
				this.formData.commonId = this.userInfo.id
				this.formData.head = this.userInfo.head
				this.formData.nickname = this.userInfo.nickname
				this.formData.image = this.fileList.toString()
				this.formData.mediaType = this.mediaType
				if (this.switchStatus) {
					this.formData.commentFlag  = 1
				} else {
					this.formData.commentFlag  = 0
				}
				if (!this.formData.content) {
					uni.showToast({
						icon: "none",
						title: '内容不能为空！',
						duration: 2000
					});
					return
				}
				this.$request.baseRequest('admin.unimall.circleFriendsInfo', 'add', {
					circleFriendsInfo: JSON.stringify(this.formData)
				}, failres => {
					uni.showToast({
						icon: "none",
						title: failres.errmsg,
						duration: 3000
					});

					uni.hideLoading()
				}).then(res => {
					debugger
				})
				uni.showToast({
					icon: "success",
					title: '保存成功！',
					duration: 2000
				});
				setTimeout(() => {
					uni.navigateBack()
				}, 2000)
			},
			selectPlace() {
				uni.chooseLocation({
					success: function(res) {
						that.formData.location = res.address
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #fff;
		padding: 40rpx;

		.row2,
		.row3 {
			border-bottom: 1px solid #E6E6E6;
			padding: 30rpx 0;
		}

		.row4 {
			padding-top: 30rpx;
		}
	}

	.submit {
		position: fixed;
		bottom: 100rpx;
		background: #112253;
		color: #fff;
		width: calc(100% - 80rpx);
		padding: 20rpx;
		box-sizing: border-box;
		text-align: center;
		border-radius: 20rpx;
	}
</style>