Nessuna descrizione

transfer.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. var proimglist = []; //保存项目图纸的数组
  2. var uploader; //上传实例
  3. $(document).ready(function() {
  4. getlevel();
  5. getarea();
  6. uploaderImages();
  7. //判断角色
  8. var $storages = window.localStorage;
  9. if($storages.getItem('roleName') == "班组") {
  10. $('#bz').show()
  11. } else if($storages.getItem('roleName') == "科室") {
  12. $('#ks').show()
  13. } else if($storages.getItem('roleName') == "部门") {
  14. $('#bm').show()
  15. } else if($storages.getItem('roleName') == "院级") {
  16. $('#otherRole').hide()
  17. $('#ks').hide()
  18. $('#bm').hide()
  19. $('#bm').hide()
  20. } else {
  21. $('#otherRole').show()
  22. }
  23. // 判断增加还是编辑
  24. var ajaxUrl;
  25. var ids = helper.request.queryString("edit_id");
  26. if(ids) {
  27. ajaxUrl = "testusertypeapi/api/TestUserType/upYhpctabs";
  28. getValue(ids);
  29. } else {
  30. ajaxUrl = "testusertypeapi/api/TestUserType/AddYhpctabs";
  31. }
  32. //保存
  33. $("#HY_save").click(function() {
  34. addValue(ajaxUrl, ids);
  35. })
  36. })
  37. function getlevel() {
  38. $("#Fxdjid").html('');
  39. equipmentdata = []
  40. $("#Fxdjid").append('<option value="">请选择风险等级</option>');
  41. $.ajax({
  42. type: "get",
  43. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/GetFxdjtabs",
  44. async: true,
  45. dataType: 'json',
  46. data: {
  47. pageindex: 1,
  48. pagesize: 1000,
  49. },
  50. success: function(data) {
  51. var leveldata = []
  52. if(data.state.toLowerCase() == 'success') {
  53. leveldata = data.data.rows
  54. $(leveldata).each(function(q, p) {
  55. $("<option value='" + p.id + "'>" + p.Fxdjname + "</option>").appendTo("#Fxdjid");
  56. $("#Fxdjid").selectpicker('refresh');
  57. });
  58. } else {
  59. $("#Fxdjid").empty();
  60. $("#Fxdjid").selectpicker('refresh');
  61. }
  62. }
  63. });
  64. }
  65. function getarea() {
  66. $("#Fxqyid").html('');
  67. equipmentdata = []
  68. $("#Fxqyid").append('<option value="">请选择风险区域</option>');
  69. $.ajax({
  70. type: "get",
  71. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/GetFxqytabs",
  72. async: true,
  73. dataType: 'json',
  74. data: {
  75. pageindex: 1,
  76. pagesize: 1000,
  77. },
  78. success: function(data) {
  79. var arealdata = []
  80. if(data.state.toLowerCase() == 'success') {
  81. arealdata = data.data.rows
  82. $(arealdata).each(function(q, p) {
  83. console.log(p)
  84. $("<option value='" + p.id + "'>" + p.Fxqyname + "</option>").appendTo("#Fxqyid");
  85. $("#Fxqyid").selectpicker('refresh');
  86. });
  87. } else {
  88. $("#Fxqyid").empty();
  89. $("#Fxqyid").selectpicker('refresh');
  90. }
  91. }
  92. });
  93. }
  94. //添加
  95. function addValue(ajaxUrl, ids) {
  96. if(!$("#title").val()) {
  97. layer.confirm('请输入标题!', {
  98. icon: 2,
  99. btn: ['确定'] //按钮
  100. });
  101. return;
  102. }
  103. if(!$("#Fxdjid").val()) {
  104. layer.confirm('请选择风险等级!', {
  105. icon: 2,
  106. btn: ['确定'] //按钮
  107. });
  108. return;
  109. }
  110. if(!$("#Fxqyid").val()) {
  111. layer.confirm('请选择风险区域!', {
  112. icon: 2,
  113. btn: ['确定'] //按钮
  114. });
  115. return;
  116. }
  117. if(!$("#Yhpcincont").val()) {
  118. layer.confirm('请输入风险详细信息!', {
  119. icon: 2,
  120. btn: ['确定'] //按钮
  121. });
  122. return;
  123. }
  124. $.ajax({
  125. type: "post",
  126. url: huayi.config.callcenter_url + ajaxUrl,
  127. async: true,
  128. dataType: 'json',
  129. data: {
  130. id: ids,
  131. Yhpctitle: $('#title').val(), // 标题
  132. Fxdjid: $("#Fxdjid option:selected").val(), //风险等级编号
  133. Fxqyid: $("#Fxqyid option:selected").val(), //风险区域编号
  134. Yhpcincont: $('#Yhpcincont').val(), // 详细信息
  135. faultpic: proimglist, // 图片
  136. Pcbz: $("#Pcbz option:selected").val(), //排查班组
  137. Pcks: $("#Pcks option:selected").val(), //排查科室
  138. Pcbm: $("#Pcbm option:selected").val(), //排查部门
  139. Pcyj: $("#Pcyj option:selected").val(), //排查院级
  140. },
  141. success: function(data) {
  142. if(data.state.toLowerCase() == 'success') {
  143. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  144. parent.layer.close(index); //再执行关闭
  145. layer.msg(data.message);
  146. parent.$('#table_all').bootstrapTable('refresh');
  147. }
  148. }
  149. });
  150. }
  151. //获取详情
  152. function getValue(ids) {
  153. $.ajax({
  154. type: "get",
  155. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/GetYhpctabsbyid",
  156. async: true,
  157. dataType: 'json',
  158. data: {
  159. id: ids
  160. },
  161. success: function(data) {
  162. if(data.state.toLowerCase() == 'success') {
  163. $('#title').val(data.data[0].Yhpctitle); //标题
  164. $('#Fxdjid').val(data.data[0].Fxdjid); //风险等级
  165. $('#Fxdjid').selectpicker('refresh');
  166. $('#Fxdjid').selectpicker('render');
  167. $('#Fxqyid').val(data.data[0].Fxqyid); //风险等级
  168. $('#Fxqyid').selectpicker('refresh');
  169. $('#Fxqyid').selectpicker('render');
  170. $('#Yhpcincont').val(data.data[0].Yhpcincont); //风险详细信息
  171. $("#Pcbz").val(data.data[0].Pcbz); //排查班组
  172. $('#Pcbz').selectpicker('refresh');
  173. $('#Pcbz').selectpicker('render');
  174. $("#Pcks").val(data.data[0].Pcks); //排查科室
  175. $('#Pcks').selectpicker('refresh');
  176. $('#Pcks').selectpicker('render');
  177. $("#Pcbm").val(data.data[0].Pcbm); //排查部门
  178. $('#Pcbm').selectpicker('refresh');
  179. $('#Pcbm').selectpicker('render');
  180. $("#Pcyj").val(data.data[0].Pcyj); //排查院级
  181. $('#Pcyj').selectpicker('refresh');
  182. $('#Pcyj').selectpicker('render');
  183. proimglist = data.data[0].faultpic;
  184. proimglist = proimglist == null ? [] : proimglist;
  185. // limitNum -= proimglist.length;
  186. uploaderImages(); //附件上传
  187. if(proimglist.length > 0) {
  188. // $('#fileNum').text(proimglist.length);
  189. var $list = $("#fileList");
  190. $.each(proimglist, function(i, v) {
  191. if(v.filesmallurl) {
  192. //原来的图片
  193. var $li = $(
  194. '<li><span class="img_mask"><i class="img_del"></i></span>' +
  195. '<img src="' + v.filesmallurl + '" title="原来的图片"/>' +
  196. '<span class="file_name">' + v.filename + '</span>' +
  197. '</li>'
  198. );
  199. $list.append($li);
  200. } else {
  201. var $liFile = $(
  202. '<li><span class="img_mask"><i class="img_del"></i></span>' +
  203. '<div class="noThumb" title="原来的文件"><i class="glyphicon glyphicon-paperclip"></i><p>无法预览</p></div>' +
  204. '<span class="file_name">' + v.filename + '</span>' +
  205. '</li>'
  206. );
  207. $list.append($liFile);
  208. }
  209. });
  210. $list.find('li').off('click');
  211. $list.find('li').on('click', '.img_del', function() {
  212. $(this).parent().parent().remove();
  213. var itemFileName = $(this).parent().parent().find('.file_name').text();
  214. $.each(proimglist, function(i, v) {
  215. if(v && v.filename == itemFileName) {
  216. proimglist.splice(i, 1);
  217. }
  218. });
  219. // $('#fileNum').text(proimglist.length);
  220. // limitNum = 6 - proimglist.length;
  221. uploaderImages();
  222. });
  223. }
  224. }
  225. }
  226. });
  227. }
  228. //上传附件
  229. function uploaderImages() {
  230. if(uploader) {
  231. uploader.destroy();
  232. }
  233. uploader = WebUploader.create({
  234. auto: true, // 选完文件后,是否自动上传
  235. swf: '../plugins/webuploader/Uploader.swf', // swf文件路径
  236. server: huayi.config.callcenter_url + "fileserverapi/Api/Upload", // 文件接收服务端
  237. pick: '#imgPicker', // 选择文件的按钮。可选
  238. formData: {
  239. uploadtype: 'studyMaterialFile'
  240. },
  241. // 只允许选择图片文件。
  242. accept: {
  243. // title: 'Images',
  244. // extensions: 'gif,jpg,jpeg,bmp,png',
  245. // mimeTypes: 'image/*'
  246. },
  247. compress: false, //webuploader默认压缩图片,设置compress:false,可以按照原始比例上传图片
  248. //fileVal: "upFile",//设置文件上传域的name。
  249. // threads: limitNum, //上传并发数。允许同时最大上传进程数,为了保证文件上传顺序
  250. // fileNumLimit: limitNum,
  251. fileSizeLimit: 50 * 1024 * 1024, // 50 M
  252. fileSingleSizeLimit: 20 * 1024 * 1024 // 20 M
  253. });
  254. uploader.on('fileQueued', function(file) {
  255. var $list = $("#fileList"),
  256. $li = $(
  257. '<li id="' + file.id + '"><span class="img_mask"><i class="img_del"></i></span>' +
  258. '<img/>' +
  259. '<span class="img_state"><i></i></span>' +
  260. '<span class="file_name">' + file.name + '</span>' +
  261. '</li>'
  262. ),
  263. $img = $li.find('img');
  264. // $list为容器jQuery实例
  265. $list.append($li);
  266. // 创建缩略图
  267. uploader.makeThumb(file, function(error, src) {
  268. if(error) {
  269. $img.replaceWith('<div class="noThumb"><i class="glyphicon glyphicon-paperclip"></i><p>无法预览</p></div>');
  270. return;
  271. }
  272. $img.attr('src', src);
  273. }, 109, 109); //109*109为缩略图尺寸
  274. //绑定删除
  275. $('#' + file.id).on('click', '.img_del', function() {
  276. uploader.removeFile(file);
  277. var $fileLi = $('#' + file.id);
  278. $fileLi.off().find('.img_del').off().end().remove();
  279. var itemFileName = $(this).parent().parent().find('.file_name').text();
  280. $.each(proimglist, function(i, v) {
  281. if(v && v.filename == itemFileName) {
  282. proimglist.splice(i, 1);
  283. helper.methods.delImgs(v.filesmallurl, v.fileurl);
  284. }
  285. });
  286. // $('#fileNum').text(proimglist.length);
  287. });
  288. });
  289. // 文件上传过程中创建进度条实时显示。
  290. uploader.on('uploadProgress', function(file, percentage) {
  291. var $li = $('#' + file.id),
  292. $percent = $li.find('.progress span');
  293. // 避免重复创建
  294. if(!$percent.length) {
  295. $percent = $('<div class="progress" style="">' +
  296. '<span class="text">0%</span>' +
  297. '<span class="percentage"></span>' +
  298. '</div>')
  299. .appendTo($li)
  300. .find('span');
  301. }
  302. $percent.eq(0).text(Math.round(percentage * 100) + '%');
  303. $percent.eq(1).css('width', Math.round(percentage * 100) + '%');
  304. });
  305. // 文件上传成功,给item添加成功class, 用样式标记上传成功。
  306. uploader.on('uploadSuccess', function(file, res) {
  307. proimglist.push(res.data[0]);
  308. // $('#fileNum').text(proimglist.length);
  309. $('#' + file.id).addClass('upload-state-done');
  310. });
  311. // 文件上传失败,显示上传出错。
  312. uploader.on('uploadError', function(file) {
  313. var $li = $('#' + file.id),
  314. $error = $li.find('div.error');
  315. // 避免重复创建
  316. if(!$error.length) {
  317. $error = $('<div class="error"></div>').appendTo($li);
  318. }
  319. $error.text('上传失败');
  320. });
  321. // 完成上传完了,成功或者失败,先删除进度条。
  322. uploader.on('uploadComplete', function(file) {
  323. $('#' + file.id).find('.progress').remove();
  324. });
  325. uploader.onError = function(code) {
  326. //console.log('Error:' + code);
  327. switch(code) {
  328. // case "Q_EXCEED_NUM_LIMIT":
  329. // layer.msg('只能上传六个文件。');
  330. // break;
  331. case "Q_TYPE_DENIED":
  332. layer.msg('文件类型不正确。');
  333. break;
  334. case "F_DUPLICATE":
  335. layer.msg('该文件已上传,请选择其它文件。');
  336. break;
  337. case "F_EXCEED_SIZE":
  338. layer.msg('单文件大小不能超过20M。');
  339. break;
  340. case "Q_EXCEED_SIZE_LIMIT":
  341. layer.msg('总文件大小不能超过50M。');
  342. break;
  343. default:
  344. break;
  345. }
  346. };
  347. }