/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <t-table
    :id="$route.meta.menuId + '_main'"
    :sign="true"
    :getCheckboxProps="
      (record) => ({
        props: {
          disabled: record.status == 15 ? true : false,
        },
      })
    "
    customScrollbar
    autoColWidth
    rowSelectFixed
    :activeKey="activeID"
    rowKey="shipbillId"
    :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"
    :attachFooter="[
      { key: 'totalPcs' },
      { key: 'totalVolume' },
      { key: 'totalWeight' },
    ]"
  >
    <a-space slot="operation" slot-scope="text, record" :size="15">
      <a href="javascript:;" @click.stop="show_info_item(record)" v-action:view >查看</a>
      <a href="javascript:;" @click.stop="copy_item(record)" v-action:copy :disabled="record.status === 15">复制</a>
      <a href="javascript:;" @click.stop="update_item(record)"  v-action:edit :disabled="record.status === 15">修改</a>
      <a href="javascript:;" @click.stop="submit_item(record)" v-action:submit :disabled="record.status === 15">提交</a>
      <a href="javascript:;" @click.stop="delete_item(record)"  v-action:cancellation :disabled="record.status === 15">作废</a>
      <a href="javascript:;" @click.stop="print_item(record)" v-action:print :disabled="record.status === 15">打印</a>
    </a-space>
  </t-table>
</template>
<script>
import { setMainColumns } from './tableConfig'
import { mainTableInfoUrl } from '../../api'

export default {
  props: {
    doneBefore: { type: Function },
    options: {
      type: Object,
      default: () => {},
    },
    selectedRowKeys: {
      type: Array,
      default: () => [],
    },
    tableExtendedField: {
      type: Array,
    },
    getFieldsValue: {
      type: Function,
    },

    activeID: {
      type: String,
    },
  },

  data() {
    return {
      confirmLoading: false,
      dataSource: [],
      mx_remoteUrl: {
        method: 'post',
        url: mainTableInfoUrl,
      },
      mx_remoteParams: {},
      mx_columns: setMainColumns(this, this.tableExtendedField),
    }
  },
  mounted() {},
  watch: {
    tableExtendedField(value) {
      if (value.length > 0) {
        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)
    },

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

        remoteUrl.data = { ...{ consigneeLocation: 1, shipperLocation: 1 }, ...remoteUrl.data, ...getFieldsValue() }
      }
    },
  },
}
</script>
