base.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /**
  2. * 公共组件js
  3. * 为每个组件页面提供公共js方法
  4. * @author 003598
  5. */
  6. /** 页面通用方法接口*/
  7. var base ={
  8. /** 通用方法-震动棒*/
  9. invalid: function($cue) {
  10. //按钮动画效果
  11. $cue.stop().delay(100)
  12. .animate({'margin-left':-5}, 100)
  13. .animate({'margin-left':5}, 100)
  14. .animate({'margin-left':-4}, 100)
  15. .animate({'margin-left':4}, 100)
  16. .animate({'margin-left':-3}, 100)
  17. .animate({'margin-left':0}, 100);
  18. },
  19. /*str:{
  20. cope:'<img width=17px; src="'+basePath+'/image/common/cope.png">'
  21. },*/
  22. /** form表单提交 */
  23. setAction : function(action, method, formId, target) {
  24. action = basePath + "/" + action;
  25. method = method || "post";
  26. formId = "#" + (formId || "mainForm");
  27. target = target || "_self";
  28. $(formId).attr("action", action).attr("method", method).attr("target",
  29. target).submit();
  30. },
  31. /** get提交*/
  32. getAction:function(action){
  33. window.location.href= basePath + "/" +action;
  34. },
  35. /** 使用AJAX提交返回结果时,判断用户是否失效*/
  36. isUserFail:function($html){
  37. if ($html.find('.login').size()>0){
  38. alert('用户失效,请重新登录');
  39. base.getAction('quit.do');
  40. }
  41. },
  42. /** 上傳圖片控件初始化方法 */
  43. initUploadImg : function(_idFile, _idImg, _width, _height,_pic) {
  44. var idFile = _idFile || 'idFile_1';
  45. var idImg = _idImg || 'idImg_1';
  46. var width = _width || 200;
  47. var height = _height || 130;
  48. var pic = _pic || ImagePreview.TRANSPARENT;
  49. if (!idFile) {
  50. idFile = 'idFile_1';
  51. }
  52. if (!idImg) {
  53. idImg = 'idImg_1';
  54. }
  55. var ip1 = new ImagePreview($$(idFile), $$(idImg), {
  56. maxWidth : 200,
  57. maxHeight : 200,
  58. showWidth : width,
  59. showHeight : height,
  60. action : basePath + "/picture/imageUp.do"
  61. });
  62. ip1.img.src = pic;
  63. ip1.file.onchange = function() {
  64. ip1.preview();
  65. };
  66. },
  67. /** ajax公共方法 */
  68. WAP_POST : function(action, data,type, callback) {
  69. var dataObj = {};
  70. if (data){
  71. dataObj = data;
  72. }
  73. if(!type){
  74. type = 'json';
  75. }
  76. $.ajax({
  77. url : basePath + "/" + action,
  78. data : dataObj,
  79. type : 'post',
  80. dataType : type,
  81. async : false, // 取消异步请求
  82. beforeSend : function() {
  83. // 可添加提前预处理
  84. },
  85. success : function(o) {
  86. if (callback && $.isFunction(callback)) {
  87. callback(o);
  88. }
  89. },
  90. complete : function(XMLHttpRequest, textStatus) {
  91. // 可添加完成后处理
  92. },
  93. error : function() {
  94. // 可添加请求错误处理
  95. }
  96. });
  97. },
  98. // 排序事件
  99. opSort : function(_$){
  100. if(_$.sortable('option','disabled')){
  101. _$.sortable();
  102. _$.sortable('enable');
  103. }else{
  104. _$.sortable('disable');
  105. }
  106. },
  107. // 预览公共方法
  108. previewBtn:function(urlTest){
  109. reviewUrl=basePath+"/review.do?"+urlTest;
  110. var DialogLocation = base.CalcShowModalDialogLocation(445, 800);
  111. window.showModalDialog(reviewUrl, window, DialogLocation);
  112. },
  113. CalcShowModalDialogLocation:function(dialogWidth, dialogHeight)
  114. {
  115. var iWidth = dialogWidth;
  116. var iHeight = dialogHeight;
  117. var iTop = (window.screen.availHeight - 20 - iHeight) / 2;
  118. var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
  119. return 'dialogWidth:' + iWidth + 'px;dialogHeight:' + iHeight + 'px;dialogTop: ' + iTop + 'px; dialogLeft: ' + iLeft + 'px;center:yes;scroll:no;status:no;resizable:0;location:no';
  120. },
  121. /**
  122. * 公共删除方法
  123. *
  124. * @param tip: 删除提示语
  125. * @param execute: 删除时执行的方法(提交后台方法)
  126. */
  127. delGetAction: function(opts) {
  128. var ops = {
  129. tip : '您确定要删除吗?',
  130. execute: null
  131. };
  132. opts = $.extend({}, ops, opts);
  133. var isDel=window.confirm(opts.tip);
  134. if(isDel){
  135. if(opts.execute && $.isFunction(opts.execute)){
  136. opts.execute();
  137. }
  138. }
  139. },
  140. /**
  141. * 转换阿拉伯数字为汉字数字
  142. * @param num
  143. * @returns
  144. */
  145. chineseNum: function(num)
  146. {
  147. if(!/^\d*(\.\d*)?$/.test(num))
  148. {
  149. alert("你输入的不是数字,请重新输入!");
  150. return false;
  151. }
  152. var AA = new Array("零","一","二","三","四","五","六","七","八","九");
  153. var BB = new Array("","拾","佰","仟","万","亿","点","");
  154. var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
  155. for(var i=a[0].length-1; i>=0; i--)
  156. {
  157. switch(k)
  158. {
  159. case 0 :
  160. re = BB[7] + re;
  161. break;
  162. case 4 :
  163. if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0])) {
  164. re = BB[4] + re;
  165. }
  166. break;
  167. case 8 :
  168. re = BB[5] + re;
  169. BB[7] = BB[5];
  170. k = 0;
  171. break;
  172. }
  173. if(k%4 == 2 && a[0].charAt(i)=="0" && a[0].charAt(i+2) != "0"){
  174. re = AA[0] + re;
  175. }
  176. if(a[0].charAt(i) != 0) {
  177. re = AA[a[0].charAt(i)] + BB[k%4] + re;
  178. }
  179. k++;
  180. }
  181. if(a.length>1) {
  182. re += BB[6];
  183. for(var i=0; i<a[1].length; i++) {
  184. re += AA[a[1].charAt(i)];
  185. }
  186. }
  187. return re;
  188. },
  189. chineseCapitalNum: function(num)
  190. {
  191. if(!/^\d*(\.\d*)?$/.test(num))
  192. {
  193. alert("你输入的不是数字,请重新输入!");
  194. return false;
  195. }
  196. var AA = new Array("零","壹","贰","叁","肆","雾","陆","柒","捌","玖");
  197. var BB = new Array("","拾","佰","仟","万","亿","点","");
  198. var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
  199. for(var i=a[0].length-1; i>=0; i--)
  200. {
  201. switch(k)
  202. {
  203. case 0 :
  204. re = BB[7] + re;
  205. break;
  206. case 4 :
  207. if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0])) {
  208. re = BB[4] + re;
  209. }
  210. break;
  211. case 8 :
  212. re = BB[5] + re;
  213. BB[7] = BB[5];
  214. k = 0;
  215. break;
  216. }
  217. if(k%4 == 2 && a[0].charAt(i)=="0" && a[0].charAt(i+2) != "0"){
  218. re = AA[0] + re;
  219. }
  220. if(a[0].charAt(i) != 0) {
  221. re = AA[a[0].charAt(i)] + BB[k%4] + re;
  222. }
  223. k++;
  224. }
  225. if(a.length>1) {
  226. re += BB[6];
  227. for(var i=0; i<a[1].length; i++) {
  228. re += AA[a[1].charAt(i)];
  229. }
  230. }
  231. return re;
  232. },
  233. /**
  234. * 校验失败提示信息设置
  235. * @param cue
  236. * @param _text
  237. * @param type 1:cue为提示对象
  238. */
  239. setFailCue:function(cue, _text, type){
  240. // 提示消息
  241. var $cue = cue;
  242. if(!type){
  243. $cue = $cue.parents('.couponBase tr').find('[name=cue]');
  244. }
  245. $cue.removeClass().addClass('redFont').empty()
  246. .text(_text);
  247. // 输入框置空
  248. cue.val("");
  249. // 获取焦点
  250. cue.focus();
  251. // 震动提示
  252. base.invalid($cue);
  253. },
  254. /** 公共验证方法*/
  255. commonVailFrom:{
  256. /**
  257. * 表单校验
  258. *
  259. * 校验input中的value是否符合提交规则:
  260. * 1.非空校验(默认校验规则)
  261. * 2.字段重复校验(可选)
  262. * 3.时间校验(可选)
  263. * 不需要校验的input值,可设置属性isNull="true"
  264. * 例如:<input type="text" isNull="true">
  265. * 注意:该校验规则集仅对input进行校验,其他输入框的校验,请另行扩展
  266. *
  267. * @author wanglei_003598
  268. * @data 20140114
  269. *
  270. * @param className 待校验的表单名称 (必填参数)
  271. * @param repeatField 校验重复字段的名称,如果该项为空则不做字段重复校验 (可填参数)
  272. * @param repeatAction 字段重复校验后台Action (可填参数)
  273. * @param activitytype 活动类型(1.微调研,2.微预约,3.优惠劵,4.微投票,5.大转盘,6.刮刮奖)
  274. * @param keywordType 关键字设置场景:0.在新增活动的时候设置的关键字,此时用activityid
  275. * 1.在关键字设置页面设置的关键字,此时用keywordid校验关键字
  276. * @param isVailTime 是否对时间进行校验 (可填参数)
  277. * (校验规则:结束时间不能小于开始时间
  278. * 如有其他时间校验规则,请另行扩展)
  279. * @param startTimeId 开始时间id (可填参数),
  280. * 注意:如果该参数不填写,即使了开启时间校验,时间校验流程也跳过。
  281. * 开启时间校验选项时,务必设置开始时间的ID。
  282. * @param endTimeId 结束时间Id(可填参数)
  283. * @param isVaildExpiryTime 是否对兑奖时间进行校验 (可填参数)
  284. * (校验规则:兑奖结束时间不能小于兑奖开始时间
  285. * 兑奖结束时间不能大于活动结束时间
  286. * 兑奖开始时间不能大于活动开始时间
  287. * 如有其他时间校验规则,请另行扩展)
  288. * @param expBeginId 兑奖开始时间(可填参数)
  289. * @param expEndId 兑奖结束时间(可填参数)
  290. *
  291. * @returns {Number} 是否可以提交: 1可提交,0:不可提交
  292. */
  293. validForm: function(opts) {
  294. var ops = {
  295. className: 'mainForm',
  296. repeatField : null,
  297. repeatAction: null,
  298. activitytype: 0,
  299. keywordType:0,
  300. isVailTime: false,
  301. startTimeId: null,
  302. endTimeId: null,
  303. isVaildExpiryTime: null,
  304. expBeginId: null,
  305. expEndId: null
  306. };
  307. opts = $.extend({}, ops, opts);
  308. // 提交标示:1可提交,0:不可提交
  309. var xxx = 1;
  310. var cope = '<img width=17px; src="'+basePath+'/image/common/cope.png">';
  311. var cue = '.{0} tr';
  312. $('.' + opts.className).find('input:text:visible').each(function(_, e){
  313. var _me = $(e);
  314. var name = _me.attr('name');
  315. var parendVal = _me.attr('parend');
  316. if (parendVal){
  317. cue = '.{0} ' + parendVal;
  318. }
  319. var $cue = _me.parents(cue.format([opts.className])).find('[name=cue]');
  320. /** 非空校验*/
  321. if (!_me.attr('isNull')){
  322. var repeatFlag = base.commonVailFrom.vaildIsNull($cue, _me);
  323. if (repeatFlag){
  324. xxx = 0;
  325. return false;
  326. }
  327. }
  328. /** 数字校验*/
  329. if($(this).attr('num'))// 数字校验
  330. {
  331. var repeatFlag = base.commonVailFrom.vailNum($cue, _me);
  332. if (repeatFlag){
  333. xxx = 0;
  334. return false;
  335. }
  336. }
  337. /** 字段重复行校验*/
  338. if (opts.repeatField && name === opts.repeatField){
  339. var repeatFlag = base.commonVailFrom.vaildRepeat($cue, _me, opts);
  340. if (repeatFlag){
  341. xxx = 0;
  342. return false;
  343. }else{
  344. $cue.removeClass().empty().append(cope);
  345. }
  346. }
  347. /** 时间校验 */
  348. if (opts.isVailTime && name === opts.endTimeId){
  349. var repeatFlag = base.commonVailFrom.vaildTime($cue, _me, opts.startTimeId);
  350. if (repeatFlag){
  351. xxx = 0;
  352. return false;
  353. }else{
  354. $cue.removeClass().empty().append(cope);
  355. }
  356. }
  357. /** 时间校验2 */
  358. if (opts.isVaildExpiryTime && name === opts.expEndId){
  359. var repeatFlag = base.commonVailFrom.vaildExpiryTime($cue, _me, opts);
  360. if (repeatFlag){
  361. xxx = 0;
  362. return false;
  363. }else{
  364. $cue.removeClass().empty().append(cope);
  365. }
  366. }else{
  367. $cue.removeClass().empty().append(cope);
  368. }
  369. });
  370. return xxx;
  371. },
  372. /** 判空校验 */
  373. vaildIsNull: function($cue, _me) {
  374. var reslut = 0;
  375. var val = _me.val();
  376. if (!val){
  377. var dic = $cue.attr('dic') + '不能空';
  378. // 提示消息
  379. $cue.removeClass().addClass('redFont').empty().text(dic);
  380. // 获取焦点
  381. _me.focus();
  382. // 震动提示
  383. base.invalid($cue);
  384. reslut = 1;
  385. }
  386. return reslut;
  387. },
  388. /** 数字校验*/
  389. vailNum: function($cue, _me){
  390. var reslut = 0;
  391. // 校验数字--正整数
  392. var vaildNum = /^[0-9]*[1-9][0-9]*$/;
  393. var val = _me.val();
  394. if (vaildNum.test(val) == false)
  395. {
  396. var dic = '请正确输入数字,数量不能小于零';
  397. // 提示消息
  398. $cue.removeClass().addClass('redFont').empty().text(dic);
  399. // 获取焦点
  400. _me.focus();
  401. // 震动提示
  402. base.invalid($cue);
  403. reslut = 1;
  404. }
  405. return reslut;
  406. }
  407. }
  408. };
  409. /**
  410. * 添加String的format方法 替换对应位置的字符串
  411. *
  412. * @param array[] 数组
  413. */
  414. String.prototype.format = function(array) {
  415. return this.replace(/\{(\d+)\}/g, function(s, i) {
  416. return array[i];
  417. });
  418. };
  419. /**
  420. * 页头页面JS
  421. * @author 003598
  422. */
  423. var topPage={
  424. /** 初始化化页头方法*/
  425. init:function(){
  426. this.initCloseBtn();
  427. //this.initBackIndexBtn();
  428. },
  429. /** 初始化退出按钮*/
  430. initCloseBtn:function(){
  431. $("#close").click(function(){
  432. location.href=basePath+"/quit.do";
  433. });
  434. }
  435. };
  436. /**
  437. * 左侧菜单栏页面JS
  438. * @author 003598
  439. */
  440. var leftMenu={
  441. // 初始化方法接口
  442. init:function(){
  443. this.initMenuMouseMove();
  444. this.initMenuClick();
  445. this.initMenuShow();
  446. this.initMenu();
  447. },
  448. // 初始化菜单,只展示选中的菜单,设置选中背景
  449. initMenu:function(){/*
  450. var $chidLi =$('#ulMenu .chidren');
  451. pageMenuId = $.trim(pageMenuId);
  452. var selectPic = basePath + '/image/left/sidebar02_on.png';
  453. $chidLi.find('li').each(function(){
  454. var menuId = $(this).attr('menuId');
  455. if(menuId == pageMenuId){
  456. $(this).css('background-image','url('+selectPic+')');
  457. $(this).parents('#ulMenu .chidren').show();
  458. return false;
  459. }
  460. });
  461. //leftMenu.menuFloat();
  462. */},
  463. // 初始化菜单栏鼠标移动此效果
  464. initMenuMouseMove:function(){
  465. $('#ulMenu>li').find('ul>li').each(function(e){
  466. // 鼠标移入元素上
  467. var muserPic = basePath + '/image/left/sidebar02_on_mouse.png';
  468. var bgPic = basePath + '/image/left/sidebar02.png';
  469. $(this).mouseover(function(e){
  470. var bgImg = $(this).css('background-image');
  471. if(bgImg.indexOf('sidebar02_on.png')<=0){
  472. $(this).css('background-image','url('+muserPic+')');
  473. }
  474. });
  475. // 鼠标从元素上离开
  476. $(this).mouseout(function(e){
  477. var bgImg = $(this).css('background-image');
  478. if(bgImg.indexOf('sidebar02_on.png')<=0){
  479. $(this).css('background-image','url('+bgPic+')');
  480. }
  481. });
  482. });
  483. },
  484. // 初始化子菜单点击事件
  485. initMenuClick:function(){
  486. $('.chidrenTitle').each(function(e){
  487. var _this = $(this);
  488. var href = _this.attr('href');
  489. var menuId = _this.attr('menuId');
  490. var action = href+'?menuId='+menuId;
  491. _this.click(function(){
  492. location.href= action;
  493. });
  494. });
  495. },
  496. /** 初始化菜单显示与隐藏*/
  497. initMenuShow:function(){
  498. $('.title').click(function(){
  499. /* var liNum = $(this).next().find('ul>li').size();
  500. var sp = 500;
  501. if (liNum<3){
  502. sp = 200;
  503. }*/
  504. /*if(!$(this).next().is(':visible')){
  505. $('#ulMenu').find('.chidren:visible').slideUp(sp);
  506. }*/
  507. /*$(this).next().slideToggle(sp);*/
  508. /*$(this).next().slideDown(sp);*/
  509. var _this = $(this);
  510. var _thisChidren = _this.next();
  511. if (!_thisChidren.is(':visible')){
  512. _thisChidren.slideDown(500);
  513. }else{
  514. _thisChidren.slideUp(500);
  515. }
  516. });
  517. },
  518. /** 菜单栏浮动效果*/
  519. menuFloat:function(){
  520. // 触发上下滚动条事件
  521. $(window).scroll( function() {
  522. // 获取页面总高度
  523. var dH = $(document).height();
  524. // 获取滚动条滚动高度
  525. var scrTop = $(this).scrollTop();
  526. // 获取菜单列表高度
  527. var orderH = $('#ulMenu').height();
  528. // 获取页头高度
  529. var topHeight = $('.top').height();
  530. var topNum = 0;
  531. if(scrTop>(topHeight-3)){
  532. $('.order').css('position', 'fixed').css('top', '0px');
  533. // 显示被遮住的菜单狼
  534. if(scrTop>(dH-orderH)){
  535. topNum = scrTop-(dH-orderH);
  536. $('.order').css('top', -(topNum));
  537. }
  538. }else{
  539. $('.order').css('position', 'inherit').css('top', '0px');
  540. }
  541. });
  542. }
  543. };
  544. /**
  545. * 右侧内容区JS
  546. * @author 003598
  547. */
  548. var rightContent ={
  549. // 初始化方法接口
  550. init:function(){
  551. this.initContent();
  552. this.winUpdate();
  553. },
  554. /** 初始化内容页面的高度*/
  555. initContent:function(_this){
  556. if(!_this){
  557. _this = $(window);
  558. }
  559. var topH = $('.top').height();
  560. var bH = _this.height();
  561. var contentH = bH-topH;
  562. // 最低高度不能小于600px
  563. if (contentH<600){
  564. contentH = 600;
  565. }
  566. $('.menu_right').css('min-height', contentH);
  567. },
  568. /** 当浏览器发生改变时,自适应浏览器的高度*/
  569. winUpdate:function(){
  570. $(window).resize(function() {
  571. rightContent.initContent($(this));
  572. });
  573. }
  574. };
  575. // 加载模板页js方法
  576. $(function(){
  577. // 加载页面初始化方法
  578. topPage.init();
  579. leftMenu.init();
  580. rightContent.init();
  581. });