<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">

var successMessage = 'سبد خرید بروز شد.';
(function () {
    Vue.use(VeeValidate);
    var invoiceVueApp = new Vue({
        el: ".invoice-container",
        data:
        {
            steps: [
                { step: 0, name: "سبد خرید", nextBtnName: "ادامه" }
                , { step: 1, name: "آدرس ها", nextBtnName: "ادامه" }
                , { step: 2, name: "پرداخت", nextBtnName: "پرداخت" }
            ],
            selectedStep: { step: 0, name: "سبد خرید", nextBtnName: "ادامه", disabled: false },
            selectedAddressStep: 1,
            invoice: {},
            activeInvoice: {},
            visiblePopoverCartItem: null,
            location: {
                shippingAddresses: []
            },
            selectedShippingAddress: {
                additionalDetails: null,
                address: null,
                cityId: 0,
                email: null,
                id: 0,
                mobile: null,
                postalCode: null,
                provinceId: 0,
                telephone: null,
                title: "آدرس محل تحویل کالا را وارد کنید",
                transferee: null

            },
            shippingAddress: { provinceId: "0" },
            currentStep: 1,
            receiptImage: null,
            receiptUploaded: false,

            needAuthentication: false,
            needAcceptTermsAndConditions: false,
            area: null,
            customArea: "",
            areaList: [],
            regionList: [],
            region: null,
            coupon: "",
            couponError: "",
        },
        components: {
            Multiselect: window.VueMultiselect.default,
        },
        methods: {
            getActiveInvoice() {
                loadingApp.show(true)
                this.$http.get("/api/userpanel/getOrders?isPaid=false&amp;page=1")
                    .then((response) =&gt; {
                        var result = response.data;
                        this.activeInvoice = result.items;
                        loadingApp.show(false)
                    }).catch(() =&gt; {
                        toastApp.failed("خطا."); loadingApp.show(false);
                    });
            },
            setSelectedCart: function (cartId) {
                this.invoice.selectedCartId = cartId;
                CartService.setSelectedCart(cartId);
            },
            setMainCart: function (cartId) {
                CartService.setMainCart(cartId).then(function (result) {
                    updateInvoice(result);
                });
            },
            toggleInvoice: function (show) {
                var $target = $(".invoice-content");
                if (!show) {
                    $target.css("height", function () {
                        return this.scrollHeight;
                    }).addClass("auto-height");
                } else {
                    $target.css("height", "").removeClass("auto-height");
                }
            },
            changeQuantity: function (cartId, cartItem, event, sign) {
                //console.log(cartItem, event);v
                var quantity = cartItem.quantity;
                switch (this.invoice.stuffCountType) {
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        quantity = sign + "1";
                        break;
                }
                loadingApp.show(true);
                if (cartItem.packageId)
                    CartService.changeCartPackages(cartId, cartItem.packageId, quantity).then(function (result) {
                        toastApp.success(successMessage);
                        updateInvoice(result);
                        loadingApp.show(false);
                    });
                else
                    CartService.changeCart(cartId, cartItem.stuffId, cartItem.skuCode, cartItem.hasAssembly, cartItem.warrantyId, quantity).then(function (result) {
                        toastApp.success(successMessage);
                        updateInvoice(result);
                        loadingApp.show(false);
                    });
            },
            removeFromCart: function (cartId, stuffId, cartItem, event) {
                console.log(cartItem, event);
                loadingApp.show(true);
                if (cartItem.packageId)
                    CartService.changeCartPackages(cartId, cartItem.packageId, 0).then(function (result) {
                        updateInvoice(result);
                        toastApp.success(successMessage);
                        loadingApp.show(false);

                    }).catch((result) =&gt; {
                        toastApp.failed(result.responseText);
                        loadingApp.show(false);
                    });
                else
                    CartService.changeCart(cartId, stuffId, cartItem.skuCode, cartItem.hasAssembly, cartItem.warrantyId, 0).then(function (result) {
                        updateInvoice(result);
                        toastApp.success(successMessage);
                        loadingApp.show(false);
                    }).catch((result) =&gt; {
                        toastApp.failed(result.responseText);
                        loadingApp.show(false);
                    });
            },
            changeSplitItemsByShippingTime: function (cartId, shouldSplit) {
                CartService.changeSplitItemsByShippingTime(cartId, shouldSplit).then(function (result) {
                    updateInvoice(result);
                    toastApp.success(successMessage);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                });
            },
            getAlternatives: function (cartItem, e) {
                if (this.visiblePopoverCartItem === cartItem) {
                    cartItem.showAlternatives = false;
                    this.visiblePopoverCartItem = null;
                    return;
                }
                cartItem.showAlternatives = true;
                this.visiblePopoverCartItem = cartItem;
                CartService.getAlternatives(cartItem.skuCode).then(function (alternatives) {
                    cartItem.alternatives = alternatives;
                    setTimeout(function () {
                        var replaceButton = $(e.target);
                        var popover = replaceButton.next(".popover");
                        popover.show().nextTo(replaceButton, { position: "left", shareBorder: "center" });
                    }, 10);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                });
                e.stopPropagation();
            },
            replaceCartItem: function (cartId, cartItem, alternative) {
                if (cartItem.skuCode === alternative.skuCode)
                    return;
                CartService.replaceCartItem(cartId, cartItem.skuCode, cartItem.hasAssembly, cartItem.warrantyId, alternative.skuCode).then(function (result) {
                    updateInvoice(result);
                    toastApp.success(successMessage);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                });
            },
            createCompareCart: function (alternative) {
                if (alternative.isReference)
                    return;
                CartService.createCompareCart(alternative.id).then(function (result) {
                    updateInvoice(result);
                    $("#invoice-modal").animate({
                        scrollTop: 0
                    }, 200);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                });
            },
            getShipingTypeTree: function (id) {
                var that = this;
                this.customArea = ""
                CartService.getShipingTypeTree(id).then(function (result) {
                    if (id)
                        that.regionList = result.addressTrees;
                    else
                        that.areaList = result.addressTrees;
                    updateInvoice(result.model);
                    loadingApp.show(false);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                    loadingApp.show(false);
                });
            },
            changeArea: function () {
                var that = this;
                this.region = null;
                //if (this.area.hasSubAddress) {
                this.getShipingTypeTree(this.area.id)
                //}
            },
            changeRegion: function () {
                if (this.area.hasSubAddress) {
                    CartService.setShipingTypeTreeRegion(this.region.id).then(function (result) {
                        updateInvoice(result);
                        loadingApp.show(false);
                    }).catch((result) =&gt; {
                        toastApp.failed(result.responseText);
                        loadingApp.show(false);
                    });
                }
            },
            getShippingAddresses: function () {
                var that = this;
                if (invoiceVueApp.selectedShippingAddress.id != 0)
                    return;
                loadingApp.show(true);
                CartService.getShippingAddresses(!this.location.provinces).then(function (result) {
                    if (that.needAuthentication || that.invoice.isAuthenticated) {
                        that.location.shippingAddresses = result.shippingAddresses;
                    } else {
                        if (localStorage.length &gt; 0)
                            that.location.shippingAddresses = JSON.parse(localStorage.getItem("invoiceShippingAddresses"));
                    }
                    if (that.location.shippingAddresses.length &gt; 0) {
                        that.selectedShippingAddress = that.location.shippingAddresses[0];//Todo
                        var provinceId = that.selectedShippingAddress.provinceId;
                    }
                    if (result.provinces) {
                        that.location.provinces = result.provinces;
                        if (provinceId)
                            that.location.selectedProvince = _.findWhere(result.provinces, { id: provinceId });
                    }
                    loadingApp.show(false);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                    loadingApp.show(false);
                });
            },
            changeAddress: function (address) {
                this.selectedShippingAddress = address;
                this.$validator.reset();
            },
            provinceSelected: function (e) {
                var provinceId = e.target.value;
                this.location.selectedProvince = _.findWhere(this.location.provinces, { id: parseInt(provinceId) });
            },
            checkout: function () {
                var that = this;
                loadingApp.show(true);
                this.$validator.validateAll().then(function (isValid) {
                    if (isValid) {
                        var detail = that.area != null ? that.area.title : "";
                        detail += (that.region != null ? " - " + that.region.title : "");
                        detail += that.customArea;
                        that.selectedShippingAddress.additionalDetails = detail;
                        CartService.checkout(that.selectedShippingAddress).then(function (result) {
                            if (result.refId != 0)
                                CartService.startPayment(result.refId)
                            updateInvoice(result.data);
                            loadingApp.show(false);
                        }).catch((result) =&gt; {
                            toastApp.failed(result.responseText);
                            loadingApp.show(false);
                        });
                    }
                });
            },
            changePaymentMethod: function (paymentMethod) {
                var that = this;
                loadingApp.show(true);
                CartService.changePaymentMethod(paymentMethod).then(function (result) {
                    updateInvoice(result.carts);
                    that.changeBtnTitle(result.paymentMethod)
                    loadingApp.show(false);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                    loadingApp.show(false);
                });
            },

            getPrintLink: function (cartId) {
                return "/cart/print/" + cartId + "/";
            },
            openModal: function (target) {
                $(".invoice.modal").one("hidden.bs.modal", function () {
                    if (target) {
                        var parts = target.split(",");
                        var $targetModal = $(parts[0]);
                        $targetModal.modal("show");
                        $targetModal.find(".header .nav " + parts[1]).click();
                    }
                }).modal("hide");


            },
            continueShopping: function () {
                var that = this;
                CartService.continueShopping().then(function () {
                    that.receiptUploaded = false;
                    $(".invoice.modal").modal("hide");
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                });
            },
            changeShippingType() {
                loadingApp.show(true);
                var that = this;
                CartService.changeShippingType(this.invoice.shippingType).then(function (result) {
                    toastApp.success(successMessage);
                    updateInvoice(result);
                    that.getShipingTypeTree(null)
                    loadingApp.show(false);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                    loadingApp.show(false);
                });
            },
            changeStep(step) {
                if (this.validateSteps(step)) {

                    this.selectedStep = this.steps[step];
                    if (step == 1) {
                        if (this.needAuthentication) {
                            if (this.invoice.isAuthenticated) {
                                this.getShipingTypeTree(null);
                                this.getShippingAddresses();
                            }
                            else {
                                this.selectedStep = this.steps[step - 1];
                                toastApp.failed("ابتدا لاگین نمایید");
                                if (location.pathname !== '/account/login/')
                                    setTimeout(() =&gt; { window.location.replace("/account/login/?returnUrl=" + location.pathname.substring(1, location.pathname.length) + "#open-cart"); }, 1000)

                            }
                        } else {
                            this.getShippingAddresses();
                            this.getShipingTypeTree(null);
                        }
                    }
                    if (step == 2) {
                        this.changeBtnTitle(this.invoice.paymentMethod)
                        if (this.invoice.minInvoicePriceForSending - this.invoice.payable &gt; 0) {
                            var text = $(".min-invoice-price-for-sending-text").text().replaceAll('\n', '').replace(/\s\s+/g, ' ');
                            alert(text);
                            this.selectedStep = this.steps[step - 1];
                            return;
                        }else if (this.areaList.length &gt; 0 &amp;&amp; this.area == null) {
                            var text = $(".area-title").text().replace('انتخاب', '').trim();
                            var _text = text + " را انتخاب نمایید.";
                            alert(_text);
                            this.selectedStep = this.steps[step - 1];
                            return;
                        } else if (this.area &amp;&amp; this.area.hasSubAddress &amp;&amp; this.region == null) {
                            var text = $(".area-title").text().replace('انتخاب', '').trim();
                            var _text = text + " را انتخاب نمایید.";
                            alert(_text);
                            this.selectedStep = this.steps[step - 1];
                            return;
                        } else if (!validator.validForm(".area-section")) {
                            var text = $(".area-title").text().replace('انتخاب', '').trim();
                            var _text = text + " را انتخاب نمایید.";
                            alert(_text);
                            this.selectedStep = this.steps[step - 1];
                            return;
                        } 
                    }
                    if (step == 3) {
                        if (this.needAcceptTermsAndConditions &amp;&amp; !this.invoice.termsAndConditions) {
                            alert("قوانین را تایید نمایید");
                            return;
                        }
                        this.checkout();
                        this.selectedStep = this.steps[step - 1];
                    }
                }
            },
            validateSteps(step) {
                step -= 1;
                if (step &lt; 0) step = 0;
                switch (step) {
                    case 0:
                        return true;
                    case 1:
                        return this.selectedShippingAddress.id != 0;
                    case 2:
                        return true;
                    default:
                }

            },
            changeBtnTitle(paymentMethod) {

                this.selectedStep.disabled = this.invoice.paymentMethod == 1 &amp;&amp; this.invoice.paymentGateway == 0 &amp;&amp; this.selectedStep.step == 2
                //this.selectedStep.disabled = this.invoice.paymentGateway == 0;
                if (this.invoice.paymentMethod == 0) {
                    this.selectedStep.disabled = true;
                    this.selectedStep.nextBtnName = "روش پرداخت را انتخاب کنید.";
                }

                if (paymentMethod == 1)
                    this.selectedStep.nextBtnName = this.invoice.paymentGateway == 0 ? "درگاه پرداخت را انتخاب کنید" : "پرداخت آنلاین";
                else if (paymentMethod == 2)
                    this.selectedStep.nextBtnName = "ثبت موقت سفارش";
                else if (paymentMethod == 4 || paymentMethod == 5)
                    this.selectedStep.nextBtnName = "ثبت سفارش";

                if (this.invoice.payable == 0) {
                    this.selectedStep.nextBtnName = "ثبت سفارش";
                    this.selectedStep.disabled = false;
                    if (this.invoice.paymentMethod != 50) {//50 is gift
                        this.changePaymentMethod(50)
                    }
                } else if (this.invoice.paymentMethod == 50) {
                    this.changePaymentMethod(0)
                }

                if (this.needAcceptTermsAndConditions &amp;&amp; this.selectedStep.step == 2) {
                    if (!this.invoice.termsAndConditions) {
                        this.selectedStep.nextBtnName = "قوانین را تایید نمایید";
                        this.selectedStep.disabled = !this.invoice.termsAndConditions;

                    }
                }

            },
            toggleSecoundModal(toggleValue, step) {
                this.selectedAddressStep = step;
                $("#invoice-modal").css("z-index", 100);
                $("#secondInvoceiModal").modal(toggleValue);
            },
            addNewAddress() {
                this.selectedAddressStep = 2;
                this.shippingAddress = {
                    provinceId: "0",
                    id: 0,
                }
            },
            saveShippingAddress() {
                var result = validator.validForm(".address-form")
                if (!result)
                    toastApp.failed("اطلاعات خواسته شده را کامل نمایید");
                else {
                    if (this.invoice.isAuthenticated) {

                        var that = this;
                        loadingApp.show(true);
                        CartService.saveShippingAddress(this.shippingAddress).then(function (result) {
                            that.location.shippingAddresses = result.shippingAddresses;
                            that.selectedAddressStep = 1;
                            loadingApp.show(false);
                        }).catch((result) =&gt; {
                            toastApp.failed(result.responseText);
                            loadingApp.show(false);
                        });
                    } else {
                        this.shippingAddress.id = Math.floor(Math.random() * 1000);
                        this.location.shippingAddresses.push(this.shippingAddress);
                        localStorage.setItem("invoiceShippingAddresses", JSON.stringify(this.location.shippingAddresses));
                        this.selectedAddressStep = 1;
                    }
                }
            },
            changePaymentGateway(ipgId) {
                this.invoice.paymentGateway = ipgId;
                CartService.changePaymentGateway(ipgId);
                this.changeBtnTitle(1);
            },
            submitCoupon() {

                if (this.coupon.trim() != '') {
                    loadingApp.show(true);
                    var that = this;
                    that.couponError = "";
                    CartService.addCoupon(this.coupon.trim()).then(function (result) {
                        updateInvoice(result);
                        that.changeBtnTitle(that.invoice.paymentMethod)
                        loadingApp.show(false);
                        that.coupon = "";
                    }).catch((result) =&gt; {
                        toastApp.failed(result.responseText);
                        that.couponError = result.responseText;

                        loadingApp.show(false);
                    });
                } else {
                    alert("کد تخفیف نمی‌تواند خالی باشد!.")
                }
            },
            removeCoupon(code) {
                loadingApp.show(true);
                var that = this;
                that.couponError = "";
                CartService.removeCoupon(code).then(function (result) {
                    updateInvoice(result);
                    that.changeBtnTitle(that.invoice.paymentMethod)
                    loadingApp.show(false);
                }).catch((result) =&gt; {
                    toastApp.failed(result.responseText);
                    loadingApp.show(false);
                });
            }
        }
        ,
    });



    $(window).on("load", function () {
        if (location.hash.indexOf("open-cart") &gt; -1 &amp;&amp; !$("body").is(".login"))
            $("#invoice-modal").modal("show")
    });

    $('#secondInvoceiModal').on('hidden.bs.modal', function () {
        $("#invoice-modal").css("z-index", "")
    });

    function updateInvoice(data) {
        invoiceVueApp.invoice = data;
        $(".basket-icon").animateCss("swing");
        window.Cart.updateBasketQuantityCount(data.quantityCount)
        if (data.invoiceId) {
            invoiceVueApp.$upload.reset('payment-receipt', {
                url: '/cart/uploadPaymentReceipt/?invoiceId=' + data.invoiceId
            });
        }

    }
    function change() {
        return Cart.changeCart.apply(null, arguments).then(function (result) {
            if (result.errorMessage)
                toastApp.failed(result.errorMessage);
            else {
                window.Cart.updateBasketQuantityCount(result.quantityCount)
                toastApp.success('سبد خرید بروز شد.');
                updateInvoice(result);
            }
        });
    }
    function add() {
        return Cart.addItemsToCart.apply(null, arguments).then(function (result) {
            if (result.errorMessage)
                toastApp.failed(result.errorMessage);
            else {
                toastApp.success('سبد خرید بروز شد.');
                updateInvoice(result);
            }
        });
    }
    function changePackage() {
        return Cart.changeCartPackages.apply(null, arguments).then(function (result) {
            if (result.errorMessage)
                toastApp.failed(result.errorMessage);
            else {
                toastApp.success('سبد خرید بروز شد.');
                updateInvoice(result);
            }
        });
    }
    $(".invoice.modal").on("show.bs.modal", function () {
        invoiceVueApp.changeStep(0);
        CartService.getCarts().then(function (result) {
            updateInvoice(result);
            invoiceVueApp.getActiveInvoice()
        });
    });
    $("#loginModal").on("hide.bs.modal", function () {
        $(this).find(".modal-content").removeClass("show-invoice-alert");
    });


    $(document).on("click", ".popover", function (e) {
        e.stopPropagation();
    });
    $(document).on("click", function () {
        closePopovers();
    });
    function closePopovers() {
        if (invoiceVueApp.visiblePopoverCartItem) {
            invoiceVueApp.visiblePopoverCartItem.showAlternatives = false;
            invoiceVueApp.visiblePopoverCartItem = null;
        }
    }
    window.Invoice = {
        updateInvoice: updateInvoice,
        change: change,
        add: add,
        changePackage: changePackage
    }
})();</pre></body></html>