<template>
  <div class="app-container">
      <el-card class="card-heard">
    <!-- <el-tabs type="border-card"> -->
      <el-timeline :reverse="false">
        <el-timeline-item v-for="(item, index) in list" :key="index">
          <template>
            <div class="title">{{ item.memo }}</div>
            <tinymce v-model="item.content" :height="300" />
            <div class="btn-container">
              <el-button
                type="primary"
                @click="submitForm(item)"
                id="item.id"
                v-hasPermi="['basic:protocol:save']" plain
                >保存修改</el-button
              >
              <el-button type="success" @click="preview(item.content)" plain
                >预览效果</el-button
              >
            </div>
          </template>
        </el-timeline-item>
      </el-timeline>
      <!-- 预览对话框 -->
      <el-dialog
        :title="title"
        :visible.sync="open"
        width="800px"

        append-to-body
      >
      <el-card class="card-heard">
        <div  v-html="content"  class="contentHtml"/>

      </el-card>
       <div slot="footer" class="dialog-footer" >

        <el-button @click="cancel">取 消</el-button>
      </div>
      </el-dialog>
    <!-- </el-tabs> -->
      </el-card>
  </div>
</template>
<script>
import { getProtocol, protocolEdit } from "@/api/basic/treaty";
import Tinymce from "@/components/Tinymce";
export default {
  name: "agreement",
  components: {
    Tinymce,
  },

  data() {
    return {
      list: [],
      loading: false,
      title:"",
       open: false,
       content:"",

    };
  },
  mounted() {},
  created() {
    this.init();
  },
  methods: {
    //初始化查询
    init() {
      getProtocol().then((data) => {
        if (data.code == 200) {
          this.list = data.rows;
        }
      });
    },
    //点击保存
    submitForm(row) {
      var form = row;
      this.loading = true;
      protocolEdit(form)
        .then((data) => {
          if (data.code == 200) {
            this.$message.success("保存修改成功");
            //刷新页面
            this.init();
          } else {
            this.$message.error(data.msg);
          }
        })
        .catch((error) => (this.loading = false));
    },
    // 点击预览
    preview(content) {
    //   this.$refs.mytinymce.preview(content);
    //预览内容
    console.log(content);

    this.content=content;
// content.replace(/<[^>]+>/g, "");

    this.title="预览";
    this.open = true;
    },
    //点击取消
    cancel(){
this.open = false;
    }
  },
};
</script>
<style scoped>
.title {
  display: flex;
  padding: 20px 0;
}
.btn-container {
  display: flex;
  justify-content: center;
  margin: 20px;
}
.contentHtml{
 height:500px;
 overflow-y: auto;
}
</style>
