GetLastedData.cshtml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. @{
  2. ViewBag.Title = "抄表历史查询";
  3. Layout = "~/Views/Shared/_Index.cshtml";
  4. }
  5. <script>
  6. $(document).ready(function () {
  7. initControl();
  8. initialPage();
  9. GetGrid();
  10. //表格表头居中显示
  11. $(".ui-th-column").css("text-align", "center");
  12. });
  13. //重设(表格)宽高
  14. function initialPage() {
  15. //resize重设(表格、树形)宽高
  16. $(window).resize(function (e) {
  17. window.setTimeout(function () {
  18. $('#gridTable').setGridWidth(($('.gridPanel').width()));
  19. $("#gridTable").setGridHeight($(window).height() - 108.5);
  20. }, 200);
  21. e.stopPropagation();
  22. });
  23. }
  24. //加载表格
  25. function GetGrid() {
  26. var selectedRowIndex = 0;
  27. var $gridTable = $('#gridTable');
  28. $gridTable.jqGrid({
  29. url: "/NBManage/NBHistorySearch/GetRealTimeData",
  30. datatype: "json",
  31. height: $(window).height() - 148.5,
  32. autowidth: true,
  33. colModel: [
  34. { label: '主键', name: 'OrganizeId', hidden: true, fixed: true },
  35. { label: "IMEI", name: "IMEI", width: 200, align: "right", sortable: false, fixed: true, hidden: true },
  36. { label: "DeviceID", name: "IOT_Code", width: 300, align: "left", sortable: false, fixed: true, hidden: true},
  37. { label: "区域名称", name: "area", width: 300, align: "left", sortable: false, fixed: true },
  38. { label: "门牌号", name: "room", width: 100, align: "left", sortable: false, fixed: true },
  39. { label: "用户编号", name: "UserNo", width: 150, align: "left", sortable: false, fixed: true },
  40. { label: "用户名称", name: "UserName", width: 150, align: "left", sortable: false, fixed: true },
  41. { label: "表类型", name: "MeterType", width: 100, align: "left", sortable: false, hidden: true, fixed: true },
  42. { label: "表地址", name: "ElecAddress", width: 150, align: "right", fixed: true },
  43. { label: "抄表时间", name:"ReadingDT" ,width: 165, align: "right", fixed: true },
  44. { label: "净累计(m³)", name:"Total", width: 150, align: "right", fixed: true },
  45. {label: "阀门状态", name: "", width: 100, align: "left", sortable: false,fixed: true}
  46. ],
  47. multiselect: true,
  48. viewrecords: true,
  49. rowNum: 3000,
  50. pager: "#gridPager",
  51. gridview: true,
  52. sortable: true,
  53. sortname: "NowRadingDT",
  54. sortorder: "desc",
  55. rownumbers: true,
  56. gridComplete: function () {
  57. $("#" + this.id).setSelection(selectedRowIndex, false);
  58. }
  59. });
  60. }
  61. // 取最新数据
  62. function getLastData() {
  63. var ids = $("#gridTable").jqGrid("getGridParam", "selarrrow");
  64. var startQueque = Promise.resolve();
  65. $(ids).each(function (index, id) {
  66. var row = $("#gridTable").jqGrid('getRowData', id);
  67. var IOT_Code = row.IOT_Code;
  68. (function (IOT_Code) {
  69. startQueque = startQueque.then(function () {
  70. $.ajax({
  71. type: 'POST',
  72. url: "/NBManage/NBEquipmentDebug/GetAjaxData?deviceId=" + IOT_Code,
  73. cache: false,
  74. ifModified: true,
  75. dataType: 'JSON',
  76. beforeSend: function () {
  77. $("#gridTable").jqGrid('setCell', id, "Total", '<img class="alarmimg" src="/Content/images/send_wait.gif" " />');
  78. $("#gridTable").jqGrid('setCell', id, "ReadingDT", '读取中...');
  79. },
  80. success: function (jsonData) {
  81. console.log(jsonData);
  82. $("#gridTable").jqGrid('setCell', id, "Total", jsonData[0].total);
  83. $("#gridTable").jqGrid('setCell', id, "ReadingDT", jsonData[0].read_time);
  84. },
  85. })
  86. });
  87. })(IOT_Code);
  88. })
  89. }
  90. function initControl() {
  91. //小区
  92. $("#AreaId").ComboBox({
  93. url: "/NBManage/NBHistorySearch/GetAreaListJson",
  94. id: "AreaId",
  95. text: "AreaName",
  96. description: "选择小区",
  97. height: "170px"
  98. });
  99. }
  100. function btn_Search() {
  101. var areaId = $("#AreaId").attr('data-value');
  102. $("#gridTable").jqGrid('setGridParam', {
  103. postData: {
  104. areaId: areaId
  105. }
  106. }).trigger('reloadGrid');
  107. }
  108. //导出
  109. function btn_export() {
  110. var datavalue = $("#gridTable").jqGrid('getRowData'); //获取全部数据
  111. dialogOpen({
  112. id: "ExcelIExportDialog",
  113. title: '导出',
  114. url: '/Utility/ExcelExportForm?gridId=gridTable&filename=历史记录',
  115. width: "500px",
  116. height: "380px",
  117. callBack: function (iframeId) {
  118. top.frames[iframeId].AcceptClick();
  119. }, btn: ['导出Excel', '关闭']
  120. });
  121. }
  122. </script>
  123. <div class="titlePanel">
  124. <div class="title-search">
  125. <table>
  126. <tr>
  127. <td>
  128. <div id="queryCondition">
  129. <div id="AreaId" type="select" class="ui-select" style="float: left; min-width: 150px; margin-right: 1px;"></div>
  130. </div>
  131. </td>
  132. <td style="padding-left: 5px;">
  133. <a id="btn_Search" class="btn btn-primary" onclick="btn_Search()"><i class="fa fa-search"></i>&nbsp;查询</a>
  134. </td>
  135. </tr>
  136. </table>
  137. </div>
  138. <div class="toolbar">
  139. <div class="btn-group">
  140. @*<a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>*@
  141. <a id="lr-replace" class="btn btn-default" onclick="getLastData();"><i class="fa fa-refresh"></i>&nbsp;取数据</a>
  142. <a id="lr-edit" class="btn btn-default" onclick="btn_export()"><i class="fa fa-file-excel-o"></i>&nbsp;导出</a>
  143. </div>
  144. </div>
  145. </div>
  146. <div class="gridPanel">
  147. <table id="gridTable"></table>
  148. <div id="gridPager"></div>
  149. </div>