main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. //招标公告
  2. var Tender = {
  3. keyWordDialog: null,
  4. getKeyWordDialog: function(clickLi){
  5. if(this.keyWordDialog == null){
  6. this.keyWordDialog = new KeyWordDialog("tender",clickLi);
  7. }
  8. return this.keyWordDialog;
  9. },
  10. scopeDialog: null,
  11. getScopeDialog: function(clickLi){
  12. if(this.scopeDialog == null){
  13. this.scopeDialog = new ScopeDialog("tender",clickLi);
  14. }
  15. return this.scopeDialog;
  16. }
  17. };
  18. //中标公告
  19. var Bid = {
  20. keyWordDialog: null,
  21. getKeyWordDialog: function(clickLi){
  22. if(this.keyWordDialog == null){
  23. this.keyWordDialog = new KeyWordDialog("bid",clickLi);
  24. }
  25. return this.keyWordDialog;
  26. },
  27. scopeDialog: null,
  28. getScopeDialog: function(clickLi){
  29. if(this.scopeDialog == null){
  30. this.scopeDialog = new ScopeDialog("bid",clickLi);
  31. }
  32. return this.scopeDialog;
  33. }
  34. };
  35. //关键字弹出框
  36. function KeyWordDialog(type,clickLi){
  37. var thisClass = this;
  38. var dialogObj = $("#"+type+"-keyword");
  39. this.type = type;
  40. this.clickLi = clickLi;
  41. this.show = function(){
  42. dialogObj.show();
  43. $("html,body").addClass("overflow-hidden");
  44. KeyWordDialog.SetContentHeight(dialogObj);
  45. $(window).resize(function(){
  46. KeyWordDialog.SetContentHeight(dialogObj);
  47. });
  48. };
  49. this.hide = function(){
  50. FOCUS=""
  51. dialogObj.hide();
  52. $("html,body").removeClass("overflow-hidden");
  53. $(window).unbind("resize");
  54. };
  55. KeyWordDialog.SetContentHeight(dialogObj);
  56. dialogObj.find(".addKeyWord").click(function(){
  57. KeyWordDialog.AppendNode(dialogObj);
  58. });
  59. dialogObj.find(".submit").click(function(){
  60. commonAjaxReq(thisClass,type);
  61. });
  62. if(dialogObj.find(".keyWordGroup").length == 0){
  63. KeyWordDialog.AppendNode(dialogObj);
  64. }
  65. }
  66. KeyWordDialog.SetContentHeight = function(dialogObj){
  67. var contentObj = dialogObj.find(".dialog-content");
  68. var padding = parseInt(contentObj.css('padding-top'))+parseInt(contentObj.css('padding-bottom'))
  69. contentObj.css("max-height",document.body.clientHeight-dialogObj.find(".dialog-head").height()-padding-40);
  70. }
  71. function resizeKey(obj,parentObj){
  72. var dialogTop=obj.closest(".dialog-main").offset().top
  73. var H=63;
  74. var ofh=obj.offset().top
  75. var psh=parentObj[0].scrollHeight;
  76. var pst=parentObj[0].scrollTop;
  77. var poh=parentObj[0].offsetHeight;
  78. //計算卷去的高度
  79. var seq=poh+pst-psh
  80. if(seq>5||seq<0){
  81. parentObj[0].scrollTop=pst-seq
  82. }else{
  83. return
  84. }
  85. if(ofh<(dialogTop+H)){
  86. parentObj[0].scrollTop=pst-((dialogTop+H)-ofh)
  87. }else{
  88. parentObj[0].scrollTop=pst+ofh-dialogTop-H
  89. }
  90. }
  91. function _KeyFocus(objn){
  92. var obj=$(objn),parentObj=obj.closest(".dialog-content");
  93. resizeKey(obj,parentObj)
  94. parentObj.unbind("resizeblock").bind("resizeblock",function(){
  95. //resizeKey(obj,$(this));
  96. parentObj.unbind("resizeblock");
  97. })
  98. //90
  99. //调整
  100. //alert(dialogTop+"="+parentObj.height()+"="+obj.offset().top+"="+parentObj[0].offsetHeight+"="+parentObj[0].scrollHeight+"="+parentObj[0].scrollTop)
  101. }
  102. //
  103. var FOCUS
  104. function setFocus(obj){
  105. if(!FOCUS){
  106. FOCUS=$(obj)
  107. var parentObj=FOCUS.closest(".dialog-content");
  108. parentObj.unbind("resizeblock").bind("resizeblock",function(){
  109. resizeKey(FOCUS,$(this));
  110. parentObj.unbind("resizeblock");
  111. })
  112. }
  113. }
  114. KeyWordDialog.AppendNode = function(dialogObj,value){
  115. var getHtml = function(index,value){
  116. return '<div class="keyWordGroup">'
  117. +'<lable style="white-space:nowrap;">关键词<font>'+index+'</font></lable>'
  118. +'<div><input type="text" onfocus="setFocus(this)" value="'+(value?value:"")+'" placeholder="示例:综合布线 电话线 网线" maxlength="100"></div>'
  119. +'<div>'+(index==1?'':'<img src="/wxswordfish/images/delete.png" class="delete">')+'</div>'
  120. +'</div>';
  121. }
  122. var count = dialogObj.find(".keyWordGroup").length;
  123. if(count >= 10){
  124. return;
  125. }
  126. var obj = $(getHtml(count+1,value));
  127. dialogObj.find(".addKeyWordArea").before(obj);
  128. //自动滚动到底部
  129. dialogObj.find(".a_end")[0].scrollIntoView();
  130. obj.find(".delete").click(function(){
  131. dialogObj.find(".addKeyWord").removeAttr("disabled");
  132. $(this).parents(".keyWordGroup").remove();
  133. dialogObj.find(".keyWordGroup").each(function(i){
  134. $(this).children("lable").children("font").text(i+1);
  135. });
  136. });
  137. if(typeof(value) == "undefined" || value == ""){
  138. obj.find("[type='text']").focus();
  139. }
  140. if(count >= 9){
  141. dialogObj.find(".addKeyWord").attr("disabled",true);
  142. }
  143. }
  144. //信息范围
  145. function ScopeDialog(type,clickLi){
  146. var thisClass = this;
  147. var dialogObj = $("#"+type+"-scope");
  148. this.type = type;
  149. this.clickLi = clickLi;
  150. this.show = function(){
  151. dialogObj.show();
  152. $("html,body").addClass("overflow-hidden");
  153. };
  154. this.hide = function(){
  155. dialogObj.hide();
  156. $("html,body").removeClass("overflow-hidden");
  157. };
  158. dialogObj.find(".dialog-content").css("max-height",document.body.clientHeight-dialogObj.find(".dialog-head").height()-40);
  159. dialogObj.find(".btn").click(function(){
  160. if($(this).parent().index() == 0){
  161. dialogObj.find(".btn").removeClass("active");
  162. }else{
  163. dialogObj.find("ul:first li:first .btn").removeClass("active");
  164. }
  165. $(this).toggleClass("active");
  166. if(dialogObj.find(".btn.active").length == 0){
  167. dialogObj.find("ul:first li:first .btn").addClass("active");
  168. }
  169. });
  170. dialogObj.find(".submit").click(function(){
  171. commonAjaxReq(thisClass,type);
  172. });
  173. }
  174. //取积分
  175. function getCredit(){
  176. var score=0
  177. $.ajax({
  178. dataType:"json",
  179. url:"/member/credit/getcredit",
  180. type:"POST",
  181. async:false,
  182. success:function(msg){
  183. if(msg){
  184. if(msg.flag){
  185. score=msg.val
  186. }else{
  187. alert("请重新进入页剑鱼页面后操作")
  188. }
  189. }
  190. },
  191. error:function(x,st,err){
  192. alert("请稍后再试"+st)
  193. }
  194. })
  195. return score
  196. }
  197. var snopshot=[];
  198. function showAlls(){
  199. var n=0,str=[],sel=[];
  200. for(var i in snopshot){
  201. if(snopshot[i]){
  202. n++;
  203. str.push((i=="tender")?"招标公告":"中标公告")
  204. sel.push("types="+i)
  205. }
  206. }
  207. if(n>0){
  208. var num=getCredit();
  209. var pay=1000*n, rem=num-pay,strs="扣除后将剩余"+rem+"积分";
  210. var contents="您添加了"+n+"个信息栏目("+str.join("、")+"),确认后系统将每月扣除"+pay+"积分,您目前的积分余额是"+num+"积分,";
  211. if(rem<0){
  212. $("#credit_yes").unbind("click").hide()
  213. strs="请充值或去赚积分。";
  214. }else{
  215. $("#credit_yes").unbind("click").bind("click",function(e){
  216. $("#rule-content").text(contents+strs)
  217. $(".tip-dialog").show();
  218. $("#tip-dialog-back").unbind("click").bind("click",function(e){
  219. $("#tip-dialog-back").unbind("click");
  220. $.ajax({
  221. dataType:"json",
  222. url:"/member/credit/swordfishpay",
  223. data:sel.join("&"),
  224. type:"POST",
  225. async:false,
  226. success:function(msg){
  227. if(msg){
  228. if(msg.flag){
  229. //有session
  230. if(msg.oprstatus){
  231. //扣积分操作成功
  232. $(".visible").hide()
  233. }else{
  234. //扣积分操作无效
  235. alert("操作无效,请重新进入页剑鱼页面后操作")
  236. }
  237. }else{
  238. //无session
  239. alert("请重新进入页剑鱼页面后操作")
  240. }
  241. }
  242. },
  243. error:function(x,st,err){
  244. alert("请稍后再试"+st)
  245. }
  246. })
  247. window.location.reload()
  248. })
  249. $("html,body").addClass("overflow-hidden");
  250. })
  251. }
  252. $("#credit_no").unbind("click").bind("click",function(e){
  253. $.ajax({
  254. dataType:"json",
  255. url:"/member/credit/swordfishpay",
  256. data:sel.join("&")+"&no=1",
  257. type:"POST",
  258. async:false,
  259. success:function(msg){
  260. if(msg){
  261. if(msg.flag){
  262. //有session
  263. if(msg.oprstatus){
  264. //取消操作成功
  265. $(".visible").hide()
  266. }else{
  267. //取消操作无效
  268. alert("操作无效,请重新进入页剑鱼页面后操作")
  269. }
  270. }else{
  271. //无session
  272. alert("请重新进入页剑鱼页面后操作")
  273. }
  274. }
  275. },
  276. error:function(x,st,err){
  277. alert("请稍后再试"+st)
  278. }
  279. })
  280. window.location.reload()
  281. })
  282. $("#txt_tip").text(contents+strs)
  283. $(".visible").show()
  284. }else{
  285. $("#credit_yes").unbind("click")
  286. $(".visible").hide()
  287. }
  288. }
  289. function showSnopshot(module,type,on){
  290. //提示扣积分
  291. //alert(getCredit())
  292. if(type==0){//初始化
  293. //是开启状态
  294. //显示天数
  295. try{
  296. var days=eval("msgset."+module+".days")
  297. if(typeof days=="number"){
  298. if (days<6){
  299. var tiptxt="本栏目推送服务期还剩<d style='color:red'>"+days+"</d>天"
  300. if(winWidth<341){
  301. tiptxt="服务期还剩<d style='color:red'>"+days+"</d>天"
  302. }
  303. }
  304. }
  305. }catch(e){}
  306. if(on){
  307. if (!eval("msgset."+module+".i_status")){
  308. snopshot[module]=true
  309. showAlls()
  310. }
  311. $("#"+module+" .show-days").html(tiptxt)
  312. }else{
  313. $("#"+module+" .show-days").html(tiptxt).hide()
  314. }
  315. }else if(type==1){//提交修改时
  316. if(on){
  317. if(module=="tender"){
  318. if(typeof(msgset.tender) != "undefined"){
  319. if(!msgset.tender.i_status){
  320. if (!msgset.tender.i_status){
  321. snopshot[module]=true
  322. }else{
  323. snopshot[module]=false
  324. }
  325. }
  326. }else{
  327. snopshot[module]=true
  328. }
  329. }else if(module=="bid"){
  330. if(typeof(msgset.bid) != "undefined"){
  331. if(!msgset.bid.i_status){
  332. if (!msgset.bid.i_status){
  333. snopshot[module]=true
  334. }else{
  335. snopshot[module]=false
  336. }
  337. }
  338. }else{
  339. snopshot[module]=true
  340. }
  341. }
  342. showAlls()
  343. }else{
  344. snopshot[module]=false
  345. showAlls()
  346. }
  347. }
  348. }
  349. function commonAjaxReq(object,module){
  350. //是关的不用处理
  351. var dataObj = {
  352. reqType: "other",
  353. snopshot:false
  354. };
  355. if($("#"+module+"-on-off").hasClass("open")){
  356. //开服务要校验
  357. showSnopshot(module,1,1)
  358. $("#"+module+" .show-days").show()
  359. }else{
  360. showSnopshot(module,1,0)
  361. $("#"+module+" .show-days").hide()
  362. }
  363. var keysString = "",scopeString = "";
  364. var thisClass = this;
  365. this.afterCommit = function(){
  366. object.hide();
  367. var value = "";
  368. switch(object.clickLi.index()){
  369. case 0:
  370. value = keysString;
  371. break;
  372. case 1:
  373. value = scopeString;
  374. break;
  375. }
  376. value = value.substring(0,value.length-1);
  377. if(object.clickLi.children(".com-last").length == 1){
  378. if(value == ""){
  379. object.clickLi.children(".com-last").remove();
  380. }else{
  381. object.clickLi.children(".com-last").text(value);
  382. }
  383. }else{
  384. if(value != ""){
  385. object.clickLi.append('<div class="com-last">'+value+'</div>');
  386. }
  387. }
  388. }
  389. //关键词
  390. this.setKeyWord = function(type){
  391. var tender_keys = [];
  392. $("#"+type+"-keyword .keyWordGroup").each(function(){
  393. var value = $.trim($(this).find("[type='text']").val()).replace(/\r\n/g,"");
  394. if(value == ""){
  395. return true;
  396. }
  397. if(object != null && object.type == type){
  398. keysString += value+";";
  399. }
  400. tender_keys.push(value.replace(/\s+/g,"+"));
  401. });
  402. return tender_keys;
  403. }
  404. //信息范围
  405. this.setScope = function(type){
  406. var tender_scope = [];
  407. $("#"+type+"-scope .btn.active").each(function(){
  408. var thisText = $(this).text();
  409. if(thisText == "全国"){
  410. tender_scope.push("A");
  411. if(object != null && object.type == type){
  412. scopeString += "全国;";
  413. }
  414. return false;
  415. }else{
  416. tender_scope.push(thisText);
  417. if(object != null && object.type == type){
  418. scopeString += thisText+";";
  419. }
  420. }
  421. });
  422. return tender_scope.join(",");
  423. }
  424. dataObj[module+"_keys"] = this.setKeyWord(module);
  425. dataObj[module+"_scope"] = this.setScope(module);
  426. if(dataObj[module+"_keys"].length > 0 && dataObj[module+"_scope"] == ""){
  427. dataObj[module+"_scope"] = "A";
  428. }
  429. dataObj[module+"_switchstatus"] = $("#"+module+"-on-off").hasClass("open")?1:0
  430. /*****************************************/
  431. $.ajax({
  432. type: "POST",
  433. url: "/member/swordfish/ajaxReq",
  434. data: dataObj,
  435. dataType: "json",
  436. traditional: true,
  437. success: function(r){
  438. if(object != null){
  439. thisClass.afterCommit();
  440. }
  441. },
  442. error: function(){
  443. }
  444. });
  445. }
  446. var winWidth=300;
  447. $(function(){
  448. winWidth=$(window).width();
  449. var turnOn = function(obj){
  450. obj.addClass("open");
  451. var liobj = obj.parents("li");
  452. liobj.next().show();
  453. liobj.nextAll(".parent-node").eq(0).addClass("border-top");
  454. if(liobj.next(".child-node").find(".com-last").length == 0){
  455. liobj.next(".child-node").find("li:eq(1)").append('<div class="com-last">全国</div>');
  456. }
  457. }
  458. var setKeyWord = function(type,keys,searchnameIsExsit){
  459. if(typeof(keys) == "undefined" || keys.length == 0){
  460. return;
  461. }
  462. for(var i=0;i<keys.length;i++){
  463. keys[i] = keys[i].replace(/\+/g," ");
  464. KeyWordDialog.AppendNode($("#"+type+"-keyword"),keys[i]);
  465. }
  466. if(!searchnameIsExsit){
  467. $("#"+type+"-content li:first .com-last").remove();
  468. $("#"+type+"-content li:first").html('<div class="com-last">'+keys.join(";")+'</div>');
  469. commonAjaxReq($("#tender-keyword"),type);
  470. }else{
  471. $("#"+type+"-content li:first").append('<div class="com-last">'+keys.join(";")+'</div>');
  472. }
  473. }
  474. var setScope = function(type,scope){
  475. var dialogObj = $("#"+type+"-scope");
  476. if(typeof(scope) == "undefined" || scope == ""){
  477. return;
  478. }
  479. if(scope == "A"){
  480. dialogObj.find("ul:first li:first .btn").addClass("active");
  481. scope = "全国";
  482. }else{
  483. dialogObj.find("ul:first li:first .btn").removeClass("active");
  484. var scopeArray = scope.split(",");
  485. for(var i=0;i<scopeArray.length;i++){
  486. dialogObj.find(".btn").each(function(){
  487. if($(this).text() == scopeArray[i]){
  488. $(this).addClass("active");
  489. return false;
  490. }
  491. });
  492. }
  493. }
  494. $("#"+type+"-content li:eq(1)").append('<div class="com-last">'+scope.replace(/,/g,";")+'</div>');
  495. }
  496. $("body").append($("#tender-keyword").clone().removeAttr("id").attr("id","bid-keyword"))
  497. .append($("#tender-scope").clone().removeAttr("id").attr("id","bid-scope"));
  498. if(typeof(msgset.tender) != "undefined"){
  499. setKeyWord("tender",msgset.tender.a_key,false);
  500. setScope("tender",msgset.tender.s_scope);
  501. if(msgset.tender.i_switchstatus){
  502. turnOn($("#tender-on-off"));
  503. //判断要不要还原提示
  504. showSnopshot("tender",0,1)
  505. }else{
  506. showSnopshot("tender",0,0)
  507. }
  508. }
  509. if(typeof(msgset.bid) != "undefined"){
  510. setKeyWord("bid",msgset.bid.a_key,false);
  511. setScope("bid",msgset.bid.s_scope);
  512. if(msgset.bid.i_switchstatus){
  513. turnOn($("#bid-on-off"));
  514. //判断要不要还原提示
  515. showSnopshot("bid",0,1)
  516. }else{
  517. showSnopshot("bid",0,0)
  518. }
  519. }
  520. //开关
  521. $(".on-off").click(function(){
  522. if(this.id == "intelligence-on-off"){//企业情报
  523. alert("开发中,敬请期待!");
  524. return;
  525. }
  526. if($(this).hasClass("open")){
  527. $(this).removeClass("open")
  528. $(this).parents("li").next().hide();
  529. $(this).parents("li").nextAll(".parent-node").eq(0).removeClass("border-top");
  530. }else{
  531. turnOn($(this));
  532. }
  533. //判断是不是开,是开再判断是不是在有效期内,如果不在有效期内,则进行提示并存快照
  534. commonAjaxReq(null,$(this).attr("v"));
  535. });
  536. //收费规则
  537. $(".rule").closest(".parent-node").click(function(){
  538. $(".credit-dialog").show();
  539. $("html,body").addClass("overflow-hidden");
  540. })
  541. $("#credit-dialog-back").click(function(){
  542. $(".credit-dialog").hide();
  543. $("html,body").removeClass("overflow-hidden");
  544. });
  545. //
  546. $("#tender-content>li").click(function(){
  547. switch($(this).index()){
  548. case 0:
  549. Tender.getKeyWordDialog($(this)).show();
  550. break;
  551. case 1:
  552. Tender.getScopeDialog($(this)).show();
  553. break;
  554. }
  555. });
  556. $("#bid-content>li").click(function(){
  557. switch($(this).index()){
  558. case 0:
  559. Bid.getKeyWordDialog($(this)).show();
  560. break;
  561. case 1:
  562. Bid.getScopeDialog($(this)).show();
  563. break;
  564. }
  565. });
  566. //剑鱼协议
  567. if(winWidth<341){
  568. $("#prexieyi").append("<br>");
  569. }
  570. //预览跳转
  571. $(".result-view-2").click(function(){
  572. var val=$(this).closest("ul").find("li:first-child>div.com-last").text().replace(/\s+/ig,"")
  573. if(val){
  574. window.location.href="/wxpush/bid/wxpushview/"+$(this).attr("v")
  575. }else{
  576. alert("请输入关键字后预览。")
  577. }
  578. })
  579. if (typeof(searchname) != "undefined" && searchname.length > 0 ){
  580. if(typeof(msgset[s_type]) != "undefined"){
  581. var keywordes = msgset[s_type].a_key
  582. if(keywordes && keywordes.length > 0){
  583. var searchnameIsExsit = false;
  584. for(var i=0;i<keywordes.length;i++){
  585. var keywordesArr = keywordes[i].split("+");
  586. for(var k=0;k<keywordesArr.length;k++){
  587. if(keywordesArr[k] == searchname){
  588. searchnameIsExsit = true;
  589. }
  590. }
  591. }
  592. if(!searchnameIsExsit){
  593. keywordes.push(searchname);
  594. }
  595. }else{
  596. keywordes.push(searchname)
  597. }
  598. }else{
  599. keywordes.push(searchname);
  600. }
  601. setKeyWord(s_type,keywordes,searchnameIsExsit);
  602. if(!$("#"+s_type +"-on-off").hasClass("open")){
  603. $("#"+s_type+"-on-off").click();
  604. }
  605. }
  606. });