<!--
 * @Author: 曹捷
 * @Date: 2019-08-19 15:24:34
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-03-23 16:01:49
 * @Description: 新增公告
 -->
<template>
  <a-modal class="obit-modal-default" :maskClosable="false" :title="showTitle" v-model:visible="showModal"
    @cancel="closeDialog" @ok="saveInfo" cancelText="取消" okText="确认" width="40%">
    <a-form v-if="showModal" :inline="true" :model="formData" :rules="rules" ref="formRef" :label-col="{span: 4}"
      :wrapper-col="{span:18}">
      <a-form-item label="公告标题" name="noticeTitle">
        <a-input placeholder="请输入公告标题" v-model:value="formData.noticeTitle"></a-input>
      </a-form-item>
      <a-form-item label="公告类型" name="noticeType">
        <obit-dict dictCode="sys_notice_type" type="radio" placeholder="请选择公告类型" v-model:value="formData.noticeType">
        </obit-dict>
      </a-form-item>
      <a-form-item label="状态" name="status">
        <obit-dict dictCode="sys_normal_disable" type="radio" placeholder="请选择状态" v-model:value="formData.status">
        </obit-dict>
      </a-form-item>
      <a-form-item label="内容" name="noticeContent">
        <obitEditorVue v-model:value="formData.noticeContent" placeholder="请输入通知内容"></obitEditorVue>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import { computed, inject, onMounted, reactive, ref, toRefs, watch } from 'vue'
import { util } from '../../../entery'
import obitEditorVue from '../../../components/obit-editor/obit-editor.vue'
export default {
  components: { obitEditorVue },
  // inheritAttrs: false,
  props: {
    open: {
      type: Boolean
    },
    addType: {
      type: String,
    },
    detailsInfo: {
      type: Object,
    },
  },
  setup (props, context) {
    let http = inject('http')
    let _data = reactive({
      showModal: props.open,
      formData: {
        status: '0',
      },
      superior: [],//下拉数据列表
      getlistLoading: false,//获取到下拉列表的数据前默认改选择器不可用
      formRef: null,
      orgList: [],
      rules: {
        noticeTitle: [
          { required: true, message: '请输入公告标题', trigger: 'blur' },
        ],
        noticeType: [
          { required: true, message: '请选择公告类型', trigger: 'blur' },
        ],
        noticeContent: [
          { required: true, message: '请输入内容', trigger: 'blur' },
        ],
      },
    })
    let _computed = {
      showTitle: computed(() => props.addType === 'add' ? '新增公告' : '修改公告')
    }
    let _methods = {
      saveInfo () {
        _data.formRef.validate().then(() => {
          let url = props.addType === 'add' ? 'system/notice/add' : 'system/notice/edit'
          http.commonPost(url, _data.formData).then(res => {
            context.emit('reload')
            _methods.closeDialog()
          })
        })
      },
      closeDialog () {
        util.util.cleanObj(_data.formData)
        context.emit('update:open', false)
      },
    }
    watch(() => props.open, (value) => {
      if (value) {
        _data.formData = util.util.cloneObj(props.detailsInfo)
      } else {
        util.util.cleanObj(_data.formData)
      }
    })
    onMounted(() => {
    })
    return {
      ..._computed,
      ...toRefs(_data),
      ..._methods
    }
  },
}
</script>
<style lang="less">
</style>