<!--
 * @Author: renxin renxin0828@163.com
 * @Date: 2023-05-23 12:40:27
 * @LastEditors: renxin renxin0828@163.com
 * @LastEditTime: 2023-05-30 19:06:48
 * @FilePath: \yx-admin\src\views\dataSupport\components\button.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!-- 新增 -->
  <a-button
    :disabled="disabled"
    v-if="buttonSet.type == button.add.value"
    type="primary"
    @click="buttonSet.click"
    >{{ buttonSet.label }}</a-button
  >
  <!-- 编辑 -->
  <a-button
    :disabled="disabled"
    v-else-if="buttonSet.type == button.edit.value"
    type="primary"
    @click="buttonSet.click"
    >{{ buttonSet.label }}</a-button
  >
  <!-- 删除 -->
  <Popconfirm
    v-else-if="buttonSet.type == button.delete.value"
    title="您确定要批量删除数据"
    ok-text="确定"
    cancel-text="取消"
    @confirm="buttonSet.click"
  >
    <a-button :disabled="disabled" color="error" type="primary">{{ buttonSet.label }}</a-button>
  </Popconfirm>
  <!-- 审核 -->
  <a-button
    :disabled="disabled"
    v-else-if="buttonSet.type == button.audit.value"
    type="primary"
    @click="buttonSet.click"
    >{{ buttonSet.label }}</a-button
  >
  <!-- 下载 -->
  <a-button
    :disabled="disabled"
    v-else-if="buttonSet.type == button.download.value"
    type="primary"
    @click="buttonSet.click"
    >{{ buttonSet.label }}</a-button
  >
  <!-- 下载 -->
  <a-button
    :disabled="disabled"
    v-else-if="buttonSet.type == button.import.value"
    type="primary"
    @click="buttonSet.click"
    >{{ buttonSet.label }}</a-button
  >
</template>

<script>
  import { Popconfirm } from 'ant-design-vue';
  import cssClass from '/@/views/dataSupport/config/cssClass.ts';
  export default {
    components: { Popconfirm },
    props: {
      buttonInfo: {
        type: null,
        label: '',
        click: () => {},
      },
      disabled: false,
    },
    setup(props) {
      const button = cssClass.bottonType;
      const buttonSet = Object.assign({}, props.buttonInfo);
      if (!buttonSet.label) {
        switch (buttonSet.type) {
          case button.add.value:
            buttonSet.label = button.add.label;
            break;
          case button.edit.value:
            buttonSet.label = button.edit.label;
            break;
          case button.delete.value:
            buttonSet.label = button.delete.label;
            break;
          case button.audit.value:
            buttonSet.label = button.audit.label;
            break;
          case button.download.value:
            buttonSet.label = button.audit.label;
            break;
          case button.import.value:
            buttonSet.label = button.audit.label;
            break;
        }
      }
      return {
        button,
        buttonSet,
      };
    },
  };
</script>

<style></style>
