main.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. $(window).resize(function(){
  45. KeyWordDialog.SetContentHeight(dialogObj);
  46. });
  47. };
  48. this.hide = function(){
  49. dialogObj.hide();
  50. $("html,body").removeClass("overflow-hidden");
  51. $(window).unbind("resize");
  52. };
  53. KeyWordDialog.SetContentHeight(dialogObj);
  54. dialogObj.find(".addKeyWord").click(function(){
  55. KeyWordDialog.AppendNode(dialogObj);
  56. });
  57. dialogObj.find(".submit").click(function(){
  58. commonAjaxReq(thisClass,type);
  59. });
  60. if(dialogObj.find(".keyWordGroup").length == 0){
  61. KeyWordDialog.AppendNode(dialogObj);
  62. }
  63. }
  64. KeyWordDialog.SetContentHeight = function(dialogObj){
  65. var contentObj = dialogObj.find(".dialog-content");
  66. var padding = parseInt(contentObj.css('padding-top'))+parseInt(contentObj.css('padding-bottom'))
  67. contentObj.css("max-height",document.body.clientHeight-dialogObj.find(".dialog-head").height()-padding-40);
  68. }
  69. KeyWordDialog.AppendNode = function(dialogObj,value){
  70. var getHtml = function(index,value){
  71. return '<div class="keyWordGroup">'
  72. +'<lable>关键词<font>'+index+'</font></lable>'
  73. +'<div><input type="text" value="'+(value?value:"")+'" placeholder="示例:综合布线 电话线 网线" maxlength="100"></div>'
  74. +'<div>'+(index==1?'':'<img src="/wxswordfish/images/delete.png" class="delete">')+'</div>'
  75. +'</div>';
  76. }
  77. var count = dialogObj.find(".keyWordGroup").length;
  78. if(count >= 10){
  79. return;
  80. }
  81. var obj = $(getHtml(count+1,value));
  82. dialogObj.find(".addKeyWordArea").before(obj);
  83. //自动滚动到底部
  84. $("#a_end")[0].scrollIntoView();
  85. obj.find(".delete").click(function(){
  86. dialogObj.find(".addKeyWord").removeAttr("disabled");
  87. $(this).parents(".keyWordGroup").remove();
  88. dialogObj.find(".keyWordGroup").each(function(i){
  89. $(this).children("lable").children("font").text(i+1);
  90. });
  91. });
  92. if(typeof(value) == "undefined" || value == ""){
  93. obj.find("[type='text']").focus();
  94. }
  95. if(count >= 9){
  96. dialogObj.find(".addKeyWord").attr("disabled",true);
  97. }
  98. }
  99. //信息范围
  100. function ScopeDialog(type,clickLi){
  101. var thisClass = this;
  102. var dialogObj = $("#"+type+"-scope");
  103. this.type = type;
  104. this.clickLi = clickLi;
  105. this.show = function(){
  106. dialogObj.show();
  107. $("html,body").addClass("overflow-hidden");
  108. };
  109. this.hide = function(){
  110. dialogObj.hide();
  111. $("html,body").removeClass("overflow-hidden");
  112. };
  113. dialogObj.find(".dialog-content").css("max-height",document.body.clientHeight-dialogObj.find(".dialog-head").height()-40);
  114. dialogObj.find(".btn").click(function(){
  115. if($(this).parent().index() == 0){
  116. dialogObj.find(".btn").removeClass("active");
  117. }else{
  118. dialogObj.find("ul:first li:first .btn").removeClass("active");
  119. }
  120. $(this).toggleClass("active");
  121. if(dialogObj.find(".btn.active").length == 0){
  122. dialogObj.find("ul:first li:first .btn").addClass("active");
  123. }
  124. });
  125. dialogObj.find(".submit").click(function(){
  126. commonAjaxReq(thisClass,type);
  127. });
  128. }
  129. //取积分
  130. function getCredit(){
  131. var score=0
  132. $.ajax({
  133. dataType:"json",
  134. url:"/member/credit/getcredit",
  135. type:"POST",
  136. async:false,
  137. success:function(msg){
  138. if(msg){
  139. if(msg.flag){
  140. score=msg.val
  141. }else{
  142. alert("请重新进入页剑鱼页面后操作")
  143. }
  144. }
  145. },
  146. error:function(x,st,err){
  147. alert("请稍后再试"+st)
  148. }
  149. })
  150. return score
  151. }
  152. var snopshot=[];
  153. function showAlls(){
  154. var n=0,str=[],sel=[];
  155. for(var i in snopshot){
  156. if(snopshot[i]){
  157. n++;
  158. str.push((i=="tender")?"招标公告":"中标公告")
  159. sel.push("types="+i)
  160. }
  161. }
  162. if(n>0){
  163. var num=getCredit();
  164. var pay=1000*n, rem=num-pay,strs="扣除后将剩余"+rem+"积分";
  165. var contents="您添加了"+n+"个信息栏目("+str.join("、")+"),确认后系统将每月扣除"+pay+"积分,您目前的积分余额是"+num+"积分,";
  166. if(rem<0){
  167. $("#credit_yes").unbind("click").hide()
  168. strs="请充值或去赚积分。";
  169. }else{
  170. $("#credit_yes").unbind("click").bind("click",function(e){
  171. $("#rule-content").text(contents+strs)
  172. $(".tip-dialog").show();
  173. $("#tip-dialog-back").unbind("click").bind("click",function(e){
  174. $("#tip-dialog-back").unbind("click");
  175. $.ajax({
  176. dataType:"json",
  177. url:"/member/credit/swordfishpay",
  178. data:sel.join("&"),
  179. type:"POST",
  180. async:false,
  181. success:function(msg){
  182. if(msg){
  183. if(msg.flag){
  184. //有session
  185. if(msg.oprstatus){
  186. //扣积分操作成功
  187. $(".visible").hide()
  188. }else{
  189. //扣积分操作无效
  190. alert("操作无效,请重新进入页剑鱼页面后操作")
  191. }
  192. }else{
  193. //无session
  194. alert("请重新进入页剑鱼页面后操作")
  195. }
  196. }
  197. },
  198. error:function(x,st,err){
  199. alert("请稍后再试"+st)
  200. }
  201. })
  202. window.location.reload()
  203. })
  204. $("html,body").addClass("overflow-hidden");
  205. })
  206. }
  207. $("#txt_tip").text(contents+strs)
  208. $(".visible").show()
  209. }else{
  210. $("#credit_yes").unbind("click")
  211. $(".visible").hide()
  212. }
  213. }
  214. function showSnopshot(module,type,on){
  215. //提示扣积分
  216. //alert(getCredit())
  217. if(type==0){//初始化
  218. //是开启状态
  219. if (!eval("msgset."+module+".i_status")){
  220. snopshot[module]=true
  221. showAlls()
  222. }else{
  223. //显示天数
  224. var days=eval("msgset."+module+".days")
  225. var tiptxt="本栏目推送服务期还剩<d style='color:red'>"+days+"</d>天"
  226. if(winWidth<341){
  227. tiptxt="服务期还剩<d style='color:red'>"+days+"</d>天"
  228. }
  229. $("#"+module+" .show-days").html(tiptxt)
  230. }
  231. }else if(type==1){//提交修改时
  232. if(on){
  233. if(module=="tender"){
  234. if(typeof(msgset.tender) != "undefined"){
  235. if(!msgset.tender.i_status){
  236. if (!msgset.tender.i_status){
  237. snopshot[module]=true
  238. }else{
  239. snopshot[module]=false
  240. }
  241. }
  242. }else{
  243. snopshot[module]=true
  244. }
  245. }else if(module=="bid"){
  246. if(typeof(msgset.bid) != "undefined"){
  247. if(!msgset.bid.i_status){
  248. if (!msgset.bid.i_status){
  249. snopshot[module]=true
  250. }else{
  251. snopshot[module]=false
  252. }
  253. }
  254. }else{
  255. snopshot[module]=true
  256. }
  257. }
  258. showAlls()
  259. }else{
  260. snopshot[module]=false
  261. showAlls()
  262. }
  263. }
  264. }
  265. function commonAjaxReq(object,module){
  266. //是关的不用处理
  267. var dataObj = {
  268. reqType: "other",
  269. snopshot:false
  270. };
  271. if($("#"+module+"-on-off").hasClass("open")){
  272. //开服务要校验
  273. showSnopshot(module,1,1)
  274. }else{
  275. showSnopshot(module,1,0)
  276. }
  277. var keysString = "",scopeString = "";
  278. var thisClass = this;
  279. this.afterCommit = function(){
  280. object.hide();
  281. var value = "";
  282. switch(object.clickLi.index()){
  283. case 0:
  284. value = keysString;
  285. break;
  286. case 1:
  287. value = scopeString;
  288. break;
  289. }
  290. value = value.substring(0,value.length-1);
  291. if(object.clickLi.children(".com-last").length == 1){
  292. if(value == ""){
  293. object.clickLi.children(".com-last").remove();
  294. }else{
  295. object.clickLi.children(".com-last").text(value);
  296. }
  297. }else{
  298. if(value != ""){
  299. object.clickLi.append('<div class="com-last">'+value+'</div>');
  300. }
  301. }
  302. }
  303. //关键词
  304. this.setKeyWord = function(type){
  305. var tender_keys = [];
  306. $("#"+type+"-keyword .keyWordGroup").each(function(){
  307. var value = $.trim($(this).find("[type='text']").val()).replace(/\r\n/g,"");
  308. if(value == ""){
  309. return true;
  310. }
  311. if(object != null && object.type == type){
  312. keysString += value+";";
  313. }
  314. tender_keys.push(value.replace(/\s+/g,"+"));
  315. });
  316. return tender_keys;
  317. }
  318. //信息范围
  319. this.setScope = function(type){
  320. var tender_scope = [];
  321. $("#"+type+"-scope .btn.active").each(function(){
  322. var thisText = $(this).text();
  323. if(thisText == "全国"){
  324. tender_scope.push("A");
  325. if(object != null && object.type == type){
  326. scopeString += "全国;";
  327. }
  328. return false;
  329. }else{
  330. tender_scope.push(thisText);
  331. if(object != null && object.type == type){
  332. scopeString += thisText+";";
  333. }
  334. }
  335. });
  336. return tender_scope.join(",");
  337. }
  338. dataObj[module+"_keys"] = this.setKeyWord(module);
  339. dataObj[module+"_scope"] = this.setScope(module);
  340. if(dataObj[module+"_keys"].length > 0 && dataObj[module+"_scope"] == ""){
  341. dataObj[module+"_scope"] = "A";
  342. }
  343. dataObj[module+"_switchstatus"] = $("#"+module+"-on-off").hasClass("open")?1:0
  344. /*****************************************/
  345. $.ajax({
  346. type: "POST",
  347. url: "/swordfish/ajaxReq",
  348. data: dataObj,
  349. dataType: "json",
  350. traditional: true,
  351. success: function(r){
  352. if(object != null){
  353. thisClass.afterCommit();
  354. }
  355. },
  356. error: function(){
  357. }
  358. });
  359. }
  360. var winWidth=300;
  361. $(function(){
  362. winWidth=$(window).width();
  363. var turnOn = function(obj){
  364. obj.addClass("open");
  365. var liobj = obj.parents("li");
  366. liobj.next().show();
  367. liobj.nextAll(".parent-node").eq(0).addClass("border-top");
  368. if(liobj.next(".child-node").find(".com-last").length == 0){
  369. liobj.next(".child-node").find("li:eq(1)").append('<div class="com-last">全国</div>');
  370. }
  371. }
  372. var setKeyWord = function(type,keys){
  373. if(typeof(keys) == "undefined" || keys.length == 0){
  374. return;
  375. }
  376. for(var i=0;i<keys.length;i++){
  377. keys[i] = keys[i].replace(/\+/g," ");
  378. KeyWordDialog.AppendNode($("#"+type+"-keyword"),keys[i]);
  379. }
  380. $("#"+type+"-content li:first").append('<div class="com-last">'+keys.join(";")+'</div>');
  381. }
  382. var setScope = function(type,scope){
  383. var dialogObj = $("#"+type+"-scope");
  384. if(typeof(scope) == "undefined" || scope == ""){
  385. return;
  386. }
  387. if(scope == "A"){
  388. dialogObj.find("ul:first li:first .btn").addClass("active");
  389. scope = "全国";
  390. }else{
  391. dialogObj.find("ul:first li:first .btn").removeClass("active");
  392. var scopeArray = scope.split(",");
  393. for(var i=0;i<scopeArray.length;i++){
  394. dialogObj.find(".btn").each(function(){
  395. if($(this).text() == scopeArray[i]){
  396. $(this).addClass("active");
  397. return false;
  398. }
  399. });
  400. }
  401. }
  402. $("#"+type+"-content li:last").append('<div class="com-last">'+scope.replace(/,/g,";")+'</div>');
  403. }
  404. $("body").append($("#tender-keyword").clone().removeAttr("id").attr("id","bid-keyword"))
  405. .append($("#tender-scope").clone().removeAttr("id").attr("id","bid-scope"));
  406. if(typeof(msgset.tender) != "undefined"){
  407. setKeyWord("tender",msgset.tender.a_key);
  408. setScope("tender",msgset.tender.s_scope);
  409. if(msgset.tender.i_switchstatus){
  410. turnOn($("#tender-on-off"));
  411. //判断要不要还原提示
  412. showSnopshot("tender",0)
  413. }
  414. }
  415. if(typeof(msgset.bid) != "undefined"){
  416. setKeyWord("bid",msgset.bid.a_key);
  417. setScope("bid",msgset.bid.s_scope);
  418. if(msgset.bid.i_switchstatus){
  419. turnOn($("#bid-on-off"));
  420. //判断要不要还原提示
  421. showSnopshot("bid",0)
  422. }
  423. }
  424. //开关
  425. $(".on-off").click(function(){
  426. if(this.id == "intelligence-on-off"){//企业情报
  427. alert("开发中,敬请期待!");
  428. return;
  429. }
  430. if($(this).hasClass("open")){
  431. $(this).removeClass("open")
  432. $(this).parents("li").next().hide();
  433. $(this).parents("li").nextAll(".parent-node").eq(0).removeClass("border-top");
  434. }else{
  435. turnOn($(this));
  436. }
  437. //判断是不是开,是开再判断是不是在有效期内,如果不在有效期内,则进行提示并存快照
  438. commonAjaxReq(null,$(this).attr("v"));
  439. });
  440. //收费规则
  441. $(".rule").closest(".parent-node").click(function(){
  442. $(".credit-dialog").show();
  443. $("html,body").addClass("overflow-hidden");
  444. })
  445. $("#credit-dialog-back").click(function(){
  446. $(".credit-dialog").hide();
  447. $("html,body").removeClass("overflow-hidden");
  448. });
  449. //
  450. $("#tender-content>li").click(function(){
  451. switch($(this).index()){
  452. case 0:
  453. Tender.getKeyWordDialog($(this)).show();
  454. break;
  455. case 1:
  456. Tender.getScopeDialog($(this)).show();
  457. break;
  458. }
  459. });
  460. $("#bid-content>li").click(function(){
  461. switch($(this).index()){
  462. case 0:
  463. Bid.getKeyWordDialog($(this)).show();
  464. break;
  465. case 1:
  466. Bid.getScopeDialog($(this)).show();
  467. break;
  468. }
  469. });
  470. });