goods_select.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. {extend name="app/shop/view/base.html"/}
  2. {block name="resources"}
  3. <style type="text/css">
  4. .table-wrap {padding: 0 20px;width: 560px;height: 385px;}
  5. .table-wrap .layui-table-body {overflow-x: hidden;height: 260px;overflow-y: scroll;}
  6. .goods-info {padding: 5px 0;align-items: center;flex-wrap:unset!important;}
  7. .goods-info .room-name {padding-left: 5px;line-height: 1}
  8. .goods-info img {width:50px;height: 50px;}
  9. .info-wrap{height: 30px;line-height: 30px;background: #f2f2f2;color: #666;padding: 5px 10px;margin-top: 15px;}
  10. </style>
  11. {/block}
  12. {block name="body"}
  13. <div class="table-wrap">
  14. <div class="info-wrap">已选择 <span id="selectNum">0</span> 件 商品</div>
  15. <table id="goods_list" lay-filter="goods_list"></table>
  16. </div>
  17. <script type="text/html" id="goodsinfo">
  18. <div class="table-btn goods-info">
  19. <img src="{{ ns.img(d.cover_img) }}">
  20. <span class="room-name" title="{{ d.name }}">{{ d.name }}</span>
  21. </div>
  22. </script>
  23. {/block}
  24. {block name="script"}
  25. <script type="text/javascript">
  26. var sku_id = '{$ids}',
  27. selectedData = [];
  28. selectedIdData = [];
  29. $(function(){
  30. var table = new Table({
  31. id: 'goodsTable',
  32. elem: '#goods_list',
  33. url: ns.url("live://shop/room/getGoodsPageList"),
  34. where: {
  35. sku_id: sku_id
  36. },
  37. cols: [
  38. [
  39. {
  40. title: '',
  41. type: 'checkbox',
  42. unresize: 'false',
  43. width: '10%',
  44. },
  45. {
  46. title: '商品信息',
  47. unresize: 'false',
  48. width: '90%',
  49. templet: "#goodsinfo"
  50. }
  51. ]
  52. ],
  53. callback: function(res, curr, count){
  54. if (res.data.length) {
  55. var checkedNum = 0;
  56. res.data.forEach(function(e,i){
  57. if ($.inArray(e.id, selectedIdData) != -1) {
  58. checkedNum += 1;
  59. res.data[i]["LAY_CHECKED"] = 'true';
  60. var index= res.data[i]['LAY_TABLE_INDEX'];
  61.      $('.table-wrap tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
  62.      $('.table-wrap tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
  63. }
  64. });
  65. if (res.data.length == checkedNum) {
  66. $('.table-wrap .layui-table-header tr input[type="checkbox"]').prop('checked', true);
  67.      $('.table-wrap .layui-table-header tr input[type="checkbox"]').next().addClass('layui-form-checked');
  68. }
  69. }
  70. }
  71. });
  72. // 监听checkbox选中状态改变事件
  73. table.on('checkboxChange', function(obj){
  74. if (obj.checked) {
  75. if ($.inArray(obj.data.id, selectedIdData) == -1) {
  76. selectedIdData.push(obj.data.id);
  77. selectedData.push(obj.data)
  78. }
  79. } else {
  80. selectedData.forEach(function(e,i){
  81. if (JSON.stringify(e) == JSON.stringify(obj.data)) {
  82. selectedData.splice(i, 1);
  83. }
  84. });
  85. selectedIdData.splice($.inArray(obj.data.id, selectedIdData), 1);
  86. }
  87. $('#selectNum').text(selectedData.length);
  88. })
  89. });
  90. function callback(fun){
  91. if (typeof fun == 'function') fun(selectedData);
  92. }
  93. </script>
  94. {/block}