纽威
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.

638 lines
20 KiB

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