<template>
  <div class="table-operator">
    <a-button type="primary" icon="plus" @click="handleAdd" v-if="buttonSwitch.add">新增</a-button>
    <a-button type="primary" icon="upload" @click="handleImportXls" v-if="buttonSwitch.import">导入</a-button>
    <a-button type="primary" icon="download" @click="handleExportXls" v-if="buttonSwitch.export">导出</a-button>
    <template v-if="buttonList">
      <a-button type="primary"
                v-for="(btn, index) in buttonList"
                :key="'cg-btn' + index"
                :icon="btn.buttonIcon"
                @click="() =>{handleClickCgButton(btn)}">{{btn.buttonName}}</a-button>
    </template>

    <a-button type="primary" ghost icon="delete" @click="handleDelBatch" v-show="table.selectedRowKeys.length > 0">批量删除</a-button>
  </div>
</template>

<script>
export default {
  name: 'CgformAutoListButtons',
  inject : ["handleAdd", "handleImportXls", "handleExportXls", "cgButtonJsHandler", "cgButtonActionHandler", "handleSuperQuery", "handleDelBatch"],
  components : {},
  props : {
    url : {
      type : Object,
      required : true
    },
    table : Object,
    buttonList : Array,
    buttonSwitch : Object,
    superQuery : Object
  },
  watch : {},
  data : function() {
    return {};
  },
  methods : {
    handleClickCgButton : function(button) {
      if ("action" === button.optType) {
        this.cgButtonActionHandler(button.buttonCode);
      } else {
        if ("js" === button.optType) {
          this.cgButtonJsHandler(button.buttonCode);
        }
      }
    }
  }

}
</script>

<style scoped>

</style>