layui-js/dist/lay/modules/transfer.js

2 lines
7.3 KiB
JavaScript
Raw Normal View History

2019-05-31 06:36:29 +00:00
/** layui-v2.5.0 MIT License By https://www.layui.com */
;layui.define("form",function(a){"use strict";var e=layui.form,i=layui.$,t={config:{},index:layui.transfer?layui.transfer.index+1e4:0,set:function(a){var e=this;return e.config=i.extend({},e.config,a),e},on:function(a,e){return layui.onevent.call(this,l,a,e)}},n=function(){var a=this,e=a.config;return{getValue:function(){return a.getValue()},config:e}},l="transfer",r="layui-transfer",d="layui-transfer-left",s="layui-transfer-right",c="layui-transfer-dataLeft",f="layui-transfer-dataRight",u="layui-transfer-btnLeft",h="layui-transfer-btnRight",o="layui-btn-disabled",y=function(a){var e=this;e.index=++t.index,e.config=i.extend({},e.config,t.config,a),e.render()};y.prototype.config={title:["列表一","列表二"],data:[],value:[],showSearch:!1,id:""},y.prototype.render=function(){var a=this,t=a.config,n="",l="",d=[];"function"==typeof t.parseData&&layui.each(t.data,function(a,e){t.data[a]=t.parseData(e)||e});var s=0,c="",f=0,u=0;layui.each(t.data,function(a,e){s=0,layui.each(t.value,function(a,i){if(e.value==i)return s=1,!0}),c='<li data-title="'+e.title+'"><input lay-skin="primary" type="checkbox" data-index="'+a+'" name="'+(0==s?"layTranLeftCheck":"layTranRightCheck")+'" title="'+e.title+'" value="'+e.value+'" class="layui-input" '+(e.disabled?"disabled":"")+"></li>",0==s?(n+=c,f+=e.disabled?0:1):(l+=c,u+=e.disabled?0:1,d.push(a))});var h=['<div class="layui-transfer layui-form" id="transfer-'+t.id+'" lay-filter="LAY-Transfer-'+a.index+'">','<div class="layui-transfer-left" data-total="'+f+'">','<div class="layui-transfer-topTitle"><input lay-skin="primary" name="layTranLeftCheck" lay-filter="layTranLeftCheckAll" type="checkbox" class="layui-input" title="'+t.title[0]+'"></div>',function(){return t.showSearch?'<div class="layui-transfer-search"><input class="layui-input" placeholder="关键字搜索"><i class="layui-icon layui-icon-search layui-transfer-searchI"></i></div><ul class="layui-transfer-data layui-transfer-dataLeft short">':'<ul class="layui-transfer-data layui-transfer-dataLeft">'}(),n+"</ul>","</div>",'<div class="layui-transfer-btn">','<button class="layui-btn layui-btn-primary layui-transfer-btnRight layui-btn-disabled"><i class="layui-icon layui-icon-next"></i></button>','<button class="layui-btn layui-btn-primary layui-transfer-btnLeft layui-btn-disabled"><i class="layui-icon layui-icon-prev"></i></button></div>','<div class="layui-transfer-right" data-arr="'+d+'" data-total="'+u+'">','<div class="layui-transfer-topTitle"><input lay-skin="primary" name="layTranRightCheck" lay-filter="layTranRightCheckAll" type="checkbox" class="layui-input" title="'+t.title[1]+'"></div>',function(){return t.showSearch?'<div class="layui-transfer-search"><input class="layui-input" placeholder="关键字搜索"><i class="layui-icon layui-icon-search layui-transfer-searchI"></i></div><ul class="layui-transfer-data layui-transfer-dataRight short">':'<ul class="layui-transfer-data layui-transfer-dataRight">'}(),l+"</ul>","</div>","</div>"].join(""),o=i(t.elem),y=o.next("."+r);y[0]&&y.remove(),a.elemTemp=i(h),o.html(a.elemTemp),a.event(),e.render("checkbox","LAY-Transfer-"+a.index)},y.prototype.event=function(){function a(a){var e=l.find(a).find(".layui-transfer-search"),t=e.children("input").val(),n=e.next();n.children("li").each(function(){i(this).data("title").indexOf(t)==-1?i(this).hide():i(this).show()})}var t=this,n=t.config,l=t.elemTemp,r="",y="",p=l.find("."+d).find(".layui-transfer-topTitle").find('input[name="layTranLeftCheck"]'),v=l.find("."+s).find(".layui-transfer-topTitle").find('input[name="layTranRightCheck"]'),k=l.find("."+d).data("total"),b=l.find("."+s).data("total");l.on("click",'input[name="layTranLeftCheck"]+',function(){var a=i(this).prev(),n=a[0].checked,d=l.find("."+c).find('input[name="layTranLeftCheck"]'),s="layTranLeftCheckAll"==a.attr("lay-filter");if(!a[0].disabled){if(s)r="",0==k?a[0].checked=!1:(d.each(function(a,e){e.disabled||(e.checked=n,n?(r+=i(d[a]).data("index")+",",i(d[a]).parent("li").addClass("selected")):i(d[a]).parent("li").removeClass("selected"))}),n?l.find("."+h).removeClass(o):l.