var isPC = ($(window).width()>768);
var fleaMarketList = new Vue({
     el: "#fleaMarketList",
     data:{
     currentId:1,
     currentID2:0,
     isShow:false,
     showflag:false,
     mainflag:false,
     userID:JSON.parse(localStorage.getItem('userInfo')),
     tabTitle: [
                {value:'1',name:'全部'},
                {value:'2',name:'临期产品'},
                {value:'3',name:'其他'}
               ],
      tabList : [
                {value:'0',name:'全部'},
                {value:'1',name:'轻光电'},
                {value:'2',name:'重光电'},
                {value:'3',name:'耗材配件'},
           ],
      listQuery:{
                pageNum:1,
                pageSize:12,
            },
      tabchildList:[],
      productsList:[],
      tabchild:{},
      listRecord: 0,
     pageInput: '1',
      params:{},

     },
     computed: {
          pageTotal: function () {
                  var total = Math.ceil(this.listRecord / this.listQuery.pageSize);

                  return total > 0 ? total : 1;
            },
           showPageBtn: function () {
                var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
                    total = total > 0 ? total : 1;
                var index = this.listQuery.pageNum, arr = [];
                if (total <= 6) {
                    for (var i = 1; i <= total; i++) {
                        arr.push(i);
                    }
                    return arr;
                }
                if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
                if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
                return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
            },
      },
     methods:{
       toPagination: function (pageNum) {
          var _this = this;
           _this.productsList = [];
            if (pageNum <= this.pageTotal) {
                _this.listQuery.pageNum = pageNum;
                _this.gettabList()
            }
        },
        checkNum: function () {
            if (this.pageInput > this.pageTotal) {
                this.pageInput = this.pageTotal;
            } else if (this.pageInput < 1) {
                this.pageInput = 1;
            }
        },
         handle: function (item) {//一級分类
               var _this = this;
               _this.currentId = item.value;
               _this.currentID2 = 0;
               if ( _this.currentId==1){
               _this.mainflag = true;
               }else {
               _this.mainflag=false;
               }
               _this.gettabList();
          },
           handleChild:function(item){ //二级分类
               var _this = this;
               _this.currentID2 = item.value;
               _this.gettabList();
          },
           gettabList:function () {
                var _this = this;
                _this.returnedTarget();
                var params = Object.assign({secondHandType: _this.currentId,instrumentType:_this.currentID2}, _this.listQuery);
                SecondApi.SeconHandProductList(params,function (res) {
                     if (res.code == 0) {
                        console.log(res);
                       if(res.data.results.length == 0){
                            _this.tabchildList = [];
                            _this.showflag = true;
                             _this.listRecord = res.data.totalRecord;
                       }else {
                            _this.showflag = false;
                            _this.isShow = true;
                            _this.tabchildList = res.data.results;
                            _this.listRecord = res.data.totalRecord;
                       }
                     }else{
                     }
                })
          },
           returnedTarget:function(){//对象合并 IE 兼容方法
            if (typeof Object.assign != 'function') {
                Object.assign = function(target) {
                    'use strict';
                    if (target == null) {
                        throw new TypeError('Cannot convert undefined or null to object');
                    }
                    target = Object(target);
                    for (var index = 1; index < arguments.length; index++) {
                        var source = arguments[index];
                        if (source != null) {
                            for (var key in source) {
                                if (Object.prototype.hasOwnProperty.call(source, key)) {
                                    target[key] = source[key];
                                }
                            }
                        }
                    }
                    return target;
                };
            }
        }
     },
     mounted:function () {
          var _this = this;
          _this.gettabList()
      },
});
