<template>
  <div>
    <CommonTable
      :is-select="!isOperation" :is-checkbox="false" :is-disabled="isReadonly" :have-page="false"
      :columns="quoteColumns" :data-source="quoteDatas" @get-selected="getSelectedInfo"
    >
      <template #title>
        <div><span>买受方报价</span></div>
        <a-divider style="margin: 8px 0;" />
        <span>处置形式：{{ disposalForm ? disposalForm.label : disposalFormData }}</span>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.dataIndex === 'quotation' && !isOperation">
          <a-input-number v-model:value="record.quotation" :controls="false" :step="0.01" style="width: 100%;" />
        </template>
        <template v-if="column.dataIndex === 'operation'">
          <a-button type="link">评价</a-button>
        </template>
      </template>
    </CommonTable>
  </div>
</template>

<script setup>
import { quoteColumn } from './assetConfig.js';
import CommonTable from '../assetsDisposal/AssetCommonTable.vue';
import { ref, defineProps, watch, computed, defineEmits } from 'vue';

const emits = defineEmits(['getAcceptor']);
const props = defineProps({
  acceptorInfo: {
    type: Object,
    default: null,
  },
  disposalForm: {
    type: Object,
    default: null,
  },
  isOperation: {
    type: Boolean,
    default: true,
  },
  isReadonly: {
    type: Boolean,
    default: false,
  },
  readDatas: {
    type: Object,
    default: null,
  },
});

const quoteDatas = ref([]);
// const quoteColumns = ref(quoteColumn);
const disposalFormData = ref('');

const quoteColumns = computed(() => {
  if (!props.isOperation) {
    return quoteColumn.filter(item => item.dataIndex != 'operation');
  } else {
    return quoteColumn;
  }
});

const getSelectedInfo = info => {
  emits('getAcceptor', info.selectedRows[0]);
};

watch(() => props.acceptorInfo, newValue => {
  if (newValue) {
    quoteDatas.value = [newValue];
  }
}, { immediate: true });

watch(() => props.readDatas, newValue => {
  if (newValue) {
    quoteDatas.value = [newValue.innerBuyerVo];
    if(!props.disposalForm){
      disposalFormData.value = newValue.assetDetailsVo.disposalWay;
    }
  }
}, { immediate: true });

</script>

<style scoped></style>