<template>
  <div class="subfield-module-item-container">
    <div class="subfield-module-header">
      <div class="subfield-module-title">
        <img src="@/assets/images/consultingAgencyManagement/customForm/icon_drag@2x.png" alt="" class="subfield-module-dragg-target-icon">
        <el-form-item v-if="comModuleInfo.edit" class="subfield-module-form-item" :rules="comModuleInfo.subfieldModuleNameRules" prop="">
          <el-input v-model="comModuleInfo.subfieldModuleName" :placeholder="comModuleInfo.subfieldModulePlaceholder" clearable
            @keyup.enter.native.stop="editOK"></el-input>
        </el-form-item>
        <span v-else>{{comModuleInfo.defaultSubfieldModuleName}}</span>
      </div>
      <div class="subfield-module-title-tool" v-if="comModuleInfo.edit">
        <img src="@/assets/images/consultingAgencyManagement/customForm/icon_verify@2x.png" alt="" class="title-tool-edit-ok" @click="editOK">
        <img src="@/assets/images/consultingAgencyManagement/customForm/icon_cancle@2x.png" alt="" class="title-tool-edit-cancel"
          @click.stop="editCancel">
      </div>
      <div class="subfield-module-title-tool" v-else>
        <img src="@/assets/images/consultingAgencyManagement/customForm/icon_edit@2x.png" alt="" class="title-tool-edit" @click="editModule">
        <img src="@/assets/images/consultingAgencyManagement/customForm/icon_delete@2x.png" alt="" class="title-tool-delete" @click="removeModule">
      </div>
    </div>
    <slot></slot>
  </div>
</template>
<script>
export default {
  name: "subfieldModule",
  props: {
    moduleInfo: Object
  },
  watch: {
    moduleInfo: {
      handler(newValue, oldValue) {
        this.comModuleInfo = newValue;
      },
      deep: true
    },
  },
  data() {
    return {
      oldComModuleName: this.moduleInfo.subfieldModuleName,
      comModuleInfo: this.moduleInfo
    };
  },
  //可访问data属性
  created() {

  },
  //计算集
  computed: {

  },
  //方法集
  methods: {
    removeModule() {
      this.$emit("removeModule", this.comModuleInfo);
    },
    editModule() {
      this.comModuleInfo.edit = true;
    },
    editCancel() {
      this.comModuleInfo.edit = false;
      this.comModuleInfo.subfieldModuleName = this.oldComModuleName;
    },
    editOK() {
      this.comModuleInfo.edit = false;
      this.comModuleInfo.defaultSubfieldModuleName = this.comModuleInfo.subfieldModuleName;
      this.oldComModuleName = this.comModuleInfo.subfieldModuleName;
      this.$emit("editOk", this.comModuleInfo);
    }
  },
}
</script>
<style lang="scss" scoped>
.subfield-module-item-container {
  margin-bottom: 12px;
  width: 100%;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  border-radius: 4px;
  overflow: hidden;

  .subfield-module-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    background: #f0f3fa;
    padding: 0px 16px;
    box-sizing: border-box;

    .subfield-module-title {
      display: flex;
      align-items: center;
      flex: 1;

      & > img {
        width: 14px;
        height: 14px;
        cursor: move;
      }
      & > span {
        font-size: 14px;
        font-weight: 400;
        margin-left: 12px;
        color: rgba(35, 35, 35, 0.8);
      }
    }

    .subfield-module-title-tool {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-left: 12px;
      & > img {
        width: 16px;
        height: 16px;
        cursor: pointer;
      }

      .title-tool-delete,
      .title-tool-edit-cancel {
        margin-left: 16px;
      }
    }
  }

  ::v-deep .subfield-module-form-item {
    margin-bottom: 0px;
    margin-left: 12px;
    flex: 1;
    .el-form-item__content {
      line-height: 32px;
    }

    .el-input {
      width: 100%;
      .el-input__inner {
        width: 100%;
        height: 32px;
        line-height: 32px;
        padding-left: 12px;

        &::placeholder {
          color: #c0c4cc !important;
          font-size: 14px !important;
        }
      }
      .el-input__suffix {
        .el-input__icon {
          line-height: 32px;
        }
      }
    }
  }
}
</style>
