select_goods.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <div class="ibox">
  4. <div class="ibox-content">
  5. <div class="row">
  6. <div class="col-xs-3">
  7. <a href="javascript:;" class="btn btn-sm btn-primary" onclick="selectGoods(this)">确定选择</a>
  8. </div>
  9. <div class="col-xs-9" style="text-align: right;">
  10. <form class="form-inline" id="form-search" action="{:url('index')}">
  11. <div class="input-group">
  12. <input type="text" class="form-control" name="title" placeholder="物品名称">
  13. </div>
  14. <div class="input-group">
  15. <span class="input-group-btn">
  16. <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
  17. </span>&nbsp;
  18. <span class="input-group-btn">
  19. <button class="btn-sm btn-primary " type="button" id="search-clear"><i class="fa fa-undo"></i></button>
  20. </span>
  21. </div>
  22. </form>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="ibox-content">
  27. <div class="jqGrid_wrapper">
  28. <table id="table" style="border-collapse: collapse"></table>
  29. <div id="pager"></div>
  30. </div>
  31. </div>
  32. </div>
  33. {/block}
  34. {block name="script"}
  35. <script>
  36. var lists = localStorage.getItem("mateapply")?JSON.parse(localStorage.getItem("mateapply")):[];
  37. var ids = localStorage.getItem("mateapplyids")?JSON.parse(localStorage.getItem("mateapplyids")):[];
  38. $(function () {
  39. $(window).bind("resize",function(){
  40. var width=$(".jqGrid_wrapper").width();
  41. $("#table").setGridWidth(width);
  42. });
  43. $.jgrid.defaults.styleUI="Bootstrap";
  44. $("#table").jqGrid({
  45. url:"{:url('selectGoods')}",
  46. datatype: "json",
  47. colModel:[
  48. {label:'',name:'id',index:'id', hidden: true},
  49. {label:'名称',name:'title',index:'title', width:60,sortable: false},
  50. {label:'价格',name:'price',index:'price', width:40,sortable: false},
  51. {label:'品牌',name:'brand',index:'brand', width:40,sortable: false},
  52. {label:'规格',name:'spec',index:'spec', width:40,sortable: false},
  53. {label:'剩余数量',name:'nums',index:'nums',width:50,editable: false,sortable: false},
  54. {label:'类型',name:'type',index:'type',width:50,editable: false,sortable: false,formatter:function (a,b,c){
  55. if(a == 1){
  56. return '固定资产';
  57. } else{
  58. return '耗材';
  59. }
  60. }},
  61. {label:'购买日期',name:'buy_time',index:'buy_time', width:50,sortable: false},
  62. ],
  63. rowNum:5,
  64. rowList:[5,10,50,100,500,1000],
  65. pager: '#pager',
  66. sortname: 'id',
  67. viewrecords: true,
  68. autowidth:true,
  69. rownumbers: true,
  70. mtype: 'post',
  71. height: 'auto',
  72. emptyrecords: "暂无数据",
  73. sortorder: "desc",
  74. multiselect: true,//可多选
  75. caption:"",
  76. loadComplete: function (xhr) {
  77. if(xhr.code==0){
  78. layer.msg(xhr.msg);
  79. return false;
  80. }else{
  81. console.log('loadComplete');
  82. // let ss = jQuery("#table").jqGrid('getRowData');
  83. // console.log('ids',ids);
  84. ids.forEach((rid) => {
  85. jQuery("#table").setSelection(rid, true);
  86. });
  87. }
  88. },
  89. onSelectAll: function(){
  90. formatSelect();
  91. },
  92. beforeSelectRow: function(rowid, e){
  93. // console.log('beforeSelectRow',rowid, e,ids);
  94. },
  95. onPaging: function(){
  96. formatSelect();
  97. },
  98. });
  99. });
  100. function formatSelect() {
  101. let objs = jQuery("#table").jqGrid('getRowData');
  102. let rowIds = jQuery("#table").jqGrid('getGridParam', 'selarrrow');
  103. console.log('onPaging',ids,rowIds);
  104. objs.forEach((item) => {
  105. if(rowIds.includes(item.id)){
  106. if(!ids.includes(item.id)){
  107. ids.push(item.id);
  108. lists.push(item);
  109. }
  110. }else{
  111. if(ids.includes(item.id)){
  112. ids = ids.filter((item2) => {
  113. return item2 != item.id;
  114. });
  115. lists = lists.filter((item2) => {
  116. return item2.id != item.id;
  117. })
  118. }
  119. }
  120. });
  121. }
  122. function selectGoods(_self) {
  123. formatSelect();
  124. parent.layer.closeAll();
  125. parent.lists = lists;
  126. parent.formatList();
  127. }
  128. </script>
  129. {/block}