<template>
  <div style="position: relative;">
    <span style="position: absolute;top: 1.5rem;left: 32rem;color: red;">处置方式：{{ disposalWay }}</span>
    <InfoWindow
      v-if="disposalId" ref="infoWindowRef" :info-window-no="infoWindowNo"
      :where-clause-source="whereClauseSource" :multiple="true" :is-search-widget="true"
    />
  </div>
</template>

<script setup>
import { queryById } from './api.js';
import { message } from 'ant-design-vue';
import Common from '../../common/Common.js';
import { ref, defineProps, defineExpose, watch } from 'vue';

const props = defineProps({
  disposalId: {
    type: String,
    default: null,
  },
});

const disposalWay = ref('');
const infoWindowRef = ref();
const whereClauseSource = ref('');
const infoWindowNo = ref('20241101_160846');

// 获取所选资产
const getSelected = () => {
  const modelDatas = infoWindowRef.value.getSelectedModelDatas();
  const assetIds = modelDatas.map(item => {
    return item.id;
  });
  return assetIds;
};

// 查询资产类型
const queryAsset = () => {
  queryById(props.disposalId).then(
    success => {
      if (success.errorCode === 0) {
        disposalWay.value = success.data.disposalWay;
      } else {
        message.warning(success.errorMessage);
      }
    },
    error => {
      Common.processException(error);
    },
  );
};

watch(() => props.disposalId, newValue => {
  if (newValue) {
    queryAsset();
    whereClauseSource.value = { customWhere: '(isApproved is null or isApproved = 0) and adpa.id = ' + newValue };
  }
}, { immediate: true });

defineExpose({
  getSelected,
});

</script>

<style scoped>
:deep(.ant-page-header-heading) {
  display: none !important;
}

:deep(.m-segmented) {
  display: none !important;
}

:deep(.flex-header) {
  flex: 0 0 40px !important;
}
</style>