<template>
	<view class="page">
		<!-- 反馈内容 -->
		<view class="feedback-data">
			<view class="titleall-box">
				<view class="titleall-left">
					<view class="titleall-left-line"></view>填写通知信息
				</view>
			</view>
			<view class="noticeInfo" style="width: 96%;margin: 0 auto;">
				<uni-forms-item label="通知标题">
					<uni-easyinput v-model="noticeTitle" placeholder="请输入" />
				</uni-forms-item>
				<uni-forms-item label="通知详细内容">
					<uni-easyinput type="textarea" v-model="noticeDesc" placeholder="请输入" />
				</uni-forms-item>
			</view>
			<view class="isNotice" style="display: flex; align-items: center; margin-top: 20rpx;justify-content: space-between;">
				<view class="lef" style="margin-left: 30rpx;">
					已选择<span>{{companysId.length}}</span>家企业
				</view>
				<view class="rig" @click="toChooseCom()" style="display: flex;align-items: center;">
					<text>选择企业</text>
					<view class="more-content">
						<view class="more-content-img">
							<image src="../../static/right2.png"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="submit-btn" @click="toPostVue()">
			<text>确认</text>
		</view>
	</view>
</template>

<script>
	import {
		data
	} from '../../uview-ui/libs/mixin/mixin';
	import request from '@/utils/request.js'
	import utils from '../../service/utils';
	export default {
		data() {
			return {
				userCode: {},
				// 选择图片路径
				filePath: [],
				uploadPath: [],
				type: "",
				lastModifyUserId: '',
				// 校验表单数据
				valiFormData: {
					title: '',
					bodyContent: '',
					subTitle: '',
				},
				// 通知信息标题
				noticeTitle:'',
				// 通知详情
				noticeDesc:'',
				creater: '',
				rules: {
					title: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					subTitle: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
				},
				baseUrl: "http://deyanggaoxin.fengshiyun.com",
				// 判断是否传了id
				isId: '',
				have: false,
				detailData: [],
				// 需要通知的公司的id
				companysId: []
			};

		},
		// onShow() {
		// 	this.getType()
		// },
		onUnload() {
			uni.$off('idInfo')
		},
		onLoad(options) {
			console.log("options", options)
			uni.$on('idInfo', res => {
				console.log("选择公司页面返回的公司ID", res)
				if(res.length > 0)
				this.companysId = res
			})
			if (JSON.stringify(options) == "{}") {
				this.have = true
			} else {
				this.isId = JSON.parse(options.data)
				console.log("Id", this.isId)
				this.getConDetail(this.isId)
			}
			this.getUser()
			let user = uni.getStorageSync('user')
			this.lastModifyUserId = user.userInfo.userId

		},
		methods: {
			// 获取上传状态
			select(e) {
				console.log('选择文件：', e)
				this.filePath = e.tempFilePaths
			},
			// 跳转到选择通知企业页面
			toChooseCom() {
				uni.navigateTo({
					url: '/pages/chooseCom/chooseCom'
				})
			},
			// 返回到发布内容页面
			toPostVue(){
				uni.$emit('tellInfo',[this.noticeTitle,this.noticeDesc])
				uni.navigateBack({
					delta:1
				})
			},
			// 获取用户信息
			getUser() {
				if (uni.getStorageSync('user')) {
					this.userCode = uni.getStorageSync('user').userInfo
					// this.userInfo = this.userCode.userAccount
					// this.userInfo = '123456'
					console.log('用户已登录！', this.userCode)
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/index'
						})
					})
				}
			},
			// 提交内容
			submitContent(ref) {
				let that = this
				this.$refs[ref].validate().then(res => {
					console.log('success', res);
					uni.showToast({
						title: `校验通过`
					})

					this.uploadPath = []
					for (let i = 0; i < this.filePath.length; i++) {
						uni.uploadFile({
							url: "http://deyanggaoxin.fengshiyun.com/api/file/Uploader/1",
							filePath: this.filePath[i],
							name: 'file',
							success: (res) => {
								console.log(JSON.parse(res.data))
								let data = JSON.parse(res.data).data
								console.log(data)
								this.uploadPath.push(data)
							}
						})
					}
					console.log('需要', this.uploadPath)
					setTimeout(function() {
						that.postAll()
					}, 1500)
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	@import 'Feedback.scss';
	.more-content{
		display: flex;
		align-items: center;
		image{
			width: 100rpx;
			height: 100rpx;
			border-radius: 100%;
		}
		.more-content-img {
			image {
				width: 24rpx;
				height: 24rpx;
			}
		}
	}
</style>