<template>
	<view class="">
		<u-toast ref="uToast"/>
		<view class="content">
			<u-form :model="model"  label-position="top" ref="uForm">
				<u-form-item :required="true" label="公告标题">
					<u-input :border="true" v-model="model.title" placeholder="请输入公告标题"/>
				</u-form-item>
				<u-form-item  :required="true" label="公告内容">
					<u-input :border="true" type="textarea" height="500" placeholder="请输入公告内容" v-model="model.notice" />
				</u-form-item>
			</u-form>
		</view>
		<view @click="confirm" class="bottom-bar" style="position: fixed;bottom:40rpx;">
			<view class="cu-btn base-bg-color radius" style="width: 80%;height: 84rpx;">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model:{}
			}
		},
		methods: {
			confirm(){
				let agencyId=this.$cache.get('agencyId')
				if (this.$isEmpty(agencyId)) {
					this.$showToast('系统错误','error')
					return
				}
				if (this.$isEmpty(this.model.title)) {
					this.$showToast('请输入标题','error')
					return
				}
				if (this.$isEmpty(this.model.notice)) {
					this.$showToast('请输入内容','error')
					return
				}
				this.model.agencyId=agencyId
				this.model.notice=encodeURIComponent(this.model.notice)
				this.$api.notice.submit(this.model).then(res=>{
					if (res.success) {
						this.$showModel('发布成功',false).then(res=>{
							uni.navigateBack({
								delta:1
							})
						})
					}else{
						this.$showToast('发布失败')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #FFFFFF;
	}
	.content{
		padding: 30rpx;
	}
</style>
