<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>账单下载中，请稍后...</div>
    </Spin>
    <div v-else v-html="message"></div>
    <businessButton :btn-config="btnConfig" />
  </div>
</template>

<script lang="js">
  import businessButton from 'professionalComponents/businessButton';

  export default {
    name: 'BillReDownLoad',
    components: {
      businessButton
    },
    props: {
      idArray: { // 获取ID用于多选
        type: Array,
        default: () => []
      },
      itemId: {// 获取当前子表表名
        type: String,
        default: () => ''
      },
      selectRowData: { // 获取选择行的数据
        type: Array,
        default: () => []
      }
    },
    async created() {
      try {
        try {
          const request = this.$props.selectRowData[0].REQUESTPARAMETERS.val;
          let data = { authInfo: '', billDate: this.$props.selectRowData[0].BILLDATE.val };
          if (request) {
            data = JSON.parse(request);
          }
          const parm = {
            billDate: this.$props.selectRowData[0].BILLDATE.val,
            oldBatchNo: this.$props.selectRowData[0].BATCHNUMBER.val,
            // authInfo: data.authInfo,
            isReload: true,
            // shopId: this.$props.selectRowData[0].SHOPID.val,
            ID: this.$props.selectRowData[0].ID.val
            // oldBatchNo: this.$props.selectRowData[0].BATCHNUMBER.val
          };
          const rsp = await this.service.interfacePlatform.billReDownLoad(parm);
          if (rsp.Code == '0') {
            this.message = `账单下载中!</br>${rsp.Message}`;
          } else {
            this.message = `下载失败!</br>失败原因：${rsp.Message} </br>`;
          }
        } catch (e) {
          console.log(e);
          this.message = '下载失败!</br>失败原因：系统出现异常，请联系管理员</br>';
        }
      } 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();
              }, // 按钮点击事件
            }
          ]
        }
      };
    },
    methods: {
      closeDialog() {
        this.$emit('closeActionDialog', true);
      }
    }
  };
</script>
