<template>
  <Dialog ref="dialog" :title="title" :maxWidth="maxWidth" @confirm="confirm" :showConfirm="!singleSelect">
    <template #default>
      <Table ref="table" :list="list" :query="query" :delProp="delProp" :labelWidth="labelWidth"
             :selectableData="selectableData"
             :rowKey="rowKey"
             :fieldName="fieldName"
             :summaryMethod="summaryMethod"
             :showSummary="showSummary"
             :maxHeight="maxHeight">
        <template #search>
          <slot name="search"/>
        </template>
        <template #default>
          <Column type="selection"  :reserveSelection="true" width="55" v-if="!singleSelect"/>
          <slot name="tableContent"/>
          <Column label="操作" :min-width="80" align="center" fixed="right" v-if="singleSelect">
            <template #default="{ row }">
<!--              <el-link type="primary" @click="handleClick(row)">查看</el-link>-->
              <el-link type="primary" @click="returnRow(row)" v-if="singleSelect">选择</el-link>
              <slot name="table" :row="row"/>
            </template>
          </Column>
        </template>
        <template #dialogs>
          <CustomDialogForm ref="customDialog" :value="form" :title="dialogTitle" width="1200px"
                            :disabled="disabled" :saveAction="action" labelWidth="150px"  @success="$refs.table.getList()">
            <slot name="slot" :form="form"/>
          </CustomDialogForm>
        </template>
      </Table>
    </template>
  </Dialog>
</template>

<script>

import Dialog from "@/components/element/Dialog.vue";
import Search from "@/components/element/form/Search.vue";
import Table from "@/components/element/table/Table.vue";
import Column from "@/components/element/table/Column.vue";
import FooterButton from "@/components/element/footerButton.vue";
import Input from "@/components/element/form/items/Input.vue";

export default {
  components: {FooterButton, Column, Search, Dialog, Table, Input},
  props: {
    labelWidth:{
      type: String,
      default: '120px'
    },
    list: {
      type: Function
    },
    spanMethod:{
      type:Function,
      default:()=>{}
    },
    data: {
      type: Array,
      default:null,
    },
    //单选
    singleSelect: {
      type: Boolean,
      default: true
    },
    title:{
      type: String,
      default: '选择器'
    },
    maxSelectable:{
      type:Number,
      default:9999
    },
    dialogTitle:{
      type: String,
      default: '详情信息'
    },
    query:{
      type: Object,
      default: ()=>{}
    },
    maxWidth:{
      type: String,
      default: '1200px'
    },
    delProp:{
      type: Array,
      default: ()=>[]
    },
    maxHeight:{
      type: String,
      default:'520px'
    },
    selectableData:{
      type: Array,
      default:() => [],
    },
    rowKey:{
      type: String,
      default:'transportNo'
    },
    fieldName:{
      type: String,
      default:'520px'
    },
    summaryMethod: {
      type: Function
    },
    showSummary: {
      type:Boolean,
      default: false
    }
  },
  data() {
    return {
      queryParams: {},
      selections: [],
      disabled:false,
      form:{}
    };
  },
  computed: {
  },

  created() {

  },
  mounted() {

  },
  watch: {},
  methods: {
    //查看
    handleClick(row) {
      this.form = {...row}
      this.$refs.customDialog.open()
    },
    returnRow(row){
      this.$refs.dialog.close();
      this.$emit('returnRow',row)
    },
    action(){},
    confirm() {
      this.selections =  this.$refs.table.selections
      if(this.selections && this.selections.length > this.maxSelectable){
        this.$message.info("最多可以选择" + this.maxSelectable + "数据")
        return;
      }
      this.$emit('confirm', this.$refs.table.selections);
      this.selections = [];
      this.queryParams = {};
      this.$refs.dialog.close();
    },
    open() {
      console.log('this',this.showSummary)
      setTimeout(()=>{

        this.$refs.dialog.open(true);
      },200)

    },


  },




}


</script>

<style scoped>


</style>

