admin.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. ;(function () {
  2. //全局ajax处理
  3. $.ajaxSetup({
  4. complete: function (jqXHR) {
  5. },
  6. data: {},
  7. error: function (jqXHR, textStatus, errorThrown) {
  8. //请求失败处理
  9. }
  10. });
  11. if ($.browser && $.browser.msie) {
  12. //ie 都不缓存
  13. $.ajaxSetup({
  14. cache: false
  15. });
  16. }
  17. //不支持placeholder浏览器下对placeholder进行处理
  18. if (document.createElement('input').placeholder !== '') {
  19. $('[placeholder]').focus(function () {
  20. var input = $(this);
  21. if (input.val() == input.attr('placeholder')) {
  22. input.val('');
  23. input.removeClass('placeholder');
  24. }
  25. }).blur(function () {
  26. var input = $(this);
  27. if (input.val() == '' || input.val() == input.attr('placeholder')) {
  28. input.addClass('placeholder');
  29. input.val(input.attr('placeholder'));
  30. }
  31. }).blur().parents('form').submit(function () {
  32. $(this).find('[placeholder]').each(function () {
  33. var input = $(this);
  34. if (input.val() == input.attr('placeholder')) {
  35. input.val('');
  36. }
  37. });
  38. });
  39. }
  40. // 所有加了dialog类名的a链接,自动弹出它的href
  41. if ($('a.js-dialog').length) {
  42. Wind.css('artDialog');
  43. Wind.use('artDialog', 'iframeTools', function () {
  44. $('.js-dialog').on('click', function (e) {
  45. e.preventDefault();
  46. var $this = $(this);
  47. art.dialog.open($(this).prop('href'), {
  48. close: function () {
  49. $this.focus(); // 关闭时让触发弹窗的元素获取焦点
  50. return true;
  51. },
  52. title: $this.prop('title')
  53. });
  54. }).attr('role', 'button');
  55. });
  56. }
  57. // 所有的ajax form提交,由于大多业务逻辑都是一样的,故统一处理
  58. var ajaxForm_list = $('form.js-ajax-form');
  59. if (ajaxForm_list.length) {
  60. Wind.css('artDialog');
  61. Wind.use('ajaxForm', 'artDialog', 'noty3', 'validate', function () {
  62. var $btn;
  63. $('button.js-ajax-submit').on('click', function (e) {
  64. var btn = $(this), form = btn.parents('form.js-ajax-form');
  65. $btn = btn;
  66. if (btn.data("loading")) {
  67. return;
  68. }
  69. //批量操作 判断选项
  70. if (btn.data('subcheck')) {
  71. btn.parent().find('span').remove();
  72. if (form.find('input.js-check:checked').length) {
  73. btn.data('subcheck', false);
  74. } else {
  75. var empty_type=btn.data('empty_tips');
  76. if(empty_type==null){
  77. empty_type='';
  78. }
  79. $('<span class="tips_error">请至少选择一项</span>').appendTo(btn.parent()).fadeIn('fast');
  80. return false;
  81. }
  82. }
  83. var msg = btn.data('msg');
  84. if (msg) {
  85. art.dialog({
  86. id: 'warning',
  87. icon: 'warning',
  88. content: btn.data('msg'),
  89. cancelVal: '关闭',
  90. cancel: function () {
  91. //btn.data('subcheck', false);
  92. //btn.click();
  93. },
  94. ok: function () {
  95. btn.data('msg', false);
  96. btn.click();
  97. }
  98. });
  99. return false;
  100. }
  101. //ie处理placeholder提交问题
  102. if ($.browser && $.browser.msie) {
  103. form.find('[placeholder]').each(function () {
  104. var input = $(this);
  105. if (input.val() == input.attr('placeholder')) {
  106. input.val('');
  107. }
  108. });
  109. }
  110. });
  111. ajaxForm_list.each(function () {
  112. $(this).validate({
  113. //是否在获取焦点时验证
  114. //onfocusout : false,
  115. //是否在敲击键盘时验证
  116. //onkeyup : false,
  117. //当鼠标点击时验证
  118. //onclick : false,
  119. //给未通过验证的元素加效果,闪烁等
  120. highlight: function (element, errorClass, validClass) {
  121. if (element.type === "radio") {
  122. this.findByName(element.name).addClass(errorClass).removeClass(validClass);
  123. } else {
  124. var $element = $(element);
  125. $element.addClass(errorClass).removeClass(validClass);
  126. $element.parent().addClass("has-error");//bootstrap3表单
  127. $element.parents('.control-group').addClass("error");//bootstrap2表单
  128. }
  129. },
  130. unhighlight: function (element, errorClass, validClass) {
  131. if (element.type === "radio") {
  132. this.findByName(element.name).removeClass(errorClass).addClass(validClass);
  133. } else {
  134. var $element = $(element);
  135. $element.removeClass(errorClass).addClass(validClass);
  136. $element.parent().removeClass("has-error");//bootstrap3表单
  137. $element.parents('.control-group').removeClass("error");//bootstrap2表单
  138. }
  139. },
  140. showErrors: function (errorMap, errorArr) {
  141. var i, elements, error;
  142. for (i = 0; this.errorList[i]; i++) {
  143. error = this.errorList[i];
  144. if (this.settings.highlight) {
  145. this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass);
  146. }
  147. //this.showLabel( error.element, error.message );
  148. }
  149. if (this.errorList.length) {
  150. //this.toShow = this.toShow.add( this.containers );
  151. }
  152. if (this.settings.success) {
  153. for (i = 0; this.successList[i]; i++) {
  154. //this.showLabel( this.successList[ i ] );
  155. }
  156. }
  157. if (this.settings.unhighlight) {
  158. for (i = 0, elements = this.validElements(); elements[i]; i++) {
  159. this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
  160. }
  161. }
  162. this.toHide = this.toHide.not(this.toShow);
  163. this.hideErrors();
  164. this.addWrapper(this.toShow).show();
  165. },
  166. submitHandler: function (form) {
  167. var $form = $(form);
  168. $form.ajaxSubmit({
  169. url: $btn.data('action') ? $btn.data('action') : $form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
  170. dataType: 'json',
  171. beforeSubmit: function (arr, $form, options) {
  172. $btn.data("loading", true);
  173. var text = $btn.text();
  174. //按钮文案、状态修改
  175. $btn.text(text + '中...').prop('disabled', true).addClass('disabled');
  176. },
  177. success: function (data, statusText, xhr, $form) {
  178. function _refresh() {
  179. // 刷新父层
  180. if (data.code === 1 && $btn.attr('reload') === 'parent') {
  181. reloadPage(window.parent)
  182. }
  183. if (data.url) {
  184. //返回带跳转地址
  185. window.location.href = data.url;
  186. } else {
  187. if (data.code == 1) {
  188. //刷新当前页
  189. reloadPage(window);
  190. }
  191. }
  192. }
  193. var text = $btn.text();
  194. //按钮文案、状态修改
  195. $btn.removeClass('disabled').prop('disabled', false).text(text.replace('中...', '')).parent().find('span').remove();
  196. if (data.code == 1) {
  197. if ($btn.data('success')) {
  198. var successCallback = $btn.data('success');
  199. window[successCallback](data, statusText, xhr, $form);
  200. return;
  201. }
  202. new Noty({
  203. text: data.msg,
  204. type: 'success',
  205. layout: 'topCenter',
  206. modal: true,
  207. animation: {
  208. open: 'animated bounceInDown', // Animate.css class names
  209. close: 'animated bounceOutUp', // Animate.css class names
  210. },
  211. timeout: 1,
  212. callbacks: {
  213. afterClose: function () {
  214. if ($btn.data('refresh') == undefined || $btn.data('refresh')) {
  215. _refresh();
  216. }
  217. }
  218. }
  219. }).show();
  220. $(window).focus();
  221. } else if (data.code == 0) {
  222. var $verify_img = $form.find(".verify_img");
  223. if ($verify_img.length) {
  224. $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random());
  225. }
  226. var $verify_input = $form.find("[name='verify']");
  227. $verify_input.val("");
  228. //$('<span class="tips_error">' + data.msg + '</span>').appendTo($btn.parent()).fadeIn('fast');
  229. $btn.removeProp('disabled').removeClass('disabled');
  230. new Noty({
  231. text: data.msg,
  232. type: 'error',
  233. layout: 'topCenter',
  234. modal: true,
  235. animation: {
  236. open: 'animated bounceInDown', // Animate.css class names
  237. close: 'animated bounceOutUp', // Animate.css class names
  238. },
  239. timeout: 1,
  240. callbacks: {
  241. afterClose: function () {
  242. _refresh();
  243. }
  244. }
  245. }).show();
  246. $(window).focus();
  247. }
  248. },
  249. error: function (xhr, e, statusText) {
  250. art.dialog({
  251. id: 'warning',
  252. icon: 'warning',
  253. content: statusText,
  254. cancelVal: '关闭',
  255. cancel: function () {
  256. reloadPage(window);
  257. },
  258. ok: function () {
  259. reloadPage(window);
  260. }
  261. });
  262. },
  263. complete: function () {
  264. $btn.data("loading", false);
  265. }
  266. });
  267. }
  268. });
  269. });
  270. });
  271. }
  272. //dialog弹窗内的关闭方法
  273. $('#js-dialog-close').on('click', function (e) {
  274. e.preventDefault();
  275. try {
  276. art.dialog.close();
  277. } catch (err) {
  278. Wind.css('artDialog');
  279. Wind.use('artDialog', 'iframeTools', function () {
  280. art.dialog.close();
  281. });
  282. }
  283. ;
  284. });
  285. //所有的删除操作,删除数据后刷新页面
  286. if ($('a.js-ajax-delete').length) {
  287. Wind.css('artDialog');
  288. Wind.use('artDialog', 'noty3', function () {
  289. $('.js-ajax-delete').on('click', function (e) {
  290. e.preventDefault();
  291. var $_this = this,
  292. $this = $($_this),
  293. href = $this.data('href'),
  294. refresh = $this.data('refresh'),
  295. msg = $this.data('msg');
  296. var _okVal = $this.data('okVal');
  297. var _cancelVal = $this.data('cancelVal');
  298. if(typeof(_okVal)=='undefined'||_okVal==null){
  299. _okVal='ok';
  300. }
  301. if(typeof(_cancelVal)=='undefined'||_cancelVal==null){
  302. _cancelVal='cancel';
  303. }
  304. href = href ? href : $this.attr('href');
  305. art.dialog({
  306. title: false,
  307. icon: 'question',
  308. content: msg ? msg : 'sure to delete?',
  309. follow: $_this,
  310. close: function () {
  311. $_this.focus(); //关闭时让触发弹窗的元素获取焦点
  312. return true;
  313. },
  314. okVal:_okVal?_okVal:"ok",
  315. ok: function () {
  316. $.getJSON(href).done(function (data) {
  317. if (data.code == '1') {
  318. new Noty({
  319. text: data.msg,
  320. type: 'success',
  321. layout: 'topCenter',
  322. modal: true,
  323. animation: {
  324. open: 'animated bounceInDown', // Animate.css class names
  325. close: 'animated bounceOutUp', // Animate.css class names
  326. },
  327. timeout: 1,
  328. callbacks: {
  329. afterClose: function () {
  330. if (refresh == undefined || refresh) {
  331. if (data.url) {
  332. //返回带跳转地址
  333. window.location.href = data.url;
  334. } else {
  335. //刷新当前页
  336. reloadPage(window);
  337. }
  338. }
  339. }
  340. }
  341. }).show();
  342. } else if (data.code == '0') {
  343. //art.dialog.alert(data.info);
  344. //alert(data.info);//暂时处理方案
  345. art.dialog({
  346. content: data.msg,
  347. icon: 'warning',
  348. ok: function () {
  349. this.title(data.msg);
  350. return true;
  351. }
  352. });
  353. }
  354. });
  355. },
  356. cancelVal: _cancelVal?_cancelVal:'cancel',
  357. cancel: true
  358. });
  359. });
  360. });
  361. }
  362. if ($('a.js-ajax-dialog-btn').length) {
  363. Wind.use('artDialog', 'noty3', function () {
  364. $('.js-ajax-dialog-btn').on('click', function (e) {
  365. e.preventDefault();
  366. var $_this = this,
  367. $this = $($_this),
  368. href = $this.data('href'),
  369. refresh = $this.data('refresh'),
  370. msg = $this.data('msg');
  371. var _okVal = $this.data('okVal');
  372. var _cancelVal = $this.data('cancelVal');
  373. if(typeof(_okVal)=='undefined'||_okVal==null){
  374. _okVal='ok';
  375. }
  376. if(typeof(_cancelVal)=='undefined'||_cancelVal==null){
  377. _cancelVal='cancel';
  378. }
  379. href = href ? href : $this.attr('href');
  380. if (!msg) {
  381. msg = "are you sure to do this?";
  382. }
  383. art.dialog({
  384. title: false,
  385. icon: 'question',
  386. content: msg,
  387. follow: $_this,
  388. close: function () {
  389. $_this.focus(); //关闭时让触发弹窗的元素获取焦点
  390. return true;
  391. },
  392. okVal:_okVal?_okVal:"ok",
  393. ok: function () {
  394. var d = art.dialog({
  395. title: false,
  396. lock: true,
  397. esc: false
  398. })
  399. $('.aui_close').hide()
  400. $.ajax({
  401. url: href,
  402. type: 'post',
  403. success: function (data) {
  404. d.close()
  405. if (data.code == 1) {
  406. new Noty({
  407. text: data.msg,
  408. type: 'success',
  409. layout: 'topCenter',
  410. modal: true,
  411. animation: {
  412. open: 'animated bounceInDown', // Animate.css class names
  413. close: 'animated bounceOutUp', // Animate.css class names
  414. },
  415. timeout: 1,
  416. callbacks: {
  417. afterClose: function () {
  418. if (refresh == undefined || refresh) {
  419. if (data.url) {
  420. //返回带跳转地址
  421. window.location.href = data.url;
  422. } else {
  423. //刷新当前页
  424. reloadPage(window);
  425. }
  426. }
  427. }
  428. }
  429. }).show();
  430. } else if (data.code == 0) {
  431. //art.dialog.alert(data.info);
  432. art.dialog({
  433. content: data.msg,
  434. icon: 'warning',
  435. ok: function () {
  436. this.title(data.msg);
  437. return true;
  438. }
  439. });
  440. }
  441. }
  442. })
  443. },
  444. cancelVal: _cancelVal?_cancelVal:'cancel',
  445. cancel: true
  446. });
  447. });
  448. });
  449. }
  450. /*复选框全选(支持多个,纵横双控全选)。
  451. *实例:版块编辑-权限相关(双控),验证机制-验证策略(单控)
  452. *说明:
  453. * "js-check"的"data-xid"对应其左侧"js-check-all"的"data-checklist";
  454. * "js-check"的"data-yid"对应其上方"js-check-all"的"data-checklist";
  455. * 全选框的"data-direction"代表其控制的全选方向(x或y);
  456. * "js-check-wrap"同一块全选操作区域的父标签class,多个调用考虑
  457. */
  458. if ($('.js-check-wrap').length) {
  459. var total_check_all = $('input.js-check-all');
  460. //遍历所有全选框
  461. $.each(total_check_all, function () {
  462. var check_all = $(this),
  463. check_items;
  464. //分组各纵横项
  465. var check_all_direction = check_all.data('direction');
  466. check_items = $('input.js-check[data-' + check_all_direction + 'id="' + check_all.data('checklist') + '"]').not(":disabled");
  467. //点击全选框
  468. check_all.change(function (e) {
  469. var check_wrap = check_all.parents('.js-check-wrap'); //当前操作区域所有复选框的父标签(重用考虑)
  470. if ($(this).prop('checked')) {
  471. //全选状态
  472. check_items.prop('checked', true);
  473. //所有项都被选中
  474. if (check_wrap.find('input.js-check').length === check_wrap.find('input.js-check:checked').length) {
  475. check_wrap.find(total_check_all).prop('checked', true);
  476. }
  477. } else {
  478. //非全选状态
  479. check_items.removeProp('checked');
  480. check_wrap.find(total_check_all).removeProp('checked');
  481. //另一方向的全选框取消全选状态
  482. var direction_invert = check_all_direction === 'x' ? 'y' : 'x';
  483. check_wrap.find($('input.js-check-all[data-direction="' + direction_invert + '"]')).removeProp('checked');
  484. }
  485. });
  486. //点击非全选时判断是否全部勾选
  487. check_items.change(function () {
  488. if ($(this).prop('checked')) {
  489. if (check_items.filter(':checked').length === check_items.length) {
  490. //已选择和未选择的复选框数相等
  491. check_all.prop('checked', true);
  492. }
  493. } else {
  494. check_all.removeProp('checked');
  495. }
  496. });
  497. });
  498. }
  499. //日期选择器
  500. var dateInput = $("input.js-date");
  501. if (dateInput.length) {
  502. Wind.use('datePicker', function () {
  503. dateInput.datePicker();
  504. });
  505. }
  506. //日期+时间选择器
  507. var dateTimeInput = $("input.js-datetime");
  508. if (dateTimeInput.length) {
  509. Wind.use('datePicker', function () {
  510. dateTimeInput.datePicker({
  511. time: true
  512. });
  513. });
  514. }
  515. var yearInput = $("input.js-year");
  516. if (yearInput.length) {
  517. Wind.use('datePicker', function () {
  518. yearInput.datePicker({
  519. startView: 'decade',
  520. minView: 'decade',
  521. format: 'yyyy',
  522. autoclose: true
  523. });
  524. });
  525. }
  526. var monthInput = $("input.js-year-month");
  527. if (monthInput.length) {
  528. Wind.use('datePicker', function () {
  529. monthInput.datePicker({
  530. startView: 'decade',
  531. minView: 'year',
  532. format: 'yyyy-mm',
  533. autoclose: true
  534. });
  535. });
  536. }
  537. // bootstrap月选择器
  538. var bootstrapMonthInput = $("input.js-bootstrap-month")
  539. if (bootstrapMonthInput.length) {
  540. Wind.css('bootstrapDatetimePicker');
  541. Wind.use('bootstrapDatetimePicker', function () {
  542. bootstrapMonthInput.datetimepicker({
  543. language: 'en-us',
  544. format: 'yyyy-mm',
  545. startView: 'year',
  546. minView: 'year',
  547. autoclose: true
  548. });
  549. });
  550. }
  551. // bootstrap日期选择器
  552. var bootstrapDateInput = $("input.js-bootstrap-date")
  553. if (bootstrapDateInput.length) {
  554. Wind.css('bootstrapDatetimePicker');
  555. Wind.use('bootstrapDatetimePicker', function () {
  556. bootstrapDateInput.datetimepicker({
  557. language: 'en-us',
  558. format: 'yyyy-mm-dd',
  559. minView: 'month',
  560. todayBtn: 1,
  561. autoclose: true
  562. });
  563. });
  564. }
  565. // bootstrap时间选择器
  566. var bootstrapTimeInput = $("input.js-bootstrap-time")
  567. if (bootstrapTimeInput.length) {
  568. Wind.css('bootstrapDatetimePicker');
  569. Wind.use('bootstrapDatetimePicker', function () {
  570. bootstrapTimeInput.datetimepicker({
  571. language: 'en-us',
  572. format: 'hh:ii:ss',
  573. startView: 1,
  574. minView: 0,
  575. autoclose: true
  576. });
  577. });
  578. }
  579. // bootstrap日期选择器日期+时间选择器
  580. var bootstrapDateTimeInput = $("input.js-bootstrap-datetime");
  581. if (bootstrapDateTimeInput.length) {
  582. Wind.css('bootstrapDatetimePicker');
  583. Wind.use('bootstrapDatetimePicker', function () {
  584. bootstrapDateTimeInput.datetimepicker({
  585. language: 'en-us',
  586. format: 'yyyy-mm-dd hh:ii',
  587. todayBtn: 1,
  588. autoclose: true
  589. });
  590. });
  591. }
  592. //tab
  593. var tabs_nav = $('ul.js-tabs-nav');
  594. if (tabs_nav.length) {
  595. Wind.use('tabs', function () {
  596. tabs_nav.tabs('.js-tabs-content > div');
  597. });
  598. }
  599. //地址联动
  600. var $js_address_select = $('.js-address-select');
  601. if ($js_address_select.length > 0) {
  602. $('.js-address-province-select,.js-address-city-select,.js-address-district-select').change(function () {
  603. var $this = $(this);
  604. var id = $this.val();
  605. var $child_area_select;
  606. var $this_js_address_select = $this.parent().parents('.js-address-select');
  607. if ($this.is('.js-address-province-select')) {
  608. $child_area_select = $this_js_address_select.children().find('.js-address-city-select');
  609. $this_js_address_select.children().find('.js-address-district-select').hide();
  610. $this_js_address_select.children().find('.js-address-district-select').next().hide();
  611. $this_js_address_select.children().find('.js-address-town-select').hide();
  612. $this_js_address_select.children().find('.js-address-town-select').next().hide();
  613. } else if($this.is('.js-address-city-select')){
  614. $child_area_select = $this_js_address_select.children().find('.js-address-district-select');
  615. $this_js_address_select.children().find('.js-address-town-select').hide();
  616. $this_js_address_select.children().find('.js-address-town-select').next().hide();
  617. }else{
  618. $child_area_select = $this_js_address_select.children().find('.js-address-town-select');
  619. }
  620. var empty_option = '<option class="js-address-empty-option" value="">请选择</option>';
  621. $child_area_select.html(empty_option);
  622. var child_area_html = $this.data('childarea' + id);
  623. if (child_area_html) {
  624. $child_area_select.show();
  625. $child_area_select.html(child_area_html);
  626. return;
  627. }
  628. $.ajax({
  629. url: $this_js_address_select.data('url'),
  630. type: 'POST',
  631. dataType: 'JSON',
  632. data: {id: id},
  633. success: function (data) {
  634. if (data.code == 1) {
  635. var areas = JSON.stringify(data.data.areas);
  636. console.log(areas.length);
  637. if (areas.length > 2) {
  638. var html = [empty_option];
  639. $.each(data.data.areas, function (i, area) {
  640. var area_html = '<option value="[id]">[name]</option>';
  641. area_html = area_html.replace('[name]', area.name);
  642. area_html = area_html.replace('[id]', area.id);
  643. html.push(area_html);
  644. });
  645. html = html.join('', html);
  646. $this.data('childarea' + id, html);
  647. $child_area_select.html(html);
  648. $child_area_select.show();
  649. $child_area_select.next().show();
  650. } else {
  651. $child_area_select.hide();
  652. $child_area_select.next().hide();
  653. }
  654. }
  655. },
  656. error: function () {
  657. },
  658. complete: function () {
  659. }
  660. });
  661. });
  662. }
  663. //地址联动end
  664. // 搜索面板控制
  665. var $jsToggleSearch = $('.js-toggle-search');
  666. if ($jsToggleSearch.length > 0) {
  667. $jsToggleSearch.click(function () {
  668. if ($('.js-search-form:visible').length) {
  669. $('.js-search-form').slideUp();
  670. } else {
  671. $('.js-search-form').slideDown();
  672. }
  673. });
  674. }
  675. })();
  676. //重新刷新页面,使用location.reload()有可能导致重新提交
  677. function reloadPage(win) {
  678. var location = win.location;
  679. location.href = location.pathname + location.search;
  680. }
  681. /**
  682. * 页面跳转
  683. * @param url 要打开的页面地址
  684. */
  685. function redirect(url) {
  686. location.href = url;
  687. }
  688. /**
  689. * 读取cookie
  690. * @param name
  691. * @returns
  692. */
  693. function getCookie(name) {
  694. var cookieValue = null;
  695. if (document.cookie && document.cookie != '') {
  696. var cookies = document.cookie.split(';');
  697. for (var i = 0; i < cookies.length; i++) {
  698. var cookie = jQuery.trim(cookies[i]);
  699. // Does this cookie string begin with the name we want?
  700. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  701. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  702. break;
  703. }
  704. }
  705. }
  706. return cookieValue;
  707. }
  708. /**
  709. * 设置cookie
  710. */
  711. function setCookie(name, value, options) {
  712. options = options || {};
  713. if (value === null) {
  714. value = '';
  715. options.expires = -1;
  716. }
  717. var expires = '';
  718. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  719. var date;
  720. if (typeof options.expires == 'number') {
  721. date = new Date();
  722. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  723. } else {
  724. date = options.expires;
  725. }
  726. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  727. }
  728. var path = options.path ? '; path=' + options.path : '';
  729. var domain = options.domain ? '; domain=' + options.domain : '';
  730. var secure = options.secure ? '; secure' : '';
  731. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  732. }
  733. /**
  734. * 打开iframe式的窗口对话框
  735. * @param url
  736. * @param title
  737. * @param options
  738. */
  739. function openIframeDialog(url, title, options) {
  740. Wind.css('artDialog');
  741. var params = {
  742. title: title,
  743. lock: true,
  744. opacity: 0,
  745. width: "95%",
  746. height: '90%'
  747. };
  748. params = options ? $.extend(params, options) : params;
  749. Wind.use('artDialog', 'iframeTools', function () {
  750. art.dialog.open(url, params);
  751. });
  752. }
  753. /**
  754. * 打开地图对话框
  755. *
  756. * @param url
  757. * @param title
  758. * @param options
  759. * @param callback
  760. */
  761. function openMapDialog(url, title, options, callback) {
  762. Wind.css('artDialog');
  763. var params = {
  764. title: title,
  765. lock: true,
  766. opacity: 0,
  767. width: "95%",
  768. height: 400,
  769. ok: function () {
  770. if (callback) {
  771. var d = this.iframe.contentWindow;
  772. var lng = $("#lng_input", d.document).val();
  773. var lat = $("#lat_input", d.document).val();
  774. var address = {};
  775. address.address = $("#address_input", d.document).val();
  776. address.province = $("#province_input", d.document).val();
  777. address.city = $("#city_input", d.document).val();
  778. address.district = $("#district_input", d.document).val();
  779. callback.apply(this, [lng, lat, address]);
  780. }
  781. }
  782. };
  783. params = options ? $.extend(params, options) : params;
  784. Wind.use('artDialog', 'iframeTools', function () {
  785. art.dialog.open(url, params);
  786. });
  787. }
  788. /**
  789. * 打开文件上传对话框
  790. * @param dialog_title 对话框标题
  791. * @param callback 回调方法,参数有(当前dialog对象,选择的文件数组,你设置的extra_params)
  792. * @param extra_params 额外参数,object
  793. * @param multi 是否可以多选
  794. * @param filetype 文件类型,image,video,audio,file
  795. * @param app 应用名,CMF的应用名
  796. */
  797. function openUploadDialog(dialog_title, callback, extra_params, multi, filetype, app) {
  798. Wind.css('artDialog');
  799. multi = multi ? 1 : 0;
  800. filetype = filetype ? filetype : 'image';
  801. app = app ? app : GV.APP;
  802. var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app;
  803. Wind.use("artDialog", "iframeTools", function () {
  804. art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
  805. title: dialog_title,
  806. id: new Date().getTime(),
  807. width: '600px',
  808. height: '350px',
  809. lock: true,
  810. fixed: true,
  811. background: "#CCCCCC",
  812. opacity: 0,
  813. ok: function () {
  814. if (typeof callback == 'function') {
  815. var iframewindow = this.iframe.contentWindow;
  816. var files = iframewindow.get_selected_files();
  817. console.log(files);
  818. if (files && files.length > 0) {
  819. callback.apply(this, [this, files, extra_params]);
  820. } else {
  821. return false;
  822. }
  823. }
  824. },
  825. cancel: true
  826. });
  827. });
  828. }
  829. /**
  830. * 单个文件上传
  831. * @param dialog_title 上传对话框标题
  832. * @param input_selector 图片容器
  833. * @param filetype 文件类型,image,video,audio,file
  834. * @param extra_params 额外参数,object
  835. * @param app 应用名,CMF的应用名
  836. */
  837. function uploadSdkPluginOne(dialog_title, input_selector, extra_params, app) {
  838. openUploadDialog(dialog_title, function (dialog, files) {
  839. $(input_selector).val(files[0].preview_url);
  840. $(input_selector+'_md5').val(files[0].file_md5);
  841. $(input_selector+'_file').val(1);
  842. }, extra_params, 0, 'file', app);
  843. }
  844. /**
  845. * 单个文件上传
  846. * @param dialog_title 上传对话框标题
  847. * @param input_selector 图片容器
  848. * @param filetype 文件类型,image,video,audio,file
  849. * @param extra_params 额外参数,object
  850. * @param app 应用名,CMF的应用名
  851. */
  852. function uploadOne(dialog_title, input_selector, filetype, extra_params, app) {
  853. openUploadDialog(dialog_title, function (dialog, files) {
  854. $(input_selector).val(files[0].filepath);
  855. $(input_selector + '-preview').attr('href', files[0].preview_url);
  856. $(input_selector + '-name').val(files[0].name);
  857. }, extra_params, 0, filetype, app);
  858. }
  859. /**
  860. * 单个图片上传
  861. * @param dialog_title 上传对话框标题
  862. * @param input_selector 图片容器
  863. * @param extra_params 额外参数,object
  864. * @param app 应用名,CMF的应用名
  865. */
  866. function uploadOneImage(dialog_title, input_selector, extra_params, app) {
  867. openUploadDialog(dialog_title, function (dialog, files) {
  868. $(input_selector).val(files[0].filepath);
  869. $(input_selector + '-preview').attr('src', files[0].preview_url);
  870. $(input_selector + '-name').val(files[0].name);
  871. }, extra_params, 0, 'image', app);
  872. }
  873. /**
  874. * 多图上传
  875. * @param dialog_title 上传对话框标题
  876. * @param container_selector 图片容器
  877. * @param item_tpl_wrapper_id 单个图片html模板容器id
  878. * @param extra_params 额外参数,object
  879. * @param app 应用名,CMF 的应用名
  880. */
  881. function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) {
  882. openUploadDialog(dialog_title, function (dialog, files) {
  883. var tpl = $('#' + item_tpl_wrapper_id).html();
  884. var html = '';
  885. $.each(files, function (i, item) {
  886. var itemtpl = tpl;
  887. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  888. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  889. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  890. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  891. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  892. html += itemtpl;
  893. });
  894. $(container_selector).append(html);
  895. }, extra_params, 1, 'image', app);
  896. }
  897. /**
  898. * 多文件上传
  899. * @param dialog_title 上传对话框标题
  900. * @param container_selector 图片容器
  901. * @param item_tpl_wrapper_id 单个图片html模板容器id
  902. * @param filetype 文件类型,image,video,audio,file
  903. * @param extra_params 额外参数,object
  904. * @param app 应用名,CMF 的应用名
  905. */
  906. function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app) {
  907. filetype = filetype ? filetype : 'file';
  908. openUploadDialog(dialog_title, function (dialog, files) {
  909. var tpl = $('#' + item_tpl_wrapper_id).html();
  910. var html = '';
  911. $.each(files, function (i, item) {
  912. var itemtpl = tpl;
  913. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  914. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  915. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  916. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  917. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  918. html += itemtpl;
  919. });
  920. $(container_selector).append(html);
  921. }, extra_params, 1, filetype, app);
  922. }
  923. /**
  924. * 查看图片对话框
  925. * @param img 图片地址
  926. */
  927. function imagePreviewDialog(img) {
  928. Wind.css('layer');
  929. Wind.use("layer", function () {
  930. layer.photos({
  931. photos: {
  932. "title": "", //相册标题
  933. "id": 'image_preview', //相册id
  934. "start": 0, //初始显示的图片序号,默认0
  935. "data": [ //相册包含的图片,数组格式
  936. {
  937. "alt": "",
  938. "pid": 666, //图片id
  939. "src": img, //原图地址
  940. "thumb": img //缩略图地址
  941. }
  942. ]
  943. } //格式见API文档手册页
  944. , anim: 5, //0-6的选择,指定弹出图片动画类型,默认随机
  945. shadeClose: true,
  946. // skin: 'layui-layer-nobg',
  947. shade: [0.5, '#000000'],
  948. shadeClose: true,
  949. })
  950. });
  951. }
  952. function artdialogAlert(msg) {
  953. Wind.css('artDialog');
  954. Wind.use("artDialog", function () {
  955. art.dialog({
  956. id: new Date().getTime(),
  957. icon: "error",
  958. fixed: true,
  959. lock: true,
  960. background: "#CCCCCC",
  961. opacity: 0,
  962. content: msg,
  963. ok: function () {
  964. return true;
  965. }
  966. });
  967. });
  968. }
  969. function openIframeLayer(url, title, options) {
  970. var params = {
  971. type: 2,
  972. title: title,
  973. shadeClose: true,
  974. // skin: 'layui-layer-nobg',
  975. anim: -1,
  976. shade: [0.001, '#000000'],
  977. shadeClose: true,
  978. area: ['95%', '90%'],
  979. move: false,
  980. content: url,
  981. yes: function (index, layero) {
  982. //do something
  983. layer.close(index); //如果设定了yes回调,需进行手工关闭
  984. }
  985. };
  986. params = options ? $.extend(params, options) : params;
  987. Wind.css('layer');
  988. Wind.use("layer", function () {
  989. layer.open(params);
  990. });
  991. }