<template>
  <a-modal
    :title="modalTitle"
    :width="1200"
    :visible="visible"
    class="ant-modal2"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <detail-list title="" :col="2">
      <detail-list-item term="类别">{{ typeMap[model.type] }}</detail-list-item>
      <detail-list-item term="标题">{{ model.title }}</detail-list-item>
      <detail-list-item term="是否置顶">{{ model.topFlag === 1 ? '是' : '否' }}</detail-list-item>
    </detail-list>
    <detail-list title="" :col="1">
      <detail-list-item term="简介">{{ model.introduction }}</detail-list-item>
      <detail-list-item term="文件"><img :src="BaseTool.Constant.FILE_URL + model.picture" width="80px" height="80px"/></detail-list-item>
      <detail-list-item term="文件">
        <a-button style="margin-left: 8px" type="primary" icon="download" @click="downTemplate(model.picture)">下载文件</a-button>
      </detail-list-item>
      <detail-list-item term="内容"></detail-list-item>
      <detail-list-item term="" v-html="model.content"></detail-list-item>
    </detail-list>
    <detail-list title="" :col="2">
      <detail-list-item term="排序">{{ model.sort }}</detail-list-item>
      <detail-list-item term="点击量">{{ model.clicks }}</detail-list-item>
      <detail-list-item term="发布人">{{ model.createdUserName }}</detail-list-item>
      <detail-list-item term="发布时间">{{ model.createdTime }}</detail-list-item>
    </detail-list>

    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
    </template>
  </a-modal>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item

export default {
  name: 'ArticleDetail',
  components: {
    DetailList,
    DetailListItem
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      model: {
        'id': null,
        'type': null,
        'title': null,
        'status': null,
        'sort': null,
        'topFlag': null,
        'introduction': null,
        'content': null,
        'picture': null,
        'clicks': null,
        'createdTime': null,
        'createdUserId': null,
        'createdUserName': null,
        'updateTime': null,
        'updateUserId': null,
        'updateUserName': null
      }
    }
  },
  props: {
    typeMap: {
      type: Object,
      default: () => ({})
    }
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    },
    downTemplate (picture) {
      const a = document.createElement('a')
      console.log('picture: ' + picture)
      a.href = picture
      a.target = '_blank'
      a.click()
    }

  }
}
</script>
