<template>
  <div class="app-container">
    <div :class="'st-content'">
      <tinymce ref="refContent" v-model="content" :height="800" />
    </div>
    <div class="xl-form scoped-bottom">
      <el-button class="xl-form-btn t1" @click="close('confirm')">保存</el-button>
      <el-button class="xl-form-btn t2" @click="close">返回楼盘页</el-button>
    </div>
  </div>
</template>
<script>
import Tinymce from '@/components/Tinymce'
export default {
  components: { Tinymce },
  mixins,
  data() {
    return {
      cObj: {},
      content: '',
    }
  },
  mounted () {
    const query = this.$route.query
    if (query.id) {
      this.$api.house.admestatecontentdetail({id: query.id}).then(res => {
        let curData = res || {}
        this.cObj = curData || {}
        this.content = curData.content || '点击这里请输入楼盘介绍'
        this.$refs.refContent.hasChange = false
      })
    }
  },
  methods: {
    fileChange (file) {
      let reader = new FileReader();
      let rs = reader.readAsArrayBuffer(file);
      let blob = null;
      reader.onload = (e) => {
        if (typeof e.target.result === 'object') {
          blob = new Blob([e.target.result])
        } else {
          blob = e.target.result
        }
        console.log(Object.prototype.toString.call(blob));
      }
    },
    close(str) {
      if (str === 'confirm') {
        const query = this.$route.query
        let newForm = {
          id: query.id
        }
        if (this.content) {
          newForm.content = this.content
        } else {
          this.$msg('请输入介绍内容')
          return
        }
        this.$api.house.admestatecontentedit(newForm).then(data => {
          this.$msgs(newForm.id ? '编辑成功' : '新增成功')
          this.$refs.refContent.hasChange = false
          this.$emit('close', newForm)
        })
      } else {
        this.$refs.refContent.hasChange = false
        this.$router.push('/house/index')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '../../styles/libEdit.scss';
.app-container {
  background: #f9f9f9;
}
.lib-edit {
  width: 900px;
  padding: 20px;
  margin: 0 auto;
  background: #fff;
  ::v-deep .el-form-item {
    margin-bottom: 10px;
  }
  ::v-deep .el-date-editor.el-input {
    width: 100%;
  }

  ::v-deep .img-upload {
    height: 180px;
    overflow: hidden;
    .icon {
      width: 280px;
    }
    .img {
      width: 280px;
    }
  }
}

.scoped-textarea {
  width: 100%;
  position: relative;
  .st-top {
    padding-bottom: 10px;
    user-select: none;
    .t {
      display: inline-block;
      vertical-align: middle;
      font-size: 14px;
      color: #2d8cf0;
      font-weight: bold;
    }
    .r {
      display: inline-block;
      vertical-align: middle;
      color: #fff;
      padding: 4px 10px;
      border-radius: 6px;
      background: #2d8cf0;
      font-weight: bold;
      font-size: 12px;
      cursor: pointer;
      &.t2 {
        background: #19be6b;
      }
    }
  }
  .st-content {
    height: 800px;
    .st-text {
      display: none;
    }
  }
  .st-text {
    position: absolute;
    bottom: 1px;
    right: 14px;
    background: #fff;
    font-size: 12px;
    z-index: 9;
    height: 16px;
    line-height: 16px;
    padding-left: 10px;
    padding-right: 10px;
    color: #595959;
    user-select: none;
  }
}

.scoped-bottom {
  position: fixed;
  bottom: 0;
  right: 0;
  background: #fff;
  width: 100%;
  box-sizing: border-box;
  padding-left: 50%;
  padding-bottom: 20px;
  padding-top: 20px;
  border-top: 1px solid #dcdcdc;
  z-index: 10;
}

::v-deep .el-drawer__body {
  padding-bottom: 30px;
}
</style>
