main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. //招标公告
  2. var Tender = {
  3. status:false,
  4. keyWordDialog: null,
  5. getKeyWordDialog: function(clickLi){
  6. if(this.keyWordDialog == null){
  7. this.keyWordDialog = new KeyWordDialog("tender",clickLi);
  8. }
  9. return this.keyWordDialog;
  10. },
  11. scopeDialog: null,
  12. getScopeDialog: function(clickLi){
  13. if(this.scopeDialog == null){
  14. this.scopeDialog = new ScopeDialog("tender",clickLi);
  15. }
  16. return this.scopeDialog;
  17. }
  18. };
  19. //中标公告
  20. var Bid = {
  21. status:false,
  22. keyWordDialog: null,
  23. getKeyWordDialog: function(clickLi){
  24. if(this.keyWordDialog == null){
  25. this.keyWordDialog = new KeyWordDialog("bid",clickLi);
  26. }
  27. return this.keyWordDialog;
  28. },
  29. scopeDialog: null,
  30. getScopeDialog: function(clickLi){
  31. if(this.scopeDialog == null){
  32. this.scopeDialog = new ScopeDialog("bid",clickLi);
  33. }
  34. return this.scopeDialog;
  35. }
  36. };
  37. //关键字弹出框
  38. function KeyWordDialog(type,clickLi){
  39. var thisClass = this;
  40. var dialogObj = $("#"+type+"-keyword");
  41. this.type = type;
  42. this.clickLi = clickLi;
  43. this.show = function(){
  44. dialogObj.show();
  45. $("html,body").addClass("overflow-hidden");
  46. $(window).resize(function(){
  47. KeyWordDialog.SetContentHeight(dialogObj);
  48. });
  49. };
  50. this.hide = function(){
  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. KeyWordDialog.AppendNode = function(dialogObj,value){
  72. var getHtml = function(index,value){
  73. return '<div class="keyWordGroup">'
  74. +'<lable>关键词<font>'+index+'</font></lable>'
  75. +'<div><input type="text" value="'+(value?value:"")+'" placeholder="示例:综合布线 电话线 网线" maxlength="100"></div>'
  76. +'<div>'+(index==1?'':'<img src="/wxswordfish/images/delete.png" class="delete">')+'</div>'
  77. +'</div>';
  78. }
  79. var count = dialogObj.find(".keyWordGroup").length;
  80. if(count >= 10){
  81. return;
  82. }
  83. var obj = $(getHtml(count+1,value));
  84. dialogObj.find(".addKeyWordArea").before(obj);
  85. //自动滚动到底部
  86. $("#a_end")[0].scrollIntoView();
  87. obj.find(".delete").click(function(){
  88. dialogObj.find(".addKeyWord").removeAttr("disabled");
  89. $(this).parents(".keyWordGroup").remove();
  90. dialogObj.find(".keyWordGroup").each(function(i){
  91. $(this).children("lable").children("font").text(i+1);
  92. });
  93. });
  94. if(typeof(value) == "undefined" || value == ""){
  95. obj.find("[type='text']").focus();
  96. }
  97. if(count >= 9){
  98. dialogObj.find(".addKeyWord").attr("disabled",true);
  99. }
  100. }
  101. //信息范围
  102. function ScopeDialog(type,clickLi){
  103. var thisClass = this;
  104. var dialogObj = $("#"+type+"-scope");
  105. this.type = type;
  106. this.clickLi = clickLi;
  107. this.show = function(){
  108. dialogObj.show();
  109. $("html,body").addClass("overflow-hidden");
  110. };
  111. this.hide = function(){
  112. dialogObj.hide();
  113. $("html,body").removeClass("overflow-hidden");
  114. };
  115. dialogObj.find(".dialog-content").css("max-height",document.body.clientHeight-dialogObj.find(".dialog-head").height()-40);
  116. dialogObj.find(".btn").click(function(){
  117. if($(this).parent().index() == 0){
  118. dialogObj.find(".btn").removeClass("active");
  119. }else{
  120. dialogObj.find("ul:first li:first .btn").removeClass("active");
  121. }
  122. $(this).toggleClass("active");
  123. if(dialogObj.find(".btn.active").length == 0){
  124. dialogObj.find("ul:first li:first .btn").addClass("active");
  125. }
  126. });
  127. dialogObj.find(".submit").click(function(){
  128. commonAjaxReq(thisClass,type);
  129. });
  130. }
  131. //取积分
  132. function getCredit(){
  133. var score=0
  134. $.ajax({
  135. dataType:"json",
  136. url:"/member/credit/getcredit",
  137. type:"POST",
  138. async:false,
  139. success:function(msg){
  140. if(msg){
  141. if(msg.flag){
  142. score=msg.val
  143. }else{
  144. alert("请重新进入页剑鱼页面后操作")
  145. }
  146. }
  147. },
  148. error:function(x,st,err){
  149. alert("请稍后再试"+st)
  150. }
  151. })
  152. return score
  153. }
  154. var snopshot=[];
  155. function showSnopshot(){
  156. //提示扣积分
  157. alert(getCredit())
  158. $(".credit-tip").show()
  159. }
  160. function commonAjaxReq(object,module){
  161. //是关的不用处理
  162. var dataObj = {
  163. reqType: "other",
  164. snopshot:false
  165. };
  166. if($("#"+module+"-on-off").hasClass("open")){
  167. //开服务要校验
  168. if(module=="tender"){
  169. if(typeof(msgset.tender) != "undefined"){
  170. if(!msgset.tender.i_switchstatus){
  171. snopshot["tender"]=true
  172. showSnopshot()
  173. }
  174. }
  175. }else if(module=="bid"){
  176. if(typeof(msgset.bid) != "undefined"){
  177. if(!msgset.bid.i_switchstatus){
  178. snopshot["bid"]=true
  179. showSnopshot()
  180. }
  181. }
  182. }
  183. }
  184. var keysString = "",scopeString = "";
  185. var thisClass = this;
  186. this.afterCommit = function(){
  187. object.hide();
  188. var value = "";
  189. switch(object.clickLi.index()){
  190. case 0:
  191. value = keysString;
  192. break;
  193. case 1:
  194. value = scopeString;
  195. break;
  196. }
  197. value = value.substring(0,value.length-1);
  198. if(object.clickLi.children(".com-last").length == 1){
  199. if(value == ""){
  200. object.clickLi.children(".com-last").remove();
  201. }else{
  202. object.clickLi.children(".com-last").text(value);
  203. }
  204. }else{
  205. if(value != ""){
  206. object.clickLi.append('<div class="com-last">'+value+'</div>');
  207. }
  208. }
  209. }
  210. //关键词
  211. this.setKeyWord = function(type){
  212. var tender_keys = [];
  213. $("#"+type+"-keyword .keyWordGroup").each(function(){
  214. var value = $.trim($(this).find("[type='text']").val()).replace(/\r\n/g,"");
  215. if(value == ""){
  216. return true;
  217. }
  218. if(object != null && object.type == type){
  219. keysString += value+";";
  220. }
  221. tender_keys.push(value.replace(/\s+/g,"+"));
  222. });
  223. return tender_keys;
  224. }
  225. //信息范围
  226. this.setScope = function(type){
  227. var tender_scope = [];
  228. $("#"+type+"-scope .btn.active").each(function(){
  229. var thisText = $(this).text();
  230. if(thisText == "全国"){
  231. tender_scope.push("A");
  232. if(object != null && object.type == type){
  233. scopeString += "全国;";
  234. }
  235. return false;
  236. }else{
  237. tender_scope.push(thisText);
  238. if(object != null && object.type == type){
  239. scopeString += thisText+";";
  240. }
  241. }
  242. });
  243. return tender_scope.join(",");
  244. }
  245. dataObj[module+"_keys"] = this.setKeyWord(module);
  246. dataObj[module+"_scope"] = this.setScope(module);
  247. if(dataObj[module+"_keys"].length > 0 && dataObj[module+"_scope"] == ""){
  248. dataObj[module+"_scope"] = "A";
  249. }
  250. dataObj[module+"_switchstatus"] = $("#"+module+"-on-off").hasClass("open")?1:0
  251. /*****************************************/
  252. $.ajax({
  253. type: "POST",
  254. url: "/swordfish/ajaxReq",
  255. data: dataObj,
  256. dataType: "json",
  257. traditional: true,
  258. success: function(r){
  259. if(object != null){
  260. thisClass.afterCommit();
  261. }
  262. },
  263. error: function(){
  264. }
  265. });
  266. }
  267. $(function(){
  268. var turnOn = function(obj){
  269. obj.addClass("open");
  270. var liobj = obj.parents("li");
  271. liobj.next().show();
  272. liobj.nextAll(".parent-node").eq(0).addClass("border-top");
  273. if(liobj.next(".child-node").find(".com-last").length == 0){
  274. liobj.next(".child-node").find("li:eq(1)").append('<div class="com-last">全国</div>');
  275. }
  276. }
  277. var setKeyWord = function(type,keys){
  278. if(typeof(keys) == "undefined" || keys.length == 0){
  279. return;
  280. }
  281. for(var i=0;i<keys.length;i++){
  282. keys[i] = keys[i].replace(/\+/g," ");
  283. KeyWordDialog.AppendNode($("#"+type+"-keyword"),keys[i]);
  284. }
  285. $("#"+type+"-content li:first").append('<div class="com-last">'+keys.join(";")+'</div>');
  286. }
  287. var setScope = function(type,scope){
  288. var dialogObj = $("#"+type+"-scope");
  289. if(typeof(scope) == "undefined" || scope == ""){
  290. return;
  291. }
  292. if(scope == "A"){
  293. dialogObj.find("ul:first li:first .btn").addClass("active");
  294. scope = "全国";
  295. }else{
  296. dialogObj.find("ul:first li:first .btn").removeClass("active");
  297. var scopeArray = scope.split(",");
  298. for(var i=0;i<scopeArray.length;i++){
  299. dialogObj.find(".btn").each(function(){
  300. if($(this).text() == scopeArray[i]){
  301. $(this).addClass("active");
  302. return false;
  303. }
  304. });
  305. }
  306. }
  307. $("#"+type+"-content li:last").append('<div class="com-last">'+scope.replace(/,/g,";")+'</div>');
  308. }
  309. $("body").append($("#tender-keyword").clone().removeAttr("id").attr("id","bid-keyword"))
  310. .append($("#tender-scope").clone().removeAttr("id").attr("id","bid-scope"));
  311. if(typeof(msgset.tender) != "undefined"){
  312. setKeyWord("tender",msgset.tender.a_key);
  313. setScope("tender",msgset.tender.s_scope);
  314. if(msgset.tender.i_switchstatus){
  315. turnOn($("#tender-on-off"));
  316. //判断要不要还原提示
  317. }
  318. }
  319. if(typeof(msgset.bid) != "undefined"){
  320. setKeyWord("bid",msgset.bid.a_key);
  321. setScope("bid",msgset.bid.s_scope);
  322. if(msgset.bid.i_switchstatus){
  323. turnOn($("#bid-on-off"));
  324. //判断要不要还原提示
  325. }
  326. }
  327. //开关
  328. $(".on-off").click(function(){
  329. if(this.id == "intelligence-on-off"){//企业情报
  330. alert("开发中,敬请期待!");
  331. return;
  332. }
  333. if($(this).hasClass("open")){
  334. $(this).removeClass("open")
  335. $(this).parents("li").next().hide();
  336. $(this).parents("li").nextAll(".parent-node").eq(0).removeClass("border-top");
  337. }else{
  338. turnOn($(this));
  339. }
  340. //判断是不是开,是开再判断是不是在有效期内,如果不在有效期内,则进行提示并存快照
  341. commonAjaxReq(null,$(this).attr("v"));
  342. });
  343. //收费规则
  344. $(".rule").closest(".parent-node").click(function(){
  345. $(".credit-dialog").show();
  346. $("html,body").addClass("overflow-hidden");
  347. })
  348. $("#credit-dialog-back").click(function(){
  349. $(".credit-dialog").hide();
  350. $("html,body").removeClass("overflow-hidden");
  351. });
  352. //
  353. $("#tender-content>li").click(function(){
  354. switch($(this).index()){
  355. case 0:
  356. Tender.getKeyWordDialog($(this)).show();
  357. break;
  358. case 1:
  359. Tender.getScopeDialog($(this)).show();
  360. break;
  361. }
  362. });
  363. $("#bid-content>li").click(function(){
  364. switch($(this).index()){
  365. case 0:
  366. Bid.getKeyWordDialog($(this)).show();
  367. break;
  368. case 1:
  369. Bid.getScopeDialog($(this)).show();
  370. break;
  371. }
  372. });
  373. });