/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <t-table
    :activeKey="activeID"
    :id="$route.meta.menuId + '_childrenTable'"
    :scroll="{ x: true }"
        :vScrollX="{enabled:false}"
        :vScrollY="{enabled:true,rows:4}"
        autoColWidth
    :dataSource="dataSource"
    ref="childrenTable"
    bordered
    :autoLoad="false"
    :columns="mx_columns"
    :remoteUrl="mx_remoteUrl"
    :remoteBefore="remoteBefore"
    dragle
    :pagination="false"
    :rowSelectType="0"
  >
  </t-table>
</template>
<script>
import { setMainColumns } from './tableConfig'
import { childrenTableInfoUrl } from '../../api'

export default {
  props: {
    options: {
      type: Object,
      default: () => {},
    },
    isShow: {
      type: Boolean,
      default: false,
    },
    currentRow: {
      type: Object,
      default: () => null,
    },
    selectedRowKeys: {
      type: Array,
      default: () => [],
    },
    tableExtendedField: {
      type: Array,
    },
    getFieldsValue: {
      type: Function,
    },
    mainRowKey: { type: null },
    activeID: {
      type: null,
    },
  },
  data() {
    return {
      confirmLoading: false,
      dataSource: [],
      mx_remoteUrl: {
        method: 'post',
        url: childrenTableInfoUrl,
      },
      mx_remoteParams: {},
      mx_columns: setMainColumns(this, this.tableExtendedField),
    }
  },
  mounted() {},
  watch: {

    mainRowKey(value) {

      if (value && this.isShow) {
        this.reload()
      } else {
        this.dataSource = []
      }
    },

    tableExtendedField(value) {
      if (value.length > 0) {
        this.mx_columns = setMainColumns(this, value)
      }
    },
  },
  methods: {
    remoteBefore(vnode, res) {
      delete res.data
      res.params = { id: this.mainRowKey }
    },
    reload(args) {
      this.dataSource = []
      this.mainRowKey&& this.$refs.childrenTable.reload({ id: this.mainRowKey })
    },
  },
}
</script>
