source_material.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <div class="layui-fluid">
  4. <div class="layui-row layui-col-space15" id="app">
  5. <div class="layui-col-md12">
  6. <div class="layui-card">
  7. <div class="layui-card-header">素材列表</div>
  8. <div class="layui-card-body">
  9. <div class="layui-btn-container conrelTable">
  10. <button class="layui-btn layui-btn-normal layui-btn-sm" type="button"
  11. onclick="action.open_add('{:Url('searchs_task')}?special_id='+{$id}+'&special_type='+{$special_type},'选择素材')">
  12. 选择素材
  13. </button>
  14. <button class="layui-btn layui-btn-normal layui-btn-sm" type="button"
  15. onclick="action.add_source('{:Url('relation')}?id='+{$id},'添加素材')">
  16. 添加素材
  17. </button>
  18. <button class="layui-btn layui-btn-normal layui-btn-sm" onclick="window.location.reload()"><i
  19. class="layui-icon layui-icon-refresh"></i> 刷新
  20. </button>
  21. </div>
  22. <table class="layui-hide" id="List" lay-filter="List"></table>
  23. <input type="hidden" id="check_source_tmp" name="check_source_tmp"/>
  24. <script type="text/html" id="image">
  25. <img lay-event='open_image' src="{{d.image}}">
  26. </script>
  27. <script type="text/html" id="pay_status">
  28. <input type='checkbox' name='pay_status' lay-skin='switch' value="{{d.id}}"
  29. lay-filter='pay_status' lay-text='收费|免费' {{ d.pay_status== 1 ? 'checked' : '' }}>
  30. </script>
  31. <script type="text/html" id="act">
  32. <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event='delstor'>
  33. <i class="layui-icon">&#xe640;</i> 删除
  34. </button>
  35. </script>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  42. {/block}
  43. {block name="script"}
  44. <script>
  45. var id = "{$id}", special_type = "{$special_type}", order = "{$order}";
  46. //实例化form
  47. layList.form.render();
  48. //加载列表
  49. layList.tableList({o: 'List', done: function () {}}, "{:Url('get_source_sure_list')}?id=" + id + "&order=" + order, function () {
  50. return [
  51. {field: 'id', title: '编号', width: '8%', align: 'center'},
  52. {field: 'title', title: '标题'},
  53. {field: 'image', title: '封面', templet: '#image', align: 'center', width: '15%'},
  54. {field: 'pay_status', title: '收费状态', align: 'center', templet: '#pay_status', width: '15%'},
  55. {field: 'sort', title: '排序', sort: true, event: 'sort', edit: 'sort', align: 'center', width: '10%'},
  56. {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '10%'}
  57. ];
  58. }, 10);
  59. //快速编辑
  60. layList.edit(function (obj) {
  61. var value = obj.value;
  62. switch (obj.field) {
  63. case 'sort':
  64. if (value < 0) return layList.msg('排序不能小于0');
  65. if (value > 99999) return layList.msg('排序不能大于99999');
  66. layList.baseGet(layList.Url({
  67. a: 'update_source_sure',
  68. q: {id: obj.data.id, value: value, field: 'sort'}
  69. }), function (res) {
  70. layList.msg(res.msg);
  71. });
  72. break;
  73. }
  74. });
  75. layList.switch('pay_status', function (odj, value) {
  76. var is_show_value = 0
  77. if (odj.elem.checked == true) {
  78. var is_show_value = 1
  79. }
  80. layList.baseGet(layList.Url({
  81. a: 'update_source_sure',
  82. q: {id: value, value: is_show_value, field: 'pay_status'}
  83. }), function (res) {
  84. layList.msg(res.msg);
  85. });
  86. });
  87. //点击事件绑定
  88. layList.tool(function (event, data, obj) {
  89. switch (event) {
  90. case 'delstor':
  91. var url = layList.U({a: 'del_source_sure', q: {id: data.id,special_id:data.special_id}});
  92. $eb.$swal('delete', function () {
  93. $eb.axios.get(url).then(function (res) {
  94. if (res.status == 200 && res.data.code == 200) {
  95. $eb.$swal('success', res.data.msg);
  96. location.reload();
  97. } else
  98. return Promise.reject(res.data.msg || '删除失败')
  99. }).catch(function (err) {
  100. $eb.$swal('error', err);
  101. });
  102. });
  103. break;
  104. }
  105. });
  106. //监听并执行排序
  107. layList.sort(['id', 'sort'], true);
  108. var action = {
  109. open_add: function (url, title) {
  110. layer.open({
  111. type: 2 //Page层类型
  112. , area: ['80%', '90%']
  113. , title: '选择素材'
  114. , shade: 0.6 //遮罩透明度
  115. , maxmin: true //允许全屏最小化
  116. , anim: 1 //0-6的动画形式,-1不开启
  117. , content: url,
  118. btn: '确定',
  119. btnAlign: 'c', //按钮居中
  120. closeBtn: 1,
  121. yes: function () {
  122. layer.closeAll();
  123. var source_tmp = $("#check_source_tmp").val();
  124. var source_tmp_list = JSON.parse(source_tmp);
  125. var arr = [];
  126. for (var i = 0; i < source_tmp_list.length; i++) {
  127. arr.push(source_tmp_list[i].id);
  128. }
  129. var ids = arr.join(',');
  130. layList.baseGet(layList.Url({
  131. a: 'add_source_sure',
  132. q: {id: id, ids: ids, special_type: special_type}
  133. }), function (res) {
  134. layList.msg(res.msg, function () {
  135. location.reload();
  136. });
  137. });
  138. }
  139. });
  140. },
  141. add_source: function () {
  142. var that = this;
  143. var url = "{:Url('special.special_type/addSources')}?id=0&special_id="+id;
  144. var title = '添加素材';
  145. layer.open({
  146. type: 2 //Page层类型
  147. , area: ['80%', '90%']
  148. , title: title
  149. , shade: 0.6 //遮罩透明度
  150. , maxmin: true //允许全屏最小化
  151. , anim: 1 //0-6的动画形式,-1不开启
  152. , content: url
  153. , end: function () {
  154. layer.closeAll();
  155. location.reload();
  156. }
  157. });
  158. },
  159. refresh: function () {
  160. layList.reload();
  161. }
  162. };
  163. </script>
  164. {/block}