<template>
  <a-modal title="企业信息" :width="500" destroyOnClose v-model:visible="visible" @ok="handleOk">
    <ns-form ref="formRef" :schemas="formSchema" :model="formData" formLayout="vertical" />
  </a-modal>
</template>

<script lang="ts">
  import { defineComponent, reactive, ref, watch } from 'vue';
  import { enterPrise } from '/@/api/origanizemanage';
  export default defineComponent({
    name: 'AddBorderVisible',
    props: { info: Object },
    emits: ['ok'],
    setup(props, { attrs, emit }) {
      let formData = ref({});
      const formRef = ref();
      const visible = ref(false);
      const toggle = () => {
        formData.value = {};
        visible.value = !visible.value;
      };
      const currentOrgId = ref();
      console.log(attrs, 'attrs');
      watch(
        () => props.info,
        () => {
          console.log(props.info, 'sdfasdf');
          currentOrgId.value = props.info?.orgId;
        },
        { deep: true, immediate: true },
      );

      const formSchema = reactive([
        {
          field: 'orgId',
          label: '组织名称',
          component: 'NsSelectApi',
          componentProps: {
            api: enterPrise.list,
            params: {
              pageNum: 0,
              pageSize: 999,
            },
            getPopupContainer: (triggerNode: any) =>
              triggerNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
                .parentNode,
            resultField: 'data.records',
            labelField: 'orgName',
            valueField: 'orgId',
            immediate: true,
            filterData: (item) => {
              return item.orgId !== currentOrgId.value;
            },
            showSearch: true,
            filterOption: (input: string, option: any) => {
              return option.orgName.toLowerCase().indexOf(input.toLowerCase()) >= 0;
            },
            placeholder: '请选择',
          },
          rules: [
            {
              required: true,
            },
          ],
        },
        {
          field: 'point',
          label: '点位数据',
          component: 'NsRadioGroup',
          componentProps: {
            radioType: 'radio',
            options: [
              { label: '分享', value: 0 },
              { label: '不分享', value: 1 },
            ],
          },
          rules: [
            {
              required: true,
              message: '请选择是否分享',
              type: 'number',
            },
          ],
        },
      ]);
      const handleOk = () => {
        formRef.value?.triggerSubmit().then((res) => {
          emit('ok', res);
        });
      };
      return { handleOk, formData, formSchema, visible, toggle, formRef };
    },
  });
</script>

<style lang="less" scoped>
  // :deep(.ns-child-form) {
  //   width: 1100px !important;
  //   justify-content: flex-start !important;
  // }
  // :deep(.ant-input-group-addon) {
  //   border: 0px solid #dcdfe2 !important;
  // }
</style>
