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.

717 lines
23 KiB

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