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

711 lines
23 KiB

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