<template>
  <div>
    <BasicTable @register="registerTable" :searchInfo="searchInfo">
      <template #bodyCell="{ column, record }">
        <!-- 地点特殊处理 -->
        <template v-if="column.key === 'address'">
          <span>{{ record.countyname }} / </span>
          <span>{{ record.streetname }} / </span>
          <span>{{ record.communityname }}</span>
        </template>
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                label: '详情',
                onClick: () => {
                  openDetailModal(record);
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
    <DetailModal
      @register="registerModal"
      :caseDetailId="caseDetailId"
      :isShowMap="true"
      width="80%"
    />
  </div>
</template>
<script lang="ts" setup>
  import { reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { useModal } from '@/components/Modal';
  import { tableColums, searchFormSchema } from './columns.data';
  // 子组件
  import DetailModal from '@/views/demo/query/detailModal.vue';
  // api
  import { fun_LoadDataBaseInfo } from '@/api/demo/query';

  const searchInfo = reactive<Recordable>({});

  const [registerTable] = useTable({
    api: fun_LoadDataBaseInfo,
    title: '案件列表',
    columns: tableColums,
    rowKey: 'id',
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    showIndexColumn: true,
    handleSearchInfoFn(info) {
      return info;
    },
    actionColumn: {
      width: 80,
      title: '操作',
      dataIndex: 'action',
    },
    beforeFetch: (data) => {
      // 接口请求前 参数处理
      var temp = data;
      temp.handle_status_id = 2;
      temp.is_dealer = 1;
      return temp;
    },
  });
  // 弹窗
  const [registerModal, { openModal }] = useModal();

  // 打开详情窗口
  let caseDetailId = '';
  function openDetailModal(record: Recordable) {
    caseDetailId = record.id;
    openModal(true, { record });
  }
</script>
<style lang="less" scoped></style>
