<template>
  <left-skeleton @save="save" @deleteFunc="deleteFunc">
    <el-form :model="form">
      <el-form-item label="标题">
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="内容" v-if="!item.item.nodetail">
        <div class="input" v-html="form.detail" contenteditable @input="setDate"></div>
      </el-form-item>
    </el-form>
  </left-skeleton>
</template>

<script setup>
// import config from '../../../../config/index';
import { defineProps, ref, inject } from 'vue';
import leftSkeleton from '../H5Editor/leftSkeleton.vue';

const saveComponents = inject('saveComponents');
const deleteItemComponents = inject('deleteItemComponents');

const props = defineProps({
  item: Object,
  index: String,
});
const item = JSON.parse(JSON.stringify(props.item));
const form = ref({
  title: item.item.title,
  detail: item.item.default_text,
});

const setDate = e => {
  form.value.detail = e.target.innerHTML;
};

const save = () => {
  item.item.title = form.value.title;
  item.item.default_text = form.value.detail;
  saveComponents(item);
};

const deleteFunc = () => {
  /**
   * 1.删除本地
   * 2.删除远程
   */
  deleteItemComponents(props.index);
};
</script>

<style scoped>
.el-upload {
  margin: 1em 0;
}

.input{
    background-color: #fff;
    border: 1px solid #eee;
    outline: none;
    padding: 10px
}
</style>
