var isPC = ($(window).width()>768);
jqMultipleShow("click", ".navList", ".tab", ".con");
var addlogistics = new Vue({
    el:'#addlogistics',
    data:{
         open:false,
         userInfo:{},
         orderList:[],
         logisticsBatch:{},
         GoodsImagesList:[],
         formData:new FormData(),
         txtVal: 0,
         desc:'',
         kdlist:[],
         logisticList:[
             {
                value:'',
                name:'',
                numList:[
                    {number:''}
                ]
             }
         ],
         params:{
            logistics:[],//物流
            logisticsBatchID:'',
            remarkImage:'',
            remark:''
         },
         select:'',
         electShow:false,
    },
    methods:{
         uploadGoodsImagesFn: function(event){//上传商品图片
            var _this = this;
            var inputDOM = _this.$refs.goodsImages;
            var file = inputDOM.files;
            _this.formData.append('file', file[0]);
            SupplierApi.uploadimg(_this.formData,function(response){
               _this.GoodsImagesList.push(response.data);
               _this.params.remarkImage =_this.GoodsImagesList.join('##').substring();
                event.target.value = '';
            });
        },
         removeGoodsImagesFn: function(index){//删除商品图片
            var _this = this;
            _this.GoodsImagesList.splice(index,1);
             _this.params.remarkImage =_this.GoodsImagesList.join('##').substring();
         },
         selshow:function(event,index){
            this.select = index;
            this.electShow = !this.electShow
         },
         addBtn:function () { //添加物流
             var _this = this;
             var obj = {
                        value:'',
                        name:'',
                        numList:[
                            {number:''}
                        ]
                  };
              _this.logisticList.push(obj);
         },
         addNum:function(item,index){
            var _this = this;
            var obj = {number:''};
            item.numList.push(obj);
         },
         subBtn:function (list) {
            var _this = this;
             _this.kdlist.splice(_this.kdlist.indexOf(list), 1);
         },
         reduceBtn:function(item){
            var _this = this;
             item.numList.splice(item.numList.indexOf(item.numList), 1);
         },
         parameter:function(){//参数信息
           var _this = this;
            _this.logisticList.forEach(function (pros) {
                    var obj = {};
                    var Code = pros.value;
                    var yName = pros.name;
                    var numList = pros.numList;
                    numList.forEach(function (item) {
                        var logisNum = item.number;
                         obj={
                            logisticsCompanyCode:Code,
                            logisticsCompanyName:yName,
                            number:logisNum
                        };
                        if(obj.logisticsCompanyCode==""&&obj.logisticsCompanyName==""){
                            CAIMEI.Alert('请选择快递公司','确定')
                        }else if(obj.number==""){
                            CAIMEI.Alert('请输入快递单号','确定')
                        }else {
                         _this.params.logistics.push(obj);
                        }
                     })
              })
         },
         ChangeLogistics:function(event,item,index){
             var donClass = '#logistics'+index;
             var domLogistics =  document.querySelector(donClass);
             item.name = domLogistics.options[domLogistics.selectedIndex].text;
             item.value =event.target.value;
         },
         turnBtn:function () {//提交发货
            var _this = this;
            console.log(_this.params)
            var shopOrderId = $('.pro-information li').attr('shopOrderID');
                _this.parameter();
                 var params = JSON.stringify(_this.params);
                SupplierApi.addLogisticsInfo({params:params},function (res) {
                    if(res.code == 0) {
                        CAIMEI.dialog('发货成功');
                        window.location.href = '/supplier/order/delivery_record.html?shopOrderID='+shopOrderId;
                      }else {

                      }
                 })
         },
    },
    mounted:function () {
      var _self = this;
      var shopOrderId=CAIMEI.getUrlParam('shopOrderId');
      var logisticsBatchId=CAIMEI.getUrlParam('logisticsBatchId');
      _self.params.logisticsBatchID =logisticsBatchId;
      SupplierApi.logisticsInfo({logisticsBatchId:logisticsBatchId,shopOrderId:shopOrderId},function (res) {
        if(res.code==0){
            _self.userInfo = res.data.userInfo;
            _self.logisticsBatch = res.data.logisticsBatch;
            _self.params.remark =_self.logisticsBatch.remark
            _self.GoodsImagesList =  _self.logisticsBatch.remarkImages;
            _self.params.remarkImage = _self.GoodsImagesList.toString()+'##';
            _self.orderList = res.data.logisticsBatch.logisticsRecordList;
            console.log( _self.params.remarkImage)
        }
      })
      SupplierApi.kdList(function (res) {
         if(res.code==0){
            var data = res.data;
            data.forEach(function(item){
               _self.kdlist.push(item);
            });
          console.log(_self.kdlist.length);
         }
      });
      if(isPC){
            _self.open=true;
        }

    }
})
