get_group.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {__NOLAYOUT__}
  2. <table id="tagGoodsTable" lay-filter="tagGoodsTable"></table>
  3. <script>
  4. var ids = {};
  5. var table_data=new Array();
  6. layui.use(['form','table'], function(){
  7. layui.table.render({
  8. elem: '#tagGoodsTable',
  9. height: '420',
  10. page: 'true',
  11. limit:'10',
  12. url: '{:createUrl("products.goods/index")}',
  13. id:'tagGoodsTable',
  14. cols: [[
  15. {type: 'checkbox'}
  16. , {field: 'id', title: 'ID', width: 80, unresize: true, sort: true,align:"center"}
  17. , {field:"cat_name",title:"分类名称",width:120,align:"center"}
  18. , {field:'photo', title:'封面', width:60,templet: function(res){
  19. return '<img src="'+ res.photo +'" style="max-width:30px; max-height:30px;">';
  20. }}
  21. , {field: 'title', title: '名称'}
  22. , {field: 'sell_price', title: '商品价格',width:150,align:'center'}
  23. , {field: 'group_price', title: '拼团价格', edit:true, width: 150, align:"center"}
  24. , {field: 'people', title: '参团人数', width: 100, align:"center"}
  25. , {field: 'end_time', title: '结束时间',width:180,align:'center'}
  26. ]],
  27. , text: {
  28. none: '<div><i class="layui-icon">&#xe702;</i>暂无相关数据</div>'
  29. }
  30. done: function(res, curr, count){
  31. table_data=res.data;
  32. for(var i=0;i< res.data.length;i++){
  33. if(ids[res.data[i].id]){
  34. res.data[i]["LAY_CHECKED"]='true';
  35. var index= res.data[i]['LAY_TABLE_INDEX'];
  36. $('#tagGoodsTable + div .layui-table-body tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
  37. $('#tagGoodsTable + div .layui-table-body tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
  38. }
  39. }
  40. var checkStatus = layui.table.checkStatus('tagGoodsTable');
  41. if(checkStatus.isAll){
  42. $('#tagGoodsTable + div .layui-table-header th[data-field="0"] input[type="checkbox"]').prop('checked', true);
  43. $('#tagGoodsTable + div .layui-table-header th[data-field="0"] input[type="checkbox"]').next().addClass('layui-form-checked');
  44. }
  45. }
  46. });
  47. //监听表格复选框选择
  48. layui.table.on('checkbox(tagGoodsTable)', function(obj){
  49. if(obj.checked){
  50. if(obj.type=='one'){
  51. ids[obj.data.goods_id] = obj.data;
  52. }else{
  53. for(var i=0;i<table_data.length;i++){
  54. ids[table_data[i].goods_id] = table_data[i];
  55. }
  56. }
  57. }else{
  58. if(obj.type=='one'){
  59. delete ids[obj.data.goods_id];
  60. }else{
  61. for(var i=0;i<table_data.length;i++){
  62. delete ids[table_data[i].goods_id];
  63. }
  64. }
  65. }
  66. });
  67. });
  68. </script>