纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

644 lines
20 KiB

3 years ago
  1. $(function () {
  2. document.body.className = localStorage.getItem('config-skin');
  3. $("[data-toggle='tooltip']").tooltip();
  4. })
  5. $.reload = function () {
  6. location.reload();
  7. return false;
  8. }
  9. $.loading = function (bool, text) {
  10. var $loadingpage = top.$("#loadingPage");
  11. var $loadingtext = $loadingpage.find('.loading-content');
  12. if (bool) {
  13. $loadingpage.show();
  14. } else {
  15. if ($loadingtext.attr('istableloading') == undefined) {
  16. $loadingpage.hide();
  17. }
  18. }
  19. if (!!text) {
  20. $loadingtext.html(text);
  21. } else {
  22. $loadingtext.html("页面加载中,请稍等...");
  23. }
  24. $loadingtext.css("left", (top.$('body').width() - $loadingtext.width()) / 2 - 50);
  25. $loadingtext.css("top", (top.$('body').height() - $loadingtext.height()) / 2);
  26. }
  27. $.request = function (name) {
  28. var search = location.search.slice(1);
  29. var arr = search.split("&");
  30. for (var i = 0; i < arr.length; i++) {
  31. var ar = arr[i].split("=");
  32. if (ar[0] == name) {
  33. if (unescape(ar[1]) == 'undefined') {
  34. return "";
  35. } else {
  36. return unescape(ar[1]);
  37. }
  38. }
  39. }
  40. return "";
  41. }
  42. $.currentWindow = function () {
  43. var iframeId = top.$(".NFine_iframe:visible").attr("id");
  44. return top.frames[iframeId];
  45. }
  46. $.currentWindow1 = function () {
  47. var iframeId = window.parent.document.getElementsByName("CartonNoAdd");
  48. return top.frames[iframeId];
  49. }
  50. $.browser = function () {
  51. var userAgent = navigator.userAgent;
  52. var isOpera = userAgent.indexOf("Opera") > -1;
  53. if (isOpera) {
  54. return "Opera"
  55. };
  56. if (userAgent.indexOf("Firefox") > -1) {
  57. return "FF";
  58. }
  59. if (userAgent.indexOf("Chrome") > -1) {
  60. if (window.navigator.webkitPersistentStorage.toString().indexOf('DeprecatedStorageQuota') > -1) {
  61. return "Chrome";
  62. } else {
  63. return "360";
  64. }
  65. }
  66. if (userAgent.indexOf("Safari") > -1) {
  67. return "Safari";
  68. }
  69. if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
  70. return "IE";
  71. };
  72. }
  73. $.download = function (url, data, method) {
  74. if (url && data) {
  75. data = typeof data == 'string' ? data : jQuery.param(data);
  76. var inputs = '';
  77. $.each(data.split('&'), function () {
  78. var pair = this.split('=');
  79. inputs += '<input type="hidden" name="' + pair[0] + '" value="' + pair[1] + '" />';
  80. });
  81. $('<form action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>').appendTo('body').submit().remove();
  82. };
  83. };
  84. $.modalOpen = function (options) {
  85. var defaults = {
  86. id: null,
  87. title: '系统提示',
  88. width: "100px",
  89. height: "100px",
  90. url: '',
  91. shade: 0.3,
  92. btn: ['确定', '关闭'],
  93. btnclass: ['btn btn-primary', 'btn btn-danger'],
  94. end: null,
  95. callBack: null
  96. };
  97. var options = $.extend(defaults, options);
  98. var _width = top.$(window).width() > parseInt(options.width.replace('px', '')) ? options.width : top.$(window).width() + 'px';
  99. var _height = top.$(window).height() > parseInt(options.height.replace('px', '')) ? options.height : top.$(window).height() + 'px';
  100. top.layer.open({
  101. id: options.id,
  102. type: 2,
  103. shade: options.shade,
  104. title: options.title,
  105. fix: false,
  106. area: [_width, _height],
  107. content: options.url,
  108. btn: options.btn,
  109. btnclass: options.btnclass,
  110. yes: function () {
  111. options.callBack(options.id)
  112. }, cancel: function () {
  113. return true;
  114. }
  115. });
  116. }
  117. $.modalOpen1 = function (options) {
  118. var defaults = {
  119. id: null,
  120. title: '系统提示',
  121. width: "100px",
  122. height: "100px",
  123. url: '',
  124. shade: 0.3,
  125. btn: ['确定'],
  126. btnclass: ['btn btn-primary', 'btn btn-danger'],
  127. callBack: null
  128. };
  129. var options = $.extend(defaults, options);
  130. var _width = top.$(window).width() > parseInt(options.width.replace('px', '')) ? options.width : top.$(window).width() + 'px';
  131. var _height = top.$(window).height() > parseInt(options.height.replace('px', '')) ? options.height : top.$(window).height() + 'px';
  132. top.layer.open({
  133. id: options.id,
  134. type: 2,
  135. closeBtn:0,
  136. shade: options.shade,
  137. title: options.title,
  138. fix: false,
  139. area: [_width, _height],
  140. content: options.url,
  141. btn: options.btn,
  142. btnclass: options.btnclass,
  143. yes: function () {
  144. options.callBack(options.id)
  145. }, cancel: function () {
  146. options.callBack(options.id)
  147. }
  148. });
  149. }
  150. $.modalOpen2 = function (options) {
  151. var defaults = {
  152. id: null,
  153. title: '系统提示',
  154. width: "100px",
  155. height: "100px",
  156. url: '',
  157. shade: 0.3,
  158. btn: ['确定', '关闭'],
  159. btnclass: ['btn btn-primary', 'btn btn-danger'],
  160. end: null,
  161. callBack: null
  162. };
  163. var options = $.extend(defaults, options);
  164. var _width = top.$(window).width() > parseInt(options.width.replace('px', '')) ? options.width : top.$(window).width() + 'px';
  165. var _height = top.$(window).height() > parseInt(options.height.replace('px', '')) ? options.height : top.$(window).height() + 'px';
  166. top.layer.open({
  167. id: options.id,
  168. type: 2,
  169. shade: options.shade,
  170. title: options.title,
  171. fix: false,
  172. area: [_width, _height],
  173. content: options.url,
  174. btn: options.btn,
  175. maxmin:true,
  176. btnclass: options.btnclass,
  177. yes: function () {
  178. options.callBack(options.id)
  179. }, cancel: function () {
  180. return true;
  181. },
  182. end: function () {
  183. var $Gird = $("#gridList");
  184. $("#gridList").trigger("reloadGrid");
  185. reloadData();
  186. }
  187. });
  188. }
  189. $.modalConfirm = function (content, callBack) {
  190. top.layer.confirm(content, {
  191. icon: "fa-exclamation-circle",
  192. title: "提示信息",
  193. btn: ['确认', '取消'],
  194. btnclass: ['btn btn-primary', 'btn btn-danger'],
  195. }, function () {
  196. callBack(true);
  197. }, function () {
  198. callBack(false)
  199. });
  200. }
  201. $.modalConfirm2 = function (content, callBack) {
  202. top.layer.confirm(content, {
  203. icon: "fa-exclamation-circle",
  204. title: "系统消息",
  205. btn: ['确定', '取消'],
  206. btnclass: ['btn btn-primary', 'btn btn-danger'],
  207. }, function () {
  208. callBack(true);
  209. }, function () {
  210. callBack(false)
  211. });
  212. }
  213. $.modalAlert = function (content, type) {
  214. var icon = "";
  215. if (type == 'success') {
  216. icon = "fa-check-circle";
  217. }
  218. if (type == 'error') {
  219. icon = "fa-times-circle";
  220. }
  221. if (type == 'warning') {
  222. icon = "fa-exclamation-circle";
  223. }
  224. top.layer.alert(content, {
  225. icon: icon,
  226. //title: "System Message",
  227. title: "系统信息",
  228. btn: ['确认'],
  229. btnclass: ['btn btn-primary'],
  230. });
  231. }
  232. $.modalMsg = function (content, type) {
  233. if (type != undefined) {
  234. var icon = "";
  235. if (type == 'success') {
  236. icon = "fa-check-circle";
  237. }
  238. if (type == 'error') {
  239. icon = "fa-times-circle";
  240. }
  241. if (type == 'warning') {
  242. icon = "fa-exclamation-circle";
  243. }
  244. top.layer.msg(content, { icon: icon, time: 4000, shift: 5 });
  245. top.$(".layui-layer-msg").find('i.' + icon).parents('.layui-layer-msg').addClass('layui-layer-msg-' + type);
  246. } else {
  247. top.layer.msg(content);
  248. }
  249. }
  250. $.modalClose = function () {
  251. var index = top.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  252. var $IsdialogClose = top.$("#layui-layer" + index).find('.layui-layer-btn').find("#IsdialogClose");
  253. var IsClose = $IsdialogClose.is(":checked");
  254. if ($IsdialogClose.length == 0) {
  255. IsClose = true;
  256. }
  257. if (IsClose) {
  258. top.layer.close(index);
  259. } else {
  260. location.reload();
  261. }
  262. }
  263. $.submitForm = function (options) {
  264. var defaults = {
  265. url: "",
  266. param: [],
  267. loading: "正在提交数据...",
  268. //loading: "Submission of data...",
  269. success: null,
  270. close: true
  271. };
  272. var options = $.extend(defaults, options);
  273. $.loading(true, options.loading);
  274. window.setTimeout(function () {
  275. if ($('[name=__RequestVerificationToken]').length > 0) {
  276. options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  277. }
  278. $.ajax({
  279. url: options.url,
  280. data: options.param,
  281. type: "post",
  282. dataType: "json",
  283. success: function (data) {
  284. if (data.state == "success") {
  285. options.success(data);
  286. $.modalMsg(data.message, data.state);
  287. if (options.close == true) {
  288. $.modalClose();
  289. }
  290. } else {
  291. $.modalAlert(data.message, data.state);
  292. }
  293. },
  294. error: function (XMLHttpRequest, textStatus, errorThrown) {
  295. $.loading(false);
  296. $.modalMsg(errorThrown, "error");
  297. },
  298. beforeSend: function () {
  299. $.loading(true, options.loading);
  300. },
  301. complete: function () {
  302. $.loading(false);
  303. }
  304. });
  305. }, 500);
  306. }
  307. $.submitForm2 = function (options) {
  308. var defaults = {
  309. url: "",
  310. param: [],
  311. loading: "正在提交数据...",
  312. //loading: "Submission of data...",
  313. success: null,
  314. close: true
  315. };
  316. var options = $.extend(defaults, options);
  317. $.loading(true, options.loading);
  318. window.setTimeout(function () {
  319. if ($('[name=__RequestVerificationToken]').length > 0) {
  320. options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  321. }
  322. $.ajax({
  323. url: options.url,
  324. data: options.param,
  325. type: "post",
  326. dataType: "json",
  327. success: function (data) {
  328. if (data.state == "success") {
  329. options.success(data);
  330. $.modalAlert(data.message, data.state);
  331. if (options.close == true) {
  332. $.modalClose();
  333. }
  334. } else {
  335. $.modalAlert(data.message, data.state);
  336. }
  337. },
  338. error: function (XMLHttpRequest, textStatus, errorThrown) {
  339. $.loading(false);
  340. $.modalMsg(errorThrown, "error");
  341. },
  342. beforeSend: function () {
  343. $.loading(true, options.loading);
  344. },
  345. complete: function () {
  346. $.loading(false);
  347. }
  348. });
  349. }, 500);
  350. }
  351. $.submitForm3 = function (options) {
  352. var defaults = {
  353. url: "",
  354. param: [],
  355. loading: "正在提交数据...",
  356. //loading: "Submission of data...",
  357. success: null,
  358. close: true
  359. };
  360. var options = $.extend(defaults, options);
  361. $.loading(true, options.loading);
  362. window.setTimeout(function () {
  363. //if ($('[name=__RequestVerificationToken]').length > 0) {
  364. // options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  365. //}
  366. $.ajax({
  367. url: options.url,
  368. data: options.param,
  369. type: "post",
  370. dataType: "json",
  371. success: function (data) {
  372. if (data.state == "success") {
  373. options.success(data);
  374. $.modalMsg(data.message, data.state);
  375. if (options.close == true) {
  376. //window.parent.reloadData();
  377. $.modalClose();
  378. }
  379. } else {
  380. $.modalAlert(data.message, data.state);
  381. }
  382. },
  383. error: function (XMLHttpRequest, textStatus, errorThrown) {
  384. $.loading(false);
  385. $.modalMsg(errorThrown, "error");
  386. },
  387. beforeSend: function () {
  388. $.loading(true, options.loading);
  389. },
  390. complete: function () {
  391. $.loading(false);
  392. }
  393. });
  394. }, 500);
  395. }
  396. $.deleteForm = function (options) {
  397. var defaults = {
  398. prompt: "注:您确定要删除该项数据吗?",
  399. //prompt: "Note: are you sure you want to delete this data?",
  400. url: "",
  401. param: [],
  402. loading: "正在删除数据...",
  403. //loading: "Deleting data...",
  404. success: null,
  405. close: true
  406. };
  407. var options = $.extend(defaults, options);
  408. if ($('[name=__RequestVerificationToken]').length > 0) {
  409. options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  410. }
  411. $.modalConfirm(options.prompt, function (r) {
  412. if (r) {
  413. $.loading(true, options.loading);
  414. window.setTimeout(function () {
  415. $.ajax({
  416. url: options.url,
  417. data: options.param,
  418. type: "post",
  419. dataType: "json",
  420. success: function (data) {
  421. if (data.state == "success") {
  422. options.success(data);
  423. $.modalMsg(data.message, data.state);
  424. } else {
  425. $.modalAlert(data.message, data.state);
  426. }
  427. },
  428. error: function (XMLHttpRequest, textStatus, errorThrown) {
  429. $.loading(false);
  430. $.modalMsg(errorThrown, "error");
  431. },
  432. beforeSend: function () {
  433. $.loading(true, options.loading);
  434. },
  435. complete: function () {
  436. $.loading(false);
  437. }
  438. });
  439. }, 500);
  440. }
  441. });
  442. }
  443. $.jsonWhere = function (data, action) {
  444. if (action == null) return;
  445. var reval = new Array();
  446. $(data).each(function (i, v) {
  447. if (action(v)) {
  448. reval.push(v);
  449. }
  450. })
  451. return reval;
  452. }
  453. $.fn.jqGridRowValue = function () {
  454. var $grid = $(this);
  455. var selectedRowIds = $grid.jqGrid("getGridParam", "selarrrow");
  456. if (selectedRowIds != "") {
  457. var json = [];
  458. var len = selectedRowIds.length;
  459. for (var i = 0; i < len ; i++) {
  460. var rowData = $grid.jqGrid('getRowData', selectedRowIds[i]);
  461. json.push(rowData);
  462. }
  463. return json;
  464. } else {
  465. return $grid.jqGrid('getRowData', $grid.jqGrid('getGridParam', 'selrow'));
  466. }
  467. }
  468. $.fn.formValid = function () {
  469. return $(this).valid({
  470. errorPlacement: function (error, element) {
  471. element.parents('.formValue').addClass('has-error');
  472. element.parents('.has-error').find('i.error').remove();
  473. element.parents('.has-error').append('<i class="form-control-feedback fa fa-exclamation-circle error" data-placement="left" data-toggle="tooltip" title="' + error + '"></i>');
  474. $("[data-toggle='tooltip']").tooltip();
  475. if (element.parents('.input-group').hasClass('input-group')) {
  476. element.parents('.has-error').find('i.error').css('right', '33px')
  477. }
  478. },
  479. success: function (element) {
  480. element.parents('.has-error').find('i.error').remove();
  481. element.parent().removeClass('has-error');
  482. }
  483. });
  484. }
  485. $.fn.formSerialize = function (formdate) {
  486. var element = $(this);
  487. if (!!formdate) {
  488. for (var key in formdate) {
  489. var $id = element.find('#' + key);
  490. var value = $.trim(formdate[key]).replace(/&nbsp;/g, '');
  491. var type = $id.attr('type');
  492. if ($id.hasClass("select2-hidden-accessible")) {
  493. type = "select";
  494. }
  495. switch (type) {
  496. case "checkbox":
  497. if (value == "true") {
  498. $id.attr("checked", 'checked');
  499. } else {
  500. $id.removeAttr("checked");
  501. }
  502. break;
  503. case "select":
  504. $id.val(value).trigger("change");
  505. break;
  506. default:
  507. $id.val(value);
  508. break;
  509. }
  510. };
  511. return false;
  512. }
  513. var postdata = {};
  514. element.find('input,select,textarea').each(function (r) {
  515. var $this = $(this);
  516. var id = $this.attr('id');
  517. var type = $this.attr('type');
  518. switch (type) {
  519. case "checkbox":
  520. postdata[id] = $this.is(":checked");
  521. break;
  522. default:
  523. var value = $this.val() == "" ? "&nbsp;" : $this.val();
  524. if (!$.request("keyValue")) {
  525. value = value.replace(/&nbsp;/g, '');
  526. }
  527. postdata[id] = value;
  528. break;
  529. }
  530. });
  531. if ($('[name=__RequestVerificationToken]').length > 0) {
  532. postdata["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
  533. }
  534. return postdata;
  535. };
  536. $.fn.bindText = function (options) {
  537. var defaults = {
  538. id: "id",
  539. text: "text",
  540. search: false,
  541. url: "",
  542. param: [],
  543. change: null
  544. };
  545. var options = $.extend(defaults, options);
  546. var $element = $(this);
  547. if (options.url != "") {
  548. $.ajax({
  549. url: options.url,
  550. data: options.param,
  551. dataType: "text",
  552. async: false,
  553. success: function (data) {
  554. $element.val(data);
  555. }
  556. });
  557. }
  558. }
  559. $.fn.bindSelect = function (options) {
  560. var defaults = {
  561. id: "id",
  562. text: "text",
  563. search: false,
  564. url: "",
  565. param: [],
  566. change: null
  567. };
  568. var options = $.extend(defaults, options);
  569. var $element = $(this);
  570. if (options.url != "") {
  571. $.ajax({
  572. url: options.url,
  573. data: options.param,
  574. dataType: "json",
  575. async: false,
  576. success: function (data) {
  577. $.each(data, function (i) {
  578. $element.append($("<option></option>").val(data[i][options.id]).html(data[i][options.text]));
  579. });
  580. $element.select2({
  581. minimumResultsForSearch: options.search == true ? 0 : -1
  582. });
  583. $element.on("change", function (e) {
  584. if (options.change != null) {
  585. options.change(data[$(this).find("option:selected").index()]);
  586. }
  587. $("#select2-" + $element.attr('id') + "-container").html($(this).find("option:selected").text().replace(/  /g, ''));
  588. });
  589. }
  590. });
  591. } else {
  592. $element.select2({
  593. minimumResultsForSearch: -1
  594. });
  595. }
  596. }
  597. $.fn.authorizeButton = function () {
  598. var moduleId = top.$(".NFine_iframe:visible").attr("id").substr(6);
  599. var dataJson = top.clients.authorizeButton[moduleId];
  600. var $element = $(this);
  601. $element.find('a[authorize=yes]').attr('authorize', 'no');
  602. if (dataJson != undefined) {
  603. $.each(dataJson, function (i) {
  604. $element.find("#" + dataJson[i].F_EnCode).attr('authorize', 'yes');
  605. });
  606. }
  607. $element.find("[authorize=no]").parents('li').prev('.split').remove();
  608. $element.find("[authorize=no]").parents('li').remove();
  609. $element.find('[authorize=no]').remove();
  610. }
  611. $.fn.dataGrid = function (options) {
  612. var defaults = {
  613. datatype: "json",
  614. autowidth: true,
  615. rownumbers: true,
  616. shrinkToFit: false,
  617. gridview: true
  618. };
  619. var options = $.extend(defaults, options);
  620. var $element = $(this);
  621. options["onSelectRow"] = function (rowid) {
  622. if ($(this).jqGrid("getGridParam", "selrow") != null) {
  623. var length = $(this).jqGrid("getGridParam", "selrow").length;
  624. var $operate = $(".operate");
  625. if (length > 0) {
  626. $operate.animate({ "left": 0 }, 200);
  627. } else {
  628. $operate.animate({ "left": '-100.1%' }, 200);
  629. }
  630. $operate.find('.close').click(function () {
  631. $operate.animate({ "left": '-100.1%' }, 200);
  632. })
  633. }
  634. };
  635. $element.jqGrid(options);
  636. };