<template>
  <div class="doc_manage_container">
    <div class="apass_breadcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item to="/technical_support">
          技术支持
        </el-breadcrumb-item>
        <el-breadcrumb-item to="/technical_support/doc_manage">
          开发文档
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          文档编辑 - {{ title }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="editpage">
      <wang-e v-model="content"></wang-e>
      <div class="apaas_button">
        <el-button type="defalut" size="mini" @click="cancelAction">
          取消
        </el-button>
        <el-button type="primary" size="mini" @click="submitAction">
          保存
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
import wangE from "@/components/wangE";
export default {
  data() {
    return {
      title: "",
      content: "",
    };
  },
  components: {
    wangE,
  },
  created() {
    if (this.$route.params.id) {
      this.$http
        .get("/apaas/support/document/get", {
          params: {
            id: this.$route.params.id,
          },
        })
        .then(({ data }) => {
          if (data.success === 1) {
            this.title = data.data.title;
            this.content = data.data.content;
          }
        });
    }
  },
  methods: {
    cancelAction() {
      this.$router.push("/technical_support/doc_manage");
    },
    submitAction() {
      this.$http
        .put("/apaas/support/document/put", {
          id: parseFloat(this.$route.params.id),
          content: this.content,
        })
        .then(({ data }) => {
          if (data.success === 1) {
            this.$message.success("保存成功");
            this.$router.push("/technical_support/doc_manage")
          } else {
            this.$message.error(data.errMsg || "保存失败");
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message.error("保存失败");
        });
    },
  },
};
</script>

<style scoped>
.doc_manage_container {
  height: 100%;
  padding: 0 20px 30px;
  box-sizing: border-box;
}
.main_container {
  height: calc(100% - 53px);
  background-color: #fff;
  border-radius: 10px;
}
.editpage {
  background-color: #fff;
  height: calc(100% - 45px);
  margin-bottom: 20px;
  box-shadow: 0px 3px 6px 0px #f4f7fc;
  border-radius: 12px;
}
.editpage .wangeditor_class {
  height: calc(100% - 100px);
  padding: 0 20px;
  box-sizing: border-box;
}
.apaas_button {
  border-top: 1px solid #e3e5ef;
  box-sizing: border-box;
  text-align: right;
  padding-top: 30px;
}
.apaas_button .el-button + .el-button {
  margin-right: 30px;
}
</style>
