source_material.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. {extend name="public/layout" /} {block name="title"}活动素材{/block} {block
  2. name="body"}
  3. <style type="text/css">
  4. body {
  5. width: 100%;
  6. height: 100%;
  7. box-sizing: border-box;
  8. padding: 15px;
  9. }
  10. .headerBack {
  11. width: 100%;
  12. height: 40px;
  13. background-color: #fff;
  14. box-sizing: border-box;
  15. padding: 0px 15px;
  16. border-radius: 4px;
  17. }
  18. .headerBack > div {
  19. height: 100%;
  20. display: flex;
  21. align-items: center;
  22. cursor: pointer;
  23. }
  24. .contentBox {
  25. width: 100%;
  26. height: calc(100vh - 80px);
  27. margin-top: 10px;
  28. background-color: #fff;
  29. border-radius: 4px;
  30. box-sizing: border-box;
  31. padding: 20px 15px;
  32. overflow: auto;
  33. }
  34. .uploadItem {
  35. width: 100px;
  36. height: 35px;
  37. text-align: center;
  38. line-height: 35px;
  39. background-color: #249efb;
  40. color: #fff;
  41. border-radius: 4px;
  42. cursor: pointer;
  43. }
  44. .uploadlist {
  45. width: 100%;
  46. height: auto;
  47. overflow: hidden;
  48. display: flex;
  49. flex-wrap: wrap;
  50. margin-top: 20px;
  51. }
  52. .itemBox {
  53. width: 180px;
  54. height: 210px;
  55. background-color: #fff;
  56. border-radius: 4px;
  57. overflow: hidden;
  58. box-sizing: border-box;
  59. padding: 10px;
  60. border: 1px solid #f2f2f2;
  61. box-shadow: 0px 6px 4px 0px rgba(0, 0, 0, 0.05);
  62. margin-right: 20px;
  63. margin-bottom: 20px;
  64. position: relative;
  65. }
  66. .itemImg {
  67. width: 100%;
  68. height: 150px;
  69. background-color: #ccc;
  70. position: relative;
  71. overflow: hidden;
  72. }
  73. .itemImg > img {
  74. width: 100%;
  75. height: 100%;
  76. object-fit: cover;
  77. }
  78. .typeStyle {
  79. position: absolute;
  80. display: inline;
  81. padding: 2px 6px;
  82. background-color: #249efb;
  83. color: #fff;
  84. top: 5px;
  85. right: 5px;
  86. border-radius: 2px;
  87. font-size: 12px;
  88. }
  89. .itemMsg {
  90. width: 100%;
  91. line-height: 40px;
  92. font-size: 12px;
  93. color: #999999;
  94. }
  95. .layui-icon-delete {
  96. position: absolute;
  97. bottom: 5px;
  98. right: 5px;
  99. color: red;
  100. cursor: pointer;
  101. }
  102. </style>
  103. <body>
  104. <div class="headerBack">
  105. <div id="backElement">
  106. <i class="layui-icon layui-icon-return" style="color: #249efb"></i>
  107. <span style="color: #249efb">返回</span>
  108. </div>
  109. </div>
  110. <div class="contentBox">
  111. <div class="uploadItem">上传素材</div>
  112. <div class="uploadlist">
  113. </div>
  114. <div id="pageElement"></div>
  115. </div>
  116. </body>
  117. {/block} {block name="js"}
  118. <script>
  119. layui
  120. .config({
  121. base: "__LAYUI__/",
  122. urlbase: "/sys",
  123. })
  124. .extend({
  125. index: "lib/index", //主入口模块
  126. })
  127. .use(
  128. ["index", "form", "upload", "layedit", "laydate", "laypage"],
  129. function () {
  130. var form = layui.form,
  131. upload = layui.upload,
  132. layedit = layui.layedit,
  133. laydate = layui.laydate,
  134. laypage = layui.laypage,
  135. $ = layui.jquery,
  136. page = 1;
  137. $("#backElement").click(function () {
  138. window.history.back();
  139. });
  140. ajaxlist();
  141. function ajaxlist() {
  142. $.ajax({
  143. type: "post",
  144. url: '{:url("activity/materialList")}',
  145. data: {
  146. id: "{$id}",
  147. page: page,
  148. limit: 20,
  149. },
  150. success: function (res) {
  151. renderlisthtml(res.data, res);
  152. laypage.render({
  153. elem: "pageElement",
  154. count: res.count, //数据总数,从服务端得到
  155. limit: 20,
  156. curr: page,
  157. jump: function (obj, first) {
  158. //obj包含了当前分页的所有参数,比如:
  159. page = obj.curr; //得到当前页,以便向服务端请求对应页的数据。
  160. //首次不执行
  161. if (!first) {
  162. //do something
  163. ajaxlist();
  164. }
  165. },
  166. });
  167. },
  168. });
  169. }
  170. function renderlisthtml(array, res) {
  171. let html = array
  172. .map((item) => {
  173. return `<div class="itemBox">
  174. <div class="itemImg">
  175. <img src="${item.url}" />
  176. <div class="typeStyle">${item.type == 0 ? '图片' : '视频'}</div>
  177. </div>
  178. <div class="itemMsg">上传于2022-04-27 12:12:12</div>
  179. <i data-id="${item.id}" class="layui-icon layui-icon-delete"></i>
  180. </div>`;
  181. })
  182. .join("");
  183. $('.uploadlist').html(html);
  184. setTimeout(() => {
  185. $('.layui-icon-delete').click(function() {
  186. let id = $(this).prop('dataset').id;
  187. layer.confirm('确定删除此活动?', { title: ['信息', 'color:#333333;background-color:#D8E6F1;'], }, function (index) {
  188. $.ajax({
  189. type: "post",
  190. url: '{:url("activity/materialDel")}',
  191. data: {
  192. id: id,
  193. },
  194. success: function (res) {
  195. if (res.code == 0) {
  196. layer.msg(res.msg, {
  197. anim: 0
  198. }, function () {
  199. ajaxlist();
  200. layer.close(index);
  201. });
  202. } else {
  203. layer.msg(res.msg, {
  204. anim: 6
  205. });
  206. }
  207. }
  208. });
  209. });
  210. })
  211. })
  212. }
  213. $(".uploadItem").click(function () {
  214. layer.open({
  215. type: 2,
  216. title: ["上传素材", "color:#333333;background-color:#D8E6F1;"],
  217. content: "{:url('activity/upload_material')}?id=" + "{$id}",
  218. // content: layui.setter.urlbase + "/activity/edit/id/" + data.id,
  219. resize: false,
  220. area: ["60%", "60%"],
  221. // btn: ['确定', '取消'],
  222. end: function (index, layero) {
  223. //点击确认触发 iframe 内容中的按钮提交
  224. // var submit = layero.find('iframe').contents().find("#activity-submit");
  225. // submit.click();
  226. ajaxlist();
  227. },
  228. });
  229. });
  230. }
  231. );
  232. </script>
  233. {/block}