vue模块组件

 

var childVue = devices({
       parentVue : this,
       templateId:'#templateDevice',
       reqUrl : '/device/list',
});

 

 

define([
    'vue',
    'request',
    'static/js/base/text!view/components/devices.html',
], function(vue, req, review) {
    return function(options){
        $(options.templateId).html(review);
        var childVue = new vue({
            el : options.templateId,
            data:{
                searchParams : {
                    keyword:'',
                    tagId:'',
                    size:5,
                    page:1
                },
                tagList:'',
                reqList:'',
                reqData:'',
                publishStatus:req.publishStatus,
                checkModels:[],
                checkAll:false,
                checkTotal:false,
                checkLength:0
            },
            methods:{
                //点击
                toggleCheck:function(item){
                    var findIndex = this.checkModels.indexOf(item.id);
                    if(findIndex != -1){
                        this.checkModels.splice(findIndex,1);
                    }else{
                        this.checkModels.push(item.id);
                    }
                },
                checkAllFuc:function(){
                    var _this = this;
                    this.checkAll = !this.checkAll;
                    if(this.checkAll==true){
                        this.checkModels = [];
                        this.reqList.forEach(function(item,index){
                            _this.checkModels.push(item.id);
                        })
                    }else{
                        this.checkModels = [];
                    }
                },
                getReqList:function(page){
                    var _this = this;
                    _this.searchParams.page = page || 1;
                    req.ajaxPost(options.reqUrl,_this.searchParams,function(data){
                        if(data.code == 200){
                            _this.reqList = data.data.pageInfo.list;
                            _this.reqData = data.data.pageInfo;
                            _this.tagList = data.data.tagList;
                            _this.reqList.forEach(function(item,index){
                                item.tagNamesArr = item.tagNames.split(',');
                            })

                            if(_this.checkTotal){
                                _this.checkLength = _this.reqData.total;
                                _this.checkAll = false;
                                _this.checkAllFuc();
                            }else{
                                _this.checkLength = 0;
                            }

                        }else{
                           alert(data.message)
                        }
                    })
                },
                checkTotalFuc:function () {
                    //跨页全选
                    var _this = this;
                    _this.checkTotal = !_this.checkTotal;
                    if(_this.checkTotal){//全部选中
                        _this.checkLength =  _this.reqData.total;
                        _this.checkAll = false;
                    }else{//取消全选
                        _this.checkAll = true;
                        _this.checkLength = _this.checkModels.length;
                    }
                    _this.checkAllFuc();
                },
                //跳转页面
                goToPage:function(page){
                    
                    if(page==0 || page > this.reqData.pages){
                        this.reqData.jumpPage = '';
                        return false;
                    }                                                       
                    this.getReqList(page);
                },
            },
            watch:{
                checkModels:function(){
                    //页内全选
                    if(this.checkModels.length == this.reqList.length ){
                        this.checkAll = true;
                    }else{
                        this.checkAll = false;
                        this.checkTotal = false;
                    }
                    if(!this.checkTotal){
                        this.checkLength = this.checkModels.length;
                    }

                }
            },
            ready:function(){
                this.getReqList();              
            }
        })
        return childVue;
    } 
});

 

转载于:https://www.cnblogs.com/vsmart/p/9684599.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值