<template>
  <a-form :model="rectifyInfo" :rules="rules" :label-col="{span: 6}" :wrapper-col="{span: 16}" ref="rectifyInfoForm">
    <a-form-item label="整改单位" prop="zgXianOrgId">
      <a-tree-select v-model:value="rectifyInfo.zgXianOrgId" style="width: 100%" :tree-data="rectifyUnits" :fieldNames="{children: 'children', value: 'id', title: 'label', key: 'id'}" search-placeholder="请选择整改单位" />
    </a-form-item>
    <a-form-item label="备注意见" prop="activityComment">
      <a-textarea v-model:value="rectifyInfo.activityComment" :rows="8" />
    </a-form-item>
  </a-form>
</template>

<script>
import { hostUrl } from '../../../utils/global_variable';
import { getOrgTreeJson } from '../Common/rectify_api';
export default {
  data() {
    return {
      rectifyInfo: {
        zgXianOrgId: null,
        activityComment: '',
      },
      loadingStat: false,
      loadingStatText: '提交',
      rules: {},
      rectifyUnits: [],
    };
  },
  computed: {
    hostUrl() {
      return hostUrl;
    },
  },
  mounted() {
    this.rectifyUnits = this.getOrgTreeJson();
  },
  methods: {
    saveRectifyUnitInfo() {
      this.$refs.rectifyInfoForm.validate((valid) => {
        if (valid) {
          // console.dir(this.rectifyInfo);
          this.$emit('saveRectifyUnitInfo', this.rectifyInfo);
          this.$refs.rectifyInfoForm.resetFields();
        } else {
          return false;
        }
      });
    },
    getOrgTreeJson() {
      getOrgTreeJson().then((res) => {
        const jsonArray = [];
        const jsonStr = JSON.stringify(res.data);
        jsonArray.push(res.data);
        this.rectifyUnits = jsonArray;
      });
    },
  },
};
</script>

<style lang='less' scoped>

</style>
