<template>
  <div class="excelHtnl">
    <div class="header" style=" position: absolute;left:10px;top:0">
      <div class="flexStar">
        <h2>编辑WBS库</h2>
        <div
          class="GoBack marleft20"
          @click="GoBack()"
        >
          返回上一级
        </div>
      </div>
      <div style="width: 37%;">
        <avue-tabs :option="option" @change="handleChange"></avue-tabs>
      </div>
    </div>
    <div
      class="excelBox"
      style="margin-top:40px;height: 100%;"
      @click="parentClick($event)"
    >
      <div style="width:60%;height: 100%;overflow: scroll;" class='parent' id='parent'></div>
      <div class="excelRight" style="width:30%;margin-left:4%;height: 100%;overflow: scroll;" >
        <span v-if="type.prop==='tab1'">
          <setInputTPT
            v-if="type.prop==='tab1'"
            :pkeyId='pkeyId'
            @cop='domss'
            :htmlData="htmlData"
          />
        </span>
        <span v-else-if="type.prop==='tab2'"> <electronicSignature :pkeyId1='pkeyId' :htmlData1="htmlData" /> </span>
        <span v-else-if="type.prop==='tab3'"> <setFormula :pkeyId1='pkeyId' :htmlData1="htmlData" /> </span>
        <span v-else-if="type.prop==='tab4'"> <editDefault :pkeyId1='pkeyId' :htmlData1="htmlData" /> </span>
        <span v-else-if="type.prop==='tab5'"> <promptSettings :pkeyId1='pkeyId' :htmlData1="htmlData" /> </span>
      </div>
    </div>
  </div>
</template>

<script>
import setInputTPT from './template/setInputTPT.vue'
import electronicSignature from './template/electronicSignature.vue'
import setFormula from './template/setFormula.vue'
import editDefault from './template/editDefault.vue'
import promptSettings from './template/promptSettings.vue'
import Vue from 'vue'
import {getExcelHtml } from '@/api/exctab/excelmodel'
export default {
  props: ['pkeyId'],
  data () {
    return {
      setUptype: 0,//右侧显示的类型1
      htmlData: {
        name: '',
        tr: '',
        td: ''
      },
      type:{},
      option:{
        column: [{
          label: '设置输入框',
          prop: 'tab1',
          width: 10,
        }, {

          label: '电签位置配置',
          prop: 'tab2',
        }, {
          label: '设置公式开放条件',
          prop: 'tab3',
        }, {

          label: '编辑默认信息',
          prop: 'tab4',
        }, {

          label: '提示设置',
          prop: 'tab5',
        }
        ]
      }
    }
  },
  mounted () {
    this.cop()
    this.type = this.option.column[0];
  },



  methods: {
    GoBack () {//返回上一级
      this.$emit('remove')
    },
    handleChange(column) {
      this.type = column;
    },
    async getExcelHtml (pkeyId) {
      const { data: res } = await getExcelHtml({ pkeyId })
      console.log(res);
      if (res.code === 200) {
        localStorage.setItem('excelHtml', res.data)
        this.copss();
      }
    },
    async cop () {
      let _that = this
      var MyComponent = await Vue.extend({
        template: localStorage.getItem('excelHtml'),
        data () {
          return {
            formData: {},
            getTokenHeader: {},
            dap_site_data:{}
          }
        },
        methods: {
          getInformation (name, tr, td) {//鼠标右键事件
            _that.getInformation(name, tr, td)
          },
          formUploadSuccess(){},
          formUploadExceed(){},
          formUploadLoading(){},
          delTableFormFile(){},
          formUploadError(){},
          uploadprogress(){},
          formRemoteMethod(){},
          getRegularExpression(){},
          checkboxGroupChange(){}
        }
      })
      var component = new MyComponent().$mount()
      document.getElementById('parent').appendChild(component.$el);
    },
    async copss () {
      let _that = this
      var MyComponent = await Vue.extend({
        template: localStorage.getItem('excelHtml'),
        data () {
          return {
            formData: {},
            getTokenHeader: {},
            dap_site_data:{}
          }
        },
        methods: {
          getInformation (name, tr, td) {//鼠标右键事件
            _that.getInformation(name, tr, td)
          },
          formUploadSuccess(){},
          formUploadExceed(){},
          formUploadLoading(){},
          delTableFormFile(){},
          formUploadError(){},
          uploadprogress(){},
          getRegularExpression(){},
          formRemoteMethod(){},
          checkboxGroupChange(){}
        }
      })
      var component = new MyComponent().$mount()
      let na = document.getElementById('parent')
      na.innerHTML = `<div
        class='parent'
        id='parent'
      ></div>`
      document.getElementById('parent').appendChild(component.$el);
    },
    domss () {
      this.copss()
    },

    getInformation (name, tr, td) {//鼠标点击事件
      this.htmlData = {
        name,
        tr,
        td
      }
    },

    //excel父节点点击检测
    parentClick(e){
      let target = e.target;

      let bgs = document.querySelectorAll("#parent .oldlace-bg")
      //console.log(bgs)
      for (let i = 0; i < bgs.length; i++) {
        bgs[i].classList.remove("oldlace-bg");
      }
      //console.log(target.getAttribute('trindex'))
      if(target.getAttribute('trindex') !== null && target.getAttribute('tdindex')){
        let tdEle = this.getParentTD(target);
        if(tdEle){
          target.classList.add("oldlace-bg");

        }
      }
    },

    getParentTD(ele){
      let targetParent = ele.parentNode;
      while (targetParent.nodeName !== "TD") {
          if(targetParent.id == 'parent'){
            return null;
          }
          targetParent = targetParent.parentNode;
      }
      return targetParent;
    },
  },
  components: {
    setInputTPT,
    electronicSignature,
    setFormula,
    editDefault,
    promptSettings
  }
}
</script>

<style lang="scss" scoped>
.excelHtnl {
  margin: 0 0 0 10px;
  background-color: #fff;
  box-sizing: border-box;
  padding: 0 20px 100px 20px;
  height: 100%;
  .header {
    border-radius: 4px;
    box-sizing: border-box;
    width: calc(100% - 20px);
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    z-index: 99;
    height: 50px;
    align-items: center;
    .GoBack {
      color: rgba(0, 82, 216, 1);
      text-decoration: underline;
      display: flex;
      align-items: center;
      font-family: SourceHanSansSC;
      cursor: pointer;
    }
  }
  .excelBox {
    margin-top: 10px;
    display: flex;
    justify-content: flex-start;
    .excelRight {
      flex-grow: 1;
      box-sizing: border-box;
      padding: 20px 0px 0px 30px;
    }
  }
}

// 设置图片样式
.hc-upload-table-form {
  position: relative;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.hc-upload-table-form .el-upload {
  position: relative;
  flex: 1;
  height: 100%;
  color: #ccc;
}
.hc-upload-table-form .el-upload .hc-table-form-icon {
  font-size: 24px;
  font-weight: 100;
}
.hc-upload-table-form .el-upload .hc-table-form-img {
  width: 100%;
  height: 100%;
}

.excelBox{
  /deep/ .oldlace-bg{
    background-color: oldlace;
  }
}
</style>



