main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. //意见反馈
  2. var feedback = null;
  3. //招标公告
  4. var Tender = {
  5. keyWordDialog: null,
  6. getKeyWordDialog: function(clickLi){
  7. if(this.keyWordDialog == null){
  8. this.keyWordDialog = new KeyWordDialog("tender",clickLi);
  9. }
  10. return this.keyWordDialog;
  11. },
  12. scopeDialog: null,
  13. getScopeDialog: function(clickLi){
  14. if(this.scopeDialog == null){
  15. this.scopeDialog = new ScopeDialog("tender",clickLi);
  16. }
  17. return this.scopeDialog;
  18. }
  19. };
  20. //中标公告
  21. var Bid = {
  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. };
  47. this.hide = function(){
  48. dialogObj.hide();
  49. $("html,body").removeClass("overflow-hidden");
  50. };
  51. var contentObj = dialogObj.find(".dialog-content");
  52. var padding = parseInt(contentObj.css('padding-top'))+parseInt(contentObj.css('padding-bottom'))
  53. contentObj.css("max-height",document.body.clientHeight-dialogObj.find(".dialog-head").height()-padding-40);
  54. dialogObj.find(".addKeyWord").click(function(){
  55. KeyWordDialog.AppendNode(dialogObj);
  56. });
  57. dialogObj.find(".submit").click(function(){
  58. commonAjaxReq(thisClass);
  59. });
  60. if(dialogObj.find(".keyWordGroup").length == 0){
  61. KeyWordDialog.AppendNode(dialogObj);
  62. }
  63. }
  64. KeyWordDialog.AppendNode = function(dialogObj,value){
  65. var getHtml = function(index,value){
  66. return '<div class="keyWordGroup">'
  67. +'<lable>关键词<font>'+index+'</font></lable>'
  68. +'<div><input type="text" value="'+(value?value:"")+'" placeholder="示例:综合布线 电话线 网线" maxlength="100"></div>'
  69. +'<div><img src="/wxrssset/images/delete.png" class="delete"></div>'
  70. +'</div>';
  71. }
  72. var count = dialogObj.find(".keyWordGroup").length;
  73. if(count >= 5){
  74. dialogObj.find(".addKeyWord").attr("disabled",true);
  75. return;
  76. }
  77. var obj = $(getHtml(count+1,value));
  78. dialogObj.find(".addKeyWordArea").before(obj);
  79. obj.find(".delete").click(function(){
  80. dialogObj.find(".addKeyWord").removeAttr("disabled");
  81. $(this).parents(".keyWordGroup").remove();
  82. dialogObj.find(".keyWordGroup").each(function(i){
  83. $(this).children("lable").children("font").text(i+1);
  84. });
  85. });
  86. if(typeof(value) == "undefined" || value == ""){
  87. obj.find("[type='text']").focus()
  88. }
  89. }
  90. //信息范围
  91. function ScopeDialog(type,clickLi){
  92. var thisClass = this;
  93. var dialogObj = $("#"+type+"-scope");
  94. this.type = type;
  95. this.clickLi = clickLi;
  96. this.show = function(){
  97. dialogObj.show();
  98. $("html,body").addClass("overflow-hidden");
  99. };
  100. this.hide = function(){
  101. dialogObj.hide();
  102. $("html,body").removeClass("overflow-hidden");
  103. };
  104. dialogObj.find(".dialog-content").css("max-height",document.body.clientHeight-dialogObj.find(".dialog-head").height()-40);
  105. dialogObj.find(".btn").click(function(){
  106. if($(this).parent().index() == 0){
  107. dialogObj.find(".btn").removeClass("active");
  108. }else{
  109. dialogObj.find("ul:first li:first .btn").removeClass("active");
  110. }
  111. $(this).toggleClass("active");
  112. if(dialogObj.find(".btn.active").length == 0){
  113. dialogObj.find("ul:first li:first .btn").addClass("active");
  114. }
  115. });
  116. dialogObj.find(".submit").click(function(){
  117. commonAjaxReq(thisClass);
  118. });
  119. }
  120. //意见反馈
  121. function Feedback(){
  122. this.show = function(){
  123. $(".feedback-dialog").show();
  124. $("html,body").addClass("overflow-hidden");
  125. };
  126. this.setCount = function(count){
  127. $(".feedback-dialog .statistics>span").text(count);
  128. };
  129. var thisClass = this;
  130. $("#feedback-textarea").on("input propertychange",function(){
  131. var count = $.trim(this.value).length;
  132. if(count > 0){
  133. $(this).parent().removeClass("red-border");
  134. }
  135. if(count > 200){
  136. this.value = this.value.substring(0,200);
  137. return;
  138. }
  139. thisClass.setCount(count);
  140. });
  141. $("#feedback-submit").click(function(){
  142. var value = $("#feedback-textarea").val();
  143. if($.trim(value) == ""){
  144. $("#feedback-textarea").focus().parent().addClass("red-border");
  145. return;
  146. }
  147. var obj = {reqType:"feedback"};
  148. $.ajax({
  149. type: "POST",
  150. url: "/swordfish/ajaxReq",
  151. data:{reqType:"feedback",value:value,title:"剑鱼-意见反馈"},
  152. dataType: "json",
  153. success: function(r){
  154. if(r.flag == "y"){
  155. $(".feedback-dialog").hide();
  156. $("html,body").removeClass("overflow-hidden");
  157. $("#feedback-textarea").val("");
  158. thisClass.setCount(0);
  159. alert("您的意见我们已经收到,谢谢!");
  160. }else{
  161. alert("提交失败!");
  162. }
  163. },
  164. error: function(){
  165. alert("网络连接错误!");
  166. }
  167. });
  168. });
  169. }
  170. function commonAjaxReq(object){
  171. var dataObj = {
  172. reqType: "other",
  173. tender_flag: $("#tender-on-off").hasClass("open"),
  174. bid_flag: $("#bid-on-off").hasClass("open")
  175. };
  176. var keysString = "",scopeString = "";
  177. var thisClass = this;
  178. this.afterCommit = function(){
  179. object.hide();
  180. var value = "";
  181. switch(object.clickLi.index()){
  182. case 0:
  183. value = keysString;
  184. break;
  185. case 1:
  186. value = scopeString;
  187. break;
  188. }
  189. value = value.substring(0,value.length-1);
  190. if(object.clickLi.children(".com-last").length == 1){
  191. if(value == ""){
  192. object.clickLi.children(".com-last").remove();
  193. }else{
  194. object.clickLi.children(".com-last").text(value);
  195. }
  196. }else{
  197. if(value != ""){
  198. object.clickLi.append('<div class="com-last">'+value+'</div>');
  199. }
  200. }
  201. }
  202. //关键词
  203. this.setKeyWord = function(type){
  204. var tender_keys = [];
  205. $("#"+type+"-keyword .keyWordGroup").each(function(){
  206. var value = $.trim($(this).find("[type='text']").val()).replace(/\r\n/g,"");
  207. if(value == ""){
  208. return true;
  209. }
  210. if(object != null && object.type == type){
  211. keysString += value+";";
  212. }
  213. tender_keys.push(value.replace(/\s+/g,"+"));
  214. });
  215. return tender_keys;
  216. }
  217. //信息范围
  218. this.setScope = function(type){
  219. var tender_scope = [];
  220. $("#"+type+"-scope .btn.active").each(function(){
  221. var thisText = $(this).text();
  222. if(thisText == "全国"){
  223. tender_scope.push("A");
  224. if(object != null && object.type == type){
  225. scopeString += "全国;";
  226. }
  227. return false;
  228. }else{
  229. tender_scope.push(thisText);
  230. if(object != null && object.type == type){
  231. scopeString += thisText+";";
  232. }
  233. }
  234. });
  235. return tender_scope.join(",");
  236. }
  237. /*******************招标公告****************/
  238. if(dataObj.tender_flag){
  239. dataObj["tender_keys"] = this.setKeyWord("tender");
  240. dataObj["tender_scope"] = this.setScope("tender");
  241. if(dataObj.tender_keys.length > 0 && dataObj.tender_scope == ""){
  242. dataObj["tender_scope"] = "A";
  243. }
  244. }
  245. /*******************中标公告****************/
  246. if(dataObj.bid_flag){
  247. dataObj["bid_keys"] = this.setKeyWord("bid");
  248. dataObj["bid_scope"] = this.setScope("bid");
  249. if(dataObj.bid_keys.length > 0 && dataObj.bid_scope == ""){
  250. dataObj["bid_scope"] = "A";
  251. }
  252. }
  253. /*****************************************/
  254. $.ajax({
  255. type: "POST",
  256. url: "/swordfish/ajaxReq",
  257. data: dataObj,
  258. dataType: "json",
  259. traditional: true,
  260. success: function(r){
  261. if(object != null){
  262. thisClass.afterCommit();
  263. }
  264. },
  265. error: function(){
  266. }
  267. });
  268. }
  269. $(function(){
  270. var turnOn = function(obj){
  271. obj.addClass("open");
  272. var liobj = obj.parents("li");
  273. liobj.next().show();
  274. liobj.nextAll(".parent-node").eq(0).addClass("border-top");
  275. if(liobj.next(".child-node").find(".com-last").length == 0){
  276. liobj.next(".child-node").find("li:eq(1)").append('<div class="com-last">全国</div>');
  277. }
  278. }
  279. var setKeyWord = function(type,keys){
  280. if(typeof(keys) == "undefined" || keys.length == 0){
  281. return;
  282. }
  283. for(var i=0;i<keys.length;i++){
  284. keys[i] = keys[i].replace(/\+/g," ");
  285. KeyWordDialog.AppendNode($("#"+type+"-keyword"),keys[i]);
  286. }
  287. $("#"+type+"-content li:first").append('<div class="com-last">'+keys.join(";")+'</div>');
  288. }
  289. var setScope = function(type,scope){
  290. var dialogObj = $("#"+type+"-scope");
  291. if(typeof(scope) == "undefined" || scope == ""){
  292. return;
  293. }
  294. if(scope == "A"){
  295. dialogObj.find("ul:first li:first .btn").addClass("active");
  296. scope = "全国";
  297. }else{
  298. dialogObj.find("ul:first li:first .btn").removeClass("active");
  299. var scopeArray = scope.split(",");
  300. for(var i=0;i<scopeArray.length;i++){
  301. dialogObj.find(".btn").each(function(){
  302. if($(this).text() == scopeArray[i]){
  303. $(this).addClass("active");
  304. return false;
  305. }
  306. });
  307. }
  308. }
  309. $("#"+type+"-content li:last").append('<div class="com-last">'+scope.replace(/,/g,";")+'</div>');
  310. }
  311. $("body").append($("#tender-keyword").clone().removeAttr("id").attr("id","bid-keyword"))
  312. .append($("#tender-scope").clone().removeAttr("id").attr("id","bid-scope"));
  313. if(typeof(msgset.tender) != "undefined"){
  314. setKeyWord("tender",msgset.tender.a_key);
  315. setScope("tender",msgset.tender.s_scope);
  316. turnOn($("#tender-on-off"));
  317. }
  318. if(typeof(msgset.bid) != "undefined"){
  319. setKeyWord("bid",msgset.bid.a_key);
  320. setScope("bid",msgset.bid.s_scope);
  321. turnOn($("#bid-on-off"));
  322. }
  323. //开关
  324. $(".on-off").click(function(){
  325. if(this.id == "intelligence-on-off"){//企业情报
  326. alert("开发中,敬请期待!");
  327. return;
  328. }
  329. if($(this).hasClass("open")){
  330. $(this).removeClass("open")
  331. $(this).parents("li").next().hide();
  332. $(this).parents("li").nextAll(".parent-node").eq(0).removeClass("border-top");
  333. }else{
  334. turnOn($(this));
  335. }
  336. commonAjaxReq(null);
  337. });
  338. //
  339. $("#tender-content>li").click(function(){
  340. switch($(this).index()){
  341. case 0:
  342. Tender.getKeyWordDialog($(this)).show();
  343. break;
  344. case 1:
  345. Tender.getScopeDialog($(this)).show();
  346. break;
  347. }
  348. });
  349. $("#bid-content>li").click(function(){
  350. switch($(this).index()){
  351. case 0:
  352. Bid.getKeyWordDialog($(this)).show();
  353. break;
  354. case 1:
  355. Bid.getScopeDialog($(this)).show();
  356. break;
  357. }
  358. });
  359. //弹出框消失
  360. $(".dialog").click(function(e){
  361. if($(e.target).hasClass("dialog")){
  362. $(this).hide();
  363. $("html,body").removeClass("overflow-hidden");
  364. }
  365. });
  366. $("#feedback").click(function(){
  367. if(feedback == null){
  368. feedback = new Feedback();
  369. }
  370. feedback.show();
  371. $("#feedback-textarea").focus().parent().removeClass("red-border");
  372. });
  373. });