9446b214cad970e1ccaac716e282ce6118912ddb.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /**
  2. * Created by zhumingyue on 2016/7/6.
  3. */
  4. AxisSmootTran = function(){
  5. var _this = this;
  6. var settimer=null;
  7. var settimer2=null;
  8. this.init = function(years,trans_name){
  9. _this.creatAnnounceBox(trans_name + "历史信息");
  10. _this.creatSmootAxisLine();
  11. _this.createYearAxis(years);
  12. };
  13. this.getscroll = function(){
  14. $(top.window).scroll( function() {
  15. var _thisScroll = $(this);
  16. var scroH = _thisScroll.scrollTop();
  17. if(scroH>200){
  18. $(".year_box_axis").css({"top":scroH });
  19. }else{
  20. $(".year_box_axis").css({"top":scroH+150 });
  21. }
  22. scroH = null;
  23. _thisScroll = null;
  24. });
  25. };
  26. /**
  27. * 创建年轴
  28. */
  29. this.createYearAxis = function(params){
  30. var $year_box_axis = document.createElement("div");
  31. $($year_box_axis).addClass("year_box_axis");
  32. var $year_now = document.createElement("div");
  33. $($year_now).addClass("year_box");
  34. var $year_now_a = document.createElement("a");
  35. $($year_now_a).addClass("year_now_a");
  36. $($year_now_a).attr("href","#dataAxisSmootTran").html("现在");
  37. $($year_now).append($year_now_a);
  38. $($year_box_axis).append($year_now);
  39. for(var key in params){
  40. var $year_box = document.createElement("div");
  41. $($year_box).addClass("year_box");
  42. $year_now_a = document.createElement("a");
  43. $($year_now_a).addClass("year_now_a");
  44. // $($year_now_a).attr("href","#" + params[key].year).html(params[key].year);
  45. $($year_now_a).attr("year", params[key].year).html(params[key].year);
  46. $($year_now_a).on("click",function(){
  47. var anchor = $(this).attr("year");
  48. $('html, body', window.parent.document).animate({
  49. scrollTop:$("#"+anchor).offset().top
  50. },1000);
  51. $(".smoot_axis_year_active").removeClass("smoot_axis_year_active");
  52. $(this).parent().addClass("smoot_axis_year_active");
  53. });
  54. $($year_box).append($year_now_a);
  55. $($year_box_axis).append($year_box);
  56. };
  57. $("#dataAxisSmootTran").append($year_box_axis);
  58. _this.getscroll();
  59. };
  60. /**
  61. * 创建输入框
  62. * @param title
  63. */
  64. this.creatAnnounceBox = function(title){
  65. var $tran_flag_img = document.createElement("img");
  66. $($tran_flag_img).addClass("tran_flag_img");
  67. $($tran_flag_img).attr("src","/nwyj/images/business/em/floods/tran_history_flag.png");
  68. var $announce_box = document.createElement("div");
  69. $($announce_box).addClass("announce_box");
  70. var $iden = document.createElement("div");
  71. $($iden).addClass("iden");
  72. var $anno_title = document.createElement("div");
  73. $($anno_title).addClass("anno_title");
  74. $anno_title_img = document.createElement("img");
  75. $($anno_title_img).attr("src","/nwyj/images/business/em/floods/smoot_title.png");
  76. $($anno_title_img).addClass("anno_title_img");
  77. $($anno_title).append($anno_title_img).append("<span>" + title + "</span>" );
  78. var $anno_input = document.createElement("textarea");
  79. $($anno_input).attr("maxlength","256");
  80. $($anno_input).attr("rows","3");
  81. $($anno_input).attr("cols","20");
  82. // onKeyDown=""if (this.value.length>=20){event.returnValue=false}""
  83. // $($anno_input).attr("onKeyDown","if(this.value.length>=20){event.returnValue=false}");
  84. /*var $anno_input = document.createElement("div");
  85. $($anno_input).attr("contentEditable",true);*/
  86. $($anno_input).addClass("anno_input");
  87. var maxLen = 256;
  88. $($anno_input).keyup(function(){
  89. var len = $(this).val().length;
  90. if(len>maxLen){
  91. len = maxLen;
  92. var str = $(this).val();
  93. $($anno_input).val(str.substring(0,maxLen));
  94. };
  95. $(".input_count").html(maxLen-len);
  96. });
  97. var $remind = document.createElement("span");
  98. $($remind).addClass("remind").html("还可以输入");
  99. var $input_count = document.createElement("span");
  100. $($input_count).addClass("input_count").html("256");
  101. var $remind_over = document.createElement("span");
  102. $($remind_over).addClass("remind_over").html("个字符");
  103. var $anno_but = document.createElement("div");
  104. $($anno_but).addClass("anno_but");
  105. var $anno_but_a = document.createElement("a");
  106. $($anno_but_a).attr("href","javascript:void;");
  107. $($anno_but_a).html("添加");
  108. $($anno_but).append($anno_but_a);
  109. $($anno_but).on("click",function(){
  110. var text = $(".anno_input").val();
  111. var params = {count:text,data:_this.getLocatData()};
  112. addSmootTimeAxisCount(params);
  113. });
  114. $($announce_box).append($anno_input).append($remind).append($input_count).append($remind_over).append($anno_but);
  115. $("#dataAxisSmootTran").append($tran_flag_img).append($iden).append($anno_title).append($announce_box);
  116. };
  117. /**
  118. * 创建时间轴线
  119. */
  120. this.creatSmootAxisLine = function(){
  121. var $smoot_axis_line = document.createElement("div");
  122. $($smoot_axis_line).addClass("smoot_axis_line");
  123. var $smoot_axis_top_line = document.createElement("div");
  124. $($smoot_axis_top_line).addClass("smoot_axis_top_line");
  125. var $smoot_axis_line_img = document.createElement("div");
  126. $($smoot_axis_line_img).addClass("smoot_axis_line_img");
  127. var $smoot_axis_nextbox = document.createElement("div");
  128. $($smoot_axis_nextbox).addClass("smoot_axis_nextbox");
  129. $($smoot_axis_line).append($smoot_axis_top_line).append($smoot_axis_line_img).append($smoot_axis_nextbox);
  130. $("#dataAxisSmootTran").append($smoot_axis_line);
  131. };
  132. /**
  133. * 得到时间年月日时分秒 返回字符 yyyy-MM-dd hh:mm:ss
  134. */
  135. this.getLocatData = function(){
  136. var dateDom = allGetServerTime();
  137. //获取本地时间,年月日时分
  138. var year = dateDom.getFullYear();
  139. var month = parseInt(dateDom.getMonth()+1);
  140. if(month<10) month = "0" + month ;
  141. var day = parseInt(dateDom.getDate());
  142. if(day<10) day = "0" + day ;
  143. var hours = parseInt(dateDom.getHours());
  144. if(hours<10) hours = "0" + hours;
  145. var minutes = parseInt(dateDom.getMinutes());
  146. if(minutes<10) minutes = "0" + minutes;
  147. var seconds = parseInt(dateDom.getSeconds());
  148. if(seconds<10) seconds = "0" + seconds;
  149. return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
  150. };
  151. this.splitData = function(param){
  152. var smoot_data = new Date(param.replace(/\-/g,"/"));
  153. var month = parseInt(smoot_data.getMonth() + 1) ;
  154. if(month<10) month = "0" + month ;
  155. var day = parseInt(smoot_data.getDate()) ;
  156. if(day<10) day = "0" + day ;
  157. var hours = parseInt(smoot_data.getHours());
  158. if(hours<10) hours = "0" + hours;
  159. var minutes = parseInt(smoot_data.getMinutes());
  160. if(minutes<10) minutes = "0" + minutes;
  161. return {y:smoot_data.getFullYear() + "-" + month + "-" + day,
  162. m:hours + ":" + minutes, fy:smoot_data.getFullYear()};
  163. };
  164. /**
  165. * 添加下一个框内容
  166. * @param text
  167. */
  168. this.addNextBox = function(params){
  169. // var params = [{count:text,data:"2016-12-21 15:22:23",fd_id:"1234567"}]
  170. var year_title ;
  171. for(var key = 0; key < params.length; key++){
  172. var $smoot_axis_next_box_history = document.createElement("div");
  173. $($smoot_axis_next_box_history).addClass("smoot_axis_next_box_history");
  174. var $smoot_next_editbox = document.createElement("div");
  175. $($smoot_next_editbox).addClass("smoot_next_editbox");
  176. $($smoot_next_editbox).attr("fd_id",params[key].fd_id);
  177. $($smoot_next_editbox).on("mouseover",function(){
  178. if(_this.settimer!=null||_this.settimer!=undefined){
  179. clear(_this.settimer);
  180. }
  181. });
  182. $($smoot_next_editbox).on("mouseleave",function(){
  183. _this.settimer2 =setTime(function(){
  184. $(this).animate({
  185. // right:"0px",zIndex:-1
  186. width:0
  187. },200);
  188. $(this).find(".smoot_edit_but").animate({
  189. width:0
  190. },200);
  191. $(this).find(".smoot_del_but").animate({
  192. width:0
  193. },200);
  194. },1);
  195. });
  196. var $smoot_edit_but = document.createElement("div");
  197. $($smoot_edit_but).addClass("smoot_edit_but");
  198. //编辑按钮的单击事件
  199. $($smoot_edit_but).on("click",function(){
  200. var edittemp = $(this).parent().parent();
  201. var hbc = $(edittemp).find(".smoot_p_count").attr("title");
  202. $(edittemp).find(".smoot_p_count").remove();
  203. var maxLen = 256;
  204. var $edit_input = document.createElement("textarea");
  205. $($edit_input).attr("title",hbc);
  206. $($edit_input).attr("maxlength",maxLen);
  207. $($edit_input).attr("rows","3");
  208. $($edit_input).attr("cols","20");
  209. $($edit_input).addClass("edit_input").val(hbc);
  210. $(edittemp).find(".smoot_span_time").after($edit_input);
  211. var $remind = document.createElement("span");
  212. $($remind).addClass("remind").html("还可以输入");
  213. var $edit_count = document.createElement("span");
  214. $($edit_count).addClass("edit_count").html(maxLen-hbc.length);
  215. var $remind_over = document.createElement("span");
  216. $($remind_over).addClass("remind_over").html("个字符");
  217. $($edit_input).after($remind_over).after($edit_count).after($remind);
  218. $($edit_input).keyup(function(){
  219. var len = $(this).val().length;
  220. if(len>maxLen){
  221. len = maxLen;
  222. var str = $(this).val();
  223. $($anno_input).val(str.substring(0,maxLen));
  224. };
  225. $(".edit_count").html(maxLen-len);
  226. });
  227. var $smoot_giveup = document.createElement("div");
  228. $($smoot_giveup).addClass("smoot_giveup").html("取消");
  229. $($smoot_giveup).on("click",function(){
  230. var $smoot_p_count = document.createElement("div");
  231. var temp_count = $(this).parent().find("textarea").attr("title");
  232. $($smoot_p_count).addClass("smoot_p_count").html(temp_count).attr("title",temp_count);
  233. $(this).parent().find("textarea").remove();
  234. $(this).parent().find(".smoot_span_time").after($smoot_p_count);
  235. $(this).parent().find(".remind").remove();
  236. $(this).parent().find(".edit_count").remove();
  237. $(this).parent().find(".remind_over").remove();
  238. $(this).parent().find(".smoot_save_edithistory").remove();
  239. $(this).remove();
  240. });
  241. var $smoot_save_edithistory = document.createElement("div");
  242. $($smoot_save_edithistory).addClass("smoot_save_edithistory").html("保存");
  243. $($smoot_save_edithistory).on("click",function(){
  244. var $save_count = $(this).parent().find("textarea");
  245. var texttemp = $($save_count).val();
  246. var overtitle = texttemp;
  247. var paramtemp = {fd_id:$(this).parent().find(".smoot_next_editbox").attr("fd_id"),disc:texttemp,ut:_this.getLocatData()};
  248. var flg = editSmootTimeAxisHistory(paramtemp);
  249. if(!flg){
  250. overtitle = $($save_count).attr("title");
  251. };
  252. var $smoot_p_count = document.createElement("div");
  253. $($smoot_p_count).addClass("smoot_p_count").html(overtitle).attr("title",overtitle);
  254. $(this).parent().find("textarea").remove();
  255. $(this).parent().find(".smoot_span_time").after($smoot_p_count);
  256. $(this).parent().find(".remind").remove();
  257. $(this).parent().find(".edit_count").remove();
  258. $(this).parent().find(".remind_over").remove();
  259. $(this).parent().find(".smoot_giveup").remove();
  260. $(this).remove();
  261. });
  262. $(edittemp).append($smoot_giveup).append($smoot_save_edithistory);
  263. });
  264. var $smoot_del_but = document.createElement("div");
  265. $($smoot_del_but).addClass("smoot_del_but");
  266. $($smoot_del_but).on("click",function(){
  267. if(confirm("确定删除吗?")){
  268. if(delSmootTimeAxisHistory($(this).parent().attr("fd_id")))
  269. $(this).parent().parent().remove();
  270. }
  271. });
  272. $($smoot_next_editbox).append($smoot_edit_but).append($smoot_del_but);
  273. $($smoot_axis_next_box_history).on("mouseover",function(){
  274. if(_this.settimer2==undefined){
  275. $(this).find(".smoot_next_editbox").animate({
  276. // right:"-20px",zIndex:2
  277. width:"25px"
  278. },200);
  279. $(this).find(".smoot_next_editbox").find(".smoot_edit_but").animate({
  280. width:"25px"
  281. },200);
  282. $(this).find(".smoot_next_editbox").find(".smoot_del_but").animate({
  283. width:"25px"
  284. },200);
  285. }else{
  286. if(_this.settimer2!=null || _this.settimer2!=undefined)
  287. clear(_this.settimer2);
  288. }
  289. });
  290. $($smoot_axis_next_box_history).on("mouseleave",function(){
  291. var cc= this;
  292. _this.settimer = setTimeout(function(){
  293. $(cc).find(".smoot_next_editbox").animate({
  294. width:0
  295. },200);
  296. $(cc).find(".smoot_next_editbox").find(".smoot_edit_but").animate({
  297. width:0
  298. },200);
  299. $(cc).find(".smoot_next_editbox").find(".smoot_del_but").animate({
  300. width:0
  301. },200);
  302. },1);
  303. });
  304. var node_year = _this.splitData(params[key].data).fy;
  305. if(key < (params.length-1)){
  306. year_title = _this.splitData(params[key+1].data).fy;
  307. }else{
  308. year_title = _this.splitData(params[key].data).fy;
  309. };
  310. if(node_year != year_title || key == params.length-1){
  311. var $smoot_axis_year_title = document.createElement("div");
  312. $($smoot_axis_year_title).addClass("smoot_axis_year_title");
  313. $($smoot_axis_year_title).attr("id",node_year);
  314. $($smoot_axis_year_title).html(node_year);
  315. $($smoot_axis_next_box_history).append($smoot_axis_year_title);
  316. };
  317. /* var node_year = _this.splitData(params[key].data).fy;
  318. // alert(onde_year + " " + year_title);
  319. if( node_year != year_title){
  320. var $smoot_axis_year_title = document.createElement("div");
  321. $($smoot_axis_year_title).addClass("smoot_axis_year_title");
  322. $($smoot_axis_year_title).html(node_year);
  323. $($smoot_axis_next_box_history).append($smoot_axis_year_title);
  324. };*/
  325. year_title = node_year;
  326. var $smoot_axis_next_line = document.createElement("div");
  327. $($smoot_axis_next_line).addClass("smoot_axis_next_line");
  328. var $smoot_history_node = document.createElement("div");
  329. $($smoot_history_node).addClass("smoot_history_node");
  330. var $smoot_year_iden = document.createElement("div");
  331. $($smoot_year_iden).addClass("smoot_year_iden");
  332. var smoot_data = _this.splitData(params[key].data);
  333. var $smoot_span_data = document.createElement("div");
  334. var $smoot_span_time = document.createElement("div");
  335. $($smoot_span_data).addClass("smoot_span_data");
  336. $($smoot_span_time).addClass("smoot_span_time");
  337. $($smoot_span_data).html(smoot_data.y);
  338. $($smoot_span_time).html(smoot_data.m);
  339. var $smoot_p_count = document.createElement("div");
  340. $($smoot_p_count).attr("contenteditable",false);
  341. $($smoot_p_count).addClass("smoot_p_count");
  342. $($smoot_p_count).html(params[key].count);
  343. $($smoot_p_count).attr("title",params[key].count);
  344. var $iden_history = document.createElement("div");
  345. $($iden_history).addClass("iden_history");
  346. $($smoot_axis_next_box_history).append($iden_history).append($smoot_axis_next_line).append($smoot_history_node);
  347. $($smoot_axis_next_box_history).append($smoot_year_iden).append($smoot_span_data).append($smoot_span_time).append($smoot_p_count);
  348. $($smoot_axis_next_box_history).append($smoot_next_editbox);
  349. $(".smoot_axis_nextbox").prepend($smoot_axis_next_box_history);
  350. $(".anno_input").text("");
  351. $(".boxc_c").text("");
  352. };
  353. };
  354. };