<template>
  <div class="page-box-row-left padding-20">
    <FormBlock :title="$t('module.orgManage.orgSelect')" direction="column" style="width:320px">
      <el-tree :data="baseData" :props="defaultProps" :load="loadCurrentOrgNode" highlight-current check-strictly lazy indent="16" default-expanded-keys="[0]" node-key="orgId" ref="orgTree" @node-click="handleNodeClick" :render-content="renderContent" :expand-on-click-node="false">
      </el-tree>
    </FormBlock>
    <FormBlock :title="$t('module.orgManage.orgDetail')" direction="column" v-if="showDetail">
      <Form ref="orgForm" :model="form" :rules="rules" label-position="right" :label-width="80">
        <div class="">
          <Row :gutter="20" class="code-row-bg">
            <Col span="11">
            <Form-item prop="orgCode" :label="$t('module.orgManage.orgCode')">
              <Input  v-model="form.orgCode" placeholder="" v-bind:readonly="canNotBeEdit"></Input>
            </Form-item>
            </Col>
            <Col span="11">
            <Form-item prop="orgName" :label="$t('module.orgManage.orgFullName')">
              <Input  v-model="form.orgName" placeholder="" v-bind:readonly="canNotBeEdit"></Input>
            </Form-item>
            </Col>
          </Row>
          <Row :gutter="20" class="code-row-bg">
            <Col span="11">
            <Form-item prop="orgShortName" :label="$t('module.orgManage.orgShort')">
              <Input  v-model="form.orgShortName" placeholder="" :disabled="canNotBeEdit"></Input>
            </Form-item>
            </Col>
            <Col span="11">
            <Form-item :label="$t('module.orgManage.orgTier')" prop="orgGradeCode">
              <Select v-model="form.orgGradeCode" filterable clearable><!--  :disabled="canNotBeEdit" -->
                <Option v-for="itemKey in Object.keys(orgGradeDic)" :value="itemKey" :key="itemKey">{{ orgGradeDic[itemKey] }}</Option>
              </Select>
            </Form-item>
            </Col>
          </Row>
          <Row :gutter="20" class="code-row-bg">
            <Col span="11">
            <Form-item prop="parentOrgName" :label="$t('module.orgManage.parentOrg')">
              <Input v-model="form.parentOrgName" :placeholder="$t('module.orgManage.hint')" disabled></Input>
            </Form-item>
            </Col>
            <Col span="11">
            <Form-item prop="orgManager" :label="$t('module.orgManage.administrator')">
              <Input  v-model="form.orgManager" maxlength="20" placeholder="" v-bind:readonly="canNotBeEdit"></Input>
            </Form-item>
            </Col>
          </Row>
          <Row :gutter="20" class="code-row-bg">
            <Col span="11">
            <Form-item prop="orgAddress" :label="$t('module.orgManage.address')">
              <Input  v-model="form.orgAddress" maxlength="100" placeholder="" v-bind:readonly="canNotBeEdit"></Input>
            </Form-item>
            </Col>
            <Col span="11">
            <Form-item prop="orgPostCode" :label="$t('module.orgManage.postalCode')">
              <Input  v-model="form.orgPostCode" maxlength="10" placeholder="" v-bind:readonly="canNotBeEdit"></Input>
            </Form-item>
            </Col>
          </Row>
          <Row :gutter="20" class="code-row-bg">
            <Col span="11">
            <Form-item prop="orderNo" :label="$t('module.orgManage.sortId')">
              <InputNumber style="width:100%;" :min="0" :max="99" v-model="form.orderNo" placeholder="" v-bind:readonly="canNotBeEdit"></InputNumber>
            </Form-item>
            </Col>
            <Col span="11">
            <Form-item prop="orgFrom" :label="$t('module.orgManage.sourceOfData')">
              <!--
                <Select v-model="form.orgFrom"  size="small" v-bind:disabled="canNotBeEdit">
                    <Option  :value="0" :key="0">手工</Option>
                    <Option  :value="1" :key="1">同步</Option>
                </Select>
                -->
              <Input v-model="orgFromShowName" readonly="true"></Input>
            </Form-item>
            </Col>
          </Row>
          <Row :gutter="20" class="code-row-bg">
            <Col span="22">
            <Form-item prop="effectDate" :label="$t('module.orgManage.validity')">
              <DatePicker :value="effectDate" format="yyyy/MM/dd" type="daterange" placement="bottom-end" placeholder="Select date" style="width:100%" v-bind:readonly="canNotBeEdit" @on-change="changeEffectDate"></DatePicker>
            </Form-item>
            </Col>
          </Row>
          <Row :gutter="20" class="code-row-bg">
            <Col span="11">
            <Form-item prop="enabled" :label="$t('module.orgManage.availability')">
              <Select v-model="form.enabled" :disabled="canNotBeEdit">
                <Option :value="0" :key="0">{{$t('common.invalid')}}</Option>
                <Option :value="1" :key="1">{{$t('common.valid')}}</Option>
              </Select>
            </Form-item>
            </Col>
            <Col span="11">
            <Form-item prop="orgPath" :label="$t('module.orgManage.orgPath')">
              <Input v-model="form.orgPath" placeholder="" readonly="true"></Input>
            </Form-item>
            </Col>

          </Row>
          <!-- 关联组织需求已被取消
          <Row :gutter="20" class="code-row-bg">
            <Col span="15">
               <Form-item prop="referenceOrgName" :label="关联组织">
                <Input size="small" v-model="referenceOrgName" placeholder="" readonly="true"></Input>
              </Form-item>
            </Col>
            <Col span="5">
                <Button style="vertical-align: text-top;width:28px;height:28px;" type="primary" shape="circle" icon="ios-search-strong" @click="openConferenceOrgTree" :disabled="showReferenceOrgTreeBtn"></Button>
            </Col>
          </Row>
          -->
          <Row :gutter="20" class="code-row-bg">
            <Col span="22">
            <Form-item prop="orgDesc" :label="$t('module.orgManage.orgDesc')">
              <Input type="textarea" :rows="4"   maxlength="100" v-model="form.orgDesc" placeholder="" v-bind:readonly="canNotBeEdit"></Input>
            </Form-item>
            </Col>
          </Row>

          <Row :gutter="22" class="code-row-bg" v-show="!canNotBeEdit">
            <Col span="20">
            <Button type="primary" @click="saveOrUpdateOrg" style="margin-left:80px;" :loading="saveLoading">{{btnTitle}}</Button>
            </Col>
          </Row>
        </div>
      </Form>
    </FormBlock>

    <!-- 关联组织需求已被取消
    <Modal v-model="modal" width="600">
      <p slot="header">
        <span>关联组织</span>
      </p>
      <div>
          <el-tree :data="conferenceOrgBaseData" :props="defaultProps" :load="loadReferenceOrgNode"   highlight-current check-strictly lazy 
          indent = "36"
          default-expanded-keys = "[0]"
          node-key="orgId"
          ref="conferenceOrgTree"
          @check-change = "checkChanged"
          :show-checkbox = "true"
          :expand-on-click-node="true">
          </el-tree>
      </div>
      <div slot="footer" class="run-modal-ftbButton">
        <Button type="primary" @click="onOk()">确定</Button>
      </div>
    </Modal>
    -->

  </div>
</template>

<script>
import Three from "../../../tools/getThree.js";
export default {
  components: {},
  props: {
    companyId: {
      type: String,
      default() {
        return "";
      }
    },
    companyCode: {
      type: String,
      default() {
        return "";
      }
    },
    companyName: {
      type: String,
      default() {
        return "";
      }
    },
    referenceCompanyId: {
      type: String,
      default() {
        return "";
      }
    },
    referenceCompanyName: {
      type: String,
      default() {
        return "";
      }
    }
  },
  data() {
    const validateOrgCode = (rule, value, callback) => {

      if (this.canNotBeEdit) {
        //当明细页面不允许编辑时，不做合法性校验
        callback();
      }
      if (value == null || value === "") {
        callback(new Error(this.$t('module.orgManage.enterCode')));
      } else if (value.length > 50) {
        callback(new Error(this.$t('module.orgManage.codeMaxFifty')));
      } else if (!new RegExp("^[a-zA-z0-9]+$").test(value)) {
        callback(new Error(this.$t('module.orgManage.codeContain')));
      }
      callback();
    };
    const validateOrgName = (rule, value, callback) => {
      if (this.canNotBeEdit) {
        //当明细页面不允许编辑时，不做合法性校验
        callback();
      }
      if (value == null || value === "") {
        callback(new Error(this.$t('module.orgManage.enterName')));
      } else if (value != value.trim()) {
        callback(new Error(this.$t('module.orgManage.noBalnk')));
      } else if (value.length > 50) {
        callback(new Error(this.$t('module.orgManage.nameMaxFifty')));
      }
      callback();
    };
    const validateOrgDesc = (rule, value, callback) => {
      if (this.canNotBeEdit) {
        //当明细页面不允许编辑时，不做合法性校验
        callback();
      }
      if (value != null && value != value.trim() && value.trim() === "") {
        callback(new Error(this.$t('module.orgManage.enterLegalDesc')));
      }
      if (value != null && value.length > 200) {
        callback(new Error(this.$t('module.orgManage.descMaxTH')));
      }
      callback();
    };
    const validateOrgShortName = (rule, value, callback) => {
      if (this.canNotBeEdit) {
        //当明细页面不允许编辑时，不做合法性校验
        callback();
      }
      if (value == null || value === "") {
        callback(new Error(this.$t('module.orgManage.enterOrgShort')));
      } else if (value != value.trim() && value.trim() === "") {
        callback(new Error(this.$t('module.orgManage.enterLegalShort')));
      }
      if (value != null && value.length > 100) {
        callback(new Error(this.$t('module.orgManage.orgShortMaxOH')));
      }
      callback();
    };
    return {
      modal: false,
      isReadOnly: true,
      noData: false,
      saveLoading: false,
      orgSelectWin: false,
      showDetail: false,
      btnTitle: this.$t('common.save'),
      firstLoading: true,
      effectDate: ['2017/12/04', '2067/12/04'],
      referenceOrgName: '',
      currentNodeIsRootOrg: false,
      form: {
        companyId: "",//组织主记录Id
        orgCode: "",  //组织编码
        orgName: "",  //组织全称

        orgShortName: "", //组织简称
        orgGradeCode: "", //组织层级编码
        orgManager: "",//组织管理者
        orgAddress: "",//地址
        orgPostCode: "",//邮编
        orgFrom: "",//数据来源（0，手工；1:同步）
        effectBegin: "",//起效日期
        effectEnd: "",//失效日期
        orderNo: "",//排序序号
        //        referenceOrgId: "",//关联组织ID
        enabled: "",//有效性（0，无效；1:有效）
        orgPath: "",//组织全路径

        orgDesc: "",
        parentOrgName: "",
        orgId: "",
        parentId: "",
        version: ""
      },

      rules: {
        orgCode: [
          { validator: validateOrgCode, trigger: "blur", required: true }
        ],
        orgName: [
          { validator: validateOrgName, trigger: "blur", required: true }
        ],
        orgDesc: [{ validator: validateOrgDesc, trigger: "blur" }],
        orgShortName: [{ validator: validateOrgShortName, trigger: "blur", required: true }]
      },
      baseData: [
        {
          orgName: this.companyName,
          orgId: "0",
          orgCode: this.companyCode,
          children: [],
          parentOrgName: "",
          parentId: -1

        }
      ],
      /* 关联组织需求已被取消
      conferenceOrgBaseData:[
        {
          orgName: this.referenceCompanyName,
          orgId: "0",
          orgCode: "",
          children: [],
          parentOrgName: "",
          parentId: -1

        }
      ],*/
      selectedData: {},
      defaultProps: {
        children: "children",
        label: "orgName"
      },
      node: {},
      nodeElement: {},
      orgGradeDic: {},
      orgFromDic: {}, //数据来源
      parentOrgPath: '',//父组件全路径
    };
  },
  computed: {
    /* showReferenceOrgTreeBtn:function(){
       if(this.referenceOrgId && this.isReadOnly){
         return true;
       }
       return false;
     },*/
    canNotBeEdit: function () {
      if (this.isReadOnly || this.form.orgFrom == '1') {
        return true;
      }
      return false;
    },
    orgFromShowName: function () {
      //默认数据员为“0”：手工
      let key = this.form.orgFrom == "" ? "0" : this.form.orgFrom;
      return this.orgFromDic[key];
    }
  },
  created() {
    this.$emit("setTitle", this.companyName);
    this.$emit("SetPageActions", [
      {
        text: '保存',
        theme: 'warning',
        action: 'EditUser',
        handle: () => {
          this.reqUpdateEhsOrgType();
        },
      }
    ]);
    this.QueryOrgGradeCode(); //初始化组织层级
    this.QueryOrgFromDic();   //初始化数据来源
  },
  mounted: function () {
    this.selectFirstOrg();
  },
  methods: {
    closePageStartFn(resolve) {
      this.$Modal.confirm({
        title: '提示',
        content: '本页面还没有暂存，请确认是否离开',
        okText: '是',
        cancelText: '否',
        onOk: () => {
          resolve();
        }
      });
    },
    append(store, data, sonData) {
      store.append(sonData, data);
      //
      let orgTree = this.$refs["orgTree"];
      orgTree.setCurrentKey(sonData.orgId);
      this.node = orgTree.getCurrentNode();
      this.btnTitle = this.$t('common.save');
    },
    gotoAddOrg(data) {
      this.selectedData = data;
      this.addOrg(false);
    },
    renderContent(h, { node, data, store }) {
      return (
        <span>
          <span>
            <span>{node.label}</span>
          </span>
          <span class="orgEditMenu" id={"MENU" + data.orgId}>
            <span
              class="orgEditSonMenu"
              on-click={() => this.addOrg(false, node)}
            >
              <i class="el-icon-plus" title={this.$t('module.orgManage.addOrg')}>
                {" "}
              </i>
            </span>
            <span
              v-show={data.parentId != -1 && data.orgFrom != '1'}  //root节点及从HR同步的组织，不能删除
              class="orgEditSonMenu"
              on-click={() => this.deleteOrg(data, node)}
            >
              <i class="el-icon-delete" title={this.$t('module.orgManage.deleteOrg')}>
                {" "}
              </i>
            </span>
          </span>
        </span>
      );
    },
    remove(store, data) {
      store.remove(data);
    },
    handleNodeClick(data, node, nodeElement) {
      this.currentNodeIsRootOrg = false;
      this.node = node;

      this.showDetail = true;
      this.btnTitle = this.$t('common.save');

      if (data.parentId == -1) {
        this.isReadOnly = true;
        this.$refs["orgForm"].resetFields();
      } else {
        this.isReadOnly = false;

        let parentNode = node.parent;
        if (parentNode.data.orgId == '0') {
          this.parentOrgPath = '';
        } else {
          this.parentOrgPath = parentNode.data.orgPath + "/";
        }
      }


      let v_parentOrgName =data.parentOrgName

      if (data.effectBegin == null || data.effectBegin.trim() == "") {
        this.initEffectDate();
      } else {
        this.effectDate = [data.effectBegin, data.effectEnd];
      }
      for (let k in this.form) this.form[k] = '';
      this.jsonObjectCopy(this.form, data);
      this.form.parentOrgName = v_parentOrgName;
      this.form.effectBegin = this.effectDate[0];//起效日期
      this.form.effectEnd = this.effectDate[1];//失效日期

      //this.referenceOrgName = data.referenceOrgName;
    },
    loadCurrentOrgNode(node, resolve) {
      if (node.level == 0) {
        resolve(this.baseData);
        return;
      }

      this.loadNode(node, resolve, this.companyId);
    },
    /*关联组织功能已被取消
    loadReferenceOrgNode(node,resolve){
       if (node.level == 0) {
        resolve(this.conferenceOrgBaseData);
        return;
      }
      
      if(this.referenceCompanyId){
        this.loadNode(node,resolve,this.referenceCompanyId);
      }
      
    },
    */
    loadNode(node, resolve, companyId) {
      let checked = node.checked;
      node.checked = false; //每次加载，均取消当前功能的复选框选中状态
      this.node = node;

      let parentId = 0;
      if (node.level != 0) {
        parentId = node.data.orgId;
      }

      $store
        .dispatch("OrgMgQueryOrgListByCompanyId", {
          companyId: companyId,
          parentId: parentId === '0' ? companyId : parentId,
          sortDTO: {
            fieldName: "",
            orderBy: ""
          }
        })
        .then(res => {
          if (res.statusCode != 0) {
            this.$Message.warning({
              content: res.msg,
              duration: 3
            });
            return;
          }
          resolve(res.dataResult);
        });
    },
    addOrg(addTopOrg, node) {
      event.stopPropagation(); //阻止点击事件向上冒泡
      let parentOrgName = "";
      let parentId = "";
      this.node = node;
      this.isReadOnly = false;

      parentOrgName = this.node.data.orgName;
      parentId = this.node.data.orgId;

      if (node.data.orgId == '0') {
        this.parentOrgPath = '';
      } else {
        this.parentOrgPath = node.data.orgPath + "/";
      }

      this.showDetail = true;
      this.btnTitle = this.$t('module.orgManage.addNewOrg');

      this.jsonObjectCopy(this.form, this.initParam());
      this.form.parentOrgName = parentOrgName;
      this.form.parentId = parentId;
      //生产有效期，默认从当前开始，到50年后结束
      this.initEffectDate();
      this.form.effectBegin = this.effectDate[0];
      this.form.effectEnd = this.effectDate[1];

    },
    changeEffectDate(value) {

      console.log(value);
      if (value && value.length > 0 && value[0] == "") {
        this.initEffectDate();
      } else {
        this.effectDate = value;
      }
    },
    deleteOrg(data, node) {
      event.stopPropagation();

      this.handleNodeClick(data, node); //此处将当前详情页修改为当前点击条目，这样做，不太理想：Yelow
      let parentNode = this.node.parent;

      new $confirm(this.$t('module.orgManage.confirmDelete'), this).then(() => {
        $store
          .dispatch("OrgMgDeleteOrgForCompany", {
            companyId: this.companyId,
            orgIds: this.form.orgId
          })
          .then(res => {
            if (res.statusCode != 0) {
              this.$Message.warning({
                content: res.msg,
                duration: 3
              });
              return;
            }
            this.$Message.warning({
              content: this.$t('module.orgManage.deleteSuccess'),
              duration: 3
            });
            //此处应该刷新组织树
            this.remove(this.node.store, this.node.data);
            //this.showDetail = false;
            // this.form.orgId = "";

            if (parentNode.level > 0) {
              this.$refs["orgTree"].setCurrentKey(parentNode.data.orgId);

              this.handleNodeClick(parentNode.data, parentNode);
            } else {
              this.baseData = [];
              this.firstLoading = true;
              this.noData = true;
            }
          });
      });
    },
    checkChanged(data, isSelected, sonNode) {

      if (isSelected) {
        this.$refs["conferenceOrgTree"].setCheckedKeys([]);
        this.$refs["conferenceOrgTree"].setCheckedKeys([data.orgId]);
      }
      console.log(data)
    },
    /*
    onOk(){
      let nodes = this.$refs["conferenceOrgTree"].getCheckedNodes();
      ;
      if(nodes.length > 0){
        this.form.referenceOrgId = nodes[0].orgId;
        this.referenceOrgName = nodes[0].orgName;
      }
      this.modal = false;
    },*/
    saveOrUpdateOrg() {
      this.$refs["orgForm"].validate(valid => {

        let v_parentOrgName = this.form.parentOrgName;
        if (valid) {

          if (this.effectDate.length == 2) {
            this.form.effectBegin = this.effectDate[0];
            this.form.effectEnd = this.effectDate[1];
          }
          //重新记录组织全路径

          this.form.orgPath = this.parentOrgPath + this.form.orgCode;


          this.saveLoading = true;
          let param = this.initParam();
          this.jsonObjectCopy(param, this.form);
          if (this.form.orgId) {
            $store
              .dispatch("OrgMgUpdateOrgForCompany", param)
              .then(response => {
                if (response.statusCode == "0") {
                  this.$Message.success({
                    content: this.$t('module.orgManage.editSuccess'),
                    duration: 3
                  });
                  this.jsonObjectCopy(this.node.data, param);
                  this.form.version = response.extra.version;//更新数据版本号
                  this.node.data.version = this.form.version;//更新数据版本号
                  //this.node.data.parentId = param.parentId;
                } else {
                  this.$Message.error({
                    content: response.msg,
                    duration: 3
                  });
                }
                this.saveLoading = false;
              });
          } else {
            $store.dispatch("OrgMgAddOrgForCompany", param).then(response => {
              if (response.statusCode == "0") {
                //this.search();
                //此处更新组织
                this.$Message.success({
                  content: this.$t('module.orgManage.addSuccess'),
                  duration: 3
                });

                console.log(param);
                param.orgId = response.dataResult;
                param.version = response.extra.version;

                this.form.orgId = param.orgId;
                this.form.version = param.version;
                //创建child子功能并初始化数据
                let child = this.initParam();
                this.jsonObjectCopy(child, param);
                Object.assign(child, {
                  parentOrgName: v_parentOrgName,
                  children: []
                });

                if (this.baseData.length == 0) {
                  this.baseData.push(child);
                } else {
                  this.append(this.node.store, this.node.data, child);
                }
              } else {
                this.$Message.error({
                  content: response.msg
                });
              }
              this.saveLoading = false;
            });
          }
        } else {
          this.$Message.error(this.$t('common.formValidateFailed'));
        }
      });
    },
    selectFirstOrg() {
      //默认显示第一个组织信息
      if (this.firstLoading && this.baseData.length > 0) {
        this.initEffectDate();
        this.$refs["orgTree"].setCurrentKey(this.baseData[0].orgId);
        this.showDetail = true;

        //初始化this.form对象
        Object.assign(this.form, this.initParam());
        this.jsonObjectCopy(this.form, this.baseData[0]);

        this.form.effectBegin = this.effectDate[0];
        this.form.effectEnd = this.effectDate[1];
        this.firstLoading = false;
        this.currentNodeIsRootOrg = true;
      }
    },
    QueryOrgGradeCode() {
      //获取组织维度
      $store
        .dispatch("GetValueSetByCode", {
          code: 'ORG_GRADE'
        })
        .then(response => {
          this.orgGradeDic = {};
          let dicArray = response.dataResult;
          for (let i = 0; i < dicArray.length; i++) {
            let dic = dicArray[i];
            this.orgGradeDic[dic.vsiKey] = dic.vsiValue;
          }
        });
    },
    QueryOrgFromDic() {
      //获取组织维度
      $store
        .dispatch("GetValueSetByCode", {
          code: 'orgFrom'
        })
        .then(response => {
          this.orgFromDic = {};
          let dicArray = response.dataResult;
          for (let i = 0; i < dicArray.length; i++) {
            let dic = dicArray[i];
            this.orgFromDic[dic.vsiKey] = dic.vsiValue;
          }
        });
    },

    initEffectDate() {
      //默认从当天开始，有效期至50年后
      let currentDate = new Date();
      let effectBeginStr = currentDate.Format("yyyy-MM-dd");

      let effectEndDate = new Date(currentDate);
      effectEndDate.setFullYear(currentDate.getFullYear() + 50);

      let effectEndStr = effectEndDate.Format("yyyy-MM-dd");

      this.effectDate = [effectBeginStr, effectEndStr];
    },
    openConferenceOrgTree() {
      //跳转至关联组织树界面
      if (this.referenceCompanyId) {
        this.modal = true;
      } else {
        this.$Message.warning({
          content: this.$t('module.orgManage.notConfigAssociatedOrg')
        });
      }

    },
    initParam() {
      let param = {
        companyId: this.companyId,
        orgCode: '',
        orgName: '',
        orgDesc: '',
        orgId: '',
        parentId: '',
        version: '0',

        orgShortName: '', //组织简称
        orgGradeCode: '', //组织层级编码
        orgManager: '',//组织管理者
        orgAddress: '',//地址
        orgPostCode: '',//邮编
        orgFrom: '',//数据来源（0，手工；1:同步）
        effectBegin: '',//起效日期
        effectEnd: '',//失效日期
        orderNo: '0',//排序序号
        //referenceOrgId: '',//关联组织ID
        enabled: '1',//有效性（0，无效；1:有效）
        orgPath: ''//组织全路径
      };
      return param;
    },
    jsonObjectCopy(target, source) {
      //只拷贝target中存在的key
      let targetKeys = Object.keys(target);
      for (const key in targetKeys) {
        if (source.hasOwnProperty(targetKeys[key])) {
          target[targetKeys[key]] = source[targetKeys[key]];
        }
      }
    },
    //保存
    reqUpdateEhsOrgType() {
      $store.commit('loading',true);
      $store.dispatch('UpdateEhsOrgType',{
        orgId: this.form.orgId,
        ehsOrgType: this.form.orgGradeCode
      }).then(res => {
        if (res.dataResult === 'success') {
          this.refreshNodeBy();
          $store.commit('loading',false);
          this.$Message.success('操作成功');
          return;
        }
        throw res;
      }).catch(err => {
        $store.commit('errorMsg',{
          load: 'loading',
          str: 'UpdateEhsOrgType保存报错',
          err
        });
      });
    },
    //对tree进行更新
    refreshNodeBy() {
      this.treeShow = false;
      setTimeout(() => {
        this.treeShow = true;
      },300);
    },
  }
};
</script>
