Нет описания

index.html 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <!DOCTYPE html>
  2. <html lang="zh-CN" class="feedback">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <title>工单创建</title>
  10. <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
  11. <link rel="stylesheet" type="text/css" href="../css/app.css" />
  12. <link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
  13. <link rel="stylesheet" type="text/css" href="../css/feedback-page.css" />
  14. <link rel="stylesheet" href="../css/webuploader.css" />
  15. <link rel="stylesheet" type="text/css" href="../css/Common.css" />
  16. </head>
  17. <body>
  18. <div class="mui-card">
  19. <div class="mui-card-header">基本信息</div>
  20. <form class="mui-input-group">
  21. <div class="mui-input-row">
  22. <label for="h_userName">姓名:</label>
  23. <input type="text" class="mui-input-clear" id="h_userName" placeholder="请输入姓名">
  24. </div>
  25. <div class="mui-input-row">
  26. <label for="h_phone">电话:</label>
  27. <input type="text" class="mui-input-clear" id="h_phone" placeholder="请输入电话">
  28. </div>
  29. <div id="showCountyPicker">
  30. <div class="mui-input-row">
  31. <label class="label" for="h_county">乡镇:</label>
  32. <input type="text" id="h_county" class="ui-alert type_con" placeholder="请选择乡镇" data-index="">
  33. <a><span class="type_down mui-icon mui-icon-arrowdown mui-pull-right"></span></a>
  34. </div>
  35. </div>
  36. <div class="mui-input-row">
  37. <label for="h_address">地址:</label>
  38. <input type="text" class="mui-input-clear" id="h_address" placeholder="请输入地址">
  39. </div>
  40. <div class="mui-input-row h_content">
  41. <label for="h_content">反映问题:</label>
  42. <textarea id="h_content" class="mui-input-clear question" placeholder="请详细描述您要反映的问题..."></textarea>
  43. </div>
  44. </form>
  45. </div>
  46. <div class="mui-card">
  47. <div class="mui-card-header">
  48. 附件
  49. <span id="fileNum">0/6</span>
  50. </div>
  51. <div class="row image-list" id="image-list">
  52. <div id="filePicker"></div>
  53. </div>
  54. </div>
  55. <div class="mui-button-row" id="Btns-box">
  56. <button type="button" data-loading-text="提交中" id="submit" class="mui-btn mui-btn-primary" onclick="return false;">提交</button>
  57. </div>
  58. <script src="../js/jquery.min.js"></script>
  59. <script src="../js/zepto.js"></script>
  60. <script src="../js/mui.min.js"></script>
  61. <script src="../js/mui.zoom.js"></script>
  62. <script src="../js/mui.previewimage.js"></script>
  63. <script src="../js/mui.picker.min.js"></script>
  64. <script src="../js/mui.poppicker.js"></script>
  65. <script src="../js/webuploader.min.js"></script>
  66. <script src="../Script/Common/huayi.config.js"></script>
  67. <script src="../Script/Common/huayi.http.js"></script>
  68. <script>
  69. mui.previewImage();
  70. var EnclosureList = []; //保存附件的数组
  71. var uploader; //上传实例
  72. Zepto(function($) {
  73. getCounty(); //获取乡镇地址
  74. uploaderImages();//上传附件
  75. $('#submit').on('tap', submitHandle);
  76. });
  77. //提交
  78. function submitHandle() {
  79. var telreg = /^\d{3,12}$/;
  80. var that = this;
  81. if(!$.trim($("#h_userName").val())) {
  82. mui.toast("请您输入姓名后再提交");
  83. return;
  84. }
  85. if(!$.trim($("#h_phone").val())) {
  86. mui.toast("请您输入手机号码后再提交");
  87. return;
  88. }
  89. if($.trim($("#h_phone").val())) {
  90. if(!telreg.test($.trim($("#h_phone").val()))) {
  91. mui.toast("请您输入正确手机号码");
  92. return;
  93. }
  94. }
  95. if(!$.trim($("#h_content").val())) {
  96. mui.toast("请您输入反映问题后再提交");
  97. return;
  98. }
  99. $.ajax({
  100. type: "post",
  101. url: huayi.config.callcenter_url + 'WxLogin/AddWorkOrder',
  102. async: true,
  103. beforeSend: function() {
  104. mui(that).button('loading');
  105. },
  106. data: {
  107. openid: helper.cookies.get("openid"),//string 是
  108. cusname: $('#h_userName').val(), //string 是 客户姓名
  109. cusphone: $('#h_phone').val(), // string 是 电话
  110. country: $('#h_county').attr('data-index'), //string 否 乡镇
  111. address: $('#h_address').val(), // string 否 住址
  112. content: $('#h_content').val(), // string 是 反映问题
  113. files: EnclosureList && EnclosureList.join(','), // string 否 附件
  114. },
  115. dataType: 'json',
  116. success: function(data) {
  117. mui(that).button('reset');
  118. if(data.state.toLowerCase() == "success") {
  119. mui.alert("提交成功", ' ', function() {
  120. window.location.href = 'WorkList.html';
  121. });
  122. }
  123. },
  124. error: function(textStatus) {
  125. mui(that).button('reset');
  126. mui.toast('网络繁忙,请稍后再试...');
  127. },
  128. complete: function(XMLHttpRequest, textStatus) {
  129. mui(that).button('reset');
  130. if(textStatus == 'timeout') {
  131. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  132. xmlhttp.abort();
  133. mui.toast('网络超时,请稍后再试...');
  134. }
  135. },
  136. });
  137. }
  138. //获取乡镇
  139. function getCounty() {
  140. $.ajax({
  141. type: "get",
  142. url: huayi.config.callcenter_url + "WxLogin/GetAreaList",
  143. dataType: 'json',
  144. async: true,
  145. data: {
  146. openid: helper.cookies.get("openid"),//string 是
  147. },
  148. success: function(data) {
  149. if(data.state.toLowerCase() == "success") {
  150. var res = data.data;
  151. if(res.length > 0) {
  152. //下拉弹出
  153. (function($, doc) {
  154. $.init();
  155. $.ready(function() {
  156. var t_countyDatas = [];
  157. res.forEach(function(item, index) {
  158. t_countyDatas.push({
  159. value: item.F_DictionaryValueId,
  160. text: item.F_Name
  161. });
  162. });
  163. var countyPicker = new $.PopPicker();
  164. countyPicker.setData(t_countyDatas);
  165. var showCountybtn = doc.getElementById('showCountyPicker');
  166. var countyRes = doc.getElementById('h_county');
  167. showCountybtn.addEventListener('tap', function(event) {
  168. countyPicker.show(function(items) {
  169. countyRes.value = items[0].text;
  170. countyRes.setAttribute("data-index", items[0].value);
  171. });
  172. }, false);
  173. });
  174. })(mui, document);
  175. }
  176. }
  177. }
  178. });
  179. }
  180. //上传附件
  181. function uploaderImages() {
  182. var limitNum = 6; //限制数量
  183. // 优化retina, 在retina下这个值是2
  184. var ratio = window.devicePixelRatio || 1;
  185. // 缩略图大小
  186. var thumbnailWidth = 50 * ratio;
  187. var thumbnailHeight = 50 * ratio;
  188. if(uploader) {
  189. uploader.destroy();
  190. }
  191. uploader = WebUploader.create({
  192. auto: true, // 选完文件后,是否自动上传
  193. swf: '../js/Uploader.swf', // swf文件路径
  194. server: huayi.config.callcenter_url + "WxLogin/UpLoadProcess", // 文件接收服务端
  195. pick: '#filePicker', // 选择文件的按钮。可选
  196. formData: {},
  197. // 只允许选择图片文件。
  198. accept: {
  199. // title: 'Images',
  200. // extensions: 'gif,jpg,jpeg,bmp,png',
  201. // mimeTypes: 'image/*'
  202. },
  203. compress: false, //webuploader默认压缩图片,设置compress:false,可以按照原始比例上传图片
  204. //fileVal: "upFile",//设置文件上传域的name。
  205. threads: limitNum, //上传并发数。允许同时最大上传进程数,为了保证文件上传顺序
  206. fileNumLimit: limitNum,
  207. fileSizeLimit: 300 * 1024 * 1024, // 300 M
  208. fileSingleSizeLimit: 50 * 1024 * 1024 // 50 M
  209. });
  210. uploader.on('fileQueued', function(file) {
  211. var $list = $("#image-list"),
  212. $li = $(
  213. '<div id="' + file.id + '" class="file-item thumbnail">' +
  214. '<div class="image-close">X</div>' +
  215. '<img>' +
  216. '<div class="info">' + file.name + '</div>' +
  217. '</div>'
  218. ),
  219. $img = $li.find('img');
  220. $list.prepend($li);
  221. // 创建缩略图
  222. uploader.makeThumb(file, function(error, src) {
  223. if(error) {
  224. $img.replaceWith('<span class="noThumb mui-icon mui-icon-paperclip"></span>');
  225. return;
  226. }
  227. $img.attr('src', src);
  228. $img.attr('data-preview-src', '');
  229. $img.attr('data-preview-group', "1");
  230. }, thumbnailWidth, thumbnailHeight);
  231. //绑定删除
  232. $('#' + file.id).on('tap', '.image-close', function() {
  233. uploader.removeFile(file);
  234. var $fileLi = $('#' + file.id);
  235. $fileLi.off().find('.image-close').off().end().remove();
  236. var itemFileImgId = $fileLi.attr('data-imgid');
  237. EnclosureList.forEach(function(v, i) {
  238. if(v == itemFileImgId) {
  239. EnclosureList.splice(i, 1);
  240. }
  241. });
  242. $('#fileNum').text(EnclosureList.length + '/' + limitNum);
  243. });
  244. });
  245. // 文件上传过程中创建进度条实时显示。
  246. uploader.on('uploadProgress', function(file, percentage) {
  247. var $li = $('#' + file.id),
  248. $percent = $li.find('.progress span');
  249. // 避免重复创建
  250. if(!$percent.length) {
  251. $percent = $('<div class="progress" style="">' +
  252. '<span class="text">0%</span>' +
  253. '<span class="percentage"></span>' +
  254. '</div>')
  255. .appendTo($li)
  256. .find('span');
  257. }
  258. $percent.eq(0).text(Math.round(percentage * 100) + '%');
  259. $percent.eq(1).css('width', Math.round(percentage * 100) + '%');
  260. });
  261. // 文件上传成功,给item添加成功class, 用样式标记上传成功。
  262. uploader.on('uploadSuccess', function(file, res) {
  263. EnclosureList.push(res.data);
  264. $('#' + file.id).attr('data-imgid', res.data);
  265. $('#fileNum').text(EnclosureList.length + '/' + limitNum);
  266. $('#' + file.id).addClass('upload-state-done');
  267. });
  268. // 文件上传失败,显示上传出错。
  269. uploader.on('uploadError', function(file) {
  270. var $li = $('#' + file.id),
  271. $error = $li.find('div.error');
  272. // 避免重复创建
  273. if(!$error.length) {
  274. $error = $('<div class="error"></div>').appendTo($li);
  275. }
  276. $error.text('上传失败');
  277. });
  278. // 完成上传完了,成功或者失败,先删除进度条。
  279. uploader.on('uploadComplete', function(file) {
  280. $('#' + file.id).find('.progress').remove();
  281. });
  282. uploader.onError = function(code) {
  283. //console.log('Error:' + code);
  284. switch(code) {
  285. case "Q_EXCEED_NUM_LIMIT":
  286. mui.toast('只能上传六个文件。');
  287. break;
  288. case "Q_TYPE_DENIED":
  289. mui.toast('图片类型不正确。');
  290. break;
  291. case "F_DUPLICATE":
  292. mui.toast('该文件已上传,请选择其它文件。');
  293. break;
  294. case "F_EXCEED_SIZE":
  295. mui.toast('文件大小不能超过5M。');
  296. break;
  297. default:
  298. break;
  299. }
  300. };
  301. }
  302. </script>
  303. </body>
  304. </html>