<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/sdk_manage/example">
          SDK管理
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          SDK示例编辑
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          {{ detail.example_name }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="editpage">
      <wang-e v-model="detail.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 {
  components: {
    wangE,
  },
  data() {
    return {
      detail: {},
    };
  },
  computed: {
    id() {
      return parseFloat(this.$route.params.id);
    },
  },
  created() {
    if (this.id) {
      this.$http
        .get("/apaas/support/sdk/example/detail", {
          params: {
            id: this.id,
          },
        })
        .then(({ data }) => {
          if (data.success === 1) {
            this.detail = data.data;
          }
        });
    }
  },
  methods: {
    cancelAction() {
      this.$router.push("/technical_support/sdk_manage/example");
    },
    submitAction() {
      this.$http
        .put("/apaas/support/sdk/example/put", {
          id: this.id,
          style_id: this.detail.style_id,
          example_name: this.detail.example_name,
          content: this.detail.content,
        })
        .then(({ data }) => {
          if (data.success === 1) {
            this.$message.success("保存成功");
            this.$router.push("/technical_support/sdk_manage/example");
          } 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>
