From a37d440d24d0c7da466183f68fdd706689c81b90 Mon Sep 17 00:00:00 2001 From: CJJ <Administrator@USER-20180117QL> Date: 星期一, 24 十二月 2018 11:13:25 +0800 Subject: [PATCH] xiugai --- gx_tieta/WebRoot/pages/js/mylayui.js | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 355 insertions(+), 2 deletions(-) diff --git a/gx_tieta/WebRoot/pages/js/mylayui.js b/gx_tieta/WebRoot/pages/js/mylayui.js index de98aef..91ecfb3 100644 --- a/gx_tieta/WebRoot/pages/js/mylayui.js +++ b/gx_tieta/WebRoot/pages/js/mylayui.js @@ -9,6 +9,7 @@ // 璁剧疆option鐨勬枃鏈�/灞炴�у��/data鍊� option.text(_list.txt); option.val(_list.val); + option.attr('selected', _list.selected); option.data('data', _list.data); Object.keys(_list.attr).forEach(function(key){ var val = _list.attr[key]; @@ -19,7 +20,7 @@ } // 鏋勯�犵敓鎴恠elect鍒楄〃鐨勫璞℃暟缁� -function getLayuiSelect(txt, val, attr, data) { +function getLayuiSelect(txt, val, attr, data, isSelected) { var obj = { val: '', txt: '', @@ -32,7 +33,359 @@ obj.txt = txt; // option鐨勬枃鏈�� obj.attr = attr; // option鐨勮嚜瀹氫箟鐨勫睘鎬� obj.data = data; // option鐨刣ata鍊� + obj.selected = isSelected?true:false; // 杩斿洖鏋勯�犵殑瀵硅薄 return obj; -} \ No newline at end of file +} + +//鏍煎紡鍖栨椂闂� +Date.prototype.format =function(format) +{ + var o = { + "M+" : this.getMonth()+1, //month + "d+" : this.getDate(), //day + "h+" : this.getHours(), //hour + "m+" : this.getMinutes(), //minute + "s+" : this.getSeconds(), //second + "q+" : Math.floor((this.getMonth()+3)/3), //quarter + "S" : this.getMilliseconds() //millisecond + }; + if(/(y+)/.test(format)) format=format.replace(RegExp.$1, + (this.getFullYear()+"").substr(4- RegExp.$1.length)); + for(var k in o)if(new RegExp("("+ k +")").test(format)) + format = format.replace(RegExp.$1, + RegExp.$1.length==1? o[k] : + ("00"+ o[k]).substr((""+ o[k]).length)); + return format; +}; + +// 椤甸潰涓垎椤典俊鎭璞� +var TblPage = function() { + this.size = 10; + this.curr = 1; + this.all = 0; + this.num = 1; +}; + +// 鍒濆鍖栧垎椤典俊鎭璞� +TblPage.prototype.init = function() { + this.size = 10; + this.curr = 1; + this.all = 0; + this._setNum(); +}; + +// 璁剧疆鍒嗛〉淇℃伅瀵硅薄 +TblPage.prototype.set = function(curr, all, size) { + this.size = size; + this.curr = curr; + this.all = all; + this._setNum(); +}; +TblPage.prototype.getPage = function() { + var temp = { + pageSize: this.size + ,pageCurr: this.curr + ,pageAll: this.all + }; + + return temp; +}; +// 璁剧疆鍒嗛〉淇℃伅鐨勫綋鍓嶉〉 +TblPage.prototype.setCurr = function(curr) { + this.curr = curr; +}; + +//璁剧疆鍒嗛〉淇℃伅鐨勬瘡椤垫樉绀虹殑鏉℃暟 +TblPage.prototype.setSize = function(size) { + this.size = size; + this._setNum(); +}; + +//璁剧疆鍒嗛〉淇℃伅鐨勬�绘潯鏁� +TblPage.prototype.setAll = function(all) { + this.all = all; + this._setNum(); +}; + +// 璁剧疆鍏辨湁澶氬皯椤� +TblPage.prototype._setNum = function() { + this.num = Math.ceil(this.all/this.size); +} + +// 瀹氫箟椤甸潰涓垎椤靛厓绱犵殑瀵硅薄 +var PagePage = function(opts) { + this.search = ''; // 鏌ヨ + this.home = ''; // 棣栭〉 + this.pre = ''; // 涓婁竴椤� + this.next = ''; // 涓嬩竴椤� + this.last = ''; // 灏鹃〉 + this.size = ''; // 姣忛〉鏄剧ず鏉℃暟 + this.num = ''; // 璺宠浆鐨勯〉鏁� + this.go = ''; // 椤甸潰璺宠浆 + this.current = ''; // 褰撳墠椤�/鎬婚〉鏁� + this.total = ''; // 鏁版嵁鎬婚噺 + this.page = opts.page; // 鍒嗛〉淇℃伅 + this._initDom(opts); + this.callback = ""; +} + +// 璁剧疆PagePage鐨勬柟娉� +PagePage.prototype = { + _initDom: function(opts) { + this.search = this._getEle(opts.search); + this.home = this._getEle(opts.home); + this.pre = this._getEle(opts.pre); + this.next = this._getEle(opts.next); + this.last = this._getEle(opts.last); + this.num = this._getEle(opts.num); + this.go = this._getEle(opts.go); + this.current = this._getEle(opts.current); + this.total = this._getEle(opts.total); + this.size = this._getEle(opts.size); + //console.log(this.search); + this.addEvent(); + } + ,_getEle: function(ele) { + //console.log(ele); + var len = ele?ele.length:0; + //console.log(len); + var rsEle = len?ele:$('#PagePageTmp'); + return rsEle; + } + ,addEvent: function() { + var _this = this; + + // 鐐瑰嚮鏌ヨ + this.search.off('click.PagePage.event').on('click.PagePage.event', function() { + if(_this._checkCallback()) { + _this.callback(); + } + }); + + // 鐐瑰嚮棣栭〉 + this.home.off('click.PagePage.event').on('click.PagePage.event', function() { + var Page = _this.page; + if(Page.curr != 1){ + Page.setCurr(1); + _this.callback(); + } + }); + + // 鐐瑰嚮涓婁竴椤� + this.pre.off('click.PagePage.event').on('click.PagePage.event', function() { + var Page = _this.page; + if(Page.curr > 1){ + Page.setCurr(Page.curr-1); + _this.callback(); + } + }); + + // 鐐瑰嚮涓嬩竴椤� + this.next.off('click.PagePage.event').on('click.PagePage.event', function() { + var Page = _this.page; + if(Page.num > Page.curr){ + Page.setCurr(Page.curr+1); + _this.callback(); + } + }); + + // 璁剧疆姣忛〉鏄剧ず鏉℃暟 + this.size.off('blur.PagePage.event').on('blur.PagePage.event', function() { + var Page = _this.page; + var value= $(this).val(); + //褰撹緭鍏ョ殑鏁板ぇ浜�0鏃� + if(value>0){ + if(value != Page.size){ + Page.setSize(parseInt(value)); + Page.setCurr(1); + } + }else{ + //褰撹緭鍏ラ潪娉曟暟瀛楁椂 + alert("璇疯緭鍏ュ悎娉曠殑鏁板瓧"); /* 璇疯緭鍏ュ悎娉曠殑鏁存暟 */ + $(this).val(Page.size); + } + }); + + // 灏鹃〉 + this.last.off('click.PagePage.event').on('click.PagePage.event', function() { + var Page = _this.page; + if(Page.curr < Page.num){ + Page.setCurr(Page.num); + _this.callback(); + } + }); + + // 璺宠浆 + this.go.off('click.PagePage.event').on('click.PagePage.event', function() { + var Page = _this.page; + var tarpage= _this.num.val(); + if(tarpage > Page.num){ + Page.setCurr(Page.num); + }else if(tarpage > 0 && tarpage!= Page.curr){ + Page.setCurr(parseInt(tarpage)); + } + _this.callback(); + }); + + } + ,setCallback:function(callback) { + this.callback = callback; + } + ,setPage: function(page) { + this.page = page; + } + ,init:function(page, callback) { + this.setPage(page); + this.setCallback(callback); + this.setVal(); + } + ,setVal: function() { + this.current.text(this.page.curr+'/'+this.page.num); + this.total.text(this.page.all); + this.size.val(this.page.size); + } + ,_checkCallback: function() { + return typeof this.callback === 'function'; + } +}; + +// 鐪�-甯�-鍖鸿仈鍔� +var LinkAge = function(url, province, city, county, callback) { + this.province = province; + this.city = city; + this.county = county; + this.url = url; + this.callback= callback; + this.data = {}; + this._init(); +}; +LinkAge.prototype = { + _init: function() { + // 璁剧疆鍥炶皟鍑芥暟 + if(typeof this.callback === 'function') { + this.callback = this.callback; + }else { + this.callback = function() {}; + } + + this._setData(); + this._updateDom(); + // this._addEvent(); + } + ,_setData: function() { + var _this = this; + // 璇锋眰json鏁版嵁 + $.ajax({ + type: 'post' + ,async: false + ,url: this.url + ,data: null + ,dataType: 'json' + ,success: function(res) { + _this.data = res; + }, + error: function(res) { + console.log(res) + } + }); + } + ,_getProvinces: function() { + var provinces = this._analyseData(this.data); + return provinces; + } + ,_getCities: function(province) { + var cities = this.data[province].child; + var rsCities = this._analyseData(cities); + return rsCities; + } + ,_getCounty: function(province, city) { + var cities = this.data[province].child; + var counties = cities[city].child; + var rsCounties = this._analyseData(counties); + return rsCounties; + } + ,_analyseData: function(data) { + var rsData = []; + // 瑙f瀽鏁版嵁 + Object.keys(data).forEach(function(key) { + var _data = data[key]; + if(_data) + var tmp = { + id: key + ,name: _data.name + }; + + if(!_data.child && _data == '甯傝緰鍖�') { + + }else { + tmp.id = key; + tmp.name = _data.child?_data.name:_data; + rsData.push(tmp); + } + + }); + + return rsData; + } + ,_updateDom: function() { + // 鐪� + var proData = this._getProvinces(); + var proOptions = this._createDom(proData); + this.province.html(proOptions); + + // 甯� + var citiesData = this._getCities(this.province.find('option:selected').attr('num')); + var citiesOptions = this._createDom(citiesData); + this.city.html(citiesOptions); + + // 鍖�/鍘� + var countiesData = this._getCounty(this.province.find('option:selected').attr('num'), this.city.find('option:selected').attr('num')); + var countiesOptions = this._createDom(countiesData); + this.county.html(countiesOptions); + + this.callback(); + } + ,_createDom: function(data) { + var options = ''; + for(var i=0; i<data.length; i++) { + var _data = data[i]; + options += '<option num="'+_data.id+'" value="'+_data.name+'">'+_data.name+'</option>'; + } + + return options; + } + ,_addEvent: function() { + var _this = this; + // 鍒囨崲鐪佽皟鏁村競鍜屽尯/鍘� + this.province.off('change.LinkAge.event').on('change.LinkAge.event', function() { + var val = $(this).find('option:selected').attr('num'); + console.log(val); + // 甯� + var citiesData = _this._getCities(val); + var citiesOptions = _this._createDom(citiesData); + _this.city.html(citiesOptions); + + + // 鍖�/鍘� + var countiesData = _this._getCounty(val, _this.city.find('option:selected').attr('num')); + var countiesOptions = _this._createDom(countiesData); + _this.county.html(countiesOptions); + + _this.callback(); + }); + + // 鍒囨崲甯� + this.city.off('change.LinkAge.event').on('change.LinkAge.event', function() { + var val = $(this).find('option:selected').attr('num'); + console.log(val); + // 鍖�/鍘� + var countiesData = _this._getCounty(_this.province.find('option:selected').attr('num'), val); + var countiesOptions = _this._createDom(countiesData); + _this.county.html(countiesOptions); + _this.callback(); + }); + } +}; + -- Gitblit v1.9.1