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; //杩欓噷鍙互鍙戦€乤jax璇锋眰 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) { //濡傛灉褰撳墠鐨勬縺娲荤殑? 灏忎簬瑕佹樉绀虹殑鏉℃暟 //鎬婚〉鏁板拰瑕佹樉绀虹殑鏉℃暟閭d釜澶у氨鏄剧ず澶氬皯? 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 } } }); }