<template>
  <div>
    <Spin
      v-if="loading"
      fix
    >
      <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"
          />
        </svg>
      </div>
      <div>正在同步唯品会，请稍后...</div>
    </Spin>
    <div
      v-else
      v-html="message"
    />
    <businessButton :btn-config="btnConfig" />
  </div>
</template>

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

  export default {
    name: 'JitDelivery_SyncPoDelivery',
    components: {
      businessButton
    },
    props: {
      idArray: { // 获取ID用于多选
        type: Array,
        default: () => []
      }
    },
    async created() {
      try {
        let str = this.idArray.join();// 数组拼接成字符串
        // 当前只允许选择一条
        let data = await jitDelivery.syncPoDelivery(str);

        if (data.code != 0) {
          this.message = data.message;
        } else {
          for (let p in data.data) {
            // console.log(p, 111);
            // console.log(data.data[p], 222);
            let str = `<p>${p}  ${data.data[p]} </p>`;
            this.message += str;
          }
          this.processedSuccessfully = true;
        }
      } catch (e) {
        console.log(e);
        this.message = '系统出现异常，请联系管理员！';
      } finally {
        this.loading = false;
      }
    },
    data() {
      return {
        loading: true,
        message: '',
        processedSuccessfully: true, // 是否处理成功
        btnConfig: {
          typeAll: 'error', // 按钮统一风格样式
          btnsite: 'right', // 按钮位置 (right , center , left)
          buttons: [
            {
              type: '', // 按钮类型
              text: '确定', // 按钮文本
              icon: '', // 按钮图标
              size: '', // 按钮大小
              disabled: false, // 按钮禁用控制
              btnclick: () => {
                this.closeDialog();
              }, // 按钮点击事件
            }
          ]
        }
      };
    },
    methods: {
      /**
       * 关闭弹窗
       */
      closeDialog() {
        this.$emit('closeActionDialog', this.processedSuccessfully);
      }
    }
  };
</script>
