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

202 lines
6.7 KiB

3 years ago
  1. //扩展jquery的格式化方法
  2. $.fn.parseForm = function () {
  3. var serializeObj = {};
  4. var array = this.serializeArray();
  5. var str = this.serialize();
  6. $(array).each(function () {
  7. if (serializeObj[this.name]) {
  8. if ($.isArray(serializeObj[this.name])) {
  9. serializeObj[this.name].push(this.value);
  10. } else {
  11. serializeObj[this.name] = [serializeObj[this.name], this.value];
  12. }
  13. } else {
  14. serializeObj[this.name] = this.value;
  15. }
  16. });
  17. return serializeObj;
  18. };
  19. window.alert = function (msg) {
  20. ShowMessage(msg);
  21. }
  22. window.alert = function (msg, type) {
  23. ShowMessageByType(msg, type);
  24. }
  25. $.fn.serializeObject = function () {
  26. var o = {};
  27. var a = this.serializeArray();
  28. $.each(a, function () {
  29. if (o[this.name]) {
  30. if (!o[this.name].push) {
  31. o[this.name] = [o[this.name]];
  32. }
  33. o[this.name].push(this.value || '');
  34. } else {
  35. o[this.name] = this.value || '';
  36. }
  37. });
  38. return o;
  39. };
  40. function positionRoute(SEQ, Contect, Method, Result) {
  41. var positionType = new Object();
  42. positionType.SEQ = SEQ;
  43. positionType.Contect = Contect;
  44. positionType.Method = Method;
  45. positionType.Result = Result;
  46. return positionType;
  47. }
  48. function serializeArray() {
  49. return this.map( function() {
  50. // Can add propHook for "elements" to filter or add form elements
  51. var elements = jQuery.prop( this, "elements" );
  52. return elements ? jQuery.makeArray( elements ) : this;
  53. } )
  54. .filter( function() {
  55. var type = this.type;
  56. // Use .is(":disabled") so that fieldset[disabled] works
  57. return this.name && !jQuery( this ).is( ":disabled" ) &&
  58. rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
  59. ( this.checked || !rcheckableType.test( type ) );
  60. } )
  61. .map( function( i, elem ) {
  62. var val = jQuery( this ).val();
  63. return val == null ?
  64. null :
  65. jQuery.isArray( val ) ?
  66. jQuery.map( val, function( val ) {
  67. return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
  68. } ) :
  69. { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
  70. } ).get();
  71. }
  72. //合并单元格
  73. function Merger(gridName, CellName) {
  74. //得到显示到界面的id集合
  75. var mya = $("#" + gridName + "").getDataIDs();
  76. //当前显示多少条
  77. var length = mya.length;
  78. for (var i = 0; i < length; i++) {
  79. //从上到下获取一条信息
  80. var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
  81. //定义合并行数
  82. var rowSpanTaxCount = 1;
  83. for (j = i + 1; j <= length; j++) {
  84. //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
  85. var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
  86. if (before[CellName] == end[CellName]) {
  87. rowSpanTaxCount++;
  88. $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });
  89. }
  90. else {
  91. rowSpanTaxCount = 1;
  92. break;
  93. }
  94. $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
  95. }
  96. }
  97. }
  98. //合并单元格//FrontCellName列未合并的行 不能合并
  99. function MergerRows(gridName, CellName, FrontCellName) {
  100. //得到显示到界面的id集合
  101. var mya = $("#" + gridName + "").getDataIDs();
  102. //当前显示多少条
  103. var length = mya.length;
  104. for (var i = 0; i < length; i++) {
  105. //从上到下获取一条信息
  106. var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
  107. //定义合并行数
  108. var rowSpanTaxCount = 1;
  109. for (j = i + 1; j <= length; j++) {
  110. //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
  111. var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
  112. if (before[CellName] == end[CellName] && before[FrontCellName] == end[FrontCellName]) {
  113. rowSpanTaxCount++;
  114. $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });
  115. }
  116. else {
  117. rowSpanTaxCount = 1;
  118. break;
  119. }
  120. $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
  121. }
  122. }
  123. }
  124. function ShowMessageByType(str, type) {
  125. if (type == "warning") { toastr.options.timeOut = "3000"; toastr.warning(str); }
  126. if (type == "error") { toastr.error(str); }
  127. if (type == "success") { toastr.options.timeOut = "3000"; toastr.success(str); }
  128. if (type == "info") { toastr.options.timeOut = "3000"; toastr.info(str); }
  129. if (type != "warning" && type != "error" && type != "success" && type != "info") { toastr.options.timeOut = "3000"; toastr.info(str); }
  130. }
  131. function ShowMessage(str) {
  132. toastr.options.timeOut = "3000";
  133. toastr.info(str);
  134. }
  135. function ShowMessage_TimeOut(str, timeOut) {
  136. toastr.options.timeOut = timeOut;
  137. toastr.info(str);
  138. }
  139. //字符串前面补0
  140. function PrefixZero(num, n) {
  141. return (Array(n).join(0) + num).slice(-n);
  142. }
  143. function GetWeek(dateString) {
  144. var da = '';
  145. if (dateString == undefined) {
  146. var now = new Date();
  147. var now_m = now.getMonth() + 1;
  148. now_m = (now_m < 10) ? '0' + now_m : now_m;
  149. var now_d = now.getDate();
  150. now_d = (now_d < 10) ? '0' + now_d : now_d;
  151. da = now.getFullYear() + '-' + now_m + '-' + now_d;
  152. } else {
  153. da = dateString;//日期格式2015-12-30
  154. }
  155. var date1 = new Date(da.substring(0, 4), parseInt(da.substring(5, 7)) - 1, da.substring(8, 10));//当前日期
  156. var date2 = new Date(da.substring(0, 4), 0, 1); //1月1号
  157. //获取1月1号星期(以周一为第一天,0周一~6周日)
  158. var dateWeekNum = date2.getDay() - 1;
  159. if (dateWeekNum < 0) { dateWeekNum = 6; }
  160. if (dateWeekNum < 4) {
  161. //前移日期
  162. date2.setDate(date2.getDate() - dateWeekNum);
  163. } else {
  164. //后移日期
  165. date2.setDate(date2.getDate() + 7 - dateWeekNum);
  166. }
  167. var d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
  168. if (d < 0) {
  169. var date3 = (date1.getFullYear() - 1) + "-12-31";
  170. return getYearWeek(date3);
  171. } else {
  172. //得到年数周数
  173. var year = date1.getFullYear();
  174. var week = Math.ceil((d + 1) / 7);
  175. return week;
  176. }
  177. }