add.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. {extend name="common/base"/}
  2. {block name="style"}
  3. <style>
  4. .footer{
  5. display: none;
  6. }
  7. #fileBox li{
  8. display: flex;
  9. flex-wrap: wrap;
  10. flex-direction: column;
  11. }
  12. .layui-table th{
  13. text-align: center !important;
  14. font-weight: 500;
  15. }
  16. .layui-anim dd{
  17. text-align: left;
  18. }
  19. .layui-th-gray{
  20. background-color: rgb(241, 241, 241);
  21. }
  22. .layui-table th{
  23. border-color: #e2e2e2
  24. }
  25. .fujian p{
  26. margin: 3px 0 5px 0;
  27. width: 11vw;
  28. overflow: hidden;
  29. text-overflow: ellipsis;
  30. text-align: center;
  31. }
  32. .fujian{
  33. width: auto;
  34. overflow: auto;
  35. justify-content:flex-start;
  36. align-content: space-between;
  37. flex-direction: column-reverse;
  38. flex-wrap: wrap;
  39. display: flex;
  40. }
  41. .fujian li{
  42. padding: 0.5vw 0.8vw 0.5vw 0.8vw;
  43. white-space: nowrap;
  44. overflow: hidden;
  45. text-overflow: ellipsis;
  46. /*display: inline-block;*/
  47. border-right: 1px solid #e2e2e2;
  48. float: left;
  49. }
  50. .layui-btn-group{
  51. display: flex;
  52. justify-content: center;
  53. }
  54. </style>
  55. {/block}
  56. {block name="body"}
  57. <form class="layui-form p-4">
  58. <h3 class="pb-3">新建联系函</h3>
  59. <table class="layui-table layui-table-form">
  60. <tr>
  61. <th class="layui-th-gray-2" style="background-color: rgb(241, 241, 241);">联系函名称 <font style="color: red !important;">*</font></th>
  62. <th colspan="8">
  63. <input type="text" name="title" lay-verify="required" lay-reqText="请输入联系函名称"
  64. placeholder="请输入联系函名称" class="layui-input" value="">
  65. </th>
  66. </tr>
  67. <tr>
  68. <th class="layui-th-gray" style="vertical-align:top;">联系函内容 <font style="color: red !important;">*</font></th>
  69. <th colspan="8">
  70. <textarea name="content" placeholder="请输入内容" class="layui-textarea" id="container_content"
  71. style="border:0;padding:0"></textarea>
  72. </th>
  73. </tr>
  74. </table>
  75. <div class="pt-3">
  76. <input type="hidden" name="id" value=""/>
  77. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
  78. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  79. </div>
  80. </form>
  81. <div class="layui-card border-y">
  82. <div class="layui-card-header" style="height:45px;border-color: #e2e2e2">
  83. <div class="layui-row">
  84. <div class="layui-col-md6">
  85. <strong>联系函附件</strong>
  86. </div>
  87. <div class="layui-col-md6" style="text-align:right">
  88. <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" id="uploadBtn">上传附件</button>
  89. </div>
  90. </div>
  91. </div>
  92. <div class="layui-row p-2 fujian" id="fileBox">
  93. <div class="layui-data-none">暂无附件</div>
  94. </div>
  95. </div>
  96. {/block}
  97. <!-- /主体 -->
  98. <!-- 脚本 -->
  99. {block name="script"}
  100. <script>
  101. const moduleInit = ['tool', 'tagpicker', 'tinymce', 'oaTool'];
  102. function gouguInit() {
  103. var form = layui.form, tool = layui.tool, oaTool = layui.oaTool;
  104. var file_id = null;
  105. //编辑器初始化
  106. var editor = layui.tinymce;
  107. var edit = editor.render({
  108. selector: "#container_content",
  109. height: 500
  110. });
  111. let a = 1;
  112. //监听提交
  113. form.on('submit(webform)', function (data) {
  114. data.field.content = tinyMCE.editors['container_content'].getContent();
  115. if (data.field.content == '') {
  116. layer.msg('<span style="color: white">请先完善文章内容</span>');
  117. return false;
  118. }
  119. if(a){
  120. let callback = function (e) {
  121. parent.layui.contactTable.reload();
  122. layer.msg(e.msg);
  123. if (e.code == 0) {
  124. tool.tabRefresh(71);
  125. tool.sideClose(1000);
  126. a = 1
  127. }
  128. }
  129. data.field.file = file_id;
  130. data.field.project_id = '{$project_id}';
  131. tool.post("/admin/project.contact/add", data.field, callback);
  132. }
  133. a = 0
  134. return false;
  135. });
  136. function fileCard(item){
  137. var host = window.location.host;
  138. var li = '';
  139. if(item.length>0){
  140. for(var a=0;a<item.length;a++){
  141. let image = ['jpg','jpeg','png','gif'];
  142. let doc = ['doc','docx','xls','xlsx','ppt','pptx','txt','pdf','zip','rar','7z'];
  143. // let down = '<a href="'+item[a].filepath+'" target="_blank" class="layui-btn layui-btn-xs layui-btn-normal" download="'+item[a].name+'">下载</a>';
  144. let down ='<a href="' + item[a]['filepath'] + '" target="_blank" class="layui-btn layui-btn-xs layui-btn-normal" download="' + item[a]['name'] + '">预览</a>';
  145. // 判断元素是否在数组中
  146. let path='/static/home/images/icon/file.png';
  147. if (image.includes(item[a].fileext)) {
  148. path=item[a].filepath;
  149. down = '<span data-href="'+item[a].filepath+'" class="layui-btn layui-btn-xs layui-btn-normal file-view-img">预览</span>';
  150. } else if (doc.includes(item[a].fileext)){
  151. path='/static/home/images/icon/'+item[a].fileext+'.png';
  152. }
  153. if(item[a].fileext == 'pdf'){
  154. down = '<span data-href="'+item[a].filepath+'" class="layui-btn layui-btn-xs layui-btn-normal file-view-pdf">预览</span>';
  155. }
  156. li += '<li id="'+item[a].id+'" data-id="'+item[a].id+'" data-title="'+item[a].name+'" data-ext="'+item[a].fileext+'"><img src="'+path+'" alt="'+item[a].filename+
  157. '" style="object-fit: contain;" class="file-item"><p title="'+item[a].name+'">'+item[a].name+
  158. '</p><div class="layui-btn-group">'+ down +
  159. '<span class="layui-btn layui-btn-xs layui-btn-danger file-del">删除</span></div></li>';
  160. }
  161. return li;
  162. }
  163. }
  164. var emptyCard = ' <div class="layui-data-none">暂无附件</div>'
  165. $('#fileBox').on('click','.file-del',function(){
  166. layer.confirm('确定要删除该文件吗?', { icon: 3, title: '提示' }, function (index) {
  167. layer.closeAll();
  168. $('#' + file_id).remove();
  169. $("#fileBox").html(emptyCard);
  170. file_id = null;
  171. });
  172. })
  173. oaTool.addFile({
  174. type: 1,
  175. isSave: true,
  176. ajaxDelete: function (file_id) {
  177. var emptyCard = ' <div class="layui-data-none">暂无附件</div>'
  178. if (e.code == 0) {
  179. $('#fileItem' + file_id).remove();
  180. $("#fileBox").html(emptyCard);
  181. file_id = null;
  182. }
  183. },
  184. ajaxSave: function (res) {
  185. let callback = function (e) {
  186. layer.msg('上传成功');
  187. $("#fileBox").html(fileCard(e));
  188. file_id = res.data.id
  189. }
  190. tool.post("/admin/project.contact/add_file", {
  191. 'file': res.data.id,
  192. }, callback);
  193. }
  194. });
  195. }
  196. </script>
  197. {/block}