<template>
  <dlg
      :dlgTitle="dlgTitle"
      :dlgWidth="dlgWidth"
      :dlgHeight="dlgHeight"
      @dlgConfirm="handleDlgConfirm"
      @dlgCancel="handleDlgCancel"
  >
    <template #dlg-content-slot>
      <list
          :table-data="props.tableData"
          :table-params="tableParams"
          v-model:selectRow="state.selectRow"
          v-model:selectionRows="selection"
          @db-click="handleDbClick"
      >
      </list>
    </template>
  </dlg>
</template>

<script lang="ts" setup>
import Dlg from "./dlg.vue"
import List from "@/views/common-component/lt-common-table/lt-table-local.vue"
import {cloneDeep} from "lodash-es";
import {ref, PropType, onMounted, computed, unref, reactive, onBeforeMount, nextTick} from "vue"
import {ColumnFilterItemInter} from "@/utils/common-type";
import { message } from 'ant-design-vue';
import {useI18n} from "vue-i18n";
const {locale} = useI18n();
const {t} = useI18n();

const emits = defineEmits(['dlgConfirm', 'dlgCancel'])

const props = defineProps({
  dlgTitle: {
    type: String,
    default: "弹窗名称"
  },
  dlgWidth: {
    type: String,
    default: "500px"
  },
  dlgHeight: {
    type: String,
    default: "300px"
  },
  tableData:{
    type:Array as PropType<any[]>,
    default(){
      return []
    }
  },
  tableParams: {
    type: Object,
    default() {
      return {
        selectedRowKeys: [],
        selectData: null,
        selectionData: [],
        isShowTextOperate: false,
        isShowIconOperate: false,
        saveUrl: "",

        columnFilter: [] as ColumnFilterItemInter[] | string[],
        columns: [] as any[],
        url: '',
        isAutoEdit: false,
        remoteQueryMode: 2,
        dataName: 'Datas',
        showIndex: true,
        showEditInDialog: false,
        ellipsis: true,
        rowKey: "",
        pagination: {
          pageSize: 25,
          hideOnSinglePage: false
        },
        showToolBar: false,
        queryParams: {} as any,
        searchBox: false,
        operateBtnOption: {
          headBtnOption: {
            ifShow: false,
            btnOption: [
              {
                visible: true,
                zhTitle: '新增',
                enTitle: 'add',
                icon: "fa fa-plus",
                clickEvent: () => {
                },
                customVisible: ((row) => {
                  return true
                })
              }
            ]
          },
          rowBtnOption: {
            ifShow: false,
            btnBaseWidth: 70,
            btnNum: 3,
            btnOption: [
              {
                visible: true,
                zhTitle: '复制',
                enTitle: 'add',
                icon: "fa fa-copy",
                clickEvent: () => {

                },
                customVisible: ((row) => {
                  return true
                })
              },
            ],
            mLeft: 5
          }
        }
      }
    }
  }
})

const state=reactive({
  selectRow:null,
})
const selection=ref([])

const handleDlgConfirm = (ifDbClick:boolean) => {
  let selectResult = []
  if (ifDbClick === true&&state.selectRow) {
    selectResult=[state.selectRow]
  } else {
    if (selection.value.length != 0) {
      selectResult=selection.value
    }else if(state.selectRow) {
      selectResult=[state.selectRow]
    }
  }
  if(selectResult.length==0){
    return message.warning(t('Formula.Common.SelectDataWarning'));
  }
  emits('dlgConfirm',selectResult)
}
const handleDlgCancel = () => {
  emits('dlgCancel')
}
const handleDbClick = (row:any)=>{
  state.selectRow=row
  handleDlgConfirm(true)
}
</script>

<style scoped>

</style>