<template>
  <div>
    <a-form layout='vertical'>
      <a-spin :spinning="loading">
        <a-tabs v-model="tabName" type="card">
          <a-tab-pane
              :tab="$t('functional-analysis.property-modal.rating')"
              key="evaluate">
            <a-tabs default-active-key="1" tabPosition="left">
              <a-tab-pane key="1" :tab="$t('functional-analysis.property-modal.occurrence')">
                <a-row :gutter='24'>
                  <a-col :md="12" :sm="24">
                    <a-form-item :label="$t('functional-analysis.property-modal.occurrence')">
                      <a-input-number
                          v-model="occurrenceInputVal"
                          :min="1"
                          :max="10"
                          @change="occurrenceInputValChange"/>
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-table
                    :data-source="occurrenceTableData"
                    :columns="occurrenceTableColumns"
                    :customRow="occurrenceCustomRow"
                    class="evaluate"
                    :rowKey="(row, index) => {return index;}"
                    :row-selection="{
                    type: 'radio',
                    selectedRowKeys: occurrenceSelectedRowKeys,
                    onChange: occurrenceRadioChange,
                  }"
                    bordered
                    size="small"
                    :scroll="{ y: 'calc(88vh - 400px)' }"
                    :pagination="false">
                </a-table>
              </a-tab-pane>
              <a-tab-pane key="2" :tab="$t('functional-analysis.property-modal.detection')">
                <a-row :gutter='24'>
                  <a-col :md="12" :sm="24">
                    <a-form-item :label="$t('functional-analysis.property-modal.detection')">
                      <a-input-number
                          v-model="detectionInputVal"
                          :min="1"
                          :max="10"
                          @change="detectionInputValChange"/>
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-table
                    :data-source="detectionTableData"
                    :columns="detectionTableColumns"
                    :customRow="detectionCustomRow"
                    class="evaluate"
                    :rowKey="(row, index) => {return index;}"
                    :row-selection="{
                    type: 'radio',
                    selectedRowKeys: detectionSelectedRowKeys,
                    onChange: detectionRadioChange,
                  }"
                    bordered
                    size="small"
                    :scroll="{ y: 'calc(88vh - 400px)' }"
                    :pagination="false">
                </a-table>
              </a-tab-pane>
            </a-tabs>
          </a-tab-pane>
          <a-tab-pane
              :tab="$t('functional-analysis.property-modal.responsible-person')"
              key="responsible">
            <a-table
                :data-source="responsibleTableData"
                :columns="responsibleTableColumns"
                :customRow="responsibleCustomRow"
                class="featureClassification"
                :rowKey="(row, index) => {return index;}"
                :row-selection="{
                type: 'radio',
                selectedRowKeys: responsibleSelectedRowKeys,
                onChange: responsibleRadioChange
              }"
                bordered
                size="small"
                :scroll="{ y: 'calc(88vh - 400px)' }"
                :pagination="false">
            </a-table>
          </a-tab-pane>
          <a-tab-pane
              :tab="$t('functional-analysis.property-modal.date-and-status')"
              key="dateAndStatus">
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.status')">
                  <a-select
                      @change="stateChange"
                      :defaultValue="state">
                    <a-select-option
                        v-for="(item, index) in stateSelect"
                        :key="index"
                        :value="item.value">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item required :label="$t('functional-analysis.property-modal.planning-date')">
                  <a-date-picker
                      class="width100"
                      :allowClear="false"
                      :value="planDate"
                      valueFormat="YYYY-MM-DD"
                      @change="planDateChange"/>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.status-task')">
                  {{ taskState }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.start-date')">
                  {{ taskMinStart }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.completion-date')">
                  {{ taskMaxEnd }}
                </a-form-item>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane
              :tab="$t('functional-analysis.property-modal.user-defined-characteristics')"
              key="userDefinedProperties">
            <a-table
                :data-source="userTableData"
                :columns="userTableColumns"
                :customRow="userCustomRow"
                :rowKey="(row, index) => {return index;}"
                :row-selection="{
                selectedRowKeys: userSelectedRowKeys,
                onChange: userCheckboxChange
               }"
                bordered
                size="small"
                :scroll="{ y: 'calc(88vh - 400px)' }"
                :pagination="false"/>
          </a-tab-pane>
          <a-tab-pane
              :tab="$t('functional-analysis.property-modal.note')"
              key="remarks">
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.language')">
                  <a-select
                      @change="currentNlsChange"
                      :defaultValue="defaultNls">
                    <a-select-option
                        v-for="(item, index) in currentNls"
                        :key="index"
                        :value="item.lkey">
                      {{ $t('global-dict.select-nls.' + item.lkey) }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.note-group')">
                  <a-select
                      @change="nodeGroupChange"
                      v-model="currentNodeGroupKey"
                  >
                    <a-select-option
                        v-for="(item, index) in nodeGroups"
                        :key="index"
                        :value="item.annotationGroup"
                    >
                      {{ item.groupName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.note')">
              <span v-for="(item, index) in struNls">
                <a-textarea
                    v-if="defaultNls[0] === item.lkey"
                    :placeholder="$t('functional-analysis.property-modal.click-to-enter-note')"
                    allowClear
                    v-model="item.description"
                    :autoSize="{ minRows: 5 }"
                    :maxLength="500"
                />
              </span>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.attachment')">
                  <a-upload
                      name="file"
                      action=""
                      accept=".jpg,.txt,.png,.doc,.docx,.xls,.xlsx,.pdf,.pptx"
                      :fileList="fileList"
                      :customRequest="customRequest"
                      :remove="removeFile">
                    <a-button v-if="$api.isLook !== '1'">
                      <a-icon type="upload"/>
                      {{ $t('global-btn.select-file') }}
                    </a-button>
                  </a-upload>
                </a-form-item>
              </a-col>
            </a-row>
          </a-tab-pane>
          <a-tab-pane
              :tab="$t('functional-analysis.property-modal.about')"
              key="about">
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.create-time')">
                  {{ insertTime }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col :md="12" :sm="24">
                <a-form-item :label="$t('functional-analysis.property-modal.update-time')">
                  {{ updateTime }}
                </a-form-item>
              </a-col>
            </a-row>
          </a-tab-pane>
        </a-tabs>
      </a-spin>
    </a-form>
    <div slot="footer"
         v-if="$api.isLook !== '1'"
         class="mt10 text-right">
      <a-button @click="closeModal">
        {{ $t('global-btn.cancel') }}
      </a-button>
      <a-button
          type="primary"
          class="ml10"
          @click="save()"
          :loading="saveLoading"
          v-preventReClick>
        {{ $t('global-btn.confirm') }}
      </a-button>
    </div>
  </div>
</template>
<script>

import {dateFormat} from "@/utils/date";
import {checkHotTableLength} from "@/utils/validate";

/**
 * 渲染发生度表格
 * @param value
 * @param row
 * @param index
 * @returns {{children, attrs: {}}}
 */
const occurrenceRenderContent = (value, row, index) => {
  const obj = {
    children: value,
    attrs: {},
  };
  if (row.standardLevel === undefined) {
    obj.attrs.colSpan = 0;
  }
  return obj;
};

/**
 * 渲染探测度表格
 * @param value
 * @param row
 * @param index
 * @returns {{children, attrs: {}}}
 */
const detectionRenderContent = (value, row, index) => {
  const obj = {
    children: value,
    attrs: {},
  };
  if (row.standardLevel === undefined) {
    obj.attrs.colSpan = 0;
  }
  return obj;
};

/**
 * 渲染负责人表格
 * @param value
 * @param row
 * @param index
 * @returns {{children, attrs: {}}}
 */
const responsibleRenderContent = (value, row, index) => {
  const obj = {
    children: value,
    attrs: {},
  };
  if (!row.userId) {
    obj.attrs.colSpan = 0;
  }
  return obj;
};

export default {
  name: "PropertyOptimizeMeasure",
  components: {},
  props: {
    tabKey: {
      type: String,
      default: "",
    },
    checkedNode: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      /** tab默认选中 */
      tabName: this.tabKey || "evaluate",
      /** 语言下拉数组 */
      currentNls: [],
      /** 语言名称数组 */
      struNls: [],
      /** 默认语言标识 */
      defaultNls: [],
      /** 评估/发生度：输入值 */
      occurrenceInputVal: "",
      /** 评估/发生度：表格数据 */
      occurrenceTableData: [],
      /** 评估/发生度：表格表头 */
      occurrenceTableColumns: [
        {
          title: () => this.$t('functional-analysis.property-modal.level'),
          align: "center",
          width: 60,
          dataIndex: 'standardLevel',
          customRender: (text, row, index) => {
            if (row.standardLevel === undefined) text = row.attr1; /** 未设置 */
            if (row.standardLevel) return text;
            return {
              children: text,
              attrs: {
                colSpan: 6,
              },
            };
          },
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.failure-probability'),
          align: "center",
          dataIndex: 'attr1',
          customRender: occurrenceRenderContent,
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.occurrence-of-scoring-criteria'),
          align: "center",
          dataIndex: 'attr2',
          customRender: occurrenceRenderContent,
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.grading-criteria-process-experience'),
          align: "center",
          dataIndex: 'attr3',
          customRender: occurrenceRenderContent,
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.grading-standard-precautions'),
          align: "center",
          dataIndex: 'attr4',
          customRender: occurrenceRenderContent,
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.example-business-product-line'),
          align: "center",
          dataIndex: 'attr5',
          customRender: occurrenceRenderContent,
          ellipsis: true,
        },
      ],
      /** 评估/发生度：选中索引 */
      occurrenceSelectedRowKeys: [],
      /** 评估/发生度：选中数据 */
      occurrenceSelectedRow: {},
      /** 评估/探测度：输入值 */
      detectionInputVal: "",
      /** 评估/探测度：表格数据 */
      detectionTableData: [],
      /** 评估/探测度：表格表头 */
      detectionTableColumns: [
        {
          title: () => this.$t('functional-analysis.property-modal.level'),
          align: "center",
          width: 60,
          dataIndex: 'standardLevel',
          customRender: (text, row, index) => {
            if (row.standardLevel === undefined) text = row.attr1; /** 未设置 */
            if (row.standardLevel) return text;
            return {
              children: text,
              attrs: {
                colSpan: 5,
              },
            };
          },
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.detection-capability'),
          align: "center",
          dataIndex: 'attr1',
          customRender: detectionRenderContent,
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.grading'),
          align: "center",
          dataIndex: 'attr2',
          customRender: detectionRenderContent,
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.detect-opportunities'),
          align: "center",
          dataIndex: 'attr3',
          customRender: detectionRenderContent,
          ellipsis: true,
        },
        {
          title: () => this.$t('functional-analysis.property-modal.example-business-product-line'),
          align: "center",
          dataIndex: 'attr5',
          customRender: detectionRenderContent,
          ellipsis: true,
        },
      ],
      /** 评估/探测度：选中索引 */
      detectionSelectedRowKeys: [],
      /** 评估/探测度：选中数据 */
      detectionSelectedRow: {},
      /** 用户定义的特性：表格数据 */
      userTableData: [],
      /** 用户定义的特性：表格表头 */
      userTableColumns: [
        {
          title: () => this.$t('functional-analysis.property-modal.name'),
          align: "center",
          dataIndex: "memo",
          key: "memo",
          ellipsis: true,
        },
      ],
      /** 用户定义的特性：选中索引 */
      userSelectedRowKeys: [],
      /** 用户定义的特性：选中数据 */
      userSelectedRows: [],
      /** 负责人：表格数据 */
      responsibleTableData: [],
      /** 负责人：表格表头 */
      responsibleTableColumns: [
        {
          title: () => this.$t('functional-analysis.property-modal.name'),
          align: "center",
          dataIndex: 'userName',
          customRender: (text, row, index) => {
            if (row.userId) return text;
            return {
              children: text,
              attrs: {
                colSpan: 2,
              },
            };
          },
        },
        {
          title: () => this.$t('functional-analysis.property-modal.telephone'),
          align: "center",
          dataIndex: 'telephone',
          customRender: responsibleRenderContent,
        }
      ],
      /** 负责人：选中索引 */
      responsibleSelectedRowKeys: [],
      /** 负责人：选中数据 */
      responsibleSelectedRow: {},
      /** 状态 */
      state: "",
      /** 状态下拉 */
      stateSelect: [
        {value: "01", name: this.$t('global-dict.un-processed')},
        {value: "02", name: this.$t('global-dict.to-be-decided')},
        {value: "03", name: this.$t('global-dict.to-be-implemented')},
        {value: "04", name: this.$t('global-dict.abandon')},
        {value: "05", name: this.$t('global-dict.finish')},
      ],
      /** 任务状态 */
      taskState: "",
      /** 任务状态字典CODE */
      taskStateDict: [
        {code: "00", value: this.$t('global-dict.not-started')},
        {code: "10", value: this.$t('global-dict.in-working')},
        {code: "20", value: this.$t('global-dict.complete')},
      ],
      /** 规划日期 */
      planDate: "",
      /** 开始日期 */
      taskMinStart: "",
      /** 完成日期 */
      taskMaxEnd: "",
      /** 备注分组 */
      nodeGroups: [],
      /** 默认备注分组Key */
      currentNodeGroupKey: undefined,
      /** 文件集合 */
      fileList: [],
      /** 创建时间 */
      insertTime: "",
      /** 更新时间 */
      updateTime: "",
      /** 保存加载中... */
      saveLoading: false,
      /** 加载中状态 */
      loading: false,
    };
  },
  mounted() {
    this.list();
  },
  methods: {
    /**
     * 关闭模态框
     */
    closeModal() {
      this.$emit("closeModal");
    },
    /**
     * 刷新右侧结构树
     */
    initRightTree() {
      this.$emit("initRightTree");
    },
    /**
     * 语言下拉选择时
     */
    currentNlsChange(val) {
      let struNls = this.struNls.filter((item) => {
        return item.lkey === val;
      })[0];
      this.defaultNls[0] = val;
    },
    /**
     * 备注分组下拉选择时
     */
    nodeGroupChange(val) {
      let _that = this;
      _that.currentNodeGroupKey = val;
      _that.$api.getNodeGroupSelect({
        fmeaId: _that.$store.getters.rfmeaId,
        struId: _that.checkedNode.id,
        annotationGroup: _that.currentNodeGroupKey,
      }).then(res => {
        if (res.flag) {
          // 处理附件
          _that.handleFileList(res.data.rdfmAttachmentList || []);
          // 处理备注分组多语言
          let nodeGroupNls = res.data.rdfmAnnotationNlsList || [];
          const newStruNls = [..._that.struNls];
          (nodeGroupNls || []).forEach(nodeGroup => {
            (newStruNls || []).forEach(nls => {
              if (nls.lkey === nodeGroup.lkey) {
                nls.description = nodeGroup.lvalue;
              }
            })
          });
          _that.struNls = newStruNls;
        } else {
          _that.$message.error(res.message, 1);
        }
      });
    },
    /**
     * 状态下拉选择时
     */
    stateChange(val) {
      this.state = val;
    },
    /**
     * 处理文件列表
     * @param files 文件
     */
    handleFileList(files) {
      this.fileList = []
      if (files.length === 0) return;
      for (let i = 0, len = files.length; i < len; i++) {
        this.fileList.push({
          data: {
            hiddenFileName: files[i].attachmentName,
            hiddenNewFileName: files[i].storageName,
            hiddenDir: files[i].attachmentPath,
            hiddenFileSize: files[i].attachmentSize,
          },
          uid: files[i].attachmentId,
          name: files[i].attachmentName,
          status: 'done',
          url: this.$api.requestUrl + '/DFMEA/funAnalysis/Rb0426141/downLoad?fmeaId=' + this.$store.getters.rfmeaId
              + '&attachmentId=' + files[i].attachmentId,
        });
      }
    },
    /**
     * 列表
     */
    list() {
      let _that = this;
      _that.loading = true;
      _that.$api.getOptimizeMeasureProperties({
        fmeaId: _that.$store.getters.rfmeaId,
        lfmeaId: _that.$store.getters.fmeaId,
        struId: _that.checkedNode.id,
      }).then((res) => {
        if (res.flag) {
          /**************** 评估/发生度 ****************/
          _that.occurrenceTableData = res.data.rfmStandardDetailOs || [];
          if (_that.occurrenceTableData && _that.occurrenceTableData.length > 0) {
            _that.occurrenceTableData.push({
              standardLevel: undefined,
              attr1: this.$t('functional-analysis.property-modal.do-not-update-child-node-info')
            });
            _that.occurrenceTableData.forEach((item, index) => {
              if (res.data.o === item.standardLevel) {
                _that.occurrenceSelectedRowKeys[0] = index;
                _that.occurrenceSelectedRow = item;
                _that.occurrenceInputVal = item.standardLevel;
              }
            });
            // 默认：未设置
            if (!res.data.o) {
              let ftSize = _that.occurrenceTableData.length;
              _that.occurrenceSelectedRowKeys[0] = ftSize - 1;
              _that.occurrenceSelectedRow = _that.occurrenceTableData[ftSize - 1];
              _that.occurrenceInputVal = _that.occurrenceSelectedRow.standardLevel;
            }
          }
          /**************** 评估/探测度 ****************/
          _that.detectionTableData = res.data.rfmStandardDetailDs || [];
          if (_that.detectionTableData && _that.detectionTableData.length > 0) {
            _that.detectionTableData.push({
              standardLevel: undefined,
              attr1: this.$t('functional-analysis.property-modal.do-not-update-child-node-info')
            });
            _that.detectionTableData.forEach((item, index) => {
              if (res.data.d === item.standardLevel) {
                _that.detectionSelectedRowKeys[0] = index;
                _that.detectionSelectedRow = item;
                _that.detectionInputVal = item.standardLevel;
              }
            });
            // 默认：未设置
            if (!res.data.d) {
              let ftSize = _that.detectionTableData.length;
              _that.detectionSelectedRowKeys[0] = ftSize - 1;
              _that.detectionSelectedRow = _that.detectionTableData[ftSize - 1];
              _that.detectionInputVal = _that.detectionSelectedRow.standardLevel;
            }
          }
          /**************** 负责人 ****************/
          _that.responsibleTableData = res.data.rdfmPersonModels || [];
          if (_that.responsibleTableData && _that.responsibleTableData.length > 0) {
            _that.responsibleTableData.push({
              userId: "",
              userName: this.$t('functional-analysis.property-modal.not-set')
            });
            _that.responsibleTableData.forEach((item, index) => {
              if (res.data.responsible == item.userId) {
                _that.responsibleSelectedRowKeys[0] = index;
                _that.responsibleSelectedRow = item;
              }
            });
            // 默认：未设置
            if (!res.data.responsible) {
              let ftSize = _that.responsibleTableData.length;
              _that.responsibleSelectedRowKeys[0] = ftSize - 1;
              _that.responsibleSelectedRow = _that.responsibleTableData[ftSize - 1];
            }
          }
          /**************** 日期与状态 ****************/
          _that.planDate = dateFormat(res.data.planDate);
          _that.taskState = _that.taskStateDict.filter((item) => {
            return item.code === res.data.taskState;
          })[0].value;
          _that.taskMinStart = dateFormat(res.data.taskMinStart);
          _that.taskMaxEnd = dateFormat(res.data.taskMaxEnd);
          /**************** 用户定义的特性 ****************/
          _that.userTableData = res.data.rdfmStruAttributeModels || [];
          _that.userTableData.forEach((item, index) => {
            if (item.checkFlag) {
              _that.userSelectedRowKeys.push(index);
              _that.userSelectedRows.push(item);
            }
          });
          /**************** 备注 ****************/
          _that.defaultNls[0] = res.data.display_nls;
          _that.currentNls = res.data.rdfmcurrentNls || [];
          // 语言Key升序
          _that.struNls = (res.data.rdfmStruNlss || []).sort((a, b) => {
            return a.lkey - b.lkey;
          });
          _that.currentNodeGroupKey = res.data.currentGroupId;
          _that.nodeGroups = res.data.rdfmAnnotationGroupList || [];
          let nodeGroupNls = res.data.rdfmAnnotationNlsList || [];
          // 处理备注分组多语言
          (nodeGroupNls || []).forEach(nodeGroup => {
            (_that.struNls || []).forEach(nls => {
              if (nls.lkey === nodeGroup.lkey) {
                nls.description = nodeGroup.lvalue;
              }
            })
          });
          // 处理附件
          _that.handleFileList(res.data.rdfmAttachmentList || []);
          /**************** 关于 ****************/
          _that.insertTime = dateFormat(res.data.rdfmMeasure?.insertTime);
          _that.updateTime = dateFormat(res.data.rdfmMeasure?.updateTime);
        } else {
          _that.$message.error(res.message, 1);
        }
      }).catch((error) => {
        _that.$message.error(error.response.data.message, 1);
      }).finally(() => {
        _that.loading = false;
      });
    },
    /**
     * 保存
     */
    save() {
      let _that = this;
      // 校验
      if (!_that.validatePropertyData()) return;

      /**************** 数据封装 Start ***********/
      let descriptions = _that.struNls.map((item) => {
        return item.description || '';
      });
      let userDefineIds = _that.userSelectedRows.map((item) => {
        return item.userDefineId;
      });
      let responsible = _that.responsibleSelectedRow ? _that.responsibleSelectedRow.userId : '';
      let hiddenFileName = [];
      let hiddenNewFileName = [];
      let hiddenDir = [];
      let hiddenFileSize = [];
      let files = _that.fileList;
      for (let i = 0, len = files.length; i < len; i++) {
        let file = files[i].data;
        hiddenFileName.push(file.hiddenFileName);
        hiddenNewFileName.push(file.hiddenNewFileName);
        hiddenDir.push(file.hiddenDir);
        hiddenFileSize.push(file.hiddenFileSize);
      }
      /**************** 数据封装 End ***********/

      _that.saveLoading = true; // 开启：加载中...
      _that.$api.saveOptimizeMeasureProperties({
        fmeaId: _that.$store.getters.rfmeaId,
        struId: _that.checkedNode.id,
        occurrence: _that.occurrenceInputVal, /** 评估/发生度 */
        detection: _that.detectionInputVal, /** 评估/发生度 */
        responsible: responsible, /** 负责人 */
        state: _that.state, /** 状态 */
        planDate: Date.parse(_that.planDate), /** 规划日期 */
        userDefineIds: userDefineIds, /** 用户定义的特性 */
        descriptions: descriptions, /** 备注 */
        lkey: _that.defaultNls[0], /** 备注分组语言Key */
        annotationGroup: _that.currentNodeGroupKey, /** 备注分组Key */
        hiddenFileName: hiddenFileName, /** 隐藏的附件名称 */
        hiddenNewFileName: hiddenNewFileName, /** 隐藏的新生成附件名称 */
        hiddenDir: hiddenDir, /** 隐藏的新生成附件名称 */
        hiddenFileSize: hiddenFileSize, /** 隐藏的新生成附件大小 */
      }).then((res) => {
        if (res.flag) {
          // 添加成功，关闭弹窗，刷新结构树
          _that.$message.success(res.message, 1);
          _that.closeModal();
          _that.initRightTree();
        } else {
          _that.$message.error(res.message, 1);
        }
      }).catch((error) => {
        _that.$message.error(error.response.data.message, 1);
      }).finally(() => {
        _that.saveLoading = false; // 关闭：加载中...
      })
    },
    /**
     * 校验：属性数据
     */
    validatePropertyData() {
      let flag = true;
      this.struNls.some((item, idx) => {
        let nlsKey = this.$t('global-dict.select-nls.' + item.lkey);
        if (checkHotTableLength(item.description, 500)) {
          this.$message.warning(this.$t('global-message.warn.name-cannot-be-empty', [nlsKey]));
          flag = false;
          return true;
        }
      });
      if (!this.planDate) {
        this.$message.warning(this.$t('global-message.warn.planning-date-cannot-be-empty'));
        flag = false;
      }
      return flag;
    },
    /**
     * 发生度：数字选择器改变时
     */
    occurrenceInputValChange(val) {
      this.occurrenceTableData.forEach((item, index) => {
        if (item.standardLevel === val) {
          this.occurrenceSelectedRowKeys = [index];
          this.occurrenceSelectedRow = item;
        }
      });
    },
    /**
     * 探测度：数字选择器改变时
     */
    detectionInputValChange(val) {
      this.detectionTableData.forEach((item, index) => {
        if (item.standardLevel === val) {
          this.detectionSelectedRowKeys = [index];
          this.detectionSelectedRow = item;
        }
      });
    },
    /**
     * 发生度：单选框改变事件
     */
    occurrenceRadioChange(rowKeys, row) {
      this.occurrenceSelectedRowKeys = rowKeys;
      this.occurrenceSelectedRow = row[0];
      this.occurrenceInputVal = row[0].standardLevel;
    },
    /**
     * 发生度：行点击事件
     */
    occurrenceCustomRow(record, index) {
      let _that = this;
      return {
        on: {
          // 鼠标单击行
          click: () => {
            _that.occurrenceSelectedRowKeys = [index];
            _that.occurrenceSelectedRow = record;
            _that.occurrenceInputVal = record.standardLevel;
          }
        }
      };
    },
    /**
     * 探测度：单选框改变事件
     */
    detectionRadioChange(rowKeys, row) {
      this.detectionSelectedRowKeys = rowKeys;
      this.detectionSelectedRow = row[0];
      this.detectionInputVal = row[0].standardLevel;
    },
    /**
     * 探测度：行点击事件
     */
    detectionCustomRow(record, index) {
      let _that = this;
      return {
        on: {
          // 鼠标单击行
          click: () => {
            _that.detectionSelectedRowKeys = [index];
            _that.detectionSelectedRow = record;
            _that.detectionInputVal = record.standardLevel;
          }
        }
      };
    },
    /**
     * 用户定义的特性：复选框改变事件
     */
    userCheckboxChange(rowKeys, row) {
      this.userSelectedRows = row;
      this.userSelectedRowKeys = rowKeys;
    },
    /**
     * 用户定义的特性：行点击事件
     */
    userCustomRow(record, index) {
      let _that = this;
      return {
        on: {
          // 鼠标单击行
          click: () => {
            if (_that.userSelectedRowKeys.indexOf(index) !== -1) {
              _that.userSelectedRows.splice(_that.userSelectedRowKeys.indexOf(index), 1);
              _that.userSelectedRowKeys.splice(_that.userSelectedRowKeys.indexOf(index), 1);
            } else {
              _that.userSelectedRowKeys.push(index)
              _that.userSelectedRows.push(record);
            }
          }
        }
      };
    },
    /**
     * 负责人：单选框改变事件
     */
    responsibleRadioChange(rowKeys, row) {
      this.responsibleSelectedRowKeys = rowKeys;
      this.responsibleSelectedRow = row[0];
    },
    /**
     * 负责人：行点击事件
     */
    responsibleCustomRow(record, index) {
      let _that = this;
      return {
        on: {
          // 鼠标单击行
          click: () => {
            _that.responsibleSelectedRowKeys = [index];
            _that.responsibleSelectedRow = record;
          }
        }
      };
    },
    /**
     * 规划日期改变时
     */
    planDateChange(val) {
      this.planDate = val;
    },
    /**
     * 通过覆盖默认的上传行为，可以自定义自己的上传实现
     * @param obj 回调对象
     */
    customRequest(obj) {
      let _that = this;
      if (obj.file.size > 52428800) {
        _that.$message.warning(this.$t('global-message.warn.uploaded-files-cannot-exceed'));
        return;
      }
      _that.loading = true;
      let fd = new FormData();
      fd.append("file", obj.file);
      fd.append("fileType", "10");
      _that.$api.uploadFile(fd).then((res) => {
        if (res.flag) {
          _that.$message.success(res.message, 1);
          obj.file.data = {
            hiddenFileName: res.data.fileName,
            hiddenNewFileName: res.data.newFileName,
            hiddenDir: res.data.filePath,
            hiddenFileSize: res.data.fileSize,
          };
          _that.fileList.push(obj.file);
        } else {
          _that.$message.error(res.message, 1);
        }
      }).catch((error) => {
        _that.$message.error(error.response.data.message, 1);
      }).finally(() => {
        _that.loading = false;
      });
    },
    /**
     * 删除文件
     * @param file 文件
     */
    removeFile(file) {
      let files = this.fileList;
      for (let i = files.length - 1; i >= 0; i--) {
        if (file.uid === files[i].uid) files.splice(i, 1);
      }
    },
  }
};
</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;
  }

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

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

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

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

// 评估/级别居中
/deep/ .evaluate {
  .ant-table-tbody {
    .ant-table-row-cell-ellipsis:nth-of-type(2) {
      text-align: center !important;
    }
  }
}

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

/deep/ a {
  color: #1890FF;
}
/deep/ .ant-table-fixed-header .ant-table-scroll .ant-table-header {
  overflow: hidden!important;
  margin-bottom: 0!important;
  padding-right: 8px;
  background: rgb(250, 250, 250);
}
</style>
