<template>
  <a-modal
      :visible="showModal"
      :title="$t('functional-analysis.edit-note.title')"
      class="creat-update-modal"
      :width="600"
      destroyOnClose
      @ok="save"
      @cancel="cancel"
      :confirmLoading="saveLoading"
  >
    <a-form layout="vertical">
      <a-form-item :label="$t('functional-analysis.add-modal.name')" required>
        <a-input
            allowClear
            v-model='inputName'
            :placeholder="$t('functional-analysis.add-modal.please-enter-name')"
            :maxLength="100"
        />
      </a-form-item>
      <a-form-item :label="$t('functional-analysis.default-settion')">
        <a-checkbox name='defaultDflag' v-model='dfeault'>
          {{ $t('functional-analysis.set-default') }}
        </a-checkbox>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
export default {
  name: "EditNoteModal",
  props: {
    showEditNoteModal: {
      type: Boolean,
      default: false
    },
  },
  watch: {
    showEditNoteModal(val) {
      this.showModal = val;
    },
  },
  data() {
    return {
      showModal: false,
      fmeaId: undefined,
      saveLoading: false,
      dfeault: false,
      inputName: undefined,
      noteId: undefined,
    };
  },
  methods: {
    /**
     * 新建
     */
    save() {
      let _that = this;
      // 验证非空
      if (!_that.inputName || !_that.inputName.trim())
        return _that.$message.warn(_that.$t('global-message.warn.please-enter-name'), 1);
      _that.loading = true;
      _that.$api.updateNodesConfig({
        fmeaId: _that.$store.getters.rfmeaId,
        annotationGroup: _that.noteId,
        groupName: _that.inputName,
        defaultFlag: _that.dfeault
      }).then(res => {
        if (res.flag) {
          _that.$message.success(res.message, 1);
          _that.$emit("closeEditNoteModal");
          _that.$emit("list");
        } else {
          _that.$message.error(res.message, 1);
        }
      }).finally(() => {
        _that.loading = false;
      });
    },
    /**
     * 取消
     * @param row
     */
    cancel() {
      let _that = this;
      _that.inputName = undefined;
      _that.dfeault = false;
      _that.fmeaId= undefined,
      _that.nodeId= undefined,
      _that.$emit("closeEditNoteModal");
    },
  },
};
</script>
<style lang="less" scoped>
/** 表格头部自动换行 */
/deep/ .ant-table-thead {
  .ant-table-row-cell-ellipsis .ant-table-column-title {
    white-space: normal;
  }
}

/deep/ .ant-table-tbody {
  .ant-table-row-cell-ellipsis:nth-of-type(2) {
    text-align: left !important;
  }
}

/*/deep/ .ant-table-fixed-header > .ant-table-content > .ant-table-scroll > .ant-table-body {
  overflow-y: auto !important;
}*/
</style>

