Keine Beschreibung

dealRunOrder.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /**
  2. * 处理设备巡检工单
  3. * */
  4. var maintainpiclist = []; //保存附件的数组
  5. var limitNum = 6; //限制数量
  6. var uploader; //上传实例
  7. $(function() {
  8. autosize($('textarea'));
  9. var edit_id = helper.request.queryString("edit_id") && helper.request.queryString("edit_id").split(',')[0];
  10. // var pro_id = helper.request.queryString("edit_id") && helper.request.queryString("edit_id").split(',')[1];
  11. if(edit_id) {
  12. // if(pro_id) {
  13. // helper.getDropList.getProUser(pro_id, $('#checkby')); //获取巡检人下拉
  14. // }
  15. //获取自定义字段
  16. getDetail(edit_id);
  17. uploaderImages(); //附件上传
  18. //本次设备巡检时间
  19. // laydate.render({
  20. // elem: '#inspectionTime',
  21. // type: 'datetime',
  22. // value: helper.DateFormat.getNowDateTime(),
  23. // theme: '#249fea',
  24. // });
  25. $('#pro_save').on('click', saveProject);
  26. }
  27. $('#quipmenttype').find('input[type="radio"]').on('change', function() {
  28. if($(this).val() === '0') {
  29. $('#checkcontents').show();
  30. } else {
  31. $('#checkcontents').hide();
  32. }
  33. });
  34. });
  35. //获取详情
  36. function getDetail(ids) {
  37. $.getJSON(huayi.config.callcenter_url + "equipmentapi/api/WoEquipmentRunning/getdetails", {
  38. id: ids,
  39. }, function(data) {
  40. if(data.state.toLowerCase() === 'success') {
  41. var res = data.data;
  42. //设备状态
  43. $('#quipmenttype').find('input[name="inlineRadioOptions"][value="' + res.quipmenttype + '"]').prop('checked', true).trigger('change');
  44. if(res.quipmenttype === 0) {
  45. $('#checkcontent').val(helper.filter.content(res.checkcontent));
  46. }
  47. //自定义字段
  48. if(res.extensionlist && res.extensionlist.length > 0) {
  49. $('#customLists').show();
  50. var shtml = '';
  51. for(var i = 0, len = res.extensionlist.length; i < len; i++) {
  52. if(res.systemid && res.systemid === '5ab3773e157ac914fb139fbb'){//日常类
  53. shtml = '<li class="form-group custom_item_radio">'+
  54. '<label for="fieldOptionValue_' + i + '" class="col-md-8 text-left"><b class="text_require">*</b><span id="fieldname_'+ i +'">' + res.extensionlist[i].name + '</span></label>'+
  55. '<div class="col-md-4" id="fieldOptionValue_' + i + '">'+
  56. '<label class="radio-inline">'+
  57. '<input type="radio" name="fieldvalueOptions_'+ i +'" value="正常" checked="checked"> 正常'+
  58. '</label>'+
  59. '<label class="radio-inline">'+
  60. '<input type="radio" name="fieldvalueOptions_'+ i +'" value="异常"> 异常'+
  61. '</label>'+
  62. '</div>'+
  63. '</li>';
  64. }else{
  65. // shtml = '<li class="form-group custom_item_input">'+
  66. // '<label for="fieldvalue_' + i + '" class="col-md-12 deal_label"><span id="fieldname_'+ i +'">' + res.extensionlist[i].name + '</span></label>'+
  67. // '<div class="col-md-12">'+
  68. // '<input value="'+ (res.extensionlist[i].value === null ? '' : res.extensionlist[i].value) +'" id="fieldvalue_' + i + '" class="form-control" type="text" placeholder="请输入' + res.extensionlist[i].name + '的值" />'+
  69. // '</div>'+
  70. // '</li>';
  71. shtml = '<li class="form-group custom_item_radio col-md-6">'+
  72. '<label for="fieldOptionValue_' + i + '" class="col-md-6 text-right deal_label"><span id="fieldname_'+ i +'">' + res.extensionlist[i].name + '</span></label>'+
  73. '<div class="col-md-6" id="fieldOptionValue_' + i + '">'+
  74. '<label class="radio-inline">'+
  75. '<input type="radio" name="fieldvalueOptions_'+ i +'" value="正常" checked="checked"> 正常'+
  76. '</label>'+
  77. '<label class="radio-inline">'+
  78. '<input type="radio" name="fieldvalueOptions_'+ i +'" value="异常"> 异常'+
  79. '</label>'+
  80. '</div>'+
  81. '</li>';
  82. }
  83. $('#customLists').append(shtml);
  84. }
  85. }
  86. //工单状态
  87. // $('#wostate').find('input[name="inlineRadioOptions1"][value="' + res.wostate + '"]').prop('checked', true);
  88. //附件
  89. maintainpiclist = res.checkpic;
  90. maintainpiclist = maintainpiclist == null ? [] : maintainpiclist;
  91. limitNum -= maintainpiclist.length;
  92. uploaderImages(); //附件上传
  93. if(maintainpiclist.length > 0) {
  94. $('#fileNum').text(maintainpiclist.length);
  95. var $list = $("#fileList");
  96. $.each(maintainpiclist, function(i, v) {
  97. if(v.filesmallurl) {
  98. //原来的图片
  99. var $li = $(
  100. '<li><span class="img_mask"><i class="img_del"></i></span>' +
  101. '<img src="' + v.filesmallurl + '" title="原来的图片"/>' +
  102. '<span class="file_name">' + v.filename + '</span>' +
  103. '</li>'
  104. );
  105. $list.append($li);
  106. } else {
  107. var $liFile = $(
  108. '<li><span class="img_mask"><i class="img_del"></i></span>' +
  109. '<div class="noThumb" title="原来的文件"><i class="glyphicon glyphicon-paperclip"></i><p>无法预览</p></div>' +
  110. '<span class="file_name">' + v.filename + '</span>' +
  111. '</li>'
  112. );
  113. $list.append($liFile);
  114. }
  115. });
  116. $list.find('li').off('click');
  117. $list.find('li').on('click', '.img_del', function() {
  118. $(this).parent().parent().remove();
  119. var itemFileName = $(this).parent().parent().find('.file_name').text();
  120. $.each(maintainpiclist, function(i, v) {
  121. if(v && v.filename == itemFileName) {
  122. maintainpiclist.splice(i, 1);
  123. }
  124. });
  125. $('#fileNum').text(maintainpiclist.length);
  126. limitNum = 6 - maintainpiclist.length;
  127. uploaderImages(); //附件上传
  128. });
  129. }
  130. }
  131. });
  132. }
  133. //保存
  134. function saveProject() {
  135. var edit_id = helper.request.queryString("edit_id") && helper.request.queryString("edit_id").split(',')[0];
  136. // if(!regexs.proTitle.test($.trim($('#maintaintime').val()))) {
  137. // if(!$.trim($('#inspectionTime').val())) {
  138. // layer.confirm('本次巡检时间不能为空!', {
  139. // icon: 2,
  140. // btn: ['确定'] //按钮
  141. // });
  142. // return;
  143. // }
  144. //
  145. // if(!$.trim($('#checkby').val())) {
  146. // layer.confirm('巡检人不能为空!', {
  147. // icon: 2,
  148. // btn: ['确定'] //按钮
  149. // });
  150. // return;
  151. // }
  152. if($('#quipmenttype').find('input[type="radio"]:checked').val() === '0') {
  153. if(!$.trim($('#checkcontent').val())) {
  154. layer.confirm('异常内容不能为空!', {
  155. icon: 2,
  156. btn: ['确定'] //按钮
  157. });
  158. return;
  159. }
  160. } else {
  161. $('#checkcontent').val('');
  162. }
  163. if(maintainpiclist.length <= 0) {
  164. layer.confirm('巡检图片不能为空!', {
  165. icon: 2,
  166. btn: ['确定'] //按钮
  167. });
  168. return;
  169. }
  170. $.post(huayi.config.callcenter_url + "equipmentapi/api/WoEquipmentRunning/deal", {
  171. id: edit_id, // 是 string id标识
  172. // thischeckime: $('#inspectionTime').val(), //是 本次巡检时间
  173. // checkby: $('#checkby').val(), //是 string 巡检人
  174. quipmenttype: $('#quipmenttype').find('input[type="radio"]:checked').val(), //是 string 设备状态 1正常,0异常
  175. checkcontent: $('#checkcontent').val(), //是 string 异常内容
  176. checkpic: maintainpiclist, //是 List<FileBaseModel> 巡检图片
  177. // wostate: $('#wostate').find('input[type="radio"]:checked').val(), //是 int 任务状态:3已处理,6挂起
  178. wostate: 3, //是 int 任务状态:3已处理,6挂起
  179. extensionlist: getFields(), //自定义字段的数组[{“name”:”字段名”,”value”:”字段值”}]
  180. }, function(data) {
  181. data = JSON.parse(data);
  182. if(data.state == "success") {
  183. var index = parent.layer.getFrameIndex(window.name);
  184. parent.layer.close(index);
  185. parent.$('#table_all').bootstrapTable('refresh');
  186. parent.layer.msg("保存成功");
  187. }
  188. });
  189. }
  190. //上传图片
  191. function uploaderImages() {
  192. if(uploader) {
  193. uploader.destroy();
  194. }
  195. uploader = WebUploader.create({
  196. auto: true, // 选完文件后,是否自动上传
  197. swf: '../plugins/webuploader/Uploader.swf', // swf文件路径
  198. server: huayi.config.callcenter_url + "fileserverapi/Api/Upload", // 文件接收服务端
  199. pick: '#imgPicker', // 选择文件的按钮。可选
  200. formData: {
  201. uploadtype: 'dealRunOrder'
  202. },
  203. // 只允许选择图片文件。
  204. accept: {
  205. title: 'Images',
  206. extensions: 'gif,jpg,jpeg,bmp,png',
  207. mimeTypes: 'image/*'
  208. },
  209. compress: false, //webuploader默认压缩图片,设置compress:false,可以按照原始比例上传图片
  210. //fileVal: "upFile",//设置文件上传域的name。
  211. threads: limitNum, //上传并发数。允许同时最大上传进程数,为了保证文件上传顺序
  212. fileNumLimit: limitNum,
  213. fileSizeLimit: 30 * 1024 * 1024, // 30 M
  214. fileSingleSizeLimit: 5 * 1024 * 1024 // 5 M
  215. });
  216. uploader.on('fileQueued', function(file) {
  217. var $list = $("#fileList"),
  218. $li = $(
  219. '<li id="' + file.id + '"><span class="img_mask"><i class="img_del"></i></span>' +
  220. '<img/>' +
  221. '<span class="img_state"><i></i></span>' +
  222. '<span class="file_name">' + file.name + '</span>' +
  223. '</li>'
  224. ),
  225. $img = $li.find('img');
  226. // $list为容器jQuery实例
  227. $list.append($li);
  228. // 创建缩略图
  229. uploader.makeThumb(file, function(error, src) {
  230. if(error) {
  231. $img.replaceWith('<div class="noThumb"><i class="glyphicon glyphicon-paperclip"></i><p>无法预览</p></div>');
  232. return;
  233. }
  234. $img.attr('src', src);
  235. }, 109, 109); //109*109为缩略图尺寸
  236. //绑定删除
  237. $('#' + file.id).on('click', '.img_del', function() {
  238. uploader.removeFile(file);
  239. var $fileLi = $('#' + file.id);
  240. $fileLi.off().find('.img_del').off().end().remove();
  241. var itemFileName = $(this).parent().parent().find('.file_name').text();
  242. $.each(maintainpiclist, function(i, v) {
  243. if(v && v.filename == itemFileName) {
  244. maintainpiclist.splice(i, 1);
  245. }
  246. });
  247. $('#fileNum').text(maintainpiclist.length);
  248. });
  249. });
  250. // 文件上传过程中创建进度条实时显示。
  251. uploader.on('uploadProgress', function(file, percentage) {
  252. var $li = $('#' + file.id),
  253. $percent = $li.find('.progress span');
  254. // 避免重复创建
  255. if(!$percent.length) {
  256. $percent = $('<div class="progress" style="">' +
  257. '<span class="text">0%</span>' +
  258. '<span class="percentage"></span>' +
  259. '</div>')
  260. .appendTo($li)
  261. .find('span');
  262. }
  263. $percent.eq(0).text(Math.round(percentage * 100) + '%');
  264. $percent.eq(1).css('width', Math.round(percentage * 100) + '%');
  265. });
  266. // 文件上传成功,给item添加成功class, 用样式标记上传成功。
  267. uploader.on('uploadSuccess', function(file, res) {
  268. maintainpiclist.push(res.data[0]);
  269. $('#fileNum').text(maintainpiclist.length);
  270. $('#' + file.id).addClass('upload-state-done');
  271. });
  272. // 文件上传失败,显示上传出错。
  273. uploader.on('uploadError', function(file) {
  274. var $li = $('#' + file.id),
  275. $error = $li.find('div.error');
  276. // 避免重复创建
  277. if(!$error.length) {
  278. $error = $('<div class="error"></div>').appendTo($li);
  279. }
  280. $error.text('上传失败');
  281. });
  282. // 完成上传完了,成功或者失败,先删除进度条。
  283. uploader.on('uploadComplete', function(file) {
  284. $('#' + file.id).find('.progress').remove();
  285. });
  286. uploader.onError = function(code) {
  287. //console.log('Error:' + code);
  288. switch(code) {
  289. case "Q_EXCEED_NUM_LIMIT":
  290. layer.msg('只能上传六张图片。');
  291. break;
  292. case "Q_TYPE_DENIED":
  293. layer.msg('图片类型不正确。');
  294. break;
  295. case "F_DUPLICATE":
  296. layer.msg('该文件已上传,请选择其它文件。');
  297. break;
  298. default:
  299. break;
  300. }
  301. };
  302. }
  303. //获取自定义字段的值
  304. function getFields() {
  305. var extensionlist = []; //自定义字段的数组[{“name”:”字段名”,”value”:”字段值”}]
  306. var custom_items_input = $('#customLists').find('.custom_item_input');
  307. var custom_items_radio = $('#customLists').find('.custom_item_radio');
  308. if(custom_items_input.length > 0){
  309. $.each(custom_items_input, function(i, v) {
  310. var inObj = {};
  311. var fieldname = $(v).find('span[id*="fieldname_"]').text();
  312. var fieldvalue = $(v).find('input[id*="fieldvalue_"]').val();
  313. inObj.name = fieldname;
  314. inObj.value = fieldvalue;
  315. extensionlist.push(inObj);
  316. });
  317. }
  318. if(custom_items_radio.length > 0){
  319. $.each(custom_items_radio, function(i, v) {
  320. extensionlist.push({
  321. "name": $(v).find('span[id*="fieldname_"]').text(),
  322. "value": $(v).find('div[id*="fieldOptionValue_"]').find('input[type=radio]:checked').val()
  323. });
  324. });
  325. }
  326. return extensionlist;
  327. }