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

2 lines
7.6 KiB
JavaScript
Raw Normal View History

2019-06-02 23:57:12 +00:00
/** layui-v2.5.1 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{getData:function(){return a.getData()},config:e}},l="transfer",r="layui-transfer",d="layui-transfer-topTitle",s="layui-transfer-search",c="layui-transfer-box",f="layui-transfer-data",u="layui-transfer-left",h="layui-transfer-right",o="layui-transfer-dataLeft",y="layui-transfer-dataRight",p="layui-transfer-btnLeft",v="layui-transfer-btnRight",k="layui-btn-disabled",b=function(a){var e=this;e.index=++t.index,e.config=i.extend({},e.config,t.config,a),e.render()};b.prototype.config={title:["列表一","列表二"],width:200,height:340,data:[],value:[],showSearch:!1,id:""},b.prototype.render=function(){var a=this,t=a.config,n="",l="",u=[];"function"==typeof t.parseData&&layui.each(t.data,function(a,e){t.data[a]=t.parseData(e)||e});var h=0,o="",y=0,p=0;layui.each(t.data,function(a,e){h=0,layui.each(t.value,function(a,i){if(e.value==i)return h=1,!0}),o='<li data-title="'+e.title+'"><input lay-skin="primary" type="checkbox" data-index="'+a+'" name="'+(0==h?"layTranLeftCheck":"layTranRightCheck")+'" title="'+e.title+'" value="'+e.value+'" class="layui-input" '+(e.disabled?"disabled":"")+"></li>",0==h?(n+=o,y+=e.disabled?0:1):(l+=o,p+=e.disabled?0:1,u.push(a))});var v=['<div class="layui-transfer layui-form layui-border-box" id="transfer-'+t.id+'" lay-filter="LAY-Transfer-'+a.index+'">','<div class="layui-transfer-left layui-transfer-box" data-total="'+y+'">','<div class="'+d+'"><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 layui-transfer-short">':'<ul class="layui-transfer-data layui-transfer-dataLeft">'}(),n+"</ul>","</div>",'<div class="layui-transfer-btn">','<button type="button" class="layui-btn layui-btn-primary layui-transfer-btnRight layui-btn-disabled"><i class="layui-icon layui-icon-next"></i></button>','<button type="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 layui-transfer-box" data-arr="'+u+'" data-total="'+p+'">','<div class="'+d+'"><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 layui-transfer-short">':'<ul class="layui-transfer-data layui-transfer-dataRight">'}(),l+"</ul>","</div>","</div>"].join(""),k=i(t.elem),b=k.next("."+r);b[0]&&b.remove(),a.elem=i(v),k.html(a.elem),a.layTop=a.elem.find("."+d),a.layBox=a.elem.find("."+c),a.laySearch=a.elem.find("."+s),a.layData=a.elem.find("."+f),a.layBox.css({width:t.width,height:t.height}),a.layData.css({height:function(){return t.height-a.layTop.outerHeight()-a.laySearch.outerHeight()-2}()}),a.event(),e.render("checkbox","LAY-Transfer-"+a.index)},b.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.elem,r="",s="",c=l.find("."+u).find("."+d).find('input[name="layTranLeftCheck"]'),f=l.find("."+h).find("."+d).find('input[name="layTranRightCheck"]'),b=l.find("."+u).data("total"),g=l.find("."+h).data("total");l.on("click",'input[name="layTranLeftC