<template>
  <div class="text-center py-2">样品信息</div>
  <a-table :dataSource="dataSource" :columns="columns">
    <template #bodyCell="{ column, record }">
      <template v-if="column.key == 'action'">
        <a-space>
          <a-radio-button value="small" v-if="type == 'edit'" @click="del(record)">删除</a-radio-button>
        </a-space>
      </template>
    </template>
  </a-table>
</template>
<script lang="ts" setup>
  import { ref, watch } from 'vue';

  import { Modal } from 'ant-design-vue';

  const props = defineProps({
    type: {
      type: String,
      default: 'edit',
    },
    Item: {
      type: Object,
      default: '',
    },
  });

  const show = ref(false);

  const dataSource = ref<any>();
  const columns = ref<any>([
    {
      title: '检测项编号',
      dataIndex: 'jcxbh',
      key: 'jcxbh',
    },
    {
      title: '监测项目',
      dataIndex: 'jcxm',
      key: 'jcxm',
    },
    {
      title: '检测方法',
      dataIndex: 'jcff',
      key: 'jcff',
    },

    {
      title: '监出限',
      dataIndex: 'jcx',
      key: 'jcx',
    },
    {
      title: '单位',
      dataIndex: 'dw',
      key: 'dw',
    },
    {
      title: '检测结果',
      dataIndex: 'jcjg',
      key: 'jcjg',
    },
    {
      title: '标准限值',
      dataIndex: 'bzxz',
      key: 'bzxz',
    },
    {
      title: '是否超标',
      dataIndex: 'sfcb',
      key: 'sfcb',
    },
    {
      title: '操作',
      dataIndex: 'action',
      key: 'action',
    },
  ]);
  async function init() {
    console.log(props.Item, '111');
    dataSource.value = props.Item;
  }
  init();
  watch(
    () => props.Item,
    (val) => {
      console.log(val, 'valbuzou');
      show.value = false;
      init();
    },
    { deep: true, immediate: true }
  );

  // 点击删除
  function del(v) {
    Modal.confirm({
      title: '确认删除',
      content: '是否确认删除数据',
      centered: true,
      okText: '确认',
      cancelText: '取消',
      onOk: async () => {
        show.value = false;
        dataSource.value.forEach((item, index) => {
          if (v.jcxbh == item.jcxbh) dataSource.value.splice(index, 1);
        });
        console.log(dataSource.value, 'dataSource.value');
      },
    });
  }
</script>
