<template>
  <div class="app-container">
    <div class="box-container">
      <div class="contain-title">查看回收内容</div>
    </div>
    <div class="content-container contentBox">
      <el-form :model="ruleForm2" status-icon ref="ruleForm2" label-width="100px" class="demo-ruleForm formTable">
        <div class="formWidth">
          <el-form-item label="标题" prop="title">
            <span>{{ruleForm2.title}}</span>
          </el-form-item>
          <el-form-item label="作者/来源" prop="source">
            {{ruleForm2.source}}
          </el-form-item>
          <el-form-item label="相关专家" prop="professors">
            {{ruleForm2.professors}}
          </el-form-item>
          <el-form-item label="相关机构" prop="orgs">
            {{ruleForm2.orgs}}
          </el-form-item>
          <el-form-item label="相关企业" prop="comps">
            {{ruleForm2.comps}}
          </el-form-item>
        </div>
        <el-form-item label="文章正文" prop="cnt" class="editBox">
          <div class="editContent" v-html="ruleForm2.cnt"></div>
        </el-form-item>
        <el-form-item class="deleTime">
          最后删除时间：{{modifyTime}}
        </el-form-item>
        <el-form-item class="publishButton">
          <el-button type="primary" @click="restore">恢复</el-button>
          <el-button @click="completeDelete">彻底删除</el-button>
        </el-form-item>
      </el-form>
      <div class="fileBox">
        <img :src="ruleForm2.imgUrl" alt="" class="fileImg">
      </div>

    </div>
  </div>
</template>

<script>
  import { inquireContentUrl, restoreUrl, thoroughDeleteSingleUrl } from '@/api/content'
  import { parseTime } from '@/utils/index'
  export default {
    data() {
      return {
        modifyTime: '',
        id: '',
        ruleForm2: {
          title: '',
          source: '',
          cnt: '',
          imgUrl: '',
          catalog: '',
          professors: '',
          orgs: '',
          comps: ''
        }
      }
    },
    created() {
      const id = this.$route.query.id
      this.id = id
      this.$http.get(inquireContentUrl, { id }, (response) => {
        if (response.success && response.data) {
          const info = response.data
          this.ruleForm2 = {
            catalog: info.catalog,
            cnt: info.cnt,
            title: info.title,
            source: info.source,
            imgUrl: info.imgUrl,
            professors: '',
            orgs: '',
            comps: ''
          }
          this.modifyTime = parseTime(info.modifyTime).substr(0, 19)
        }
      })
    },
    methods: {
      restore(formName) {
        this.$confirm(`确定恢复${this.ruleForm2.title}内容？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.$http.get(restoreUrl, { id: this.id }, response => {
            if (response.success) {
              if (response.data) {
                this.$router.go(-1)
                this.$message({
                  message: '恢复成功',
                  type: 'success'
                })
              } else {
                this.$http.get(inquireContentUrl, { id: this.id }, (response) => {
                  if (response.success && response.data) {
                    const info = response.data
                    if (!info.actived) {
                      this.$message({
                        message: '状态改变',
                        type: 'warning'
                      })
                    }
                  }
                })
              }
            }
          })
        }).catch(() => {
        })
      },
      completeDelete() {
        this.$confirm('确定彻底删除该条回收站内容？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.$http.get(thoroughDeleteSingleUrl, { id: this.id }, response => {
            if (response.success) {
              this.$router.go(-1)
              this.$message({
                message: '删除成功',
                type: 'success'
              })
            }
          })
        }).catch(() => {
        })
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .deleTime {
    text-align: right
  }

  .formTable {
    width: 943px
  }

  .formWidth {
    width: 500px
  }

  .content-container {
    position: relative;
  }

  .fileBox {
    position: absolute;
    top: 20px;
    left: 550px;
    text-align: center
  }

  .editContent {
    height: 500px;
    border: 1px solid #409EFF;
    overflow: hidden;
  }

  .publishButton {
    text-align: center;
  }

  .fileImg {
    width: 400px;
    height: 200px;
    border: 1px solid #409EFF;
  }
</style>