BillsDemo.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="utf-8">
  5. <title></title>
  6. <link rel="stylesheet" href="src/css/bootstrap/bootstrap.min.css" >
  7. <link rel="stylesheet" href="src/css/main.css">
  8. <link rel="stylesheet" href="src/css/font-awesome/font-awesome.min.css">
  9. <link rel="stylesheet" href="src/css/cust_flex_grid.css">
  10. <!--
  11. <link rel="stylesheet" href="src/css/bootstrap/themes.css">
  12. -->
  13. <!-- app scripts and styles -->
  14. </head>
  15. <script src="/src/lib/jquery-1.9.1.min.js"></script>
  16. <script type="text/javascript" src="/src/wijmo/controls/wijmo.min.js"></script>
  17. <link href="/src/wijmo/styles/wijmo.min.css" rel="stylesheet"/>
  18. <script type="text/javascript" src="/src/wijmo/controls/wijmo.grid.min.js"></script>
  19. <script type="text/javascript" src="/src/wijmo/controls/wijmo.grid.sheet.min.js"></script>
  20. <script type="text/javascript" src="/src/scripts/treeDataHelper.js"></script>
  21. <body>
  22. <nav class="navbar navbar-light bg-faded p-0 ">
  23. <span class="header-logo px-1" >
  24. Smartcost
  25. </span>
  26. <div class="float-lg-right navbar-text pb-0">
  27. <div class="dropdown d-inline-block">
  28. <button class="btn btn-link btn-sm dropdown-toggle" type="button" data-toggle="dropdown">康彤</button>
  29. <div class="dropdown-menu dropdown-menu-right">
  30. <a class="dropdown-item" href="user-info.html">个人信息</a>
  31. <a class="dropdown-item" href="user-bug.html">购买</a>
  32. <a class="dropdown-item" href="user-set.html">设置</a>
  33. </div>
  34. </div>
  35. <span class="btn btn-link btn-sm new-msg" >
  36. <i class="fa fa-envelope-o" aria-hidden="true"></i>&nbsp;6
  37. </span>
  38. <button class="btn btn-link btn-sm">
  39. 注销
  40. </button>
  41. </div>
  42. </nav>
  43. <p>测试 FlexGrid 控件:</p>
  44. <div>
  45. <input type="button" value="新增" onclick="billOperation('insert')"/>
  46. <input type="button" value="删除" onclick="billOperation('remove')"/>
  47. <input type="button" value="升级" onclick="billOperation('upgrade')"/>
  48. <input type="button" value="降级" onclick="billOperation('downgrade')"/>
  49. <input type="button" value="上移" onclick="billOperation('moveup')"/>
  50. <input type="button" value="下移" onclick="billOperation('movedown')"/>
  51. </div>
  52. <div id="theGrid" style="width:100%; height:600px;" class="custom-flex-grid"></div>
  53. <p>测试 FlexSheet 控件:</p>
  54. <div id="flexsheet" style="width:100%;height:auto;"></div>
  55. <!--
  56. -->
  57. </body>
  58. <script id="scriptInit" type="text/javascript">
  59. $(document).ready(function () {
  60. $.ajax({
  61. type:"POST",
  62. url: 'http://localhost:3010/api/getBills',
  63. dataType: 'json',
  64. data: {"user_id": ""},
  65. cache: false,
  66. timeout: 10000,
  67. success: function(result){
  68. //var data = result.data;
  69. var data = result.data.slice(0);
  70. for (var i = 0; i < data.length; i++) {
  71. data[i]["chk"] = (i%2 == 0);
  72. }
  73. tree_Data_Helper.sortDataBySerial(data);
  74. //*
  75. buildGrid(tree_Data_Helper.buildTreeData(data));
  76. /*/
  77. buildNormalGrid(data);
  78. //*/
  79. //buildSheet(data);
  80. },
  81. error: function(jqXHR, textStatus, errorThrown){
  82. alert('没有清单!');
  83. //or create local default cache...
  84. }
  85. });
  86. });
  87. function billOperation(opr) {
  88. switch (opr) {
  89. case 'insert':
  90. break;
  91. case 'remove':
  92. break;
  93. case 'upgrade':
  94. break;
  95. case 'downgrade':
  96. break;
  97. case 'moveup':
  98. break;
  99. case 'movedown':
  100. break;
  101. }
  102. }
  103. function buildNormalGrid(data) {
  104. var grid = new wijmo.grid.FlexGrid('#theGrid',
  105. {
  106. autoGenerateColumns: false,
  107. columns: buildColumns(),
  108. selectionMode: wijmo.grid.SelectionMode.ListBox
  109. }
  110. );
  111. grid.itemFormatter = function(panel, r, c, cell) {
  112. if (wijmo.grid.CellType.Cell == panel.cellType) {
  113. var col = panel.columns[c];
  114. if (col.name == 'button') {
  115. var html = '<div>' +
  116. ' ' +
  117. '<button class="btn btn-default btn-sm" onclick="editRow(' + r + ' )">' +
  118. '<span class="glyphicon glyphicon-pencil"></span> Edit' +
  119. '</button>' +
  120. '</div>';
  121. cell.innerHTML = html;
  122. }
  123. } else if (wijmo.grid.CellType.ColumnHeader == panel.cellType) {
  124. cell.style["text-align"] = "center";
  125. cell.onclick = function() {selectCol(grid, c)};
  126. } else if (wijmo.grid.CellType.RowHeader == panel.cellType) {
  127. cell.innerHTML = r + 1;
  128. cell.style["font-weight"] = "normal";
  129. } else if (wijmo.grid.CellType.TopLeft == panel.cellType) {
  130. cell.innerHTML = "^_^";
  131. }
  132. }
  133. grid.itemsSource = data;
  134. }
  135. function buildGrid(treeData) {
  136. // create the grid
  137. var grid = new wijmo.grid.FlexGrid('#theGrid');
  138. // populate the grid and set childItemsPath to show data hierarchically
  139. grid.childItemsPath = 'items';
  140. grid.itemFormatter = function(panel, r, c, cell) {
  141. if (wijmo.grid.CellType.Cell == panel.cellType) {
  142. var col = panel.columns[c];
  143. panel.rows[r].isReadOnly = false;
  144. } else if (wijmo.grid.CellType.ColumnHeader == panel.cellType) {
  145. cell.style["text-align"] = "center";
  146. cell.onclick = function() {selectCol(grid, c)};
  147. } else if (wijmo.grid.CellType.RowHeader == panel.cellType) {
  148. cell.innerHTML = r + 1;
  149. cell.style["font-weight"] = "normal";
  150. } else if (wijmo.grid.CellType.TopLeft == panel.cellType) {
  151. cell.innerHTML = "^_^";
  152. }
  153. }
  154. grid.initialize({
  155. autoGenerateColumns: false,
  156. columns: buildColumns(),
  157. itemsSource: treeData, // hierarchical data
  158. childItemsPath: 'items' // set hierarchy path
  159. });
  160. //grid.collapseGroupsToLevel(1);
  161. }
  162. function buildColumns() {
  163. var rst = [
  164. { header: '项目节', name: "", binding: 'Code', allowSorting: false, width: 160 },
  165. { header: '清单子目号', name: "", binding: 'B_Code', allowSorting: false, width: 160 },
  166. { header: '名称', name: "", binding: 'Name', allowSorting: false, width: 380 },
  167. { header: '单位', name: "", binding: 'Units', allowSorting: false, align: 'Center', width: 100 },
  168. { header: '清单数量', name: "", binding: 'Quantity', allowSorting: false, align: 'Right', width: 100 },
  169. { header: '设计数量1', name: "", binding: 'DesignQuantity', allowSorting: false, align: 'Right', width: 100 },
  170. { header: '设计数量2', name: "", binding: 'DesignQuantity2', allowSorting: false, align: 'Right', width: 100 },
  171. { header: '清单单价', name: "", binding: 'UnitPrice', allowSorting: false, align: 'Right', width: 100 },
  172. { header: '经济指标', name: "", binding: "DesignPrice", allowSorting: false, width: 100 },
  173. { header: '金额', name: "", binding: "TotalPrice", allowSorting: false, width: 100 },
  174. { header: '备注', name: "", binding: "Memostr", allowSorting: false, width: 200 },
  175. //{ header: ' ', name: "button", binding: "button", allowSorting: false, width: 100 },
  176. { header: ' ', name: "check", binding: "chk", allowSorting: false, width: 100 }
  177. ];
  178. return rst;
  179. }
  180. function selectCol(grid, colIdx) {
  181. if (grid.rows.length > 0) {
  182. grid.selection = new wijmo.grid.CellRange(0, colIdx, grid.rows.length - 1, colIdx);
  183. }
  184. }
  185. function buildSheet(sheetData) {
  186. var flex = new wijmo.grid.sheet.FlexSheet('#flexsheet');
  187. flex.addUnboundSheet('Empty Sheet');
  188. flex.selectedSheetIndex = 0;
  189. }
  190. </script>
  191. </html>