/*
 *@description:
 *@author: hudw
 *@date: 2022-03-14 15:14:53
*/
<template>
  <p-table rowSelectFixed autoMaxHeight :dataSource.sync="dataSource" :activeKey="activeID" :id="$route.meta.menuId + '_main'"
    :selectedRowKeys="selectedRowKeys" :scroll="{ x: true }" ref="childrenTable" bordered :autoLoad="false"
    :columns="mx_columns" :remoteUrl="mx_remoteUrl" dragle :rowSelectType="2" v-on="$listeners">
    <template slot="operation" slot-scope="text,record">
      <a href="javascript:;" @click.stop="show_info_item(record)" v-action:child_view>查看</a>
      <a-divider type="vertical" />
      <a href="javascript:;" @click.stop="update_item(record)" :disabled="!record.status" v-action:child_edit>修改</a>
      <a-divider type="vertical" />
      <a href="javascript:;" @click.stop="() => { }">
        <p-switch @click="toggle_item(record)" :checked="!!record.status" size="small" v-action:child_status></p-switch>
      </a>
      <a-divider type="vertical" />
      <a href="javascript:;" @click.stop="delete_item(record)" v-action:child_del>删除</a>
    </template>
  </p-table>
</template>
<script>


import { setMainColumns } from './tableConfig';
import { childrenTableInfoUrl, deleteChildrenItem, paperIsEnable } from '../../api';

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
    },
    clearAll:false,
    mainId: { type: null },
    activeID: {
      type: null
    },
  },
  data() {
    return {
      confirmLoading: false,
      dataSource: [],
      mx_remoteUrl: {
        method: 'post',
        url: childrenTableInfoUrl
      },
      mx_remoteParams: {},
      mx_columns: setMainColumns(this),
    };
  },
  mounted() {

  },
  watch: {
    clearAll(v){
      if(v){
        this.dataSource=[]
      }

    },
    mainId(value) {
      if (value) {
        this.reload({ data: { providerId: value } })
      }
    },
    tableExtendedField(value) {
      if (value.length > 0) {
        value.forEach((element, index) => {
          this.mx_columns.splice(7 + index, 0, element);
        });
      }

    },

  },
  methods: {

    show_info_item(record) {
      this.$emit('view', record)
    },
    delete_item(record) {
      deleteChildrenItem(this, [record.id])
    },
    update_item(record) {
      this.$emit('update', record)
    },
    toggle_item(record) {
      let status = +(!record.status)
      return paperIsEnable(this, [{ shipperId: record.id }], status, this.mainId)
    },
    reload(args) {
      if (!args) {
        args = {
          data: { providerId: this.mainId }
        }
      }
      return this.$refs.childrenTable.reload(args)
    },


  }
};

</script>
