/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <t-table
    :id="$route.meta.menuId + '_main'"
    :extendedObjectCode="11"
    autoColWidth
    :scroll="{ x: true }"
    :vScrollX="{enabled:false}"
    :vScrollY="{enabled:true,rows:10}"
    ref="mainTable"
    rowKey="id"
    bordered
    :columns="mx_columns"
    :remoteUrl="mx_remoteUrl"
    :remoteBefore="remoteBefore"
    dragle
    rowSelectFixed
    :rowSelectType="2"
    v-on="$listeners"
  >
    <a-space slot="operation" slot-scope="text,record">
      <a href="javascript:;" @click.stop="show_info_item(record)">查看</a>
      <a href="javascript:;" @click.stop="update_item(record)" :disabled="!record.status">修改</a>
      <a href="javascript:;" @click.stop="() => { }">
        <p-switch @click="toggle_item(record)"  :replaceFields="{ true: 10, false: 0 }"  :checked="record.status" size="small"></p-switch>
      </a>
      <a href="javascript:;" @click.stop="delete_item(record)">删除</a>
    </a-space>
  </t-table>
</template>
<script>


import { setMainColumns } from '../js/tableConfig';
import { mainTableInfoUrl, mainIsEnable,deleteMainItem } from '../js/api';


export default {
  props: {
    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),
    };
  },
  mounted() {

  },
  watch: {
    tableExtendedField(value) {
      if (value.length > 0) {
         this.mx_columns=setMainColumns(this,value)


      }

    },
    activeID(v) {
      this.$refs.mainTable.activeID = v
    }
  },
  methods: {

    show_info_item(record) {
      this.$emit('view', record)
    },
    delete_item(record) {
      deleteMainItem(this, [{ id: record.id }]).then(()=>{
        this.$emit('deleteMainItem')
      })

    },
    update_item(record) {
      this.$emit('update', record)
    },
    toggle_item(record) {
      let status = +(!record.status)
      return mainIsEnable(this, [{ id: record.id }], status)
    },
    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() }

      }
    }

  }
};

</script>
