edit.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. {extend name="common/base"/}
  2. {block name="style"}
  3. <style>
  4. .layui-layer-content{color: #2d2d2d;}
  5. </style>
  6. {/block}
  7. {block name="body"}
  8. <form class="layui-form p-4">
  9. <h3 class="pb-3">编辑联系函</h3>
  10. <table class="layui-table layui-table-form">
  11. <tr>
  12. <td class="layui-td-gray">联系函名称<font>*</font></td>
  13. <td>
  14. <input type="text" name="title" lay-verify="required" lay-reqText="请输入文档名称" placeholder="请输入文档名称" class="layui-input" value="{$detail.title}">
  15. </td>
  16. </tr>
  17. <tr>
  18. <td class="layui-td-gray" style="vertical-align:top;">联系函内容<font>*</font></td>
  19. <td colspan="5">
  20. <textarea name="content" placeholder="请输入内容" class="layui-textarea" id="container_content" style="border:0;padding:0">{$detail.content}</textarea>
  21. </td>
  22. </tr>
  23. </table>
  24. <div class="pt-3">
  25. <input type="hidden" name="id" value="{$detail.id}" />
  26. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
  27. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  28. </div>
  29. </form>
  30. <div class="layui-card border-y">
  31. <div class="layui-card-header" style="height:45px;">
  32. <div class="layui-row">
  33. <div class="layui-col-md6">
  34. <strong>联系函附件</strong>
  35. </div>
  36. <div class="layui-col-md6" style="text-align:right">
  37. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="uploadBtn">上传附件</button>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="layui-row p-2" id="fileBox">
  42. {:fileCard($file_array)}
  43. {empty name="$file_array" }
  44. <div class="layui-data-none">暂无附件</div>
  45. {/empty}
  46. </div>
  47. </div>
  48. {/block}
  49. <!-- /主体 -->
  50. <!-- 脚本 -->
  51. {block name="script"}
  52. <script>
  53. const moduleInit = ['tool', 'tagpicker', 'tinymce','oaTool'];
  54. function gouguInit() {
  55. var form = layui.form,tool=layui.tool,oaTool = layui.oaTool;
  56. var file_id = '{$detail.file}';
  57. //编辑器初始化
  58. var editor = layui.tinymce;
  59. var edit = editor.render({
  60. selector: "#container_content",
  61. height: 500
  62. });
  63. let a = 1;
  64. //监听提交
  65. form.on('submit(webform)', function (data) {
  66. layer.confirm('<div style="color:red">提交后内容将无法更改,请检查内容是否准确无误!<br>点击”确认“按钮,提交报告</div>', {
  67. icon: 3,
  68. title: '提交确认'
  69. },function () {
  70. data.field.content = tinyMCE.editors['container_content'].getContent();
  71. if (data.field.content == '') {
  72. layer.msg('请先完善文章内容');
  73. return false;
  74. }
  75. if(a){
  76. let callback = function (e) {
  77. parent.layui.contactTable.reload();
  78. layer.msg(e.msg);
  79. if (e.code == 0) {
  80. tool.tabRefresh(71);
  81. tool.sideClose(1000);
  82. a = 1
  83. }
  84. }
  85. data.field.file = file_id;
  86. tool.post("/admin/project.contact/edit_company", data.field, callback);
  87. }
  88. })
  89. a = 0
  90. return false;
  91. });
  92. function fileCard(item){
  93. var host = window.location.host;
  94. var li = '';
  95. if(item.length>0){
  96. for(var a=0;a<item.length;a++){
  97. let image = ['jpg','jpeg','png','gif'];
  98. let doc = ['doc','docx','xls','xlsx','ppt','pptx','txt','pdf','zip','rar','7z'];
  99. // let down = '<a href="'+item[a].filepath+'" target="_blank" class="layui-btn layui-btn-xs layui-btn-normal" download="'+item[a].name+'">下载</a>';
  100. let down ='<a href="' + item[a]['filepath'] + '" target="_blank" class="layui-btn layui-btn-xs layui-btn-normal" download="' + item[a]['name'] + '">预览</a>';
  101. // 判断元素是否在数组中
  102. let path='/static/home/images/icon/file.png';
  103. if (image.includes(item[a].fileext)) {
  104. path=item[a].filepath;
  105. down = '<span data-href="'+item[a].filepath+'" class="layui-btn layui-btn-xs layui-btn-normal file-view-img">预览</span>';
  106. } else if (doc.includes(item[a].fileext)){
  107. path='/static/home/images/icon/'+item[a].fileext+'.png';
  108. }
  109. if(item[a].fileext == 'pdf'){
  110. down = '<span data-href="'+item[a].filepath+'" class="layui-btn layui-btn-xs layui-btn-normal file-view-pdf">预览</span>';
  111. }
  112. 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+
  113. '" style="object-fit: contain;" class="file-item"><p title="'+item[a].name+'">'+item[a].name+
  114. '</p><div class="layui-btn-group">'+ down +
  115. '<span class="layui-btn layui-btn-xs layui-btn-danger file-del">删除</span></div></li>';
  116. }
  117. return li;
  118. }
  119. }
  120. var emptyCard = ' <div class="layui-data-none">暂无附件</div>'
  121. $('#fileBox').on('click','.file-del',function(){
  122. layer.confirm('确定要删除该文件吗?', { icon: 3, title: '提示' }, function (index) {
  123. let callback = function (e) {
  124. layer.closeAll();
  125. file_id = null;
  126. layer.msg(e.msg);
  127. $('#' + file_id).remove();
  128. $("#fileBox").html(emptyCard);
  129. }
  130. tool.delete("/admin/project.contact/delete_file", {id:file_id}, callback);
  131. });
  132. })
  133. oaTool.addFile({
  134. type: 1,
  135. isSave: true,
  136. ajaxDelete: function (file_id) {
  137. let callback = function (e) {
  138. layer.msg(e.msg);
  139. var emptyCard = ' <div class="layui-data-none">暂无附件</div>'
  140. file_id = null;
  141. if (e.code == 0) {
  142. $('#fileItem' + file_id).remove();
  143. $("#fileBox").html(emptyCard);
  144. }
  145. }
  146. tool.delete("/admin/project.contact/delete_file", {id: file_id}, callback);
  147. },
  148. ajaxSave: function (res) {
  149. let callback = function (e) {
  150. layer.msg('上传成功');
  151. $("#fileBox").html(fileCard(e));
  152. file_id = res.data.id
  153. }
  154. tool.post("/admin/project.contact/add_file", {
  155. 'file': res.data.id,
  156. }, callback);
  157. }
  158. });
  159. }
  160. </script>
  161. {/block}