<template>
  <div>
    <div>
      {{ t('permission.common.typeText') }}
      <h-radio-group v-model:value="org" @change="changeOrg">
        <h-radio value="current">{{ t('permission.common.typeCurrent') }}</h-radio>
        <h-radio value="all">{{ t('permission.common.typeAll') }}</h-radio>
      </h-radio-group>
    </div>
    <h-divider />
    <member-transfer ref="componentRef" :options="options" id="AdminMember-queryTransfer" />
  </div>
</template>

<script lang="ts">
import { defineComponent, provide, ref } from 'vue';
import MemberTransfer from './MemberTransfer.vue';
import { getInfo, ICP_CONFIG } from '@remote/icpx-platform/utils';
/* import { getInfo, ICP_CONFIG } from '@/utils/commMethods'; */
import { useI18n } from '@crami/locale';
export default defineComponent({
  name: 'PermissionPllicyContent',
  components: {
    MemberTransfer,
  },
  props: {
    modalParam: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  setup(props) {
    console.log(props);
    const { t } = useI18n();
    const componentRef = ref();
    // currentOrgId  组织id
    const org = ref('current');
    const { lang, connect, companyId } = getInfo(ICP_CONFIG);
    const commStr = {
      lang,
      connect,
      companyId,
    };
    // const tableFlag = ref(true);
    // const tableData = ref([]);
    const options = ref({
      queryParam: {
        params: {
          // parentId: 'P_SYS_COMPANY_155f6a331e804b69a6fc47e6273699fc',
          viewName: props.modalParam.params.para.listParams.params.viewName,
          lang,
          connect,
          companyId,
          ids: props.modalParam.data,
        },
        url: props.modalParam.params.para.listParams.url,
        columns: undefined,
      },
      treeParam: {
        params: {
          lang,
          connect,
          companyId,
          loadAll: props.modalParam.params.para.treeParamAll.params.loadAll,
          loadAllStructure: props.modalParam.params.para.treeParamAll.params.loadAllStructure,
          paraList: JSON.stringify(commStr),
          treeViewName: props.modalParam.params.para.treeParamAll.params.treeViewName,
        },
      },
      data: props.modalParam.data,
      attr: props.modalParam.params.attr,
      org: org.value,
      // tableChangeFlag: tableFlag.value,
    });
    provide('options', options);
    const getTableData = () => {
      return (componentRef.value as any).getTableKeys();
    };
    const changeOrg = value => {
      options.value.treeParam.params = {
        lang,
        connect,
        companyId,
        loadAll: props.modalParam.params.para.treeParamAll.params.loadAll,
        loadAllStructure: props.modalParam.params.para.treeParamAll.params.loadAllStructure,
        paraList: JSON.stringify(commStr),
        treeViewName: props.modalParam.params.para.treeParamAll.params.treeViewName,
      };
      options.value.data = getTableData().join(';');
      options.value.org = value.target.value;
      //调用
      console.log(componentRef.value);
      if (options.value.org == 'current') {
        componentRef.value.transferRef.filterTreeDataByNode({
          value1: window.localStorage.getItem('userGroup') || '',
        });
      } else {
        componentRef.value.transferRef.filterTreeDataByNode();
      }
    };

    return { t, componentRef, options, org, getTableData, changeOrg };
  },
});
</script>

<style lang="less"></style>
