;
var operationPage = new Vue({
    el: "#operationPage",
    data: {
        isRequset:true,
        noMore: false,
        StatusList:[
            {value:0,name:'所有'},
            {value:1,name:'已提交'},
            {value:2,name:'已对接'},
            {value:3,name:'已评价'},
            {value:4,name:'已取消'}
        ],
        listQuery:{
            userID:0,
            linkName : '',
            mobile : '',
            pageNum:1,
            pageSize:10
        },
        listRecord: 0,
        pageInput: '1',
        operationList:[],
        confirmedCount:'',//待確認數量
        paymentCount:'',//待付款
        waitShipmentsCount:'',//待发货
        shipmentsCount:'',//已发货
        salesReturnCount:'',//退货款
    },
    filters: {
        stateExp:function (state){ //订单状态文字和颜色
            var stateText = '',
                stateTextObject={
                    2:'已绑定',
                    1:'未绑定'
                };
                Object.keys(stateTextObject).forEach(function(key){
                    if(key == state){
                    stateText = stateTextObject[key]
                }
             });
            return stateText;
        },
        stateTextExp:function (state){ //订单状态文字和颜色
            var stateText = '',
                stateTextObject={
                    1:'有效',
                    2:'已使用',
                    3:'已过期'
                };
                Object.keys(stateTextObject).forEach(function(key){
                    if(key == state){
                    stateText = stateTextObject[key]
                }
             });
            return stateText;
        }
    },
    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) {//点击切换分页
            if (pageNum <= this.pageTotal) {
                this.listQuery.pageNum = pageNum;
                this.GetQueryListData();
            }
        },
        checkNum: function () {//输入跳转分页
            if (this.pageInput > this.pageTotal) {
                this.pageInput = this.pageTotal;
            } else if (this.pageInput < 1) {
                this.pageInput = 1;
            }
        },
        GetQueryListData:function(){//查询运营人员列表
            var _self = this;
            SupplierApi.GetMyOperationList(_self.listQuery,function (response) {
                if(response.code == 0){
                    var data = response.data;
                    if(data.results && data.results.length>0) {
                        _self.operationList = [];
                        _self.operationList = data.results;
                        _self.listRecord = data.totalRecord;
                    }else{
                        _self.operationList = [];
                        _self.operationList = data.results;
                         _self.listRecord = data.totalRecord;
                    }
                    _self.isRequset = false;
                }else{
                    CAIMEI.Alert(response.msg, '确定', false);
                }
            })
        },
        searchOperationFn:function(){//点击搜索
            this.GetQueryListData();
        },
        UpdataOperationFn:function(data){//更新邀请码
            var _self = this;
            CAIMEI.Modal('确定更新邀请码吗？更新后将会短信通知该运营人员','取消','确定',function () {
                SupplierApi.UpdateInvitationCode({id:data.id},function (response) {
                    if(response.code == 0 ){ //删除成功
                        CAIMEI.dialog(response.msg,true,function () {
                            _self.GetQueryListData();
                        });
                    }else{
                        CAIMEI.Alert(response.msg,'确定',false);
                    }
                })
            });
        },
        DeleteOperationFn:function(data){//删除运营人员
            var _self = this;
            CAIMEI.Modal('确定删除运营人员吗？','取消','确定',function () {
                SupplierApi.DeleteMyOperation({id:data.id},function (response) {
                    if(response.code == 0 ){ //删除成功
                        CAIMEI.dialog('删除成功',true,function () {
                            _self.GetQueryListData();
                        });
                    }else{
                        CAIMEI.Alert(response.msg,'确定',false);
                    }
                })
            });
        },
        ColorFn: function(state){//设置邀请码状态亚瑟
            var stateColor = '',
                stateColorObject={
                    1:'#1DEDC5',
                    2:'#1D7DED',
                    3:'#ED1D1D'
                };
            Object.keys(stateColorObject).forEach(function(key){
                if(key == state){
                    stateColor = stateColorObject[key]
                }
            });
            return stateColor;
        },
        statusColorFn: function(state){//设置状态颜色
            var stateColor = '',
                stateColorObject={
                    1:'#333333',
                    2:'#13ce66'
                };
            Object.keys(stateColorObject).forEach(function(key){
                if(key == state){
                    stateColor = stateColorObject[key]
                }
            });
            return stateColor;
        },
    },
    mounted: function () {
        if(globalUserData){
            this.listQuery.userID = globalUserData.userId;
            this.listQuery.orderState = CAIMEI.getUrlParam('state');
            this.GetQueryListData();
        }
        console.log(this.listQuery.orderState)
        $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
        $('.navLayout').find('.navList').eq(2).addClass("on").find('.con').show().find('a').eq(1).addClass("on");

    }
});
