main.js 90 KB

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