<template>
    <view class="create">
        <u--textarea v-model="content" count height="200" maxlength="200" placeholder="请输入公告内容"></u--textarea>

        <u-button type="primary" text="发布" @click="onCreate"></u-button>
    </view>
</template>

<script>
    import {
        createGroupAnnouncement
    } from '@/apis/interfaces/im.js'

    export default {
        data() {
            return {
                targetId: '',
                content: ''
            }
        },
        onLoad(e) {
            this.targetId = e.targetId
        },
        methods: {
            onCreate() {
                createGroupAnnouncement(this.targetId, this.content).then(res => {
                    uni.showToast({
                        title: '发布成功',
                        success: () => {
                            setTimeout(() => {
                                uni.navigateBack()
                            }, 1000)
                        }
                    })
                }).catch(err => {
                    uni.showToast({
                        icon: 'none',
                        title: err.message
                    })
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .create {
        padding: $padding;

        .u-button {
            margin-top: $padding;
        }
    }
</style>
