<template>
<!--  <editor @getMindValue="getMindValue" :mind-value="dataSource" :show-button="showButton" />-->
</template>

<script>
// import editor from "../components/BaiduMind/components/editor.vue";
export default {
  name: "KBmind",
  // components: {editor},
  props: {
    itemRow: {
      default: () => {},
      type: Object
    },
    itemDetail: {
      default: () => {},
      type: Object
    },
    // 所有配置数据
    recordConfig: {
      type: Object,
      default: () => {
      }
    },
  },
  data() {
    return {
      dataSource: {},
      buttonDatas: {
        editableList: []
      },
      isDisabledDetail: false
    }
  },
  computed: {
    //控制上传按钮显隐
    showButton(){
      // 脚本控制可编辑 优先级最高
      if (this.itemRow && this.itemRow.isShowEdit) {
        return true;
      }
      /*
      * 这一步用来判断是否从台账点开或者是否开启流程（disabledDetail为true）。
      * 然后判断是待办还是已办
      */
      if (this.isDisabledDetail || !this.buttonDatas || !this.buttonDatas.currentTaskInstanceVo) {
        // 在子表
        if (this.itemDetail) {
          return !this.itemDetail.disabled
        }else{
          //在表单
          return !this.recordConfig.options.disabled
        }
      }
      const currentTaskInstanceVo = this.buttonDatas.currentTaskInstanceVo;
      const identityString =  currentTaskInstanceVo && currentTaskInstanceVo.identityString;
      // 当已办的时候
      if (identityString && identityString.indexOf('已办') !== -1) {
        return false
      }
      // 当待办的时候，走过的节点统一禁用
      const currentFormCode = this.buttonDatas.formCode;
      const stepFormCode = sessionStorage.getItem('stepFormCode');
      if (stepFormCode == currentFormCode || !stepFormCode){
        return true
      }else{
        return false
      }
    },
  },
  methods: {
    getMindValue(mindValue){
      this.$emit('change',mindValue);
      this.itemDetail && this.$emit('setFieldValue',this.itemDetail.key,mindValue,this.itemRow ? this.itemRow : this.recordConfig);
    },
  },
  created() {
    if (sessionStorage.getItem('buttonDatas')) {
      this.buttonDatas = JSON.parse(sessionStorage.getItem('buttonDatas'));
    }
    console.log(this.recordConfig,'this.recordConfig')

    this.isDisabledDetail = JSON.parse(sessionStorage.getItem('disabledDetail'));
    if (this.itemDetail && this.itemDetail.key) {
      this.dataSource = JSON.parse(this.itemRow[this.itemDetail.key]) || {};
      return;
    }
    if (this.$attrs.value) {
      this.dataSource = JSON.parse(JSON.parse(this.$attrs.value));
      console.log(this.dataSource,'dataSource')

    }

  }
}
</script>

<style scoped>

</style>
