<template>
  <div v-if="redDocument != undefined" class="container-fluid">
    <stockOutLineInstanceBlue v-if="!redDocument" :stock-out-id="stockOutId" />
    <stockOutLineInstanceRed v-if="redDocument" :stock-out-id="stockOutId" />
  </div>
</template>

<script>
import stockOutLineInstanceBlue from './StockOutLineInstanceBlue.vue';
import stockOutLineInstanceRed from './StockOutLineInstanceRed.vue';
import Common from '../common/Common.js';
import { UserStorageResource } from 'pc-component-v3';


export default {
  components: {
    stockOutLineInstanceBlue,
    stockOutLineInstanceRed,
  },
  data: function () {
    return {
      redDocument: undefined,
      stockOutId: undefined,
    };
  },

  mounted: function () {
    var uuid = this.$route.params.uuid;
    UserStorageResource.uniqueByKey(uuid + '_modelData').then(
      str => {
        // if(str.errorCode != 0) {
        //   Notify.error('提示', str.errorMessage, false);
        //   return;
        // }
        if (str.data != null) {
          console.log(str.data);
          var modelData = JSON.parse(str.data);
          this.stockOutId = modelData.id;
          this.getDocumentType();
        }
      },
      errorData => {
        Common.processException(errorData);
      },
    );
  },
  methods: {
    getDocumentType: function () {
      var _self = this;
      $.ajax({
        type: 'get',
        url: Common.getApiURL(
          'StockOutResource/uniqueIsRedDocByStockOutId?stockOutId=' +
            _self.stockOutId,
        ),
        beforeSend: function (request) {
          Common.addTokenToRequest(request);
        },
        success: function (data) {
          _self.redDocument = data;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          Common.processException(XMLHttpRequest, textStatus, errorThrown);
        },
      });
    },
  },
};
</script>