<template>
  <div>
    <Spin fix v-if="loading">
      <div class="loader">
        <svg class="circular" viewBox="25 25 50 50">
          <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="5" stroke-miterlimit="10"></circle>
        </svg>
      </div>
      <div>正在从 WMS 撤回中，请稍后...</div>
    </Spin>
    <div v-else>{{ message }}</div>
    <businessButton :btn-config="btnConfig" />
  </div>
</template>

<script lang="js">
  import businessButton from 'professionalComponents/businessButton';
  import { refundOrder } from '@yunque/service/index';

  export default {
    name: 'RefundOrderWithdrawFromWMS',
    components: {
      businessButton
    },
    props: {
      idArray: { // 获取ID用于多选
        type: Array,
        default: () => []
      },
      itemId: {// 获取当前子表表名
        type: String,
        default: () => ''
      },
      selectRowData: { // 获取选择行的数据
        type: Array,
        default: () => []
      }
    },
    async created() {
      try {
        const rsp = await refundOrder.withdrawFromWMS(this.idArray.join(','));
        if (!rsp) {
          this.message = '请求数据异常或没有任何返回值';
        } else {        
           this.message = rsp.message;        
        }
      } catch (e) {
        this.message = `${e.name} 系统出现异常，${e.message}`;
      } finally {
        this.loading = false;
      }
    },
    data() {
      return {
        loading: true,
        message: '',
        btnConfig: {
          typeAll: 'error', // 按钮统一风格样式
          btnsite: 'right', // 按钮位置 (right , center , left)
          buttons: [
            {
              type: '', // 按钮类型
              text: '确定', // 按钮文本
              icon: '', // 按钮图标
              size: '', // 按钮大小
              disabled: false, // 按钮禁用控制
              btnclick: () => {
                this.closeDialog(true);
              }, // 按钮点击事件
            }
          ]
        }
      };
    },
    methods: {
      closeDialog(refreshGrid = false) {
        this.$emit('closeActionDialog', refreshGrid);
      }
    }
  };
</script>
