get_goods_data.php 2.9 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', 'laydate','table'], function(){
  7. layui.table.render({
  8. elem: '#tagGoodsTable',
  9. height: '420',
  10. page: 'true',
  11. limit:'10',
  12. url: "{:createUrl('products.index/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: 'create_time', title: '创建时间',width:180,align:'center'}
  24. ]],
  25. , text: {
  26. none: '<div><i class="layui-icon">&#xe702;</i>暂无相关数据</div>'
  27. }
  28. done: function(res, curr, count){
  29. table_data=res.data;
  30. for(var i=0;i< res.data.length;i++){
  31. if(ids[res.data[i].id]){
  32. res.data[i]["LAY_CHECKED"]='true';
  33. var index= res.data[i]['LAY_TABLE_INDEX'];
  34. $('#tagGoodsTable + div .layui-table-body tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
  35. $('#tagGoodsTable + div .layui-table-body tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
  36. }
  37. }
  38. var checkStatus = layui.table.checkStatus('tagGoodsTable');
  39. if(checkStatus.isAll){
  40. $('#tagGoodsTable + div .layui-table-header th[data-field="0"] input[type="checkbox"]').prop('checked', true);
  41. $('#tagGoodsTable + div .layui-table-header th[data-field="0"] input[type="checkbox"]').next().addClass('layui-form-checked');
  42. }
  43. }
  44. });
  45. layui.table.on('checkbox(tagGoodsTable)', function(obj){
  46. if(obj.checked){
  47. if(obj.type=='one'){
  48. ids[obj.data.id] = obj.data;
  49. }else{
  50. for(var i=0;i<table_data.length;i++){
  51. ids[table_data[i].id] = table_data[i];
  52. }
  53. }
  54. }else{
  55. if(obj.type=='one'){
  56. delete ids[obj.data.id];
  57. }else{
  58. for(var i=0;i<table_data.length;i++){
  59. delete ids[table_data[i].id];
  60. }
  61. }
  62. }
  63. });
  64. });
  65. </script>