/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <p-card :bordered="false" :title="title" style="margin-bottom: 10px">
    <a-space slot="extra">
      <slot name="extra" />
    </a-space>
    <!-- :bodyStyle="{minHeight:'400px',width:'100%',overflow: 'auto', maxHeight:'400px'}" -->

    <t-table
      :id="$route.meta.menuId + '_main'"
      :sign="true"
      autoColWidth
      rowSelectFixed
      :activeKey="activeID"
      rowKey="id"
      :scroll="{ x: true }"
      :vScrollX="{enabled:true}"
      :vScrollY="{enabled:true,rows:10}"
      ref="mainTable"
      bordered
      :columns="mx_columns"
      :doneBefore="doneBefore"
      :remoteUrl="mx_remoteUrl"
      :remoteBefore="remoteBefore"
      dragle
      :rowSelectType="2"
      v-on="$listeners"
      :getCheckboxProps="
        (record) => ({
          props: {
            disabled: record.status >= 2 ? true : false,
          },
        })
      "
    >
      <slot name="operation" slot="operation" slot-scope="text, record" :record="record" :text="text" />
    </t-table>
  </p-card>
</template>
<script>
import { setMainColumns } from './tableConfig';
export default {
  props: {
    doneBefore: { type: Function },
    options: {
      type: Object,
      default: () => {},
    },
    operation: {
      type: null,
    },
    selectedRowKeys: {
      type: Array,
      default: () => [],
    },
    tableExtendedField: {
      type: Array,
    },
    getFieldsValue: {
      type: Function,
    },

    activeID: {
      type: String,
    },
    title: {
      type: null,
    },

    url: {
      type: null,
    },
    columns: {
      type: null,
    },
    setMainColumns: {
      type: Function,
      default:setMainColumns
    }
  },

  data() {
    return {
      confirmLoading: false,
      dataSource: [],
      mx_remoteUrl: {
        method: 'post',
        url: this.url,
      },
      mx_remoteParams: {},
      mx_columns: !this.columns ? this.setMainColumns(this, this.tableExtendedField) : this.columns,
    };
  },
  mounted() {},
  watch: {
    tableExtendedField(value) {
      if (value.length > 0) {
        this.mx_columns = !this.columns ? this.setMainColumns(this, value) : this.columns
      }
    },
    // activeID(v) {
    //   console.log("activeID", v)
    //   this.$refs.mainTable.activeID = v
    // }
  },
  methods: {
    print_item() {
      alert('开发中...');
      this.$emit('print', record);
    },
    copy_item(record) {
      this.$emit('copy', record);
    },
    submit_item(record) {
      this.$emit('submit', [record.id]);
    },
    show_info_item(record) {
      this.$emit('view', record);
    },

    update_item(record) {
      this.$emit('update', [record]);
    },

    reload(args) {
      return this.$refs.mainTable.reload(args);
    },
    remoteBefore(vNode, remoteUrl) {
      let searchBar = this.$parent.$refs.searchBar;
      if (searchBar) {
        const { getFieldsValue } = searchBar;
        remoteUrl.data = { ...remoteUrl.data, ...getFieldsValue() };

        if (Array.isArray(remoteUrl.data.createStartTime)) {
          remoteUrl.data.createEndTime = remoteUrl.data.createStartTime[1];
          remoteUrl.data.createStartTime = remoteUrl.data.createStartTime[0];
        }
        if (Array.isArray(remoteUrl.data.updateStartTime)) {
          remoteUrl.data.updateEndTime = remoteUrl.data.updateStartTime[1];
          remoteUrl.data.updateStartTime = remoteUrl.data.updateStartTime[0];
        }
      }
    },
  },
};
</script>
