<template>
  <!-- 地块调查 风险评估 -->
  <a-table :columns="participantsColumns" :data-source="localData" :pagination="false" bordered size="middle">
    <template #headerCell="{ column }">
      <span :class="{ required: psfs === 1 && !['mail', 'bz', 'action'].includes(column.dataIndex) }"> {{ column.title }}</span>
    </template>
    <template #bodyCell="{ column, record }">
      <a-input v-model:value="record[column.dataIndex]" @input="emit('update:data', localData)" />
    </template>
    <!--操作栏-->
    <template #action="{ index }">
      <a-button type="link" @click="toDelete(index)">删除</a-button>
    </template>
  </a-table>
</template>
<script lang="ts" setup>
  import { ref, watch } from 'vue';
  import { participantsColumns } from '../data';
  import { decrypts } from '@/utils/checkTip';

  const props = defineProps({
    data: {
      type: Object,
    },
    psfs: {
      type: Number,
    },
  });
  const emit = defineEmits(['update:data']);
  const localData = ref([]);
  watch(
    () => props?.data,
    async (val: any) => {
      if (val) {
        localData.value = val.map((item) => ({ ...item }));
        localData.value.forEach(async (item: any) => {
          item.lxdh = await decrypts(item.lxdh, false);
        });
      }
    },
    { deep: true, immediate: true }
  );
  function toDelete(index) {
    localData.value.splice(index, 1);
    emit('update:data', localData.value);
  }
  defineExpose({
    localData,
  });
</script>
