/*
 *@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,
        },
      })
    "
    rowSelectFixed
    :activeKey="activeID"
    rowKey="id"
    :scroll="{ x: true}"
    ref="mainTable"
    bordered
    :vScrollX="{enabled:false}"
     :vScrollY="{enabled:true,rows:10}"
     autoColWidth
    :columns="mx_columns"
    :doneBefore="doneBefore"
    :remoteUrl="mx_remoteUrl"
    :remoteBefore="remoteBefore"
    dragle
    :rowSelectType="2"
    v-on="$listeners"
  >
    <a-space slot="operation" :size="15" slot-scope="text, record">
      <a href="javascript:;" @click.stop="show_info_item(record)">查看</a>
      <a href="javascript:;" @click.stop="update_item(record)">费用录入</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: () => {},
    },
    operation: {
      type: null,

    },
    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('submit', [record.id])
    },
    show_info_item(record) {
      this.$emit('view', record)
    },

    update_item(record) {
      this.$emit('update', [record])
    },
    adjustAccounts_item(record) {
      this.$emit('adjustAccounts', [record.id],record.id)
    },
    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 = { ...remoteUrl.data, ...getFieldsValue() };
        for (let key in remoteUrl.data) {
          let item = remoteUrl.data[key]

          if (item&&key.includes('_')) {
            let nameArr = key.split('_');
            remoteUrl.data[nameArr[0]] = item[0];
            remoteUrl.data[nameArr[1]] = item[1];
            delete remoteUrl.data[key];
          }
        }
      }
    },
  },
}
</script>
