/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <t-table
    :id="$route.meta.menuId + '-goods-table'"
    :sign="true"
    rowSelectFixed
    :customScrollbar="true"
    :autoColWidth="autoColWidth"
    :activeKey="activeID"
    :rowKey="rowKey"
    :selectedRowKeys="selectedRowKeys"
    :scroll="{ x: true }"
    :vScrollX="{enabled:false}"
    :vScrollY="{enabled:true,rows:4}"
    ref="mainTable"
    bordered
    :columns="mx_columns"
    :dataSource="dataSource"
    :doneBefore="t_doneBefore"
    :remoteUrl="mx_remoteUrl"
    :remoteBefore="s_remoteBefore"
    dragle
    :autoLoad="false"
    :rowSelectType="rowSelectType"
    v-on="$listeners"
  >
  <template slot="operation" slot-scope="text, record">
        <slot name="operation" :text="text" :record="record"> </slot>
      </template>
  </t-table>
</template>
<script>
import { setMainColumns } from './tableConfig'

export default {
  name: 'goodsTable',
  props: {
    url: {
      type: String,
    },
    doneBefore: { type: Function },
    rowSelectType: { type: null,default: false },
    options: {
      type: Object,
      default: () => {},
    },
    selectedRowKeys: {
      type: Array,
      default: () => [],
    },
    tableExtendedField: {
      type: Array,
    },
    getFieldsValue: {
      type: Function,
    },
    autoColWidth: {
      type: null,
      default: true
    },
    remoteBefore: {
      type: Function,
    },
    rowKey: {
      type: null,
      default: '_row_count', //1运单模式,2收货方模式
    },
    tableColumnsList: {
       type: Array,
    },

    activeID: {
      type: null,
    },
  },

  data() {
    let mx_remoteUrl = {
      method: 'post',
      url: this.url,
    }

    return {
      confirmLoading: false,
      dataSource: [],
      mx_remoteUrl,
      mx_remoteParams: {},
      mx_columns: this.tableColumnsList?this.tableColumnsList:setMainColumns(this,this.tableExtendedField),
    }
  },
  mounted() {

  },
  watch: {
    tableColumnsList(value) {
      this.mx_columns=value
    },
    tableExtendedField(value) {
      if (value.length > 0&&!this.tableColumnsList) {
        this.mx_columns = setMainColumns(this, value)
      }
    },
    // 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('submitItem', [record.shipbillId])
    },
    show_info_item(record) {
      this.$emit('view', record)
    },
    delete_item(record) {
      this.$emit('delete', [record.shipbillId])
    },
    update_item(record) {
      this.$emit('update', record)
    },
    t_doneBefore(res) {
      // if (!res || !res.success) {
      //   _this.$exception(res)
      // }
      this.doneBefore && this.doneBefore(res)
    },
    reload(args) {
      return this.$refs.mainTable.reload(args)
    },


    s_remoteBefore(vNode, remoteUrl) {
      let searchBar = this.$parent.$parent.$parent.$refs.searchBar

      if (searchBar) {
        const { getFieldsValue } = searchBar
        remoteUrl.data = { ...this.mx_remoteUrl.data,...remoteUrl.data, ...getFieldsValue() }
      } else {
        remoteUrl.data = { ...this.mx_remoteUrl.data,...remoteUrl.data }
      }
      this.mx_remoteUrl=remoteUrl
      this.remoteBefore && this.remoteBefore(vNode, remoteUrl)
    },
  },
}
</script>
