window.onload = function () { var app = new Vue({ el: '#app', data: { csurl: 'https://custproj00011-2.ceydz.com/front/hnsdkj/authCode/securityCode', dataList: [], getDataList: [], show1: true, show2: false, show3: false, current: 1, showItem: 5, allpage: 1, securityCode: '', first:true, VGBEL:'' }, methods: { dz_codeSearch: function () { if(this.$options.mounted[0]() == true) { var _this = this; var params = { securityCode: this.securityCode }; this.$http.post(this.csurl, params, {emulateJSON: true}).then(function (res) { _this.getDataList = JSON.parse(res.body); console.log(_this.getDataList) if (res.body == 'null') { _this.show3 = true; _this.show1 = _this.show2 = false; } else { if (_this.getDataList.length > 0) { _this.show2 = true; _this.show1 = _this.show3 = false; _this.allpage = Math.ceil(_this.getDataList.length / 4); _this.$options.computed.pages(); _this.showData(1) } else { _this.show3 = true; _this.show1 = _this.show2 = false; } } }, function (res) { console.log(res); }); } }, goto: function (index) { if (index == this.current) return; this.current = index; //这里可以发送ajax请求 this.showData(index) }, showData: function (page) { this.dataList = []; var allLength = 4; if (page < this.allpage) { allLength = page * 4; } else { allLength = this.getDataList.length; } for (var i = (page - 1) * 4; i < allLength; i++) { this.dataList.push(this.getDataList[i]) } this.VGBEL = this.getDataList[0].VGBEL } }, mounted:function () { var back = false; if(this.first == true) { verifyCode = new GVerify("v_container"); this.first = false }else { if($("#securityCode").val().length < 1){ alert('请输入防伪码'); $("#securityCode").focus(); return; } if($("#valCode").val().length < 3){ alert('请输入验证码'); $("#valCode").focus(); return; } if (verifyCode.validate($("#valCode").val())) { back = true }else { alert('验证码输入错?'); back = false } } return back }, computed: { pages: function () { var pag = []; if (this.current < this.showItem) { //如果当前的激活的? 小于要显示的条数 //总页数和要显示的条数那个大就显示多少? var i = Math.min(this.showItem, this.allpage); while (i) { pag.unshift(i--); } } else { //当前页数大于显示页数? var middle = this.current - Math.floor(this.showItem / 2),//从哪里开 ? i = this.showItem; if (middle > (this.allpage - this.showItem)) { middle = (this.allpage - this.showItem) + 1 } while (i--) { pag.push(middle++); } } return pag } } }); }