import { UniversalDataService } from '/js/ApiDataServer/Universal.js';
import { OrderDataService } from '/js/ApiDataServer/Order.js';
import { StoreDataService } from '/js/ApiDataServer/Store.js';
import { RESPONSE_STATUS } from '/js/constants.js';
import { Decorator } from '/js/util/dacorator.js';

var vMain = new Vue({
    el: "#content",
    data: function () {
        return {
            ltStores: [],
            orderMainId: -1,
            list: [],
            packingTitle: ""
        };
    },
    created: async function () {
        this.orderMainId = uj.getParameterByName("oid");
        this.ltStores = await StoreDataService.GetMarketStoreList(-1);
        this.loadData();
        this.packingTitle = await UniversalDataService.GetPackingTitle();
    },
    methods: {
        async loadData() {
            var v = this;
            var res = await OrderDataService.GetPrint(v.orderMainId);
            if (res.status == RESPONSE_STATUS.OK) {
                v.list = res.data;
                v.list.forEach(function (packingObj) {
                    packingObj.scheduleDate = Decorator.ChangeISODateTimeToDate(packingObj.scheduleDate);
                    if (packingObj.shippingDate != null) {
                        packingObj.shippingDate = Decorator.ChangeISODateTimeToDate(packingObj.shippingDate);
                    }

                    var c = 0;
                    if (packingObj.orderObj != null) {
                        c += packingObj.orderObj.details.list.length;
                        packingObj.orderObj.details.list.forEach(function (item) {
                            item.startDate = Decorator.ChangeISODateTimeToDate(item.startDate);
                            item.endDate = Decorator.ChangeISODateTimeToDate(item.endDate);
                        });
                    }

                    if (c > 2) {
                        packingObj.pageCss = "a4";
                    } else {
                        packingObj.pageCss = "a5";
                    }
                });

            } else {
                var data = res.data;
                alert(data.message);
            }
        }
    }
});