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

676 lines
22 KiB

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