ans-common.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. function bindDateEvent(){
  2. var checkTypeDates = $("#dwSurveyQuContent .checkType[value='DATE']");
  3. $.each(checkTypeDates,function(){
  4. var surveyQuItemBody = $(this).parents(".surveyQuItemBody");
  5. var paramInt01 = surveyQuItemBody.find(".paramInt01");
  6. var dateFmt = "yyyy-MM-dd";
  7. var dateType = "date";
  8. if(paramInt01[0]){
  9. var paramInt01Val = paramInt01.val();
  10. if(paramInt01Val==="1"){
  11. dateFmt="yyyy";
  12. dateType="year";
  13. }else if(paramInt01Val==="2"){
  14. dateFmt="yyyy-MM";
  15. dateType="month";
  16. }else if(paramInt01Val==="3"){
  17. dateFmt="yyyy-MM-dd";
  18. dateType="date";
  19. }else if(paramInt01Val==="4"){
  20. dateFmt="yyyy-MM-dd HH:mm:ss";
  21. dateType="datetime";
  22. }else if(paramInt01Val==="5"){
  23. dateFmt="HH:mm:ss";
  24. dateType="time";
  25. }else if(paramInt01Val==="6"){
  26. dateFmt="HH:mm";
  27. dateType="time";
  28. }
  29. }
  30. // console.debug("dateType:"+dateType);
  31. // validateCheck($(this).parents(".li_surveyQuItemBody"),true);
  32. laydate.render({
  33. elem: surveyQuItemBody.find("input.fillblankInput")[0] //指定元素
  34. ,type: 'datetime'
  35. ,format: dateFmt
  36. ,type: dateType
  37. });
  38. });
  39. }
  40. function checkoutData(checkType, value) {
  41. var validateStatus = true;
  42. if(value.length<=0){
  43. validateStatus = false;
  44. }
  45. if (checkType == "NO") {
  46. if(value.length<=0){
  47. validateStatus = false;
  48. }
  49. }else if (checkType == "EMAIL") {
  50. var __email = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
  51. if (!__email.test(value)) {
  52. validateStatus = false;
  53. }
  54. } else if (checkType == "UNSTRCN") {
  55. var __cn = /^[\u3220-\uFA29]+$/;
  56. if (__cn.test(value)) {
  57. validateStatus = false;
  58. }
  59. } else if (checkType == "STRCN") {
  60. var __cn = /^[\u3220-\uFA29]+$/;
  61. if (!__cn.test(value)) {
  62. validateStatus = false;
  63. }
  64. } else if (checkType == "NUM") {
  65. // "number[/[+|-][int|integer|float|double|money|{位数正则}.{位数正则}]]"
  66. // var __regex = /^\d+(\.\d+)?$/;
  67. var __regex = /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/;
  68. if (!__regex.test(value)) {
  69. validateStatus = false;
  70. }
  71. } else if (checkType == "DIGITS") {
  72. var __regex = /^\d+$/;
  73. if (!__regex.test(value)) {
  74. validateStatus = false;
  75. }
  76. } else if (checkType == "TELENUM") {
  77. var tel = /^\d{3,4}-{1}\d{7,9}-?\d{1,6}$/;
  78. var tel400800 = /^(400{1}-?[0-9]{3}-?[0-9]{4})|(800{1}-?[0-9]{3}-?[0-9]{4})$/
  79. if (!(tel.test(value) || tel400800.test(value))) {
  80. validateStatus = false;
  81. }
  82. } else if (checkType == "PHONENUM") {
  83. var length = value.length;
  84. var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
  85. if (!(length == 11 && mobile.test(value))) {
  86. validateStatus = false;
  87. }
  88. } else if (checkType == "TELE_PHONE_NUM") {
  89. var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
  90. var tel = /^\d{3,4}-{1}\d{7,9}-?\d{1,6}$/;
  91. var tel400800 = /^(400{1}-?[0-9]{3}-?[0-9]{4})|(800{1}-?[0-9]{3}-?[0-9]{4})$/
  92. if (!(tel400800.test(value) || tel.test(value) || mobile.test(value))) {
  93. validateStatus = false;
  94. }
  95. } else if (checkType == "DATE") {
  96. //日期的正则表达式
  97. /*
  98. var reg1 = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;//2014-01-01
  99. var regExp1 = new RegExp(reg1);
  100. var reg2 = /^(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;//12:00:00
  101. var regExp2 = new RegExp(reg2);
  102. var reg3 = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;//2014-01-01 12:00:00
  103. var regExp3 = new RegExp(reg3);
  104. if(!(regExp1.test(value) || regExp2.test(value) || regExp3.test(value) )){
  105. // alert("日期格式不正确,正确格式为:2014-01-01");
  106. errorType = "DATE";
  107. validateStatus = false;
  108. }
  109. */
  110. /*if (/Invalid|NaN/.test(new Date(value).toString())) {
  111. validateStatus = false;
  112. }*/
  113. validateStatus = true;
  114. } else if (checkType == "IDENTCODE") {
  115. var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(value);
  116. if (!(check && (value.length == 15 || value.length == 18))) {
  117. validateStatus = false;
  118. }
  119. } else if (checkType == "ZIPCODE") {
  120. var tel = /^[0-9]{6}$/;
  121. if (!tel.test(value)) {
  122. validateStatus = false;
  123. }
  124. } else if (checkType == "URL"){
  125. var strRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i;
  126. if (!strRegex.test(value)) {
  127. validateStatus = false;
  128. }
  129. }
  130. return validateStatus;
  131. }
  132. var upEventIndex = 0;
  133. function wwwUpload(){
  134. var ctx = $("#ctx").val();
  135. var url = '/api/dwsurvey/up/up-file-wb.do';
  136. //alert('data');
  137. $("#dwSurveyQuContentAppUl .fileupload").unbind();
  138. $("#dwSurveyQuContentAppUl .fileupload").fileupload({
  139. url: url,
  140. // maxFileCount:1,
  141. dataType: 'json',
  142. // forceIframeTransport: true,
  143. // autoUpload:true,
  144. // formData: {"safe":"webInf"},
  145. add: function(e, data) {
  146. var thObj = $(this);
  147. showUpFileMsg(thObj,"准备上传...");
  148. var surveyQuItemBody = $(this).parents(".surveyQuItemBody");
  149. var paramInt01 = surveyQuItemBody.find(".paramInt01").val();
  150. var paramInt02 = surveyQuItemBody.find(".paramInt02").val();
  151. var randOrder = surveyQuItemBody.find(".randOrder").val();
  152. var upAppend=surveyQuItemBody.find(".upFileDiv .upAppend");
  153. if(upAppend[0] && randOrder>0 && upAppend.size()>=randOrder ){
  154. // alert("最多只能上传"+randOrder+"个附件");
  155. showUpFileMsg(thObj,"最多只能上传"+randOrder+"个附件");
  156. return ;
  157. }
  158. if(paramInt01==1){
  159. /*
  160. var acceptFileTypes = /^image\/(gif|jpe?g|png)$/i;
  161. //文件类型判断
  162. if(data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
  163. alert("上传文件类型不对,请上传图片文件!");
  164. return ;
  165. }
  166. */
  167. var acceptFileTypes = /(\.|\/)(gif|jpg|jpeg|png|bmp)$/i;
  168. //文件类型判断
  169. if(!acceptFileTypes.test(data.originalFiles[0].name)) {
  170. // alert("上传文件类型不对,请上传图片文件!");
  171. showUpFileMsg(thObj,"上传文件类型不对,请上传图片文件!");
  172. return ;
  173. }
  174. }
  175. if(paramInt01==2){
  176. // var acceptFileTypes = /\/(txt|doc?x|xls?x|ppt?x|pdf|xml)$/i;
  177. var acceptFileTypes = /(\.|\/)(txt|doc|docx|xls|xlsx|ppt|pptx|pdf|xml)$/i;
  178. //文件类型判断
  179. if(!acceptFileTypes.test(data.originalFiles[0].name)) {
  180. // alert("上传文件类型不对,请上传文本文件!");
  181. showUpFileMsg(thObj,"上传文件类型不对,请上传文本文件!");
  182. return ;
  183. }
  184. }
  185. //文件大小判断
  186. if(paramInt02!=null && paramInt02!=""){
  187. var maxSize = 1024*1024*paramInt02;
  188. if(data.originalFiles[0]['size'] > maxSize) {
  189. // alert("文件大小超出限制,最大支持"+paramInt02+"M");
  190. showUpFileMsg(thObj,"文件大小超出限制,最大支持"+paramInt02+"M");
  191. return;
  192. }
  193. }
  194. /*
  195. var url = getUrl(data.files[0]);
  196. surveyQuItemBody.find(".quFillblankItem").prepend("<label class='upImgLabel' ><img class='upAppend' src='${ctx}"+url+"' height='150' >&nbsp;<a href='' ><i class='fa fa-times' aria-hidden='true'></i></a>" +
  197. "<input type='hidden' class='upFileName' value='"+data.files[0].name+"' />"+
  198. "<input type='hidden' class='upFilePath' value='' />"+
  199. "</label>");
  200. */
  201. data.submit();
  202. showUpFileMsg(thObj,"上传中...");
  203. },
  204. change: function (e, data) {
  205. //alert("change:"+data.files.length);
  206. /*
  207. $.each(data.files, function (index, file) {
  208. alert('Selected file: ' + file.name);
  209. console.log(file);
  210. });
  211. */
  212. },
  213. done: function (e, data) {
  214. // alert(JSON.stringify(data));
  215. // "{\"success\":\"true\",\"filename\":\"粉刷.jpeg \",\"location\":\"/file/images/粉刷.jpeg\"}"
  216. // var result = data.result[0].body ? data.result[0].body.innerHTML : data.result;
  217. // result = JSON.parse(result);
  218. // var result = eval("("+data.result+")");
  219. // var location = result.location;
  220. // var fileName = result.filename;
  221. var location = null;
  222. var fileName = null;
  223. var httpResult = data.result;
  224. var resultCode = httpResult.resultCode;
  225. var resultData = httpResult.data;
  226. if(resultCode==200){
  227. //实际只会有一条
  228. $.each(resultData,function (i,item){
  229. location = item.location;
  230. fileName = item.filename;
  231. });
  232. }
  233. //如果是图片,则取回进行显示
  234. var surveyQuItemBody = $(this).parents(".surveyQuItemBody");
  235. var paramInt01 = surveyQuItemBody.find(".paramInt01").val();
  236. if(false){
  237. // surveyQuItemBody.find(".quFillblankItem .upAppend").remove();
  238. // <label class='upImgLabel' ><img class='upAppend' src='' height='150' ><a href='' ><i class='fa fa-times' aria-hidden='true'></i></a></label>
  239. // surveyQuItemBody.find(".quFillblankItem").prepend("<img class='upAppend' src='${ctx}"+location+"' height='150' style='margin-bottom:8px;border:1px solid grey;padding:6px;' />");
  240. surveyQuItemBody.find(".quFillblankItem").prepend("<label class='upImgLabel' ><img class='upAppend' src='"+ctx+location+"' height='150' >&nbsp;<a href='' ><i class='fa fa-times' aria-hidden='true'></i></a></label>");
  241. surveyQuItemBody.find("span.fileinput-button span").text("继续上传");
  242. surveyQuItemBody.find(".fileuploadPath").val(location+"___"+fileName);
  243. }else{
  244. var fileuploadPathName = surveyQuItemBody.find(".fileuploadPath").attr("uphidinputname")+"_"+(upEventIndex++);
  245. var fileSaveValue = location+"___"+fileName;
  246. // surveyQuItemBody.find(".quFillblankItem .upAppend").remove();
  247. // surveyQuItemBody.find(".quFillblankItem").prepend("<div class='upAppend' style='margin-bottom:8px;border:1px solid grey;padding:6px;' > 文件名称:"+fileName+" </div>");
  248. surveyQuItemBody.find(".quFillblankItem .upFileDiv").prepend('<div class="upAppend" ><label style="overflow: auto;width: 95%;">文件名称:'+fileName+'</label><a href="#" class="removeUpFile" ><i class="fa fa-times" aria-hidden="true"></i></a>' +
  249. '<input type="hidden" class="fileuploadSaveValue" name="'+fileuploadPathName+'" value="'+fileSaveValue+'" />' +
  250. '</div>');
  251. surveyQuItemBody.find("span.fileinput-button span").text("继续上传");
  252. // surveyQuItemBody.find(".fileuploadPath").val(fileSaveValue);
  253. }
  254. bindUpEvent();
  255. surveyQuItemBody.find(".answerTag").val(1);
  256. var quCoItemUlLi = $(this).parents(".quCoItemUlLi");
  257. quCoItemUlLi.find('.progress').fadeOut(3000);
  258. //保存路径
  259. var li_surveyQuItemBody = $(this).parents(".li_surveyQuItemBody");
  260. runlogic(li_surveyQuItemBody,$(this));
  261. validateCheck(surveyQuItemBody,false);
  262. answerProgressbar(surveyQuItemBody);
  263. },
  264. progressall: function (e, data) {
  265. var quCoItemUlLi = $(this).parents(".quCoItemUlLi");
  266. var progress = parseInt(data.loaded / data.total * 100, 10);
  267. quCoItemUlLi.find('.progress').show();
  268. quCoItemUlLi.find('.progress .progress-bar').css(
  269. 'width',
  270. progress + '%'
  271. );
  272. quCoItemUlLi.find('.progressAfter').remove();
  273. quCoItemUlLi.find('.progress').after("<div class='progressAfter' style='font-size: 14px;color: dodgerblue;margin-top: 10px;'>上传进度:"+progress+"%</div>");
  274. }
  275. }).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
  276. }
  277. function showUpFileMsg(thObj,upMessage) {
  278. var quCoItemUlLi = $(thObj).parents(".quCoItemUlLi");
  279. var progress = quCoItemUlLi.find('.progress');
  280. if(progress[0]){
  281. quCoItemUlLi.find('.progressAfter').remove();
  282. progress.show();
  283. progress.after("<div class='progressAfter' style='font-size: 14px;color: dodgerblue;margin-top: 10px;'>"+upMessage+"</div>");
  284. }
  285. }
  286. function bindUpEvent(){
  287. $(".removeUpFile").unbind();
  288. $(".removeUpFile").click(function(){
  289. var surveyQuItemBody = $(this).parents(".li_surveyQuItemBody");
  290. $(this).parents(".upAppend").remove();
  291. runlogic(surveyQuItemBody,null);
  292. validateCheck(surveyQuItemBody,false);
  293. answerProgressbar(surveyQuItemBody);
  294. var quId = surveyQuItemBody.find(".quId").val();
  295. // removeLocalStorage("qu_UPLOADFILE_"+quId);
  296. localStorageQu(surveyQuItemBody);
  297. return false;
  298. });
  299. }