datalist.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. {extend name="common/base"/}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <form class="layui-form gg-form-bar border-t border-x">
  6. <div class="layui-input-inline">
  7. <select name="cate_id">
  8. <option value="">请选择商品分类</option>
  9. {volist name=":set_recursion(get_goods_cate())" id="v"}
  10. <option value="{$v.id}">{$v.title}</option>
  11. {/volist}
  12. </select>
  13. </div>
  14. <div class="layui-input-inline" style="width:300px;">
  15. <input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
  16. </div>
  17. <div class="layui-input-inline">
  18. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
  19. </div>
  20. </form>
  21. <table class="layui-hide" id="goods" lay-filter="goods"></table>
  22. </div>
  23. <script type="text/html" id="toolbarDemo">
  24. <div class="layui-btn-container">
  25. <span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加商品">+ 添加商品</span>
  26. </div>
  27. </script>
  28. <script type="text/html" id="status">
  29. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok green{{# } else { }}layui-icon-close red{{# } }}"></i>
  30. </script>
  31. <script type="text/html" id="is_home">
  32. <i class="layui-icon {{# if(d.is_home == 1){ }}layui-icon-ok green{{# } else { }}layui-icon-close red{{# } }}"></i>
  33. </script>
  34. <script type="text/html" id="barDemo">
  35. <div class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
  36. </script>
  37. {/block}
  38. <!-- /主体 -->
  39. <!-- 脚本 -->
  40. {block name="script"}
  41. <script>
  42. const moduleInit = ['tool'];
  43. function gouguInit() {
  44. var table = layui.table,tool = layui.tool, form = layui.form;
  45. layui.pageTable = table.render({
  46. elem: '#goods',
  47. title: '商品列表',
  48. toolbar: '#toolbarDemo',
  49. url: '/admin/goods/datalist',
  50. page: true,
  51. limit: 20,
  52. cellMinWidth: 80,
  53. cols: [
  54. [
  55. {
  56. fixed: 'left',
  57. field: 'id',
  58. title: '编号',
  59. align: 'center',
  60. width: 80
  61. },{
  62. field: 'cate_title',
  63. title: '所属分类',
  64. align: 'center',
  65. width: 100
  66. },{
  67. field: 'type_str',
  68. title: '属性',
  69. align: 'center',
  70. width: 80
  71. },{
  72. field: 'title',
  73. title: '商品名称',
  74. },{
  75. field: 'base_price',
  76. title: '市场价格',
  77. align: 'center',
  78. width: 90
  79. },{
  80. field: 'price',
  81. title: '实际价格',
  82. align: 'center',
  83. width: 90
  84. },{
  85. field: 'stocks',
  86. title: '商品库存',
  87. align: 'center',
  88. width: 80
  89. },{
  90. field: 'sales',
  91. title: '商品销量',
  92. align: 'center',
  93. width: 80
  94. },{
  95. field: 'read',
  96. title: '阅读量',
  97. align: 'center',
  98. width: 80
  99. },{
  100. field: 'is_home',
  101. title: '首页显示',
  102. toolbar: '#is_home',
  103. align: 'center',
  104. width: 90
  105. },{
  106. field: 'sort',
  107. title: '排序',
  108. align: 'center',
  109. width: 80
  110. },{
  111. field: 'status',
  112. title: '上下架',
  113. toolbar: '#status',
  114. align: 'center',
  115. width: 80
  116. },{
  117. field: 'admin_name',
  118. title: '创建人',
  119. align: 'center',
  120. width: 100
  121. },{
  122. field: 'create_time',
  123. title: '创建时间',
  124. align: 'center',
  125. width: 160
  126. },{
  127. fixed: 'right',
  128. field: 'right',
  129. title: '操作',
  130. toolbar: '#barDemo',
  131. width: 136,
  132. align: 'center'
  133. }
  134. ]
  135. ]
  136. });
  137. //监听表头工具栏事件
  138. table.on('toolbar(goods)', function(obj){
  139. if (obj.event === 'add') {
  140. tool.side("/admin/goods/add");
  141. return false;
  142. }
  143. });
  144. //监听表格行工具事件
  145. table.on('tool(goods)', function(obj) {
  146. var data = obj.data;
  147. if (obj.event === 'read') {
  148. tool.side('/admin/goods/read?id='+obj.data.id);
  149. }
  150. else if (obj.event === 'edit') {
  151. tool.side('/admin/goods/edit?id='+obj.data.id);
  152. }
  153. else if (obj.event === 'del') {
  154. layer.confirm('确定要删除该记录吗?', {
  155. icon: 3,
  156. title: '提示'
  157. }, function(index) {
  158. let callback = function (e) {
  159. layer.msg(e.msg);
  160. if (e.code == 0) {
  161. obj.del();
  162. }
  163. }
  164. tool.delete("/admin/goods/del", { id: data.id }, callback);
  165. layer.close(index);
  166. });
  167. }
  168. return false;
  169. });
  170. //监听搜索提交
  171. form.on('submit(searchform)', function(data) {
  172. layui.pageTable.reload({
  173. where: {
  174. keywords: data.field.keywords
  175. },
  176. page: {
  177. curr: 1
  178. }
  179. });
  180. return false;
  181. });
  182. }
  183. </script>
  184. {/block}
  185. <!-- /脚本 -->