/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <t-table
    customScrollbar
    :activeKey="activeID"
    :id="$route.meta.menuId + '_childrenTable'"
    @selectChange="(selectedKeys)=>{selectedRowKeys=selectedKeys}"
    :scroll="{ x: true }"
    :vScrollY="{enabled:true,rows:4}"
    :dataSource="dataSource"
    ref="childrenTable"
    bordered
    :autoLoad="false"
    :columns="mx_columns"
    :remoteUrl="mx_remoteUrl"
    dragle
    :rowSelectType="0"
    :remoteBefore="remoteBefore"

  >
  </t-table>
</template>
<script>
import { setMainColumns } from './tableConfig'
import { childrenTableInfoUrl, deleteChildrenItem } from '../../api'
const SELECT_KEY = 'shipbillId'

export default {
  props: {
    options: {
      type: Object,
      default: () => {},
    },
    st: {
      /**0=不显示, 1=新建，2=修改 ，3=查看 */
      type: Number,
      default: 0,
    },
    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.reload({ data: { [SELECT_KEY]: value } })
      } else {
        this.dataSource=[]
      }
    },
    tableExtendedField(value) {
      if (value.length > 0) {
        this.mx_columns = setMainColumns(this, value)
      }
    },
  },
  methods: {
    remoteBefore(vNode, remoteUrl) {
      remoteUrl.data[SELECT_KEY]=this.mainRowKey
    },
    delete_item(record) {
      deleteChildrenItem(this, [record.id])
    },

    reload(args) {
      if (!args) {
        args = {
          data: { providerId: this.mainId },
        }
      }
      this.dataSource=[]
      return this.$refs.childrenTable.reload(args)
    },
  },

}
</script>
