<template>
  <div>
    <div class="config_button">
      <el-button type="primary" @click="save" size="mini">保存</el-button>
      <el-button @click="goBack" size="mini">取消</el-button>
    </div>
    <div id="bar" class="bar"></div>
    <div id="editor" class="editor"></div>
  </div>
</template>
<script>
var E = require("wangeditor");
export default {
  data() {
    return {
      key: "",
      value: ""
    };
  },
  methods: {
    save: function() {
      var that = this;
      var param = {
        key: this.key,
        value: this.value
      };
      this.$http.saveSysConfig(param, this).then(res => {
        if (res.code === 0) {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1000,
            onClose: function() {
              that.$router.back();
            }
          });
        }
      });
    },
    goBack: function() {
      this.$router.back();
    }
  },
  mounted: function() {
    var that = this;
    var editor = new E("#bar", "#editor");
    editor.customConfig.uploadImgShowBase64 = true;
    editor.customConfig.colors = [
        '#00000000',
        '#000000',
        '#eeece0',
        '#1c487f',
        '#4d80bf',
        '#c24f4a',
        '#8baa4a',
        '#7b5ba1',
        '#46acc8',
        '#f9963b',
        '#ffffff'
    ];
    //editor.customConfig.uploadImgServer = process.env.SERVER_PATH + 'editupload'
    //editor.customConfig.uploadFileName = 'file'
    editor.customConfig.onchange = function(html) {
      that.value = html;
    };
    editor.create();

    var key = this.$route.query.key;
    this.key = key;

    this.$http.getSysConfig({ key: key }, this).then(res => {
      if (res.code === 0) {
        editor.txt.html(res.obj);
      }
    });
  }
};
</script>

<style scoped>
.bar {
  background-color: #f1f1f1;
  border: 1px solid #ccc;
}
.editor {
  border: 1px solid #ccc;
  border-top: none;
  height: 700px;
}

.config_button {
  margin-bottom: 20px;
}
.operation {
  display: flex;
  height: 50px;
  border-bottom: 1px solid #e6e6e6;
  margin-bottom: 10px;
}
.operation .btn {
  display: flex;
  height: 28px;
}
.operation .btn,
.operation .el-input,
.operation .el-select {
  width: 150px;
  margin-right: 8px;
}
</style>
