/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <t-table
    :activeKey="activeID"
    :id="$route.meta.menuId + '_childrenTable_0'"
    :selectedRowKeys="selectedRowKeys"
    :scroll="{ x: true }"
    :dataSource="dataSource"
    ref="childrenTable"
    :vScrollX="{enabled:false}"
     :vScrollY="{enabled:true,rows:4}"
     autoColWidth
     rowKey="id"
    bordered
    :autoLoad="false"
    :columns="mx_columns"
    :remoteUrl="mx_remoteUrl"
    :remoteBefore="remoteBefore"
    dragle
    :rowSelectType="0"
  >
  </t-table>
</template>
<script>
import shipbillTableConfig from './shipbillTableConfig'
import { childrenShipBillTableUrl } 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() {
   const mx_remoteUrl={
        method: 'post',
        url: childrenShipBillTableUrl
      }
    return {
      confirmLoading: false,
      dataSource: [],
      mx_remoteUrl,
      mx_remoteParams: {},
      mx_columns: shipbillTableConfig(this,'收入', this.tableExtendedField).filter(item=>item.dataIndex),
    }
  },
  mounted() {
    this.mainRowKey&& this.$refs.childrenTable.reload({ id: this.mainRowKey })

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

    tableExtendedField(value) {
      if (value.length > 0) {
        this.mx_columns = shipbillTableConfig(this, '收入', value).filter(item=>item.dataIndex)
      }
    },
  },
  methods: {
    remoteBefore(vnode, res) {
      // delete res.data
      res.data = { ...res.data, id: this.mainRowKey }
    },
    reload(args) {
      this.dataSource = []

      this.mainRowKey&& this.$refs.childrenTable.reload({ id: this.mainRowKey })
    },
  },
}
</script>
