From f99e01a5e62998ea3ccdd3e74c51bc6a0ca68bb9 Mon Sep 17 00:00:00 2001 From: whyclj <1525436766@qq.com> Date: 星期三, 02 一月 2019 17:39:10 +0800 Subject: [PATCH] Merge branch 'dev_lxw' of https://whyclj@gitlab.com/whyclxw1/gx_tieta.git into dev_lxw --- gx_tieta/WebRoot/pages/js/mylayui.js | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 224 insertions(+), 0 deletions(-) diff --git a/gx_tieta/WebRoot/pages/js/mylayui.js b/gx_tieta/WebRoot/pages/js/mylayui.js index 94808f7..785509f 100644 --- a/gx_tieta/WebRoot/pages/js/mylayui.js +++ b/gx_tieta/WebRoot/pages/js/mylayui.js @@ -251,3 +251,227 @@ } }; +// 鐪�-甯�-鍖鸿仈鍔� +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(); + }); + } +}; + +//layui琛ㄦ牸鍐呭鏇存柊 +var LayuiTbl = function(options, layui, laytpl, cache) { + this.opts = options; + this.cache = cache; + this.layui = layui; + this.tpl = laytpl; + this.ele = options.elem; + this.col = options.cols[0]; +}; + +// 璁剧疆鍘熷瀷鍑芥暟 +LayuiTbl.prototype = { + updateTr: function(index, data) { + var layui = this.layui; + + var preData = this.cache[index]; + var _data = $.extend(preData||{}, data||{}); + var tds = this._getBodyTds(index); + var tdRs = this._getFixedRTds(index); + //console.log(_data); + // 閬嶅巻 + var _this = this; + layui.each(_data, function(key, value) { + // 閬嶅巻tds鐨勫�� + tds.each(function(k) { + var _field = $(this).data('field'); + if(key == _field) { + var cell = $(this).find('.layui-table-cell'); + var content = _this._getContent(key, value, _data); + cell.html(content); + } + }); + }); + + // 淇敼娴姩 + layui.each(_data, function(key, value) { + // 閬嶅巻tds鐨勫�� + tdRs.each(function(k) { + var _field = $(this).data('field'); + if(key == _field) { + var cell = $(this).find('.layui-table-cell'); + var content = _this._getContent(key, value, _data); + cell.html(content); + } + }); + }); + } + ,_getBodyTds: function(index) { + var layuiTableView = $(this.ele).next('.layui-table-view'); + var layuiTableBody = layuiTableView.find('.layui-table-body .layui-table tbody'); + var trList = layuiTableBody.find('tr'); + + return trList.eq(index).find('td'); + } + ,_getFixedRTds: function(index) { + var layuiTableView = $(this.ele).next('.layui-table-view'); + var layuiFixedR = layuiTableView.find('.layui-table-fixed.layui-table-fixed-r .layui-table tbody'); + var trList = layuiFixedR.find('tr'); + return trList.eq(index).find('td'); + } + ,_getContent: function(key, value, data) { + var col = this.col; // 鎵�鏈夌殑鍒� + var laytpl = this.tpl; + var rs = ''; + var templet = ''; + // 閬嶅巻鎵�鏈夌殑鍒� + for(var i=0; i<col.length; i++) { + var _col = col[i]; + // 鍒ゆ柇褰撳墠鍐呭鏄惁涓哄搴旂殑闇�瑕佹洿鏂扮殑鏁版嵁 + if(key == _col.field) { + // 鍒ゆ柇鏄惁鏈夋ā鏉� + templet = _col.templet?$(_col.templet).html():_col.toolbar?$(_col.toolbar).html():value.toString(); + //console.log(templet); + // 鏍规嵁妯℃澘鏋勬垚content + laytpl(templet).render(data, function(html) { + rs = html; + }); + + return rs; + } + } + + return false; + } +}; + -- Gitblit v1.9.1