<template>
  <div v-if="redDocument != undefined" class="container-fluid">
    <stockInLineInstanceBlue v-if="!redDocument" :stock-in-id="stockInId" />
    <stockInLineInstanceRed v-if="redDocument" :stock-in-id="stockInId" />
  </div>
</template>

<script>
import stockInLineInstanceBlue from './StockInLineInstanceBlue.vue';
import stockInLineInstanceRed from './StockInLineInstanceRed.vue';
import Common from '../common/Common.js';
import { UserStorageResource } from 'pc-component-v3';


export default {
  components: {
    stockInLineInstanceBlue,
    stockInLineInstanceRed,
  },
  data: function () {
    return {
      redDocument: undefined,
      stockInId: 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.stockInId = modelData.id;
          this.getDocumentType();
        }
      },
      errorData => {
        Common.processException(errorData);
      },
    );
  },
  methods: {
    getDocumentType: function () {
      var _self = this;
      $.ajax({
        type: 'get',
        url: Common.getApiURL(
          'stockInResource/uniqueIsRedByStockInId?stockInId=' + _self.stockInId,
        ),
        beforeSend: function (request) {
          Common.addTokenToRequest(request);
        },
        success: function (data) {
          _self.redDocument = data;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          Common.processException(XMLHttpRequest, textStatus, errorThrown);
        },
      });
    },
  },
};
</script>