main.js 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791
  1. //这里的代码是最早写的,很乱,以后整合优化
  2. var editors = [];
  3. var editors_index = [];
  4. var tables = [];
  5. var select = '';
  6. var submitButton = '';
  7. var editorWidth = 0;
  8. var admingroup = false;
  9. String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
  10. if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
  11. return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
  12. } else {
  13. return this.replace(reallyDo, replaceWith);
  14. }
  15. }
  16. Array.prototype.remove = function(val) {
  17. var index = -1;
  18. for(var i = 0; i < this.length; i++)
  19. {
  20. if(this[i] == val)
  21. {
  22. index = i;
  23. }
  24. }
  25. if (index > -1) {
  26. this.splice(index, 1);
  27. }
  28. };
  29. Array.prototype.replaceOne = function(old, val) {
  30. var index = -1;
  31. for(var i = 0; i < this.length; i++)
  32. {
  33. if(this[i] == old)
  34. {
  35. index = i;
  36. }
  37. }
  38. if (index > -1) {
  39. this.splice(index, 1, val);
  40. }
  41. };
  42. $(document).ready(function()
  43. {
  44. //init();
  45. });
  46. function init(ew)
  47. {
  48. if (ew) {
  49. editorWidth = ew;
  50. } else {
  51. editorWidth = 0;
  52. }
  53. editors = [];
  54. editors_index = [];
  55. initEditor();
  56. select = '';
  57. edit();
  58. del();
  59. checkbox();
  60. image();
  61. change();
  62. autocomplete();
  63. template();
  64. submit();
  65. loadShow();
  66. initPic();
  67. initDate();
  68. initLayui();
  69. initColor();
  70. initUpdate();
  71. initClipboard();
  72. initEmoji();
  73. initSearch();
  74. //更新页面一些功能,上边的一些功能等找时间再优化吧
  75. dever_update.init();
  76. hljs.initHighlightingOnLoad();
  77. table();
  78. }
  79. function initSearch()
  80. {
  81. $("#form1 input").bind('keypress', function (event) {
  82. if (event.keyCode == 13) {
  83. $("#search_button").click();
  84. }
  85. });
  86. }
  87. function initEmoji()
  88. {
  89. if ($('.dever-emoji').length) {
  90. $('.dever-emoji').each(function()
  91. {
  92. emoji($(this), $(this).html());
  93. })
  94. }
  95. }
  96. function emoji(e, content)
  97. {
  98. var handle = function()
  99. {
  100. e.html(twemoji.parse(content)).show(200);
  101. };
  102. if (typeof jEmoji != 'object') {
  103. $.getScript('//twemoji.maxcdn.com/2/twemoji.min.js?11.4', function() {
  104. /*
  105. $("head").append("<link>");
  106. var css = $("head").children(":last");
  107. css.attr({
  108. rel: "stylesheet",
  109. type: "text/css",
  110. href: config.script + '/lib/emoji/emoji.css'
  111. });
  112. */
  113. return handle();
  114. });
  115. } else {
  116. return handle();
  117. }
  118. }
  119. function checkClick(e)
  120. {
  121. var objEvt = $._data(e[0], "events");
  122. if (objEvt && !objEvt["click"]) {
  123. return false;
  124. }
  125. return true;
  126. }
  127. function initClipboard()
  128. {
  129. var clipboard = new ClipboardJS('.clipboard');
  130. clipboard.on('success', function(e) {
  131. notify('复制成功', e.trigger);
  132. e.clearSelection();
  133. });
  134. clipboard.on('error', function(e) {
  135. notify('复制失败', e.trigger);
  136. });
  137. }
  138. function initUpdate()
  139. {
  140. if ($('.update_show_editor').length) {
  141. $('.update_show_editor').each(function() {
  142. $(this).bind('click', function()
  143. {
  144. var url = $(this).attr('key');
  145. var value = $(this).attr('editor_id');
  146. var title = $(this).attr('value');
  147. var send = '';
  148. if ($(this).attr('data-value')) {
  149. send = $(this).attr('data-value');
  150. }
  151. $.post(url, {value:send}, function(t)
  152. {
  153. var func = function() {
  154. var url = $('#editor_applet_pic').val();
  155. var appid = $('#editor_applet_id').val();
  156. var path = $('#editor_applet_path').val();
  157. var link = $('#editor_applet_link').val();
  158. if (!appid) {
  159. //alert('请选择小程序');
  160. //return;
  161. }
  162. if (!path) {
  163. alert('请填写路径');
  164. return;
  165. }
  166. if (!url) {
  167. alert('请上传封面');
  168. return;
  169. }
  170. var w = 750/2;
  171. KindEditor.insertHtml('#' + value, '<img src="'+url+'" style="width:'+w+'px;" data-applet="'+url+'||'+appid+'||'+path+'||'+link+'"/>');
  172. layer.closeAll();
  173. };
  174. showAlert(t, func, title);
  175. image();
  176. })
  177. })
  178. });
  179. }
  180. }
  181. function initLayui()
  182. {
  183. layui.use('layer', function() {
  184. var layer = layui.layer;
  185. layer.ready(function() {
  186. $(".dever-img").each(function()
  187. {
  188. layer.photos({
  189. photos: '#' + $(this).attr('id'),
  190. shade : 0.5
  191. });
  192. });
  193. });
  194. });
  195. }
  196. function initColor()
  197. {
  198. if ($('.dever-color').length) {
  199. $('.dever-color').each(function()
  200. {
  201. var self = $(this);
  202. var val = self.val();
  203. if (!val) {
  204. val = '#000000';
  205. }
  206. self.css('border-right', '40px solid '+val);
  207. self.colpick({
  208. layout:'hex',
  209. submit:0,
  210. colorScheme:'dark',
  211. color: val,
  212. onChange : function (hsb,hex,rgb,el,bySetColor) {
  213. $(el).css('border-color','#'+hex);
  214. if(!bySetColor) $(el).val('#' + hex);
  215. }
  216. }).keyup(function(){
  217. $(this).colpickSetColor(this.value);
  218. });
  219. })
  220. }
  221. }
  222. function formData(form)
  223. {
  224. var d = {};
  225. var t = $(form).serializeArray();
  226. var u = '';
  227. $.each(t, function() {
  228. if (this.name.indexOf('search_') != -1) {
  229. d[this.name] = this.value;
  230. u += '&' + this.name + '=' + this.value;
  231. }
  232. });
  233. return [d,u];
  234. }
  235. function initMenu()
  236. {
  237. if(typeof(config.layout) != "undefined")
  238. {
  239. $('.list-unstyled li').each(function(j)
  240. {
  241. $(this).unbind('click').bind('click', function()
  242. {
  243. if ($(this).index() == i) {
  244. //return;
  245. }
  246. $('.list-unstyled .active').each(function()
  247. {
  248. $(this).attr('class', '');
  249. $(this).find('a').attr('class', '');
  250. })
  251. $(this).attr('class', 'active');
  252. var a = $(this).find('a');
  253. a.attr('class', 'subdrop');
  254. //alert($(this).attr('class'));
  255. })
  256. });
  257. /*
  258. $('.project-list').each(function(i)
  259. {
  260. $(this).unbind('click').bind('click', function()
  261. {
  262. if ($(this).index() == i) {
  263. return;
  264. }
  265. $('.project-list').each(function()
  266. {
  267. $(this).find('i').parent().attr('class', '');
  268. $(this).find('ul').attr('class', 'list-unstyled upload-menu');
  269. })
  270. $(this).find('i').parent().attr('class', 'active');
  271. $(this).find('ul').attr('class', 'list-unstyled upload-menu in');
  272. })
  273. });
  274. */
  275. }
  276. }
  277. function setOption(e, id)
  278. {
  279. var s = $("select[name="+id+"]");
  280. var v = s.val();
  281. if (!select) {
  282. select = s.clone();
  283. }
  284. s.find('option[parent]').remove();
  285. //查找出需要显示的option并复制
  286. var options = select.find("option[parent="+e.val()+"]").clone();
  287. //将需要显示的option添加到select中
  288. s.append(options);
  289. //因为option.remove()不会刷新控件,需要将新的option切换上去
  290. //这里排除了options.size() == 0的情况
  291. var state = 2;
  292. s.find('option').each(function()
  293. {
  294. var val = $(this).val();
  295. if (v == val) {
  296. state = 1;
  297. }
  298. });
  299. if (state == 1) {
  300. s.val(v);
  301. } else {
  302. s.val(0);
  303. }
  304. }
  305. function table()
  306. {
  307. if ($('.table-responsive').length) {
  308. $('.table-responsive[data-pattern]').each(function()
  309. {
  310. $(this).responsiveTable('update');
  311. });
  312. }
  313. }
  314. function pjax(param)
  315. {
  316. param.timeout = 8000;
  317. $.pjax(param);
  318. }
  319. function initDate()
  320. {
  321. $.datetimepicker.setLocale('ch');
  322. if($(".manage_date").length)
  323. {
  324. $(".manage_date").each(function()
  325. {
  326. $(this).datetimepicker(
  327. {
  328. //datepicker:false,
  329. format:'Y-m-d H:i:s',
  330. lang:'ch'
  331. });
  332. });
  333. }
  334. if($(".manage_day").length)
  335. {
  336. $(".manage_day").each(function()
  337. {
  338. $(this).datetimepicker(
  339. {
  340. //inline:true,
  341. timepicker:false,
  342. format:'Y-m-d',
  343. lang:'ch'
  344. });
  345. });
  346. }
  347. if($(".manage_sday").length)
  348. {
  349. $(".manage_sday").each(function()
  350. {
  351. $(this).datetimepicker(
  352. {
  353. //inline:true,
  354. timepicker:false,
  355. format:'Y-m-d',
  356. lang:'ch'
  357. });
  358. });
  359. }
  360. if($(".manage_sdate").length)
  361. {
  362. $(".manage_sdate").each(function()
  363. {
  364. $(this).datetimepicker(
  365. {
  366. //datepicker:false,
  367. format:'Y-m-d H:i:s',
  368. lang:'ch'
  369. });
  370. });
  371. }
  372. layui.use('laydate', function() {
  373. var laydate = layui.laydate;
  374. if ($('.manage_year').length) {
  375. $('.manage_year').each(function(i) {
  376. $(this).attr('id', 'manage_year_' + i);
  377. laydate.render({
  378. elem: '#manage_year_' + i,
  379. type: 'year',
  380. });
  381. })
  382. }
  383. if ($('.manage_month').length) {
  384. $('.manage_month').each(function(i) {
  385. $(this).attr('id', 'manage_month_' + i);
  386. laydate.render({
  387. elem: '#manage_month_' + i,
  388. type: 'month',
  389. });
  390. })
  391. }
  392. });
  393. }
  394. function initPic()
  395. {
  396. $('a[rel]').fancybox();
  397. }
  398. function initEditor(e)
  399. {
  400. if (!e) {
  401. e = $('.editor');
  402. }
  403. if(e.length)
  404. {
  405. var param = false;
  406. var editor = [];
  407. e.each(function()
  408. {
  409. var parent = $(this).parent().parent();
  410. //alert(parent.attr('id'));
  411. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  412. {
  413. return;
  414. }
  415. if (!param) {
  416. param = loadEditorParam($(this));
  417. }
  418. editor.push($(this).attr('id'));
  419. });
  420. if (editor) {
  421. for (var i in editor) {
  422. var id = editor[i];
  423. if (typeof(id) == 'string' && !editors[id]) {
  424. param.index = editors_index.length;
  425. editors[id] = KindEditor.create('#' + id, param);
  426. editors_index.push(id);
  427. }
  428. }
  429. }
  430. }
  431. if ($('.editor_tool').length) {
  432. $('.editor_tool').each(function()
  433. {
  434. $(this).click(function()
  435. {
  436. var tool = $(this).attr('tool');
  437. var id = $(this).attr('editor_id');
  438. editors[id].clickToolbar(tool);
  439. })
  440. });
  441. }
  442. }
  443. function loadEditorParam(e)
  444. {
  445. if(!e.length)
  446. {
  447. return;
  448. }
  449. var key = e.attr('key');
  450. var media = e.attr('media');
  451. var token = e.attr('token');
  452. var host = e.attr('host');
  453. var domain = e.attr('domain');
  454. var path = e.attr('path');
  455. var upload_search = e.attr('upload_search');
  456. var upload_search_value = e.attr('upload_search_value');
  457. var yun = {};
  458. if (token && host) {
  459. yun.token = token;
  460. yun.host = host;
  461. yun.domain = domain;
  462. yun.path = path;
  463. }
  464. if (!media) {
  465. media = key;
  466. }
  467. var view = config.upload.replace('save', 'view');
  468. var param = {
  469. height : "400px",
  470. allowImageUpload: true, //上传图片框本地上传的功能,false为隐藏,默认为true
  471. allowImageRemote : true, //上传图片框网络图片的功能,false为隐藏,默认为true
  472. allowFileManager : true, //浏览图片空间
  473. allowMediaUpload : true,
  474. filterMode : false, //HTML特殊代码过滤
  475. themeType : 'default',
  476. filePostName : 'file',
  477. dialogOffset : 0, //对话框距离页面顶部的位置,默认为0居中,
  478. uploadJson : config.upload + '.kindeditor?key=' + key + '&search=' + upload_search_value,
  479. uploadResJson : config.uploadRes + '.kindeditor?key=' + key + '&search=' + upload_search_value,
  480. uploadMediaJson : config.upload + '.kindeditor?key=' + media + '&search=' + upload_search_value,
  481. uploadYunJson : yun,
  482. fileManagerJson : view + '.files?key=' + media + '&upload_search=' + upload_search,
  483. htmlTags : {
  484. section : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  485. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  486. span : [
  487. 'id', 'class', '.color', '.background-color', '.font-size','.letter-spacing', '.background',
  488. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  489. ],
  490. div : [
  491. 'id', 'class', 'data-applet', 'data-file', 'data-id', 'data-key','.dever-video', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  492. '.background-color', '.font-size','.letter-spacing', '.font-weight', '.background',
  493. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  494. ],
  495. table: [
  496. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  497. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  498. '.font-size', '.font-weight', '.font-style', '.text-decoration', '.background',
  499. '.width', '.height', '.border-collapse'
  500. ],
  501. 'td,th': [
  502. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  503. '.text-align', '.color', '.background-color', '.font-size','.letter-spacing', '.font-weight',
  504. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  505. ],
  506. a : ['id', 'class', 'href', 'target', 'name'],
  507. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  508. img : ['id', 'class', 'data-applet', 'data-file', 'data-id', 'data-key', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  509. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  510. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size','.letter-spacing', '.background',
  511. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  512. ],
  513. pre : ['id', 'class'],
  514. hr : ['id', 'class', '.page-break-after'],
  515. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  516. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  517. },
  518. items : [
  519. 'preview', 'undo', 'redo', '|', 'cut', 'copy', 'paste',
  520. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  521. 'justifyfull', 'indent', 'outdent', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', 'source', '/',
  522. 'formatblock', 'fontsize', 'fontheight', '|', 'forecolor', 'hilitecolor', 'bold',
  523. 'italic', 'underline', 'lineheight', 'removeformat', 'insertorderedlist','|', 'image','table', 'hr', 'pagebreak','link', 'unlink'
  524. ]
  525. /*
  526. items : [
  527. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  528. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  529. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  530. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  531. 'formatblock', 'fontsize', 'fontheight', '|', 'forecolor', 'hilitecolor', 'bold',
  532. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage','table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  533. 'anchor', 'link', 'unlink'
  534. ]
  535. */
  536. //media
  537. /*
  538. items : [
  539. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  540. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  541. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  542. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  543. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  544. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  545. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  546. 'anchor', 'link', 'unlink', '|', 'about'
  547. ]
  548. */
  549. }
  550. if (editorWidth > 0) {
  551. param.width = editorWidth + 'px';
  552. param.minWidth = editorWidth + 'px';
  553. }
  554. return param;
  555. }
  556. //更新页面的提交按钮
  557. function submit()
  558. {
  559. if($(".save-data").length)
  560. {
  561. if (submitButton) {
  562. $(".save-data").each(function()
  563. {
  564. $(this).html(submitButton);
  565. })
  566. }
  567. $(".save-data").unbind('click').bind('click', function()
  568. {
  569. if (editors) {
  570. for (var i in editors) {
  571. if (i.indexOf('update_') != -1) {
  572. editors[i].sync();
  573. }
  574. }
  575. }
  576. //return;
  577. submitButton = $(this).html();
  578. $(this).html('loading...');
  579. $(this).unbind('click');
  580. submit_action();
  581. })
  582. }
  583. }
  584. //直接提交更新页的数据
  585. function submit_action()
  586. {
  587. $(".form1").submit();
  588. }
  589. //设置某一个input的值
  590. function set_update(id, value)
  591. {
  592. if($(id).length)
  593. {
  594. $(id).val(value);
  595. }
  596. }
  597. /**
  598. * 批量复制数据
  599. */
  600. function copy_data(e)
  601. {
  602. var html = '<div>';
  603. html += '<div><span>请输入要复制的数量:</span><input type="text" class="form-control form_margin" id="temp_copy_num" /></div>';
  604. html += '</div>';
  605. $('#dever_modal_body').html(html);
  606. $('#dever_modal_title').html('复制数据');
  607. $("#dever_modal_yes").unbind('click').bind('click', function()
  608. {
  609. set_update('#copy_num', $("#temp_copy_num").val());
  610. set_update('#update_where_id', 0);
  611. submit_action();
  612. });
  613. }
  614. //头部菜单
  615. function topMenu(e)
  616. {
  617. var p = e.parent().parent().parent().find('span');
  618. p.html(e.html());
  619. //更新当前的精细权限
  620. var url = config.host + 'top.update_action?json=1';
  621. var id = e.attr('data-id');
  622. $.post(url, {id:id}, function(t)
  623. {
  624. var href = location.href;
  625. if(location.href.indexOf('where_id') != -1)
  626. {
  627. var temp = location.href.split('where_id');
  628. href = temp[0] + 'where_id=' + t;
  629. }
  630. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  631. {
  632. pjax({url: href, container: config.layout})
  633. }
  634. else
  635. {
  636. location.href = href;
  637. }
  638. })
  639. }
  640. //头部菜单
  641. function topCMenu(e)
  642. {
  643. var p = e.parent().parent().parent().find('span');
  644. p.html(e.html());
  645. //更新当前的精细权限
  646. var url = config.host + 'company.set?json=1';
  647. var id = e.attr('data-id');
  648. $.post(url, {company_id:id}, function(t)
  649. {
  650. location.reload();
  651. })
  652. }
  653. //链接跳转
  654. function go(key, value)
  655. {
  656. var href = location.href;
  657. if(location.href.indexOf(key) != -1)
  658. {
  659. var temp = location.href.split(key + '=');
  660. href = temp[0] + key + '=' + value + '&' + temp[1];
  661. } else {
  662. href = href + '&' + key + '=' + value;
  663. }
  664. location.href = href;
  665. }
  666. //更新页面的批量载入选择
  667. function loadShow()
  668. {
  669. if($(".show_input").length)
  670. {
  671. $(".show_input input:radio").each(function()
  672. {
  673. if ($(this).attr('checked'))
  674. {
  675. inputShow($(this), $(this).attr('show_id'), 'input');
  676. }
  677. var filter = $(this).attr('lay-filter');
  678. if (filter && filter.indexOf('_all') == -1) {
  679. form.on('radio('+filter+')', function(data) {
  680. inputShow($(this), $(this).attr('show_id'), 'input');
  681. })
  682. }
  683. })
  684. $(".show_input input:checkbox").each(function()
  685. {
  686. if ($(this).attr('checked'))
  687. {
  688. inputShow($(this), $(this).attr('show_id'), 'input');
  689. }
  690. var filter = $(this).attr('lay-filter');
  691. if (filter && filter.indexOf('_all') == -1) {
  692. form.on('checkbox('+filter+')', function(data) {
  693. inputShow($(this), $(this).attr('show_id'), 'input');
  694. })
  695. }
  696. })
  697. $(".show_input select").each(function()
  698. {
  699. if($(this).find('option:selected').text())
  700. {
  701. inputShow($(this), $(this).attr('show_id'));
  702. }
  703. })
  704. }
  705. if($(".control_url").length)
  706. {
  707. $(".control_url input:radio").each(function()
  708. {
  709. if ($(this).attr('checked'))
  710. {
  711. inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
  712. }
  713. var filter = $(this).attr('lay-filter');
  714. if (filter) {
  715. form.on('radio('+filter+')', function(data) {
  716. inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
  717. })
  718. }
  719. })
  720. $(".control_url input:checkbox").each(function()
  721. {
  722. if ($(this).attr('checked'))
  723. {
  724. inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
  725. }
  726. var filter = $(this).attr('lay-filter');
  727. if (filter) {
  728. form.on('checkbox('+filter+')', function(data) {
  729. inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
  730. })
  731. }
  732. })
  733. $(".control_url select").each(function()
  734. {
  735. if($(this).find('option:selected').text())
  736. {
  737. inputShowUrl($(this), $(this).attr('control_url'), $(this).attr('data-id'));
  738. }
  739. })
  740. }
  741. }
  742. function menuGroup(id, e)
  743. {
  744. if (typeof(layer) != 'undefined' && admingroup) {
  745. layer.close(admingroup);
  746. }
  747. $('.menu_group').hide();
  748. $('.menu_group_' + id).show();
  749. $('.menu_group_' + id).eq(0).addClass('layui-nav-itemed');
  750. }
  751. function inputShow(e,n,t)
  752. {
  753. $(".show_" + n).hide();
  754. if (e.attr('v')) {
  755. var v = e.attr('v');
  756. } else {
  757. var v = e.val();
  758. }
  759. if (t == 'input') {
  760. var item = e.parent().find('input');
  761. item.each(function()
  762. {
  763. if($(this).get(0).checked == true)
  764. {
  765. inputShowOne($(this),n);
  766. }
  767. });
  768. } else {
  769. var item = e.parent().find('select');
  770. item.each(function()
  771. {
  772. if($(this).find('option:selected').text())
  773. {
  774. inputShowOne($(this),n);
  775. }
  776. });
  777. }
  778. var array = ['input', 'textarea'];
  779. for(var a in array)
  780. {
  781. if ($(".show_" + n).find(array[a]).length) {
  782. var s = $(".show_" + n).find(array[a]);
  783. var p = s.parent().parent().parent().css('display');
  784. var c = s.attr('class');
  785. if (c.indexOf('validate[required]') > -1 && p == 'none') {
  786. $(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
  787. }
  788. if (c.indexOf('validates') > -1) {
  789. $(".show_" + n).find(array[a]).removeClass('validates').addClass('validate[required]');
  790. }
  791. }
  792. }
  793. }
  794. function inputShowOne(e,n)
  795. {
  796. var value = e.val();
  797. var ele = '.show_' + n + '_ajax';
  798. if ($(ele).length) {
  799. $(ele).each(function()
  800. {
  801. var self = $(this);
  802. var url = self.attr('dever-ajax');
  803. $.getJSON(url + value + '&callback=?', function(t) {
  804. self.find('.margin-top').html(t.data);
  805. inputShowOneValiDate(self);
  806. checkbox();
  807. })
  808. })
  809. } else {
  810. ele = '.show_' + n + '_' + value;
  811. inputShowOneValiDate($(ele));
  812. }
  813. }
  814. function inputShowOneValiDate(e)
  815. {
  816. e.show();
  817. var array = ['input', 'textarea'];
  818. for(var a in array)
  819. {
  820. if(e.length && e.attr('class').indexOf('show_no') == -1)
  821. {
  822. e.find(array[a]).each(function()
  823. {
  824. var parent = $(this).parent();
  825. if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
  826. {
  827. $(this).addClass('validate[required]');
  828. }
  829. })
  830. }
  831. }
  832. }
  833. //批量更新
  834. var list_mul_state = 1;
  835. function list_mul(e, t, url)
  836. {
  837. if (t == 1) {
  838. var type = parseInt($("#mul_type").val());
  839. if(type != 1 && type != 2)
  840. {
  841. showAlert('您还没有选择数据');
  842. return;
  843. }
  844. }
  845. if (list_mul_state == 2) {
  846. showAlert('请不要重复点击');
  847. return;
  848. }
  849. var index = layer.confirm('确定进行此项操作吗?', function()
  850. {
  851. list_mul_state = 2;
  852. $('#method').val('mul');
  853. $('#function').val('msg');
  854. layer.close(index);
  855. if (url) {
  856. $('#method').val('mul.' + url);
  857. }
  858. $('#form1').attr('target', 'f1').submit();
  859. })
  860. }
  861. //搜索
  862. function list_search(e)
  863. {
  864. $('#method').val('search');
  865. $('#function').val('');
  866. $('#form1').attr('target', '').submit();
  867. }
  868. //更新数据
  869. function update(e, id, project, table, notice, menu_id)
  870. {
  871. var call = function()
  872. {
  873. var col = e.attr('name').replace('up_col_', '');
  874. var value = e.val();
  875. var old = e.attr('data-old');
  876. var url = config.host + 'database.update_action_commit?json=1';
  877. $.post(url, {where_id:id,col:col,value:value,project:project,table:table,menu_id:menu_id}, function(t)
  878. {
  879. var t = eval('('+t+')');
  880. if (t.status == 1) {
  881. e.attr('data-old', value);
  882. notify('操作已成功!您的操作已修改当前选项!', e);
  883. preview();
  884. } else {
  885. msg(t);
  886. e.val(old);
  887. }
  888. })
  889. }
  890. if(notice)
  891. {
  892. var index = layer.confirm(notice, function(i, l)
  893. {
  894. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  895. layer.close(index);
  896. call();
  897. });
  898. }
  899. else
  900. {
  901. call();
  902. }
  903. }
  904. function notify(msg, e)
  905. {
  906. if (!e) {
  907. layer.msg(msg);
  908. return;
  909. }
  910. layer.tips(msg, e, {
  911. tips: [1, '#3595CC']
  912. });
  913. /*
  914. var notice = new PNotify({
  915. title: '提示信息',
  916. text: msg,
  917. buttons: {
  918. closer: false,
  919. sticker: false
  920. }
  921. });
  922. notice.get().click(function() {
  923. notice.remove();
  924. });
  925. */
  926. }
  927. //模板选择
  928. function template()
  929. {
  930. if(config.template)
  931. {
  932. $('body').attr('class', 'theme-' + config.template);
  933. }
  934. if($(".selector").length)
  935. {
  936. $(".selector").each(function()
  937. {
  938. if($(this).data('check') == 'checked')
  939. {
  940. selector($(this));
  941. }
  942. })
  943. }
  944. }
  945. //选择器
  946. function selector(e)
  947. {
  948. var value = e.data('value');
  949. var name = e.data('name');
  950. $('#'+name+'_value').val(value);
  951. $('.'+name+'_selector').children().css({'border':'2px solid #ccc'});
  952. e.children().css({'border':'2px solid #1e9fff'});
  953. if(name == 'update_template')
  954. {
  955. $('body').attr('class', 'theme-' + value);
  956. }
  957. }
  958. //根据e的值,来载入其他数据
  959. function loading(e, data, type)
  960. {
  961. if (type == 1) {
  962. var value = e.attr('v');
  963. } else {
  964. var value = e.val();
  965. if (e.attr('id') && e.attr('id').indexOf('_temp') != -1) {
  966. var id = e.attr('id').replace('_temp', '');
  967. if ($('#' + id).length) {
  968. var value = $('#' + id).val();
  969. }
  970. }
  971. }
  972. if (data.element) {
  973. if (data.url) {
  974. data.value = value;
  975. $.getJSON(data.url + '&json=1', data, function(t) {
  976. $('#update_'+data.element+'').val(t.data);
  977. });
  978. } else {
  979. $('#update_'+data.element+'').val(value);
  980. }
  981. } else if(data.url) {
  982. var parent = e.parent().parent();
  983. var tagName = parent.prop("tagName");
  984. var pid = '';
  985. if (tagName == 'TD') {
  986. pid = parent.parent().attr('id');
  987. }
  988. data.value = value;
  989. data.where_id = $('#update_where_id').val();
  990. data.table = $('#table').val();
  991. data.project = $('#project').val();
  992. if (data.col) {
  993. if (data.col.indexOf(',') != -1) {
  994. var s = data.col.split(',');
  995. for (var i in s) {
  996. if (i >= 0) {
  997. var a = s[i];
  998. if (pid) {
  999. var b = $('#update_'+ (pid + '_i_' + a));
  1000. if (b.length) {
  1001. var ue = b;
  1002. } else {
  1003. var ue = $('#update_'+a);
  1004. }
  1005. } else {
  1006. var ue = $('#update_'+a);
  1007. }
  1008. data[s[i]] = ue.val();
  1009. if (!data[s[i]]) {
  1010. data[s[i]] = ue.attr('v');
  1011. }
  1012. }
  1013. }
  1014. } else {
  1015. var a = data.col;
  1016. if (pid) {
  1017. var b = $('#update_'+ (pid + '_i_' + a));
  1018. if (b.length) {
  1019. var ue = b;
  1020. } else {
  1021. var ue = $('#update_'+a);
  1022. }
  1023. } else {
  1024. var ue = $('#update_'+a);
  1025. }
  1026. data[a] = ue.val();
  1027. if (!data[a]) {
  1028. data[a] = ue.attr('v');
  1029. }
  1030. }
  1031. }
  1032. $.getJSON(data.url + '&json=1', data, function(s) {
  1033. t = s.data;
  1034. if (typeof(t) == 'object') {
  1035. var r = t.remove;
  1036. if (r) {
  1037. for(var i in r) {
  1038. $(r[i]).remove();
  1039. }
  1040. }
  1041. var o = t.option;
  1042. if (o) {
  1043. for (var i in o) {
  1044. if (pid) {
  1045. var ti = pid + '_i_' + i;
  1046. var ue = $('#update_'+ti);
  1047. } else {
  1048. var ue = $('#update_'+i);
  1049. }
  1050. ue.html(o[i]);
  1051. }
  1052. }
  1053. var d = t.data;
  1054. t = t.html;
  1055. if (d) {
  1056. for(var i in d) {
  1057. if (pid) {
  1058. var ti = pid + '_i_' + i;
  1059. var ue = $('#update_'+ti);
  1060. } else {
  1061. var ue = $('#update_'+i);
  1062. }
  1063. var div = ue.prop("tagName");
  1064. if (div == 'DIV') {
  1065. ue.html(d[i]);
  1066. } else {
  1067. ue.val(d[i]);
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if (t) {
  1073. if (t.indexOf('onblur') != -1) {
  1074. eval(t);
  1075. } else {
  1076. if (t.indexOf('status') == -1) {
  1077. if (data.type == 1) {
  1078. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  1079. {
  1080. $(this).remove();
  1081. });
  1082. } else {
  1083. $('.checking_-1,.checking_3,.checking_4').each(function()
  1084. {
  1085. $(this).remove();
  1086. });
  1087. }
  1088. if (!parent.parent().find('.bind_show').length) {
  1089. if (tagName == 'TD') {
  1090. parent.next().html('<div class="bind_show">' + t + '</div>');
  1091. } else {
  1092. parent.after('<div class="bind_show">' + t + '</div>');
  1093. }
  1094. } else if (parent.parent().find('.bind_show').html() != t) {
  1095. parent.parent().find('.bind_show').html(t);
  1096. }
  1097. checkbox();
  1098. }
  1099. }
  1100. }
  1101. });
  1102. }
  1103. }
  1104. //根据e的值,来载入其他数据,先检测是否选中
  1105. function checking(name, e, data)
  1106. {
  1107. var value = [];
  1108. $('.' + name).each(function()
  1109. {
  1110. if($(this).get(0).checked == true)
  1111. {
  1112. value.push($(this).val());
  1113. }
  1114. });
  1115. if(data.url)
  1116. {
  1117. data.value = value.join(',');
  1118. data.where_id = $('#update_where_id').val();
  1119. data.table = $('#table').val();
  1120. data.project = $('#project').val();
  1121. if(data.check)
  1122. {
  1123. data.check_value = false;
  1124. $(data.check).each(function()
  1125. {
  1126. if($(this).get(0).checked == true)
  1127. {
  1128. data.check_value = $(this).val();
  1129. }
  1130. });
  1131. }
  1132. $.getJSON(data.url, data, function(s)
  1133. {
  1134. t = s.data;
  1135. var parent = e.parent().parent().parent();
  1136. if(t.indexOf('status') == -1)
  1137. {
  1138. if(data.type == 1)
  1139. {
  1140. $('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
  1141. {
  1142. $(this).remove();
  1143. });
  1144. }
  1145. else
  1146. {
  1147. $('.checking_-1,.checking_3,.checking_4').each(function()
  1148. {
  1149. $(this).remove();
  1150. });
  1151. }
  1152. parent.after(t);
  1153. checkbox();
  1154. }
  1155. });
  1156. }
  1157. }
  1158. function autocomplete()
  1159. {
  1160. if ($("input").length) {
  1161. $("input").each(function()
  1162. {
  1163. $(this).attr('autocomplete', 'off');
  1164. });
  1165. }
  1166. if($("input[complete]").length)
  1167. {
  1168. $("input[complete]").each(function()
  1169. {
  1170. var cache = {};
  1171. var self = $(this);
  1172. self.autocomplete(
  1173. {
  1174. minLength: 2,
  1175. source: function( request, response )
  1176. {
  1177. var term = request.term.split( /,\s*/ );
  1178. request.term = term.pop();
  1179. if ( request.term in cache ) {
  1180. response( cache[ request.term ] );
  1181. return;
  1182. }
  1183. var cate = self.attr('complete_cate');
  1184. if (cate) {
  1185. request[cate] = $('#update_' + cate).val();
  1186. }
  1187. $.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
  1188. data = data.data
  1189. cache[ term ] = data;
  1190. var state = true;
  1191. for(var i in data)
  1192. {
  1193. if(data[i].id <=0)
  1194. {
  1195. state = false;
  1196. }
  1197. }
  1198. if(state)
  1199. {
  1200. response( data );
  1201. }
  1202. });
  1203. },
  1204. focus: function() {
  1205. // prevent value inserted on focus
  1206. return false;
  1207. },
  1208. select: function( event, ui )
  1209. {
  1210. //log( "Selected: " + ui.item.value + " aka " + ui.item.id );
  1211. var value = self.attr('complete_callback');
  1212. var id = self.attr('id').replace('_temp', '');
  1213. var name = self.attr('name').replace('_temp', '');
  1214. //var e = $("#" + id);
  1215. var e = self;
  1216. var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
  1217. if (!$("#" + id + '_show').length) {
  1218. e.parent().append(html);
  1219. }
  1220. if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
  1221. {
  1222. var link = '';
  1223. var attr = '';
  1224. var pic = '';
  1225. if (ui.item['pic']) {
  1226. pic = '<a href="javascript:;"><img src="'+ui.item['pic']+'" width="100"></a>';
  1227. }
  1228. if (ui.item['link']) {
  1229. link = ui.item['link'];
  1230. attr = ' target="_blank"';
  1231. }
  1232. var html = '<tr><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+ui.item[value]+'"/>&nbsp;&nbsp;'+pic+'<a href="'+link+'" '+attr+' title="'+ui.item.value+'">'+ui.item.value+'</td><td width="10%"><a href="javascript:;" onclick="autocomplete_del($(this), \''+id+'\', \''+ui.item[value]+'\', \''+name+'\')">[删除]</a></td></tr>';
  1233. $("#" + id + '_show').append(html);
  1234. if (!autocomplete_value[id]) {
  1235. autocomplete_value[id] = [];
  1236. }
  1237. autocomplete_value[id].push(ui.item[value]);
  1238. }
  1239. ui.item.value = '';
  1240. }
  1241. });
  1242. })
  1243. }
  1244. }
  1245. function autocomplete_del(e, id, value, name)
  1246. {
  1247. e.parent().parent().remove();
  1248. autocomplete_value[id].remove(value);
  1249. var len = autocomplete_value[id].length;
  1250. if (len < 1 && !($('#del_' + name).length)) {
  1251. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1252. }
  1253. }
  1254. function searchbox(id, e)
  1255. {
  1256. var self = e.parent().find("input");
  1257. var v = self.val();
  1258. var key = self.attr('id').replace('_temp', '');
  1259. var request = {};
  1260. request.term = v;
  1261. var cate = self.attr('searchbox_cate');
  1262. if (cate) {
  1263. var c = cate.split(',');
  1264. for (var i in c) {
  1265. if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
  1266. request[c[i]] = $('#'+c[i]).val();
  1267. }
  1268. }
  1269. }
  1270. var index = layer.msg('加载中...');
  1271. $.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
  1272. layer.close(index);
  1273. var data = data.data;
  1274. if (!data) {
  1275. showAlert('没有搜索到数据');
  1276. return;
  1277. }
  1278. var html = '<div class="layui-tab layui-tab-brief"" overflow><ul class="layui-tab-title" style="height: 60px; overflow: auto;">{cate}</ul><div class="layui-tab-content" style="padding-top: 0px;">{content}</div><div style="margin-left:10px"><input type="checkbox" onclick="searchbox_checkall($(this), \'searchbox_'+id+'\')"/>&nbsp;全选<button type="button" onclick="searchbox_yes(\''+self.attr('id')+'\', \'.searchbox_'+id+'\', true)" class="btn btn-primary layui-btn layuiadmin-btn-list" style="margin-left:10px;margin-top: -2px;"><i class="fa fa-save"></i> 确定</button></div></div>';
  1279. if (data) {
  1280. var j = 0;
  1281. var c = '';
  1282. var s = '';
  1283. var cateHtml = '';
  1284. var content = '';
  1285. for (var i in data) {
  1286. if (j == 0) {
  1287. c = 'class="layui-this"';
  1288. s = 'layui-show';
  1289. } else {
  1290. c = '';
  1291. s = '';
  1292. }
  1293. cateHtml += '<li '+c+'>'+data[i].name+'</li>';
  1294. j++;
  1295. var item = '<div class="layui-tab-item '+s+'"><div style="margin-top: 10px;overflow: auto;max-height: 500px;"><table class="table table-small-font table-bordered">{head}';
  1296. var p = false;
  1297. for (var k in data[i].child) {
  1298. if (data[i].child[k].name) {
  1299. var pic = '';
  1300. if (data[i].child[k].pic) {
  1301. pic = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
  1302. p = true;
  1303. }
  1304. var check = '';
  1305. if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
  1306. check = 'checked';
  1307. }
  1308. item += '<tr><td width="10%"><input '+check+' type="checkbox" onclick="searchbox_checkone($(this), \''+self.attr('id')+'\', \''+key+'\', '+data[i].child[k].id+', \''+key+'\')" class="searchbox_'+id+' searchbox_'+id+'_'+data[i].id+'" data-class="searchbox_'+id+'_'+data[i].id+'" data-pic="'+data[i].child[k].pic+'" data-name="'+data[i].child[k].name+'" data-value="'+data[i].child[k].id+'" data-link="'+data[i].child[k].link+'" value="'+data[i].child[k].id+'"/></td>'+pic+'<td><a href="" >'+data[i].child[k].name+'</td></tr>';
  1309. }
  1310. }
  1311. item += '</table></div></div>';
  1312. var head = '<tr><td width="10%"><input type="checkbox" class="searchbox_'+id+'" onclick="searchbox_checkall($(this), \'searchbox_'+id+'_'+data[i].id+'\')"/></td><td>标题</td></tr>';
  1313. if (p) {
  1314. head = head.replace('</td><td>', '</td><td>图片</td><td>');
  1315. }
  1316. item = item.replace('{head}', head);
  1317. content += item;
  1318. }
  1319. if (cateHtml) {
  1320. html = html.replace('{cate}', cateHtml);
  1321. }
  1322. if (content) {
  1323. html = html.replace('{content}', content);
  1324. }
  1325. }
  1326. var config = {
  1327. type: 1,
  1328. shade: 0.3,
  1329. title : false,
  1330. shadeClose : true,
  1331. area : ['800px', '600px'],
  1332. content: html
  1333. };
  1334. layer.open(config);
  1335. layui.use('element', function(){
  1336. var element = layui.element;
  1337. });
  1338. });
  1339. }
  1340. function searchbox_checkall(e, id)
  1341. {
  1342. $('.' + id).each(function()
  1343. {
  1344. $(this).get(0).checked = e.get(0).checked;
  1345. //$(this).click();
  1346. })
  1347. }
  1348. function searchbox_checkone(e, id, key, value)
  1349. {
  1350. if (!e.get(0).checked) {
  1351. $('#searchbox_check_' + key + '_' + value).remove();
  1352. searchbox_value.remove(value);
  1353. var len = searchbox_value.length;
  1354. var name = key.replace('_value', '');
  1355. if (len < 1 && !($('#del_' + name).length)) {
  1356. $("#" + key + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1357. }
  1358. } else {
  1359. var c = '.' + e.attr('data-class');
  1360. searchbox_yes(id, c, false);
  1361. }
  1362. }
  1363. function searchbox_yes(e, c, state)
  1364. {
  1365. var self = $("#" +e);
  1366. $(c).each(function()
  1367. {
  1368. if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
  1369. var value = self.attr('searchbox_callback');
  1370. var id = self.attr('id').replace('_temp', '');
  1371. var name = self.attr('name').replace('_temp', '');
  1372. var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
  1373. if (!$("#" + id + '_show').length) {
  1374. self.parent().append(html);
  1375. }
  1376. if (!$("#" + id + '_show').find('#searchbox_check_'+id+'_'+$(this).attr('data-value')).length)
  1377. {
  1378. var link = '';
  1379. var attr = '';
  1380. var pic = '';
  1381. if ($(this).attr('data-pic') && $(this).attr('data-pic') != 'undefined') {
  1382. pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
  1383. }
  1384. if ($(this).attr('data-link')) {
  1385. link = $(this).attr('data-link');
  1386. attr = ' target="_blank"';
  1387. }
  1388. var html = '<tr id="searchbox_check_'+id+'_'+$(this).attr('data-value')+'"><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+$(this).attr('data-value')+'"/>&nbsp;&nbsp;'+pic+'<a href="'+link+'" '+attr+' title="'+$(this).attr('data-name')+'">'+$(this).attr('data-name')+'</td><td width="10%"><a href="javascript:;" onclick="searchbox_del($(this), \''+id+'\', \''+$(this).attr('data-value')+'\', \''+name+'\')">[删除]</a></td></tr>';
  1389. $("#" + id + '_show').append(html);
  1390. if (!searchbox_value[id]) {
  1391. searchbox_value[id] = [];
  1392. }
  1393. searchbox_value[id].push($(this).attr('data-value'));
  1394. }
  1395. }
  1396. })
  1397. if (state == true) {
  1398. layer.closeAll();
  1399. }
  1400. }
  1401. function searchbox_del(e, id, value, name)
  1402. {
  1403. e.parent().parent().remove();
  1404. searchbox_value.remove(value);
  1405. var len = searchbox_value.length;
  1406. if (len < 1 && !($('#del_' + name).length)) {
  1407. $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
  1408. }
  1409. }
  1410. //后台通用的提示
  1411. function msg(value)
  1412. {
  1413. $("#dever_modal_no").click();
  1414. if(!value.data)
  1415. {
  1416. value.data = value.msg;
  1417. }
  1418. if(value == 1)
  1419. {
  1420. location.reload();
  1421. return;
  1422. }
  1423. submit();
  1424. var url = '';
  1425. if(value.data != 'reload' && value.status == 2 && value.code == 1)
  1426. {
  1427. if ($('#dever_submit').length && value.uuid) {
  1428. $('#dever_submit').val(value.uuid);
  1429. }
  1430. showAlertFlag = false;
  1431. list_mul_state = 1;
  1432. showAlert(value.msg, false, '错误提示');
  1433. //alert(value.data);
  1434. //location.reload();
  1435. return;
  1436. }
  1437. else if(value.data == 'reload')
  1438. {
  1439. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1440. {
  1441. pjax({url: location.href, container: config.layout})
  1442. }
  1443. else
  1444. {
  1445. location.reload();
  1446. }
  1447. return;
  1448. }
  1449. else if(value.data == 'refer')
  1450. {
  1451. history.back();
  1452. return;
  1453. }
  1454. else
  1455. {
  1456. if(value.data.indexOf('http') != -1)
  1457. {
  1458. url = value.data;
  1459. }
  1460. else if($("#url").length)
  1461. {
  1462. url = $("#url").val();
  1463. }
  1464. else
  1465. {
  1466. notify(value.data)
  1467. return;
  1468. }
  1469. if(url)
  1470. {
  1471. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1472. {
  1473. pjax({url: url, container: config.layout});
  1474. }
  1475. else
  1476. {
  1477. location.href = url;
  1478. }
  1479. }
  1480. else
  1481. {
  1482. if(typeof(config.layout) != "undefined" && $(config.layout).length)
  1483. {
  1484. pjax({url: location.href, container: config.layout});
  1485. }
  1486. else
  1487. {
  1488. location.reload();
  1489. }
  1490. }
  1491. }
  1492. return;
  1493. }
  1494. /**
  1495. * 处理多选问题,处理全选按钮
  1496. */
  1497. function checkbox()
  1498. {
  1499. if($(".autoload").length)
  1500. {
  1501. $(".autoload").each(function()
  1502. {
  1503. if($(this).get(0).checked == true)
  1504. {
  1505. $(this).removeClass('autoload');
  1506. $(this).load();
  1507. }
  1508. });
  1509. }
  1510. if($(".autoload_text").length)
  1511. {
  1512. $(".autoload_text").each(function()
  1513. {
  1514. if($(this).val())
  1515. {
  1516. $(this).removeClass('autoload_text');
  1517. $(this).load();
  1518. }
  1519. });
  1520. }
  1521. var name = 'checkbox-checkall';
  1522. var checkbox = $("." + name);
  1523. if(checkbox.length)
  1524. {
  1525. if (checkbox.attr('title')) {
  1526. checkbox.each(function()
  1527. {
  1528. var self = $(this);
  1529. var ele = "." + name + "-" + self.val();
  1530. var len = $(ele).length;
  1531. $(ele).each(function()
  1532. {
  1533. if(this.checked == true)
  1534. {
  1535. self.get(0).checked = true;
  1536. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1537. inputShow($(this), 'col');
  1538. }
  1539. }
  1540. var filter = $(this).attr('lay-filter');
  1541. if (filter) {
  1542. form.on('checkbox('+filter+')', function (data) {
  1543. var next = $(this).next();
  1544. var state = $(this).attr('data-state');
  1545. if(data.elem.checked == true)
  1546. {
  1547. if (state == 2) {
  1548. self.get(0).checked = true;
  1549. } else {
  1550. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1551. self.get(0).checked = true;
  1552. }
  1553. }
  1554. if(self.attr('type') == 'radio')
  1555. {
  1556. //如果父选项是radio类型,做下限制
  1557. //alert(1);
  1558. }
  1559. if($("#mul_type").length)
  1560. {
  1561. $("#mul_type").val(1);
  1562. }
  1563. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1564. {
  1565. next.attr('disabled', false);
  1566. }
  1567. }
  1568. else
  1569. {
  1570. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1571. {
  1572. next.attr('disabled', true);
  1573. }
  1574. }
  1575. var num = 0;
  1576. var id = $(this).attr('name');
  1577. var hidden = id;
  1578. id = id.replace('[]', '');
  1579. $(ele).each(function()
  1580. {
  1581. if($(this).get(0).checked == true)
  1582. {
  1583. num = 1;
  1584. /*
  1585. if ($('#' + id).length) {
  1586. $('#' + id).remove();
  1587. }*/
  1588. }
  1589. });
  1590. if(num == 0)
  1591. {
  1592. self.get(0).checked = false;
  1593. if($("#mul_type").length)
  1594. {
  1595. $("#mul_type").val(0);
  1596. }
  1597. if (state == 2) {
  1598. } else if (!$('#' + id).length) {
  1599. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+id+'" />');
  1600. }
  1601. }
  1602. form.render('checkbox');
  1603. });
  1604. }
  1605. });
  1606. var filter = self.attr('lay-filter');
  1607. form.on('checkbox('+filter+')', function (data) {
  1608. $("." + name + "-" + $(this).val()).each(function()
  1609. {
  1610. this.checked = data.elem.checked;
  1611. var next = $(this).next();
  1612. if(this.checked == true)
  1613. {
  1614. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1615. {
  1616. next.attr('disabled', false);
  1617. }
  1618. if($("#mul_type").length)
  1619. {
  1620. $("#mul_type").val(1);
  1621. }
  1622. }
  1623. else
  1624. {
  1625. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1626. {
  1627. next.attr('disabled', true);
  1628. }
  1629. if($("#mul_type").length)
  1630. {
  1631. $("#mul_type").val(0);
  1632. }
  1633. }
  1634. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('Show') > 0) {
  1635. //inputShow($(this), 'col');
  1636. inputShow($(this), $(this).attr('show_id'), 'input');
  1637. }
  1638. form.render('checkbox');
  1639. });
  1640. });
  1641. form.render('checkbox');
  1642. });
  1643. } else {
  1644. checkbox.unbind('click').bind('click', function()
  1645. {
  1646. var self = $(this);
  1647. $("." + name + "-" + self.val()).each(function()
  1648. {
  1649. $(this).get(0).checked = self.get(0).checked;
  1650. var next = $(this).next();
  1651. if($(this).get(0).checked == true)
  1652. {
  1653. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1654. {
  1655. next.attr('disabled', false);
  1656. }
  1657. if($("#mul_type").length)
  1658. {
  1659. $("#mul_type").val(1);
  1660. }
  1661. }
  1662. else
  1663. {
  1664. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1665. {
  1666. next.attr('disabled', true);
  1667. }
  1668. if($("#mul_type").length)
  1669. {
  1670. $("#mul_type").val(0);
  1671. }
  1672. }
  1673. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('Show') > 0) {
  1674. //inputShow($(this), 'col');
  1675. inputShow($(this), $(this).attr('show_id'), 'input');
  1676. }
  1677. })
  1678. });
  1679. checkbox.each(function()
  1680. {
  1681. var self = $(this);
  1682. var len = $("." + name + "-" + self.val()).length;
  1683. $("." + name + "-" + self.val()).each(function()
  1684. {
  1685. $(this).unbind('click').bind('click', function()
  1686. {
  1687. var next = $(this).next();
  1688. var state = $(this).attr('data-state');
  1689. if($(this).get(0).checked == true)
  1690. {
  1691. if (state == 2) {
  1692. self.get(0).checked = true;
  1693. } else {
  1694. if ($("." + name + "-" + self.val()+":checked").length >= len) {
  1695. self.get(0).checked = true;
  1696. }
  1697. }
  1698. if(self.attr('type') == 'radio')
  1699. {
  1700. //如果父选项是radio类型,做下限制
  1701. //alert(1);
  1702. }
  1703. if($("#mul_type").length)
  1704. {
  1705. $("#mul_type").val(1);
  1706. }
  1707. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1708. {
  1709. next.attr('disabled', false);
  1710. }
  1711. }
  1712. else
  1713. {
  1714. if(next.length && next.attr('type') != 'checkbox' && next.attr('type') != 'hidden')
  1715. {
  1716. next.attr('disabled', true);
  1717. }
  1718. }
  1719. var num = 0;
  1720. $("." + name + "-" + self.val()).each(function()
  1721. {
  1722. if($(this).get(0).checked == true)
  1723. {
  1724. num = 1;
  1725. }
  1726. });
  1727. var id = $(this).attr('name');
  1728. var hidden = id;
  1729. id = id.replace('[]', '');
  1730. if(num == 0)
  1731. {
  1732. self.get(0).checked = false;
  1733. if($("#mul_type").length)
  1734. {
  1735. $("#mul_type").val(0);
  1736. }
  1737. if (state == 2) {
  1738. } else if (!$('#' + id).length) {
  1739. self.parent().append('<input type="hidden" value="0" id="'+id+'" name="'+hidden+'" />');
  1740. }
  1741. } else {
  1742. /*
  1743. if ($('#' + id).length) {
  1744. $('#' + id).remove();
  1745. }*/
  1746. }
  1747. })
  1748. if($(this).get(0).checked == true)
  1749. {
  1750. self.get(0).checked = true;
  1751. if ($(this).attr('onclick') && $(this).attr('onclick').indexOf('show') > 0) {
  1752. inputShow($(this), 'col');
  1753. }
  1754. }
  1755. });
  1756. })
  1757. }
  1758. }
  1759. }
  1760. /**
  1761. * 处理双击编辑
  1762. */
  1763. function edit()
  1764. {
  1765. if($(".edit").length)
  1766. {
  1767. $(".edit").each(function()
  1768. {
  1769. $(this).bind('dblclick', function()
  1770. {
  1771. var col = $(this).attr('data-col');
  1772. var project = $(this).attr('data-project');
  1773. var table = $(this).attr('data-table');
  1774. var url = $(this).attr('data-url');
  1775. var id = $(this).attr('data-id');
  1776. var html = $(this).attr('data-content');
  1777. var type = $(this).attr('data-type');
  1778. if($(this).find(".edit-content").length)
  1779. {
  1780. html = $(this).find(".edit-content").html();
  1781. html = html.replace('<!--', '<');
  1782. html = html.replace('-->', '>');
  1783. }
  1784. if (html == '点此编辑') {
  1785. html = '';
  1786. }
  1787. if(html.indexOf('input') == -1)
  1788. {
  1789. if(type && type == 'textarea')
  1790. {
  1791. $(this).html('<textarea type="text" name="edit" id="edit" rows="10" cols="60" class="layui-input">'+html+'</textarea>');
  1792. }
  1793. else
  1794. {
  1795. $(this).html('<input type="text" name="edit" id="edit" value="'+html+'" class="layui-input">');
  1796. }
  1797. var self = $(this);
  1798. self.find("#edit").focus();
  1799. self.find("#edit").blur(function()
  1800. {
  1801. var value = self.find("#edit").val();
  1802. if(!value)
  1803. {
  1804. alert('不能为空');
  1805. return;
  1806. }
  1807. if($(this).find(".edit-content").length)
  1808. {
  1809. $(this).find(".edit-content").html(value);
  1810. }
  1811. else
  1812. {
  1813. self.attr('data-content', value);
  1814. }
  1815. self.html(value);
  1816. $.post(url, {project:project,table:table,value:value,where_id:id,col:col}, function(t)
  1817. {
  1818. notify('修改成功', self);
  1819. preview();
  1820. /*
  1821. if(type && type == 'textarea')
  1822. {
  1823. self.html(t);
  1824. }
  1825. */
  1826. })
  1827. })
  1828. }
  1829. });
  1830. })
  1831. }
  1832. }
  1833. function preview()
  1834. {
  1835. if($("#preview").length)
  1836. {
  1837. var time = Date.parse(new Date());
  1838. var src = $('#preview').attr('src').split('#');
  1839. $('#preview').attr('src', src[0] + '&' + time + '#' + src[1]);
  1840. }
  1841. }
  1842. function del()
  1843. {
  1844. if($(".oper_delete").length)
  1845. {
  1846. $(".oper_delete").each(function()
  1847. {
  1848. var href = $(this).attr('href');
  1849. $(this).attr('href', '#');
  1850. $(this).unbind('click');
  1851. $(this).bind('click', function()
  1852. {
  1853. del_act(href);
  1854. });
  1855. })
  1856. }
  1857. }
  1858. /**
  1859. * 处理删除
  1860. */
  1861. function del_act(href)
  1862. {
  1863. var index = layer.confirm('确定进行此项操作吗?', function(i, l)
  1864. {
  1865. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  1866. $.getJSON(href + '&json=1&callback=?', {}, function(t)
  1867. {
  1868. msg(t);
  1869. layer.close(index);
  1870. })
  1871. });
  1872. }
  1873. /**
  1874. * 处理特殊加载的按钮
  1875. */
  1876. function load(href, content, title)
  1877. {
  1878. if (!content) {
  1879. content = '确定进行此项操作吗?';
  1880. }
  1881. if (!title) {
  1882. title = '温馨提示';
  1883. }
  1884. var i = 0;
  1885. var flag = false;
  1886. var send = {title:title}
  1887. var index = layer.confirm(content, send, function(i, l)
  1888. {
  1889. if (!flag) {
  1890. i++;
  1891. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  1892. if(href.indexOf('&') == -1)
  1893. {
  1894. href += '?json=1&callback=?';
  1895. }
  1896. else
  1897. {
  1898. href += '&json=1&callback=?';
  1899. }
  1900. $.getJSON(href, {}, function(t)
  1901. {
  1902. if (t.status == 2) {
  1903. flag = false;
  1904. showAlert(t.msg, false, '错误提示');
  1905. return;
  1906. } else {
  1907. // 修改标志位
  1908. flag = true;
  1909. msg(t);
  1910. layer.close(index);
  1911. //location.reload();
  1912. }
  1913. })
  1914. }
  1915. })
  1916. /*
  1917. showAlert('确定进行此项操作吗?', function()
  1918. {
  1919. $("#dever_modal_no").click();
  1920. $.getJSON(href + '&json=1', {}, function(t)
  1921. {
  1922. msg(t);
  1923. })
  1924. });
  1925. */
  1926. }
  1927. /**
  1928. * 处理特殊页面
  1929. */
  1930. function loadPage(href, title, submit)
  1931. {
  1932. if(href.indexOf('&') == -1)
  1933. {
  1934. href += '?json=1&callback=?';
  1935. }
  1936. else
  1937. {
  1938. href += '&json=1&callback=?';
  1939. }
  1940. $.getJSON(href, {}, function(t)
  1941. {
  1942. var func = false;
  1943. if (submit) {
  1944. }
  1945. showAlert(t.data, func, title);
  1946. })
  1947. }
  1948. /**
  1949. * 处理特殊加载的按钮
  1950. */
  1951. function jump(href, form)
  1952. {
  1953. if (form) {
  1954. var param = formData(form);
  1955. href += param[1];
  1956. }
  1957. if (href.indexOf('list_excel') != -1) {
  1958. layer.confirm('确认导出数据吗?', function()
  1959. {
  1960. Excel.export(href);
  1961. })
  1962. } else {
  1963. location.href = href;
  1964. }
  1965. }
  1966. /**
  1967. * 处理change
  1968. */
  1969. function change()
  1970. {
  1971. if($(".change").length)
  1972. {
  1973. $(".change").each(function()
  1974. {
  1975. var key = $(this).attr('data-child');
  1976. /*
  1977. $('.' + key).each(function()
  1978. {
  1979. if($(this).find('select option:selected').val())
  1980. {
  1981. $(this).show();
  1982. $('#set_cate_id_child').get(0).value = $(this).attr('parent');
  1983. }
  1984. });
  1985. */
  1986. $(this).change(function()
  1987. {
  1988. $('.' + key).hide();
  1989. var v = $('.' + key + '_' + $(this).val());
  1990. var s = v.find('select');
  1991. s.change(function()
  1992. {
  1993. $('.' + key + '_value').val($(this).val());
  1994. })
  1995. if(v.length)
  1996. {
  1997. $('.' + key + '_value').val(s.val());
  1998. v.show();
  1999. }
  2000. else
  2001. {
  2002. $('.' + key + '_value').val(-1);
  2003. }
  2004. });
  2005. if($(this).val() > 0)
  2006. {
  2007. $(this).change();
  2008. }
  2009. });
  2010. }
  2011. }
  2012. /**
  2013. * 处理图库系统
  2014. */
  2015. function image()
  2016. {
  2017. if($(".dever-note").length)
  2018. {
  2019. $(".dever-note").each(function()
  2020. {
  2021. var key = $(this).attr('key');
  2022. $(this).inlineattachment(
  2023. {
  2024. uploadUrl: config.upload + '.drag?key='+ key
  2025. });
  2026. });
  2027. }
  2028. if($(".image_upload").length)
  2029. {
  2030. $(".image_upload").each(function(i)
  2031. {
  2032. //如果是大文件
  2033. if ($(this).attr('l')) {
  2034. loadUploadL(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');
  2035. } else {
  2036. var parent = $(this).parent().parent();
  2037. //alert(parent.attr('id'));
  2038. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  2039. {
  2040. return;
  2041. }
  2042. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.lib + 'upload/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2043. }
  2044. })
  2045. }
  2046. if($(".upload_show").length)
  2047. {
  2048. $(".upload_show").each(function(i)
  2049. {
  2050. var parent = $(this).parent().parent();
  2051. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  2052. {
  2053. return;
  2054. }
  2055. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2056. })
  2057. }
  2058. if($(".upload_cover").length)
  2059. {
  2060. $(".upload_cover").each(function(i)
  2061. {
  2062. var parent = $(this).parent().parent();
  2063. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  2064. {
  2065. return;
  2066. }
  2067. showUploadCover(i,$(this),$(this).attr('key'),config.upload + '.videoCover', config.lib + 'upload/', 1);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2068. })
  2069. }
  2070. if($(".upload_show_editor").length)
  2071. {
  2072. $(".upload_show_editor").each(function(i)
  2073. {
  2074. var parent = $(this).parent().parent();
  2075. if(parent.attr('id') && parent.attr('id').indexOf('-child-0') != -1)
  2076. {
  2077. return;
  2078. }
  2079. showUpload(i,$(this),$(this).attr('key'),config.upload + '.files', config.lib + 'upload/', 3);//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  2080. })
  2081. }
  2082. }
  2083. /**
  2084. * 修改密码
  2085. */
  2086. function pass(e)
  2087. {
  2088. var html = '<style>.password_edit div{margin:10px;}.password_edit input{width:200px;}</style><div class="password_edit">';
  2089. html += '<div><label class="layui-form-label">旧密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_old_password" /></div>';
  2090. html += '<div><label class="layui-form-label">新密码:</label><input type="password" class="form-control form_margin layui-input" id="edit_new_password" /></div>';
  2091. html += '</div>';
  2092. var edit = function()
  2093. {
  2094. var old_password = $("#edit_old_password").val();
  2095. var new_password = $("#edit_new_password").val();
  2096. if(!old_password || !new_password)
  2097. {
  2098. alert('请输入密码');
  2099. return;
  2100. }
  2101. if(old_password == new_password)
  2102. {
  2103. alert('旧密码和新密码相同');
  2104. return;
  2105. }
  2106. $.post(config.host + 'auth.password', {old:old_password,new:new_password}, function(t)
  2107. {
  2108. alert(t);
  2109. })
  2110. };
  2111. showAlert(html, edit, '修改密码');
  2112. /*
  2113. $('#dever_modal_body').html(html);
  2114. $('#dever_modal_title').html('修改密码');
  2115. */
  2116. }
  2117. var MSG = [];
  2118. /**
  2119. * 打开弹窗
  2120. */
  2121. //function showMsg(title, e, id, func)
  2122. function showMsg(title, e, id, func, param)
  2123. {
  2124. if(id.indexOf('http://') == -1)
  2125. {
  2126. if($(id).length)
  2127. {
  2128. var html = $(id).html();
  2129. if($(id).html())
  2130. {
  2131. var html = $(id).html();
  2132. MSG[id] = html;
  2133. $(id).html('');
  2134. }
  2135. else
  2136. {
  2137. var html = MSG[id];
  2138. }
  2139. }
  2140. else
  2141. {
  2142. var html = id;
  2143. }
  2144. showAlert(html, func, title);
  2145. /*
  2146. $('#dever_modal_body').html(html);
  2147. $('#dever_modal_title').html(title);
  2148. if (func) {
  2149. $("#dever_modal_yes").unbind('click').bind('click', func);
  2150. } else {
  2151. $("#dever_modal_yes").unbind('click').bind('click', function(){$("#dever_modal_no").click()});
  2152. }
  2153. */
  2154. }
  2155. else
  2156. {
  2157. var url = id;
  2158. var send = {};
  2159. if (param) {
  2160. send = param;
  2161. }
  2162. if (e && e.attr('msg-send')) {
  2163. send.data = e.attr('msg-send');
  2164. }
  2165. if (url.indexOf('?') != -1) {
  2166. url = url + '&';
  2167. } else {
  2168. url = url + '?';
  2169. }
  2170. $.getJSON(url+'json=1&callback=?',send,function(t)
  2171. {
  2172. t = t.data;
  2173. showAlert(t, func, t);
  2174. /*
  2175. $('#dever_modal_body').html(t);
  2176. $('#dever_modal_title').html(title);
  2177. if(func)
  2178. {
  2179. $("#dever_modal_yes").unbind('click').bind('click', func);
  2180. }
  2181. */
  2182. });
  2183. }
  2184. }
  2185. function updateMsg(id)
  2186. {
  2187. $("#"+id).submit();
  2188. }
  2189. var showAlertFlag = false;
  2190. function showAlert(msg, func, title, index, t)
  2191. {
  2192. if (!title) {
  2193. title = '温馨提示';
  2194. }
  2195. var type = 0;
  2196. if (msg.indexOf('<') != -1) {
  2197. type = 1;
  2198. }
  2199. if (t) {
  2200. type = t;
  2201. }
  2202. var config = {
  2203. type: 0,
  2204. title: title,
  2205. shade: 0.1,
  2206. shadeClose : true,
  2207. content: msg
  2208. };
  2209. if (index) {
  2210. config.zIndex = index;
  2211. }
  2212. config.scrollbar = false;
  2213. if (type == 1) {
  2214. config.type = 1;
  2215. config.btn = ['保存', '关闭'];
  2216. if (func) {
  2217. config.area = ['800px', '550px'];
  2218. config.btn = ['保存', '关闭'];
  2219. } else {
  2220. config.area = ['800px', '550px'];
  2221. config.btn = ['关闭'];
  2222. }
  2223. } else if (type == 2) {
  2224. config.type = 1;
  2225. config.btn = [];
  2226. config.area = ['800px', '550px'];
  2227. }
  2228. config.cancel = config.btn2 = function(index)
  2229. {
  2230. layer.close(index);
  2231. };
  2232. if (msg.indexOf('保存成功') != -1) {
  2233. config.end = function(index)
  2234. {
  2235. layer.closeAll();
  2236. };
  2237. }
  2238. if (func) {
  2239. config.yes = function(index)
  2240. {
  2241. if (!showAlertFlag) {
  2242. showAlertFlag = true;
  2243. func(index);
  2244. }
  2245. };
  2246. } else {
  2247. config.yes = config.cancel;
  2248. }
  2249. config.success = function() {
  2250. //$('.layui-layer-content').css('padding', '10px');
  2251. }
  2252. config.end = function() {
  2253. $('.layui-layer-content').css('overflow-x', 'auto');
  2254. $('#update_button').show();
  2255. }
  2256. var index = layer.open(config);
  2257. }
  2258. function fastEdit(e, url, title, col, index, type)
  2259. {
  2260. var func = function()
  2261. {
  2262. $(".fast").submit();
  2263. };
  2264. var send = {};
  2265. if (col) {
  2266. send.col = col;
  2267. }
  2268. $.get(url + '&fast=1',send,function(t)
  2269. {
  2270. var html = '';
  2271. var valid = '';
  2272. var action = '';
  2273. //if ($(t).find('form').length && !$(t).find('#form1').length) {
  2274. if ($(t).find('form').length) {
  2275. if ($(t).find('form').length > 1 && $(t).find('form').eq(1).html()) {
  2276. var form_1 = $(t).find('form').eq(1);
  2277. form_1.addClass('layui-card-body');
  2278. } else {
  2279. var form_1 = $(t).find('form').eq(0);
  2280. }
  2281. action = form_1.attr('action');
  2282. form_1.addClass('fast');
  2283. form_1.find('#function').eq(0).val('showYes');
  2284. var html = form_1.prop("outerHTML");
  2285. if ($(t).find('#valid').length) {
  2286. var valid = $(t).find('#valid').prop("outerHTML");
  2287. html = html + valid;
  2288. }
  2289. if (html.indexOf('left: 740px') != -1) {
  2290. html = html.replace('left: 740px', 'left:583px;')
  2291. }
  2292. if ($(t).find('.dever_no_save').length) {
  2293. func = false;
  2294. }
  2295. } else {
  2296. html = t;
  2297. func = false;
  2298. }
  2299. /*
  2300. if ($(html).find('.layui-card-body').length > 0) {
  2301. html = html.replace('class="layui-card-body"', 'class="layui-card-body" style="display:none"');
  2302. html = html.replaceAll('class="layui-btn layuiadmin-btn-list"', 'class="layui-btn layuiadmin-btn-list" style="display:none"');
  2303. }
  2304. */
  2305. if (!action) {
  2306. type = 2;
  2307. func = false;
  2308. }
  2309. showAlertFlag = false;
  2310. if (index == 1) {
  2311. showAlert(html, func, title, 19850422, type);
  2312. } else {
  2313. showAlert(html, func, title, false, type);
  2314. }
  2315. $('.layui-layer-content').css('overflow-x', 'hidden');
  2316. if ($('#update_button').length) {
  2317. $('#update_button').hide();
  2318. }
  2319. layui.use(['form'], function(){
  2320. layui.form.render();
  2321. /*
  2322. $('select').each(function() {
  2323. if ($(this).attr('xm-select')) {
  2324. layui.formSelects.render($(this).attr('xm-select'));
  2325. }
  2326. });*/
  2327. });
  2328. init(560);
  2329. });
  2330. }
  2331. /*
  2332. var test =
  2333. {
  2334. refreshPage: false,
  2335. addAjaxFlag: true,
  2336. //添加收藏
  2337. add: function(cfg)
  2338. {
  2339. }
  2340. }
  2341. */
  2342. function showToggle(e)
  2343. {
  2344. var id = e.attr('toggle');
  2345. var child = e.attr('toggle_child');
  2346. var parent = e.parent();
  2347. parent.parent().find('li').removeClass('active');
  2348. parent.addClass('active');
  2349. $(child).fadeOut(100);
  2350. $(id).fadeIn(500);
  2351. initEditor($(id).find('.editor'));
  2352. }
  2353. function addChange(e)
  2354. {
  2355. var val = e.val();
  2356. if (val == 0) {
  2357. var o = e.find('option:selected');
  2358. var type = o.attr('data-type');
  2359. if (type && type == 'add') {
  2360. var url = o.attr('data-url');
  2361. var p = e.parent();
  2362. if (p.find('.addchange').length < 1) {
  2363. p.html(p.html() + '<div class="addchange" style="display: inline-block;margin-left: 10px;"></div>');
  2364. }
  2365. var id = e.attr('id');
  2366. p.find('.addchange').html('<input type="text" class="update_value form-control layui-input " id="add_'+id+'" value="" autocomplete="off" style="width:60%;display: inline;" autofocus="autofocus" /><button class="btn btn-default layui-btn layuiadmin-btn-list" type="button" style="vertical-align: middle;margin-bottom: 2px;margin-left: 10px;" onclick="addChangeAction(\''+url+'\',\''+id+'\', $(this))">创建</button>');
  2367. }
  2368. e.val('0');
  2369. }
  2370. }
  2371. function addChangeAction(url, id, self)
  2372. {
  2373. var send = {};
  2374. var e = $('#' + id);
  2375. send.value = $('#add_' + id).val();
  2376. if (!send.value) {
  2377. layer.alert('没有填写内容');
  2378. return;
  2379. }
  2380. send.json = 1;
  2381. $.getJSON(url, send, function(t)
  2382. {
  2383. if (t.status == 1) {
  2384. e.append('<option value="'+t.data.id+'">'+send.value+'</option>');
  2385. e.val(t.data.id);
  2386. self.parent().remove();
  2387. } else {
  2388. layer.alert(t.msg);
  2389. }
  2390. });
  2391. }
  2392. function inputShowUrl(e, url, id)
  2393. {
  2394. if (e.attr('v')) {
  2395. var val = e.attr('v');
  2396. } else {
  2397. var val = e.val();
  2398. }
  2399. var send = {};
  2400. send['json'] = 1;
  2401. send['id'] = id;
  2402. send['value'] = val;
  2403. if (url.indexOf('{') != -1) {
  2404. var start = url.split('{');
  2405. var end = start[1].split('}');
  2406. url = start[0] + end[1];
  2407. if (end[0].indexOf(',')) {
  2408. var param = end[0].split(',');
  2409. } else {
  2410. var param = [];
  2411. param[0] = end[0];
  2412. }
  2413. for (var i in param) {
  2414. if (typeof(param[i]) == 'string') {
  2415. var e = $('#update_'+param[i]);
  2416. if (e.length > 1) {
  2417. e.each(function() {
  2418. if ($(this).get(0).checked) {
  2419. send[param[i]] = $(this).val();
  2420. }
  2421. })
  2422. } else {
  2423. send[param[i]] = e.val();
  2424. }
  2425. }
  2426. }
  2427. }
  2428. $.getJSON(url, send, function(t)
  2429. {
  2430. if (t.status == 1) {
  2431. for (var i in t.data) {
  2432. var e1 = $('#update_' + i).parent().parent();
  2433. e1.html(t.data[i]);
  2434. e1.parent().show();
  2435. }
  2436. layui.use(['form'], function(){
  2437. layui.form.render();
  2438. });
  2439. checkbox();
  2440. }
  2441. });
  2442. }
  2443. function loadChange(e, load)
  2444. {
  2445. if (e.attr('v')) {
  2446. var val = e.attr('v');
  2447. } else {
  2448. var val = e.val();
  2449. }
  2450. showLoad(load, [val]);
  2451. }
  2452. function showLoad(id, value)
  2453. {
  2454. var e = $('#update_' + id);
  2455. if (!value) {
  2456. e.html('');
  2457. return;
  2458. }
  2459. e.html('加载中...');
  2460. var url = e.attr("data-load");
  2461. var cate = e.attr("data-cate");
  2462. var id = e.attr("data-id");
  2463. var send = {};
  2464. send['json'] = 1;
  2465. if (cate) {
  2466. send[cate] = value.join(',');
  2467. }
  2468. if (id) {
  2469. send['id'] = id;
  2470. }
  2471. $.getJSON(url, send, function(t)
  2472. {
  2473. if (t.status == 1) {
  2474. if (t.data == 'no') {
  2475. if (e.html() == '加载中...') {
  2476. e.html('');
  2477. }
  2478. } else {
  2479. e.html(t.data);
  2480. }
  2481. } else {
  2482. e.html('');
  2483. }
  2484. layui.use(['form'], function(){
  2485. layui.form.render();
  2486. });
  2487. checkbox();
  2488. });
  2489. }
  2490. var level_value = [];
  2491. var select_api = {};
  2492. var select_api_name = [];
  2493. var select_api_title = '';
  2494. var select_api_open = '';
  2495. function select_linkage(level, id, url, name, value, valid, w, total, search, level_param, col, api, type, title, open, load)
  2496. {
  2497. var e = '#' + id;
  2498. var parent = value.split(',');
  2499. var cur = parent[0];
  2500. parent.remove(cur);
  2501. value = parent.join(',');
  2502. var html = '';
  2503. var old = level;
  2504. var level_name = '';
  2505. if (!total) {
  2506. level_id = 0;
  2507. } else {
  2508. level_id = $(e + '_' + level).val();
  2509. if (level_id.indexOf('|') != -1) {
  2510. var temp = level_id.split('|');
  2511. if (level == 1) {
  2512. select_api_name = [];
  2513. }
  2514. level_id = temp[0];
  2515. level_name = temp[1];
  2516. select_api_name[level-1] = level_name;
  2517. }
  2518. if (level >= total) {
  2519. //$(e).show();
  2520. if (load) {
  2521. var key = total-1;
  2522. if (level_value[key]) {
  2523. level_value[key] = level_id;
  2524. } else {
  2525. level_value.push(level_id);
  2526. }
  2527. showLoad(load, level_value);
  2528. }
  2529. return;
  2530. }
  2531. level = parseInt(level) + 1;
  2532. }
  2533. var api_name = '';
  2534. if (col && api) {
  2535. select_api_title = title;
  2536. select_api_open = open;
  2537. if (name.indexOf('_no') == -1) {
  2538. api_name = name;
  2539. } else {
  2540. var t = name.split('_no');
  2541. api_name = t[0];
  2542. }
  2543. name += '_no';
  2544. }
  2545. $.getJSON(url + '&json=1&callback=?', {level_search:search, level_id:level_id, level_num:level,level_param:level_param}, function(t) {
  2546. var check = '';
  2547. if (t.status == 1) {
  2548. if (level == 2) {
  2549. level_value = [];
  2550. }
  2551. if (load && level_id > 0) {
  2552. level_value.push(level_id);
  2553. showLoad(load, level_value);
  2554. }
  2555. var total = t.data.level_total;
  2556. var data = t.data.list;
  2557. if(!$(e + '_' + level).length) {
  2558. html = '<select lay-ignore data-validation-placeholder="-1" style="display:inline;margin-top:10px;'+w+'" class="layui-input layui-select update_value form-control '+valid+' '+name+'" id="'+id+'_'+level+'" name="'+name+'[]" onchange="select_linkage(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+total+', \''+search+'\', \''+level_param+'\', \''+col+'\', \''+api+'\', \''+type+'\', \''+title+'\', \''+open+'\', \''+load+'\');">';
  2559. }
  2560. for (a in data) {
  2561. if (data[a].value) {
  2562. check = '';
  2563. if (cur == data[a].value) {
  2564. check = ' selected';
  2565. }
  2566. var v = data[a].value;
  2567. if (col && api) {
  2568. v = data[a].value + '|' + data[a].name;
  2569. }
  2570. html += '<option value="'+v+'" '+check+'>'+data[a].name+'</option>';
  2571. }
  2572. }
  2573. if(!$(e + '_' + level).length) {
  2574. html += '</select><span>&nbsp;&nbsp;</span>';
  2575. $(e).append(html);
  2576. $(e + '_' + level).change();
  2577. } else {
  2578. $(e + '_' + level).html(html);
  2579. $(e + '_' + level).change();
  2580. }
  2581. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  2582. } else {
  2583. if (level == 2) {
  2584. level_value = [];
  2585. if (load && level_id < 0) {
  2586. showLoad(load, false);
  2587. }
  2588. }
  2589. if (load && level_id > 0) {
  2590. level_value.push(level_id)
  2591. showLoad(load, level_value);
  2592. }
  2593. $(e + '_' + old).nextAll('select').remove();
  2594. $(e + '_' + old).next('span').nextAll('span').remove();
  2595. }
  2596. if (col && api && level_id > 0) {
  2597. var send = {};
  2598. send[col] = level_id;
  2599. $.getJSON(api + '&json=1&callback=?', send, function(r) {
  2600. var h = '<ul style="list-style:none;margin-top: 20px;display:;" class="">';
  2601. if (type == 'checkbox') {
  2602. h += '<li style="display:inline;margin-left:15px;"><input class="update_value" type="checkbox" onclick="select_linkage_check_all($(this), \'check_level_'+level_id+'\', \''+level_id+'\', \''+select_api_name.join('->')+'\', \''+e+'\', \''+api_name+'\')" value=""/>&nbsp;&nbsp;全选</li>';
  2603. }
  2604. for (var i in r.data) {
  2605. if (r.data[i]['name']) {
  2606. var checked = false;
  2607. if (select_api['level_' + level_id] && select_api['level_' + level_id]['value'] && select_api['level_' + level_id]['value']['id_' + r.data[i]['id']] && select_api['level_' + level_id]['value']['id_' + r.data[i]['id']]['state'] == 1) {
  2608. checked = true;
  2609. }
  2610. h += '<li style="display:inline;margin-left:15px;"><input onclick="select_linkage_check($(this), \''+level_id+'\', \''+select_api_name.join('->')+'\', \''+e+'\', \''+api_name+'\')" '+(checked ? 'checked' : '')+' class="update_value check_level_'+level_id+'" type="' + type + '" id="'+id+'_'+r.data[i]['id']+'" value="'+r.data[i]['id']+'|' + r.data[i]['name'] + '"/>&nbsp;&nbsp;' + r.data[i]['name'] + '</li>';
  2611. }
  2612. }
  2613. h += '</ul>';
  2614. $(e + '_content').html(h);
  2615. });
  2616. }
  2617. /*
  2618. if ($('#' + name + '_level_value').length) {
  2619. var total = $(id).find('select').length;
  2620. $('#' + name + '_level_value').val(total);
  2621. }
  2622. if ($('#' + name + '_up_value').length) {
  2623. $('#' + name + '_up_value').val($(id + '_-2').val());
  2624. }
  2625. */
  2626. });
  2627. if (col && api) {
  2628. select_linkage_check_show(e, api_name);
  2629. }
  2630. }
  2631. function select_linkage_check_all(e, cur, level_id, level_name, id, api_name)
  2632. {
  2633. var checked = e.prop('checked');
  2634. $('.' + cur).each(function() {
  2635. $(this).prop('checked', checked);
  2636. select_linkage_check($(this), level_id, level_name, id, api_name);
  2637. })
  2638. }
  2639. function select_linkage_check(e, level_id, level_name, id, api_name, cid)
  2640. {
  2641. var level_key = 'level_' + level_id;
  2642. if (!select_api[level_key]) {
  2643. select_api[level_key] = {};
  2644. select_api[level_key]['id'] = level_id;
  2645. select_api[level_key]['name'] = level_name;
  2646. select_api[level_key]['value'] = {};
  2647. }
  2648. var value = e.val();
  2649. var temp = value.split('|');
  2650. var key = 'id_' + temp[0];
  2651. if (e.prop('checked')) {
  2652. select_api[level_key]['value'][key] = {};
  2653. select_api[level_key]['value'][key]['id'] = temp[0];
  2654. select_api[level_key]['value'][key]['name'] = temp[1];
  2655. select_api[level_key]['value'][key]['state'] = 1;
  2656. } else {
  2657. if (select_api[level_key] && select_api[level_key]['value'] && select_api[level_key]['value'][key]) {
  2658. select_api[level_key]['value'][key]['state'] = 2;
  2659. }
  2660. if (cid) {
  2661. $(cid).prop('checked', false);
  2662. }
  2663. }
  2664. select_linkage_check_show(id, api_name);
  2665. }
  2666. function select_linkage_check_show(id, api_name)
  2667. {
  2668. if (select_api) {
  2669. var select_api_json = JSON.stringify(select_api);
  2670. var html = '<div style="margin-top: 20px;display:;border: 1px solid #5050b1;padding: 10px;">';
  2671. for (var i in select_api) {
  2672. if (select_api[i]['value']) {
  2673. html += '[' + select_api[i]['name'] + ']:<ul style="list-style:none;" class="">';
  2674. for (var j in select_api[i]['value']) {
  2675. var n = '&nbsp;&nbsp;' + select_api[i]['value'][j]['name'];
  2676. if (select_api_open) {
  2677. var o = select_api_open.replace('{id}', select_api[i]['value'][j]['id']);
  2678. n = '<a href="javascript:;" onclick="fastEdit($(this), \''+o+'\', \''+select_api_title+'\', \'\', 1,1)">'+n+'</a>';
  2679. }
  2680. if (select_api[i]['value'][j]['state'] == 2) {
  2681. n += '[已删除]';
  2682. var checked = false;
  2683. } else {
  2684. var checked = true;
  2685. }
  2686. html += '<li style="display:inline;margin-left:15px;"><input onclick="select_linkage_check($(this), \''+select_api[i]['id']+'\', \''+select_api[i]['name']+'\', \''+id+'\', \''+api_name+'\', \''+id+'_'+select_api[i]['value'][j]['id']+'\')" '+(checked ? 'checked' : '')+' class="update_value" type="checkbox" id="s_'+select_api[i]['value'][j]['id']+'_test" name="s_'+select_api[i]['value'][j]['id']+'_test" value="'+select_api[i]['value'][j]['id']+'|' + select_api[i]['value'][j]['name'] + '"/>'+n+'</li>';
  2687. }
  2688. html += '</ul>';
  2689. }
  2690. }
  2691. html += '</div>';
  2692. html += '<textarea name="'+api_name+'" style="display:none">'+select_api_json+'</textarea>';
  2693. $(id + '_data').html(html);
  2694. }
  2695. }
  2696. /*
  2697. function select_mul(level, id, url, name, value, valid, w, num)
  2698. {
  2699. if(level == 0)
  2700. {
  2701. $(id).find('select').remove();
  2702. $(id).find('span').remove();
  2703. return;
  2704. }
  2705. var parent = value.split(',');
  2706. var cur = parent[0];
  2707. parent.remove(cur);
  2708. value = parent.join(',');
  2709. var html = '';
  2710. var old = level;
  2711. if(level != -1)
  2712. {
  2713. if($(id + '_' + level).length)
  2714. {
  2715. level = $(id + '_' + level).val();
  2716. }
  2717. alert(level);
  2718. if(level == 0)
  2719. {
  2720. $(id + '_' + old).nextAll('select').remove();
  2721. $(id + '_' + old).next('span').nextAll('span').remove();
  2722. if($('#' + name + '_level_value').length)
  2723. {
  2724. var total = $(id).find('select').length;
  2725. $('#' + name + '_level_value').val(total);
  2726. }
  2727. if(old == -2 && $('#' + name + '_value_value').length)
  2728. {
  2729. $('#' + name + '_value_value').val(level);
  2730. }
  2731. return;
  2732. }
  2733. if(old == -2)
  2734. {
  2735. $(id + '_' + old).nextAll('select').remove();
  2736. $(id + '_' + old).next('span').nextAll('span').remove();
  2737. }
  2738. if($('#' + name + '_value_value').length)
  2739. {
  2740. $('#' + name + '_value_value').val(level);
  2741. }
  2742. }
  2743. var total = $(id).find('select').length;
  2744. if(num > 0 && total >= num)
  2745. {
  2746. return;
  2747. }
  2748. var get = url.replace('{level}', level);
  2749. if(level == -1)
  2750. {
  2751. level = -2;
  2752. }
  2753. if(!$(id + '_' + level).length)
  2754. {
  2755. $.getJSON(get + '&json=1', {total:total,level:level}, function(t)
  2756. {
  2757. var check = '';
  2758. if(t.status == 1)
  2759. {
  2760. html = '<select style="'+w+'display:inline;margin-top:10px;" class="update_value form-control '+valid+' dever-mul-'+name+'_'+level+'" name="'+name+'[]" onchange="select_mul(\''+level+'\', \''+id+'\', \''+url+'\', \''+name+'\', \''+value+'\', \''+valid+'\', \''+w+'\', '+num+');">';
  2761. console.log(t.data);
  2762. for(a in t.data)
  2763. {
  2764. if(t.data[a].value)
  2765. {
  2766. check = '';
  2767. if(cur == t.data[a].value)
  2768. {
  2769. check = ' selected';
  2770. }
  2771. html += '<option value="'+t.data[a].value+'" '+check+'>'+t.data[a].name+'</option>';
  2772. }
  2773. }
  2774. html += '</select><span>&nbsp;&nbsp;</span>';
  2775. $(id).append(html);
  2776. $(id + '_' + level).change();
  2777. }
  2778. else
  2779. {
  2780. $(id + '_' + old).nextAll('select').remove();
  2781. $(id + '_' + old).next('span').nextAll('span').remove();
  2782. }
  2783. if($('#' + name + '_level_value').length)
  2784. {
  2785. var total = $(id).find('select').length;
  2786. $('#' + name + '_level_value').val(total);
  2787. }
  2788. if($('#' + name + '_up_value').length)
  2789. {
  2790. $('#' + name + '_up_value').val($(id + '_-2').val());
  2791. }
  2792. });
  2793. }
  2794. }
  2795. */
  2796. //处理更新页面的一些功能,写到一起吧
  2797. var dever_update =
  2798. {
  2799. addIndex : 2,
  2800. index : [],
  2801. auto : false,
  2802. save_key : '',
  2803. init : function()
  2804. {
  2805. var self = this;
  2806. self.index = [];
  2807. // 增加整个更新的表单
  2808. if($(".dever_update_add").length)
  2809. {
  2810. $('.dever_update_add').unbind('click').bind('click', function()
  2811. {
  2812. self.add($(this));
  2813. })
  2814. }
  2815. /* 以后再增加 同时更新另外一个表
  2816. if($(".form-add-content").length)
  2817. {
  2818. var url = config.host + 'auth.password';
  2819. var url = 'http://localhost/dever/manage/?database.update?project=weixin&table=message&menu=weixin&menu_id=39&ajax=1';
  2820. $.get(url, function(t)
  2821. {
  2822. $(".form-add-content").html(t);
  2823. init();
  2824. })
  2825. }
  2826. */
  2827. //增加某一部分表单
  2828. if($(".dever_form_add").length)
  2829. {
  2830. $('.dever_form_add').each(function()
  2831. {
  2832. var key = $.attr('toggle_key');
  2833. if(typeof(self.index[key]) == "undefined")
  2834. {
  2835. self.index[key] = 0;
  2836. }
  2837. $(this).unbind('click').bind('click', function()
  2838. {
  2839. self.append($(this));
  2840. })
  2841. })
  2842. self.del();
  2843. }
  2844. // 开启自动保存
  2845. if($("#struct").length)
  2846. {
  2847. var save = $("#struct").attr('save');
  2848. if(save == 'yes')
  2849. {
  2850. //检测
  2851. self.save_key = location.href + 'test';
  2852. self.check();
  2853. }
  2854. }
  2855. if($('.dever-note').length)
  2856. {
  2857. $('.dever-note').each(function()
  2858. {
  2859. var mditor = new Mditor($(this),{
  2860. fixedHeight:true
  2861. });
  2862. mditor.openPreview();
  2863. })
  2864. }
  2865. },
  2866. save : function()
  2867. {
  2868. //var data = $("#data-1").html();
  2869. var data = [];
  2870. $(".update_value").each(function(i)
  2871. {
  2872. if($(this).attr("update_type") == 'checked')
  2873. {
  2874. data[i] = $(this).get(0).checked;
  2875. }
  2876. else if($(this).attr("update_type") == 'html')
  2877. {
  2878. data[i] = $(this).html();
  2879. }
  2880. else if($(this).attr("update_type") == 'src')
  2881. {
  2882. data[i] = $(this).attr('src');
  2883. }
  2884. else
  2885. {
  2886. data[i] = $(this).val();
  2887. }
  2888. });
  2889. store.set(this.save_key, data.join('|||'));
  2890. //console.info(data);
  2891. },
  2892. recover : function()
  2893. {
  2894. var index = layer.confirm('确定恢复上次保存的数据吗?', function(i, l)
  2895. {
  2896. $(l).find('.layui-layer-btn0').css('pointer-events','none');
  2897. var data = store.get(this.save_key).split('|||');
  2898. if(data)
  2899. {
  2900. var value = $(".update_value");
  2901. for(var k in data)
  2902. {
  2903. var e = value.eq(k);
  2904. if(e.attr('update_type') == 'checked')
  2905. {
  2906. if(data[k] == 'true')
  2907. {
  2908. e.get(0).checked = true;
  2909. }
  2910. else
  2911. {
  2912. e.get(0).checked = false;
  2913. }
  2914. }
  2915. else if(e.attr('update_type') == 'html')
  2916. {
  2917. e.html(data[k]);
  2918. }
  2919. else if(e.attr('update_type') == 'src')
  2920. {
  2921. e.attr('src', data[k]);
  2922. }
  2923. else
  2924. {
  2925. if(e.attr('id'))
  2926. {
  2927. var id = e.attr('id');
  2928. if(typeof(editors[id]) != "undefined")
  2929. {
  2930. editors[id].html(data[k]);
  2931. }
  2932. }
  2933. e.val(data[k]);
  2934. }
  2935. }
  2936. store.set(this.save_key, '');
  2937. this.check();
  2938. }
  2939. })
  2940. },
  2941. check : function()
  2942. {
  2943. var data = store.get(this.save_key);
  2944. var self = this;
  2945. if(data)
  2946. {
  2947. $(".dever_save").unbind('click').bind('click', function()
  2948. {
  2949. self.recover();
  2950. }).show();
  2951. }
  2952. else
  2953. {
  2954. $(".dever_save").hide();
  2955. self.auto = setInterval(function(){self.save()}, 3000);
  2956. }
  2957. },
  2958. del : function()
  2959. {
  2960. var self = this;
  2961. if($(".dever_form_delete").length)
  2962. {
  2963. $('.dever_form_delete').each(function()
  2964. {
  2965. $(this).unbind('click').bind('click', function()
  2966. {
  2967. var parent = $(this).parent();
  2968. var id = parent.attr('id');
  2969. var index = parseInt($('#tab-' + id).attr('toggle_id'));
  2970. var key = $('#tab-' + id).attr('toggle_key');
  2971. if(index <= 1 && self.index[key] <= index)
  2972. {
  2973. }
  2974. else if(index <= 1 && self.index[key] > index)
  2975. {
  2976. index = index+1;
  2977. $("#tab-"+key+"-child-" + index).click();
  2978. }
  2979. else
  2980. {
  2981. index = index-1;
  2982. $("#tab-"+key+"-child-" + index).click();
  2983. };
  2984. $('#tab-' + id).parent().remove();
  2985. parent.remove();
  2986. self.index[key]--;
  2987. })
  2988. })
  2989. }
  2990. },
  2991. append : function(e)
  2992. {
  2993. var self = this;
  2994. var key = e.attr('toggle_key');
  2995. var parent = e.parent().parent().parent();
  2996. var child = '.dever_'+key+'_child';
  2997. if(typeof(self.index[key]) == "undefined")
  2998. {
  2999. self.index[key] = 0;
  3000. }
  3001. if (isNaN(self.index[key])) {
  3002. self.index[key] = 0;
  3003. }
  3004. if(self.index[key] <= 0)
  3005. {
  3006. self.index[key] = parent.find(child).length;
  3007. }
  3008. if(self.index[key] > 100)
  3009. {
  3010. layer.showAlert('最多只能增加100条');
  3011. return;
  3012. }
  3013. var p = e.parent();
  3014. var id = key + '-child-' + self.index[key];
  3015. var name = '第' + (self.index[key]) + '条';
  3016. p.before('<li style="margin:0px;padding:0 15px;"><a href="javascript:;" id="tab-'+id+'" toggle_key="'+key+'" toggle_id="'+self.index[key]+'" toggle_child="'+child+'" toggle="#'+id+'" onclick="showToggle($(this))">'+name+'</a></li>');
  3017. var e = e.parent().parent();
  3018. var n = e.next();
  3019. var p = e.parent();
  3020. var content = n.html();
  3021. content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
  3022. var cname = n.attr('class');
  3023. if (cname.indexOf('layui-tab') > -1) {
  3024. content = '<div id="'+id+'" style="display:none;" class="'+n.attr('class')+'">' + content + '</div>';
  3025. } else {
  3026. //content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+' dever_form_add_child">' + content + '</div>';
  3027. content = '<div id="'+id+'" style="display:none;margin:10px" class="'+n.attr('class')+'">' + content + '</div>';
  3028. }
  3029. p.append(content);
  3030. if ($("#" + id).find('.ke-container').length >= 1) {
  3031. $("#" + id).find('.ke-container').eq(0).remove();
  3032. }
  3033. $('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order').val())+1);
  3034. self.del();
  3035. //$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
  3036. self.index[key]++;
  3037. image();
  3038. loadShow();
  3039. autocomplete();
  3040. change();
  3041. form.render();
  3042. initPic();
  3043. initDate();
  3044. /*
  3045. layui.use(['formSelects'], function(){
  3046. $('#' + id + " select").each(function()
  3047. {
  3048. if ($(this).attr('xm-select')) {
  3049. layui.formSelects.render($(this).attr('xm-select'));
  3050. }
  3051. })
  3052. });
  3053. */
  3054. },
  3055. add : function(e)
  3056. {
  3057. var self = this;
  3058. var p = e.parent();
  3059. var id = 'data-' + this.addIndex;
  3060. var name = '新增数据-' + (this.addIndex-1);
  3061. p.before('<li><a href="#'+id+'" data-toggle="tab">'+name+'</a></li>');
  3062. var content = $("#content").find('.tab-pane').eq(0).html();
  3063. content = content.replaceAll('update_', 'update_' + this.addIndex + '__');
  3064. content = '<div class="tab-pane fade" id="'+id+'">' + content + '</div>';
  3065. $("#content").append(content);
  3066. $('#update_' + this.addIndex + '__where_id').val('-1');
  3067. this.addIndex++;
  3068. }
  3069. }
  3070. $.fn.pasteEvents = function( delay ) {
  3071. if (delay == undefined) delay = 20;
  3072. return $(this).each(function() {
  3073. var $el = $(this);
  3074. $el.on("paste", function() {
  3075. $el.trigger("prepaste");
  3076. setTimeout(function() { $el.trigger("postpaste"); }, delay);
  3077. });
  3078. });
  3079. };
  3080. $("textarea").on("postpaste", function()
  3081. {
  3082. if($(this).val().indexOf('<') != -1)
  3083. {
  3084. $(this).val(toMarkdown($(this).val()));
  3085. }
  3086. }).pasteEvents();
  3087. function showYes(msg)
  3088. {
  3089. if (msg.msg == 'reload') {
  3090. location.reload();
  3091. return;
  3092. }
  3093. showAlertFlag = false;
  3094. if (msg.status == 2) {
  3095. list_mul_state = 1;
  3096. layer.alert(msg.msg);
  3097. } else {
  3098. showAlert('保存成功', function() {
  3099. if (select_api_open) {
  3100. $('.layui-layer-content').css('overflow-x', 'auto');
  3101. $('#update_button').show();
  3102. layer.closeAll();
  3103. } else {
  3104. if(msg.data.indexOf('http') != -1) {
  3105. location.href = msg.data;
  3106. } else if (msg.data && msg.data == 'refer') {
  3107. history.back();
  3108. } else {
  3109. location.reload();
  3110. }
  3111. }
  3112. });
  3113. }
  3114. }
  3115. function setDay(e, d)
  3116. {
  3117. $('#search_option_sday').val(d);
  3118. $('.sday_button').removeClass('sday_button_border');
  3119. e.addClass('sday_button_border');
  3120. var date = new Date();
  3121. var year = date.getFullYear();
  3122. var month = date.getMonth()+1;
  3123. var day = date.getDate();
  3124. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  3125. //获取30天前得日期
  3126. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  3127. var lastY = lastDate.getFullYear();
  3128. var lastM = lastDate.getMonth()+1;
  3129. var lastD = lastDate.getDate();
  3130. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  3131. $('.manage_sday').eq(0).val(LDate);
  3132. $('.manage_sday').eq(1).val(nowDate);
  3133. }
  3134. function setDate(e, d)
  3135. {
  3136. $('#search_option_sdate').val(d);
  3137. $('.sdate_button').removeClass('sdate_button_border');
  3138. e.addClass('sdate_button_border');
  3139. var date = new Date();
  3140. var year = date.getFullYear();
  3141. var month = date.getMonth()+1;
  3142. var day = date.getDate();
  3143. var nowDate = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  3144. //获取30天前得日期
  3145. var lastDate = new Date(date - 1000 * 60 * 60 * 24 * d);
  3146. var lastY = lastDate.getFullYear();
  3147. var lastM = lastDate.getMonth()+1;
  3148. var lastD = lastDate.getDate();
  3149. var LDate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);
  3150. $('.manage_sdate').eq(0).val(LDate + ' 00:00:00');
  3151. $('.manage_sdate').eq(1).val(nowDate + ' 23:59:59');
  3152. }
  3153. function showVideo(video)
  3154. {
  3155. var html = '<meta name="referrer" content="no-referrer"><video width="400" height="300" controls autoplay="autoplay"><source src="'+video+'" type="video/mp4">您的浏览器不支持Video标签。</video>';
  3156. showAlert(html);
  3157. }
  3158. function sku(e)
  3159. {
  3160. var data = $('#sku_table_col').html();
  3161. data = JSON.parse(data);
  3162. var thead = [];
  3163. var tbody = [];
  3164. var mthead = [];
  3165. var mtbody = [];
  3166. for (var i in data) {
  3167. if (data[i]['verify'] == 'number') {
  3168. var type = 'required|number';
  3169. var value = '0';
  3170. } else {
  3171. var type = 'required';
  3172. var value = '';
  3173. }
  3174. if (data[i]['type'] == 'input') {
  3175. var icon = 'layui-icon-cols';
  3176. } else {
  3177. var icon = '';
  3178. }
  3179. mthead.push({title: data[i]['name'], icon: icon});
  3180. var option = {type: data[i]['type'], field: i, value: value, verify: type, reqtext: data[i]['name'] + '不能为空'};
  3181. if (option.type == 'select') {
  3182. option.option = eval("(" + data[i]['option'] + ")");
  3183. }
  3184. mtbody.push(option);
  3185. if (option.type != 'image') {
  3186. thead.push({title: data[i]['name'], icon: 'layui-icon-cols'});
  3187. tbody.push(option);
  3188. }
  3189. }
  3190. var obj = skuTable.render({
  3191. //规格类型 1统一规格 2多规格
  3192. isAttributeValue: e.attr('data-type'),
  3193. //规格类型容器id
  3194. isAttributeElemId: 'sku_spec_type',
  3195. //规格表容器id
  3196. specTableElemId: 'sku_spec_table',
  3197. //sku表容器id
  3198. skuTableElemId: 'sku_table',
  3199. //规格拖拽排序
  3200. sortable: true,
  3201. //sku表相同属性值是否合并行
  3202. rowspan: true,
  3203. //请求成功返回状态码值
  3204. requestSuccessCode: 1,
  3205. //上传接口地址
  3206. //接口要求返回格式参考 upload.json
  3207. uploadUrl: e.attr('data-upload'),
  3208. //统一规格配置项
  3209. singleSkuTableConfig: {
  3210. thead: thead,
  3211. tbody: tbody
  3212. },
  3213. //多规格配置项
  3214. multipleSkuTableConfig: {
  3215. thead: mthead,
  3216. tbody: mtbody
  3217. },
  3218. //商品id 配合specDataUrl和skuDataUrl使用
  3219. productId: e.attr('data-id'),
  3220. //规格数据, 一般从后台获取,
  3221. specData: [],
  3222. specDataUrl: e.attr('data-spec'),
  3223. skuData : [],
  3224. skuDataUrl: e.attr('data-sku'),
  3225. });
  3226. }
  3227. var append_total = 10;
  3228. function append(self, id)
  3229. {
  3230. var e = self.parent().parent().parent().find('.table_copy');
  3231. var html = e.html();
  3232. var parent = e.parent();
  3233. var total = parent.find('tr').length-1;
  3234. append_total++;
  3235. total += append_total;
  3236. html = html.replaceAll('_-1_', '_' + total + '_');
  3237. html = html.replaceAll('up_', 'update_');
  3238. var class_name = 'update_' + id;
  3239. id = class_name + '_c_' + total;
  3240. parent.append('<tr id="'+id+'" class="'+class_name+'">' + html + '</tr>');
  3241. form.render();
  3242. /*
  3243. $('#' + id + " select").each(function()
  3244. {
  3245. if ($(this).attr('xm-select')) {
  3246. layui.formSelects.render($(this).attr('xm-select'));
  3247. }
  3248. });
  3249. */
  3250. initDate();
  3251. }
  3252. function init_xm(xm_id, xm_radio, xm_tips, xm_url, xm_data, xm_value, xm_on)
  3253. {
  3254. if (!xm_on) {
  3255. xm_on = function(){};
  3256. }
  3257. var xm_table = xm_id + '_table';
  3258. var xm = xmSelect.render({
  3259. el: "#" + xm_id,
  3260. data: xm_data,
  3261. tips:xm_tips,
  3262. name:xm_id,
  3263. initValue: xm_value,
  3264. radio:xm_radio,
  3265. clickClose: xm_radio,
  3266. layVerify: "required",
  3267. layVerType: "msg",
  3268. autoRow: true,
  3269. toolbar: { show: false },
  3270. model: xm_radio ? { label: { type: 'text' } } : {},
  3271. filterable: true,
  3272. autoRow: true,
  3273. height: 'auto',
  3274. paging: xm_url ? true : false,
  3275. pageRemote: xm_url ? true : false,
  3276. remoteSearch: xm_url ? true : false,
  3277. on: xm_on,
  3278. //direction: 'down',
  3279. remoteMethod: function(val, cb, show, pageIndex) {
  3280. if (!pageIndex) {
  3281. pageIndex = 1;
  3282. }
  3283. if(!val){
  3284. //return cb([]);
  3285. }
  3286. if (!xm_url) {
  3287. return cb(xm_data);
  3288. }
  3289. var data = {
  3290. id: xm_table,
  3291. keyword: val,
  3292. pg: pageIndex
  3293. };
  3294. if (xm_url.indexOf('{') != -1) {
  3295. var start = xm_url.split('{');
  3296. var end = start[1].split('}');
  3297. xm_url = start[0] + end[1];
  3298. if (end[0].indexOf(',')) {
  3299. var param = end[0].split(',');
  3300. } else {
  3301. var param = [];
  3302. param[0] = end[0];
  3303. }
  3304. for (var i in param) {
  3305. if (typeof(param[i]) == 'string') {
  3306. var e = $('#update_'+param[i]);
  3307. if (e.length > 1) {
  3308. e.each(function() {
  3309. if ($(this).get(0).checked) {
  3310. data[param[i]] = $(this).val();
  3311. }
  3312. })
  3313. } else {
  3314. var v = e.val();
  3315. if (!v) {
  3316. e = $('input[name="update_'+param[i]+'"]');
  3317. if (e.val()) {
  3318. v = e.val();
  3319. }
  3320. }
  3321. data[param[i]] = v;
  3322. }
  3323. }
  3324. if (!data[param[i]]) {
  3325. data[param[i]] = -1;
  3326. }
  3327. }
  3328. }
  3329. var success = function(response) {
  3330. if (typeof response == "string") {
  3331. response = JSON.parse(response);
  3332. }
  3333. if (response.status == 2) {
  3334. cb([]);
  3335. return;
  3336. }
  3337. if (!response.data.list) {
  3338. if (response.page && response.page.total_page) {
  3339. cb(response.data, response.page.total_page)
  3340. } else {
  3341. cb(response.data)
  3342. }
  3343. } else {
  3344. if (response.page && response.page.total_page) {
  3345. cb(response.data.list, response.page.total_page)
  3346. } else {
  3347. cb(response.data.list)
  3348. }
  3349. }
  3350. /*
  3351. if (response.data.table) {
  3352. xm.update({
  3353. content: response.data.table,
  3354. });
  3355. layui.table.init(xm_table, response.data.table_config).on('row('+xm_table+')', function(obj) {
  3356. var values = xm.getValue();
  3357. var item = obj.data;
  3358. var has = values.find(function(i){
  3359. return i.value === item.value
  3360. });
  3361. var send = {};
  3362. send.arr = [ item ];
  3363. if (has) {
  3364. xm.delete(send.arr);
  3365. } else if (xm_radio) {
  3366. xm.setValue(send.arr);
  3367. xm.closed();
  3368. } else {
  3369. xm.append(send.arr);
  3370. }
  3371. xm_on && xm_on(send)
  3372. })
  3373. }*/
  3374. };
  3375. $.ajax({
  3376. dataType: "json",
  3377. url: xm_url,
  3378. data: data,
  3379. timeout:0,
  3380. success: success
  3381. });
  3382. },
  3383. });
  3384. }