var isPC = ($(window).width() > 768);
var delivergoods = new Vue({
    el: '#delivergoods',
    data: {
        ShopID: '',
        userInfo: {},
        productList: [],
        submitIds: [],//去结算商品Ids
        inputVal:'',
        allChecked: false,
        check:false,
        open: false,
    },
    methods: {
        opentittle: function () {
            this.open = !this.open;
        },
        computedPrice: function (order) { //单选
            var _self = this;
            var productsCheckedLength=0;
            this.$nextTick(function () {
                    if(event.target.checked){
                         _self.submitIds.push(order);
                         productsCheckedLength++;
                    }else {
                      _self.submitIds.splice(_self.submitIds.indexOf(order), 1);
                    }
                    if(productsCheckedLength==_self.productList.length){
                        _self.allChecked=true;
                    }else {
                       _self.allChecked=false
                    }
            });
        },
        ckeckAll: function () { //全選
            var _self = this;
            this.$nextTick(function(){
                if (_self.allChecked) {
                    _self.submitIds = [];
                    _self.productList.forEach(function (order) {
                            _self.check = true;
                            _self.submitIds.push(order);
                        })
                }else{
                        _self.submitIds = [];
                    _self.productList.forEach(function(order){
                        _self.check = false;
                    });
                }

            });
        },
        delivery:function () {
        var _this = this;
        if(_this.submitIds.length==0){
           CAIMEI.Modal('请至少选择一项商品进行发货','确定','取消',function () {})
        }else {
         CAIMEI.Modal('确定发货吗？确定后将不能修改','取消','确定',function () {
             var obj= JSON.stringify(_this.submitIds);
               CAIMEI.Storage.setItem('orderList',obj);
                setTimeout(function(){
                    window.location.href = '/supplier/order/logistics.html';
                },200)
         })

        }

        },
        changeCountSub:function(order) {//商品数量减
        var _this = this;
            if(_this.inputVal > 1) {
                _this.inputVal--;
            }
            order.inputVal =_this.inputVal;
        },
        changeaddCount:function (order) {//商品数量加
            var _this = this;
            var num=order.notOutStore - order.actualCancelNum;
            if(_this.inputVal>=num){
                _this.inputVal =num
            }else {
             _this.inputVal++
            }
            order.inputVal = _this.inputVal;
        },

    },
    created:function(){

    },
    mounted: function () {
        var _this = this;
        if (globalUserData) {
            _this.ShopID = globalUserData.shopId;
        }
        console.log()
        if (isPC) {
            _this.open = true;
        }
        SupplierApi.ShipmentsInfo({shopOrderId: _this.ShopID}, function (res) {
            if (res.code == 0) {
                _this.userInfo = res.data.userInfo;
                res.data.orderProductList.forEach(function(order){
                       order.inputVal = order.notOutStore - order.actualCancelNum;
                       _this.inputVal=order.inputVal
                    });
                _this.productList = res.data.orderProductList;
            }
        })
    },
})
