<template>
<manual-block :data-model="dataModel" :ID="blockId"></manual-block>
</template>

<script>
import util from '@src/common/util.js'
import ManualBlock from '../../../block/manualBlock.vue'

export default {
  components: {
    'manual-block': ManualBlock
  },
  props: {
    blockId: {
      type: [Number, String]
    }
  },
  data() {
    return {
      dataModel: {
        type: 'Manual',
        specialID: window.initdata.ID,
        catalogID: window.initdata.catalogID,
        ID: this.blockId || '',
        content: ''
      }
    }
  },
  async created() {
    if (this.blockId) {
      const res = await axios.get(`/ui/special/blockcontent/${this.blockId}`, {
        params: {
          'type': this.dataModel.type
        }
      })
      if (res.data.data.content) {
        this.dataModel = res.data.data
      }
    }
  },
  methods: {
    async confirm() {
      var content = this.dataModel.content
      if (content === '') {
        this.$message({
          message: '请选择内容记录',
          type: 'warning'
        })
        window.eventHub.$emit('articleConfirmInvalid')
        return null
      }
      let res = await axios.post('/ui/special/blockcontent', this.dataModel)
      util.showResponseMessage(res.data)
      if (res.data.status === 1) {
        window.eventHub.$emit('blockPicked', res.data.ID)
      }
    }
  }
}
</script>
<style>
.dlg-articlepicker .manual-block-div .el-tabs__header{display:none;}
</style>
