ans-common.js 14 KB

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