exchangeContractUpload.jsp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <script type="text/javascript">
  3. var upload_load =function(id){
  4. $.ajax({
  5. type: "post",//使用get方法访问后台
  6. dataType: "json",//返回json格式的数据
  7. url: "exchangeHouseAction_findById",//要访问的后台地址
  8. data: "exchangeHouse.id="+id,//要发送的数据
  9. success: function(msg){
  10. for(var i=0;i< msg.obj.agreementFile.length;i++){
  11. var $image = $("<div style='width: 120px;height: 80px;float:left;'><a target='_blank' href='" + msg.obj.agreementFile[i].filePath + "'><img src='" + msg.obj.agreementFile[i].filePath + "' width='120' height='80'/></a><img src='images/de.png' id='img" + msg.obj.agreementFile[i].id + "' onclick='removeImg(" + msg.obj.agreementFile[i].id + ")' width='15' height='15' style='float: right;position: relative;top: -77px;right: 2px; cursor:pointer;'></div>");
  12. $("#agreementFile_upload_file").append ($image);
  13. }
  14. }
  15. })
  16. $("#id_pickUp").val(id);
  17. $("#agreementFile_upload").change(function(){
  18. var obj = document.getElementById('agreementFile_upload');
  19. if(imageFormat(obj)){
  20. $("#exchangeHouseFileForm").form('submit',{
  21. url :whzl.basePath+'/exchangeHouseAction_addUploadFile',
  22. success : function(result){
  23. $("#agreementFile_upload").attr("value","");
  24. $.ajax({
  25. type: "post",//使用get方法访问后台
  26. dataType: "json",//返回json格式的数据
  27. url: "exchangeHouseAction_findById",//要访问的后台地址
  28. data: "exchangeHouse.id="+id,//要发送的数据
  29. complete :function(){$("#load").hide();},//AJAX请求完成时隐藏loading提示
  30. success: function(msg){
  31. $("#agreementFile_upload_file").children('div').remove();
  32. for(var i=0;i< msg.obj.agreementFile.length;i++){
  33. var $image = $("<div style='width: 120px;height: 80px;float:left;'><a target='_blank' href='" + msg.obj.agreementFile[i].filePath + "'><img src='" + msg.obj.agreementFile[i].filePath + "' width='120' height='80'/></a><img src='images/de.png' id='img" + msg.obj.agreementFile[i].id + "' onclick='removeImg(" + msg.obj.agreementFile[i].id + ")' width='15' height='15' style='float: right;position: relative;top: -77px;right: 2px; cursor:pointer;'></div>");
  34. $("#agreementFile_upload_file").append ($image);
  35. }
  36. }
  37. });
  38. }
  39. });
  40. }
  41. });
  42. }
  43. function imageFormat(obj){
  44. var files = obj.files;
  45. for(var i=0;i<files.length;i++){
  46. /**判断图片格式*/
  47. if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(files[i].name)){
  48. $.messager.alert('提示','图片类型必须是.gif,jpeg,jpg,png中的一种');
  49. return false;
  50. }
  51. /**判断图片大小*/
  52. if(files[i].size>3000*1024){
  53. $.messager.alert('提示','单张图片不得大于3M。');
  54. return false;
  55. }
  56. }
  57. return true;
  58. }
  59. //删除图片
  60. var removeImg = function(id){
  61. $.messager.confirm('提示', '确定删除么?删除后将无法恢复', function(r){
  62. if (r){
  63. $("#img" + id).parent().remove();
  64. $.ajax({
  65. type: "post",//使用post方法访问后台
  66. dataType: "json",//返回json格式的数据
  67. url:whzl.basePath + "/uploadFileAction_deleteUploadFile",
  68. data:{
  69. "uploadFile.id":id
  70. },
  71. error: function(msg){//msg为返回的数据,在这里做数据绑定
  72. $.messager.alert("提示","删除失败!");
  73. }
  74. });
  75. }
  76. });
  77. }
  78. </script>
  79. <div class="easyui-tabs" id="tabs_upload">
  80. <div title="合同文件上传" id="fyxx_upload">
  81. <form id="exchangeHouseFileForm" method="post" enctype="multipart/form-data">
  82. <table class="mytable" style="width: 100%;" id="department_table">
  83. <tr id="agreementFile_tr">
  84. <th width = "20%">协议书上传<input id="id_pickUp" name="exchangeHouse.id" type="hidden"/></th>
  85. <td width = "80%">
  86. <div>
  87. <input type="button" value="上传" onclick="agreementFile_upload.click()">
  88. <input type="file" accept="image/gif, image/jpeg" name="agreementFile" id="agreementFile_upload" style="float:left; width:0px;display: none" >
  89. </div>
  90. </td>
  91. </tr>
  92. <tr>
  93. <td id="agreementFile_upload_file" colspan="2" height=110></td>
  94. </tr>
  95. </table>
  96. </form>
  97. </div>
  98. </div>