devManage.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. app.controller('devManageCtrl', ['$scope', '$filter', '$http', '$state', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'QRCodeOptions', 'FileUploader', function ($scope, $filter, $http, $state, $stateParams, $timeout, uiGridConstants, i18nService, toaster, QRCodeOptions, FileUploader) {
  2. i18nService.setCurrentLang("zh-cn");
  3. moment.locale('zh-cn');
  4. var managerId = $stateParams.managerId;
  5. var agentId = $stateParams.agentId;
  6. var dealerId = $stateParams.dealerId;
  7. var searchKey = $stateParams.searchKey || "";
  8. $scope.gridOptions = {
  9. data: 'myData',
  10. showGridFooter: true, //是否显示grid footer
  11. // rowHeight: 80,
  12. //-------- 分页属性 ----------------
  13. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  14. paginationCurrentPage: 1, //当前页码
  15. paginationPageSize: 10, //每页显示个数
  16. totalItems: 0,// 总数量
  17. useExternalPagination: true,//是否使用分页按钮
  18. //过滤
  19. // enableFiltering: true,
  20. columnDefs: [],
  21. //---------------api---------------------
  22. onRegisterApi: function (gridApi) {
  23. $scope.gridApi = gridApi;
  24. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  25. if ($scope.setPagingData) {
  26. $scope.getPagedDataAsync(newPage, pageSize, true);//翻页是强制刷新
  27. }
  28. });
  29. }
  30. };
  31. //查询条件
  32. var condition = $scope.condition = {
  33. registered: {value: true, label: "已注册"},
  34. online: {value: "", label: "-选择在线状态-"},
  35. logicalCode: '',
  36. searchKey: searchKey,
  37. fileContent: ''
  38. };
  39. //枚举常量
  40. $scope.enum = {};
  41. $scope.enum.registered = [
  42. {value: "", label: "-选择注册状态-"},
  43. {value: true, label: "已注册"},
  44. {value: false, label: "未注册"}
  45. ];
  46. $scope.enum.online = [
  47. {value: "", label: "-选择在线状态-"},
  48. {value: 0, label: "离线设备"},
  49. {value: 1, label: "在线设备"},
  50. ];
  51. //事件
  52. $scope.event = {
  53. statusChange: function (key, item) {
  54. condition[key].value = item.value;
  55. condition[key].label = item.label;
  56. this.search()
  57. },
  58. search: function () {
  59. // 就在当前 厂商|代理商|经销商的域下进行搜索
  60. if (condition.searchKey === "") {
  61. $.confirm({
  62. content: '条件为空,数据量较大,确定继续?',
  63. buttons: {
  64. ok: {
  65. text: '搜索',
  66. action: function () {
  67. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize, true);
  68. }
  69. },
  70. }
  71. });
  72. } else {
  73. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  74. }
  75. },
  76. searchByLogicalCode: function () {
  77. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  78. }
  79. };
  80. $scope.batchQuery = function () {
  81. $(".devManageMain #batchQueryForm").modal();
  82. $scope.dialogData = {}
  83. }
  84. $scope.batchQueryOk = function () {
  85. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize, true);
  86. };
  87. $scope.changeFile = function (files) {
  88. if (files.length) {
  89. var file = files[0];
  90. var reader = new FileReader();
  91. // 文件不能大于1M
  92. if (file.size > 1000 * 1024) {
  93. toaster.pop("info", "提示", "文件太大,请重新选择");
  94. } else {
  95. reader.onload = function () {
  96. if (reader.result) {
  97. var text = reader.result
  98. $scope.condition.fileContent = text
  99. $scope.dialogData.fileName = file.name
  100. $scope.$apply();
  101. }
  102. };
  103. reader.readAsText(file);
  104. }
  105. }
  106. }
  107. function getLogicalList(logicalCodeList) {
  108. var needList = logicalCodeList.split("\n")
  109. for (var i = needList.length - 1; i >= 0; i--) {
  110. var item = needList[i];
  111. needList[i] = $.trim(item);
  112. if (needList[i] === '') {
  113. needList.splice(i, 1)
  114. }
  115. }
  116. needList = needList.filter(function (item, i, self) {
  117. var flag = self.indexOf(item) === i
  118. return flag;
  119. })
  120. return needList
  121. }
  122. // 查询条件缓存,用于导出报表用
  123. $scope.queryCache = {}
  124. // 导出查询设备的报表
  125. $scope.exportDevice = function () {
  126. if ($.isEmptyObject($scope.queryCache)) {
  127. toaster.pop("info", "提示", "请先根据条件查询一次数据");
  128. return
  129. }
  130. $http({
  131. method: 'POST',
  132. url: '/superadmin/exportDevice',
  133. data: $scope.queryCache
  134. }).then(function (response) {
  135. toaster.pop("success", "提示", "操作成功,请到结果页面下载报表");
  136. $state.go('app.tool.offlineTask', {
  137. searchKey: response.data.payload
  138. });
  139. }, function (response) {
  140. toaster.pop("error", "提示", "保存失败!");
  141. });
  142. }
  143. $scope.modelEvent = {
  144. //根据条件搜索粉丝详情
  145. searchDetail: function () {
  146. //重新加载 折线图
  147. loadChartData();
  148. },
  149. startTimeOpen: false,
  150. endTimeOpen: false,
  151. timeChange: function (passDay) {
  152. $scope.modelEvent.startTimeOpen = false;
  153. $scope.modelEvent.endTimeOpen = false;
  154. },
  155. quickTime: function (evt, passDay) {
  156. $scope.chartCondition.startTime = moment().add(-(passDay - 1), "day").format("YYYY-MM-DD");
  157. $scope.chartCondition.endTime = moment().format("YYYY-MM-DD");
  158. },
  159. };
  160. $scope.powerModelEvent = {
  161. //根据条件搜索粉丝详情
  162. searchDetail: function () {
  163. //重新加载 折线图
  164. loadPowerChartData();
  165. },
  166. startTimeOpen: false,
  167. endTimeOpen: false,
  168. timeChange: function (passDay) {
  169. $scope.powerModelEvent.startTimeOpen = false;
  170. $scope.powerModelEvent.endTimeOpen = false;
  171. },
  172. quickTime: function (evt, passDay) {
  173. $scope.powerChartCondition.startTime = moment().add(-(passDay - 1), "day").format("YYYY-MM-DD");
  174. $scope.powerChartCondition.endTime = moment().format("YYYY-MM-DD");
  175. },
  176. };
  177. function setColumnDefs() {
  178. $scope.gridOptions.columnDefs = [
  179. {
  180. field: 'oper', displayName: '查看',
  181. width: 230,
  182. enableFiltering: false,
  183. enableSorting: false,
  184. enableHiding: false,//禁止在列选择器中隐藏
  185. enableColumnMenu: false,// 是否显示列头部菜单按钮
  186. cellTemplate: '<div class="grid-button">' +
  187. '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.showChart(row.entity)"><i class="iconfont icon-wifi" style="font-size: 12px"></i> 信号</button>' +
  188. '<button class="btn btn-sm btn-rounded btn-info" ng-if="row.entity.supportPG" ng-click="grid.appScope.showPowerChart(row.entity)"><i class="iconfont icon-voltage" style="font-size: 12px"></i> 功率</button>' +
  189. '<button class="btn btn-sm btn-rounded btn-success" ng-click="grid.appScope.queryChargeRecord(row.entity)"><i class="iconfont icon-recharge" style="font-size: 12px"></i> 续费记录</button>' +
  190. '</div>'
  191. },
  192. {
  193. field: 'logicalCode',
  194. displayName: '逻辑编号',
  195. width: 80,
  196. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showDevDetailInfo(\'设备详细信息\',row.entity)" >{{row.entity.logicalCode}}</div>'
  197. },
  198. {
  199. field: 'devNo',
  200. displayName: '设备编号',
  201. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showDevDetailInfo(\'设备详细信息\',row.entity)" >{{row.entity.devNo}}</div>'
  202. },
  203. {
  204. field: 'devTypeCode',
  205. displayName: '设备Code',
  206. cellTemplate: '<div class="temp-row" >{{row.entity.devType.code}}</div>'
  207. },
  208. {
  209. field: 'simStatus',
  210. displayName: 'sim卡状态',
  211. },
  212. {
  213. field: 'owner',
  214. displayName: '经销商',
  215. width: 140,
  216. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showDevOwnerInfo(\'设备属主信息\',row.entity)" >{{row.entity.dealer.nickname + " " + row.entity.dealer.username}}</div>'
  217. },
  218. {
  219. field: 'softVer',
  220. displayName: '软件版本',
  221. width: 60
  222. },
  223. {
  224. field: 'hwVer',
  225. displayName: '硬件版本',
  226. width: 60
  227. },
  228. {
  229. field: 'coreVer',
  230. displayName: '核心版本',
  231. width: 60,
  232. },
  233. {
  234. field: 'driverCode',
  235. displayName: '驱动编码',
  236. width: 60,
  237. },
  238. {
  239. field: 'online',
  240. displayName: '在线状态',
  241. width: 80,
  242. cellTemplate: '<div class="temp-row" ng-class="{\'text-success\':row.entity.online==1}" ng-bind="(row.entity.online==1)?\'在线(\' + row.entity.signal + \')\':\'离线(\'+row.entity.signal + \')\'"></div>'
  243. },
  244. {
  245. field: 'lastOffTime', displayName: '最近离线时间',
  246. cellTemplate: '<div class="temp-row" ng-bind="row.entity.lastOffTime?(row.entity.lastOffTime| date:\'yyyy-MM-dd HH:mm:ss\'):\'无\'"></div>',
  247. width: 140
  248. },
  249. {
  250. field: 'registered',
  251. displayName: '注册状态',
  252. width: 80,
  253. cellTemplate: '<div class="temp-row" ng-class="{\'text-success\':row.entity.registered!=false,\'text-danger\':row.entity.registered==false}">{{row.entity.registered==false?"未注册":"已注册"}}</div>'
  254. },
  255. {
  256. field: 'createdTime',
  257. displayName: '注册时间',
  258. width: 140,
  259. },
  260. {
  261. field: 'iccid',
  262. displayName: 'ICCID',
  263. width: 120,
  264. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showSimCard(row.entity.iccid)" >{{row.entity.iccid}}</div>'
  265. },
  266. {
  267. field: 'simExpireDate',
  268. displayName: '过期时间',
  269. width: 140,
  270. },
  271. {
  272. field: 'server',
  273. displayName: '服务器',
  274. width: 140,
  275. },
  276. {
  277. field: 'oper',
  278. displayName: '操作',
  279. enableFiltering: false,
  280. enableSorting: false,
  281. enableHiding: false,//禁止在列选择器中隐藏
  282. enableColumnMenu: false,// 是否显示列头部菜单按钮
  283. width: 480,
  284. cellTemplate: '<div class="grid-button">' +
  285. '<button class="btn btn-sm btn-rounded btn-success" ng-click="grid.appScope.getQRCode(row.entity)"><i class="fa fa-qrcode"></i>二维码</button>' +
  286. '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.unbindDevice(row.entity)" ng-disabled="row.entity.registered==false"><i class="fa fa-trash-o"></i>解绑</button>' +
  287. '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.cleanCache(row.entity)"><i class="fa fa-trash-o"></i>清理缓存</button>' +
  288. '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.setDebugFlag(row.entity)"><i class="fa fa-flag"></i>调试标记</button>' +
  289. '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.sendCommand(row.entity)"><i class="fa fa-file-code-o"></i> 指令</button>' +
  290. '<button class="btn btn-sm btn-rounded btn-success" ng-click="grid.appScope.leaseDev(row.entity)"><i class="fa fa-bullhorn"></i>出租设备</button>' +
  291. '</div>'
  292. },
  293. ];
  294. var fields = $scope.gridOptions.columnDefs;
  295. for (var index in fields) {
  296. var item = fields[index];
  297. if (item && item['minWidth'] == null) {
  298. item['minWidth'] = 100;
  299. }
  300. }
  301. }
  302. $scope.setPagingData = function (data) {
  303. var pagedData = data.data.dataList;
  304. $scope.myData = pagedData;
  305. $scope.gridOptions.totalItems = data.data.total;
  306. };
  307. $scope.getPagedDataAsync = function (curPage, pageSize, force) {
  308. if ($scope.gridOptionsLoading) {
  309. return;
  310. }
  311. var params = {
  312. pageSize: pageSize,
  313. pageIndex: curPage,
  314. };
  315. if (condition.registered.value !== '') {
  316. params.registered = condition.registered.value
  317. }
  318. if (condition.online.value !== '') {
  319. params.online = condition.online.value
  320. }
  321. if (condition.logicalCode !== "") {
  322. params.logicalCode = condition.logicalCode
  323. }
  324. if (condition.searchKey !== "") {
  325. params.searchKey = condition.searchKey
  326. }
  327. if (dealerId) {
  328. params.dealerId = dealerId;
  329. }
  330. if (agentId) {
  331. params.agentId = agentId;
  332. }
  333. if (managerId) {
  334. params.managerId = managerId;
  335. }
  336. // 如果没有条件,则不查询,因为数据量太大,加载太卡!
  337. if (force) {
  338. // nothing
  339. } else if (!params.dealerId && !params.agentId && !params.managerId && !params.logicalCode && !params.searchKey) {
  340. toaster.pop("info", "温馨提示", "请输入查询条件进行查询");
  341. return
  342. }
  343. // 批量查询时候的条件
  344. var logicalCodeList = getLogicalList($scope.condition.fileContent)
  345. if (logicalCodeList.length > 0) {
  346. params.logicalCodeList = logicalCodeList
  347. }
  348. $scope.queryCache = params;
  349. $scope.gridOptionsLoading = true;
  350. $http.get('/superadmin/getDeviceDetailList', {
  351. params: params
  352. }).then(function (data) {
  353. data = data.data
  354. $scope.gridOptionsLoading = false;
  355. $scope.setPagingData(data, curPage, pageSize);
  356. }).catch(function (data) {
  357. toaster.pop("error", "提示", "获取数据列表失败");
  358. });
  359. };
  360. function initDataGrid(force) {
  361. //首次加载表格
  362. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize, force);
  363. }
  364. setColumnDefs();
  365. initDataGrid();
  366. $scope.getQRCode = function (entity) {
  367. $(".devManageMain #devQRCodePanel").modal();
  368. var currentDomain = location.protocol + "//" + location.host;
  369. var dataURL = QRCodeOptions.getQRCodeImageData({
  370. text: currentDomain + "/userLogin?l=" + entity.logicalCode,
  371. label: entity.logicalCode,
  372. // logoDom: $("#qrcodeOptPreviewLogo")[0]
  373. });
  374. $(".devManageMain #previewImg").attr({
  375. "width": 200,
  376. "height": 240,
  377. "src": dataURL
  378. });
  379. };
  380. $scope.closeQRCode = function () {
  381. $(".devManageMain #devQRCodePanel").modal('hide');
  382. };
  383. //强制解绑
  384. $scope.unbindDevice = function (entity) {
  385. $.confirm({
  386. content: '确定解绑?',
  387. buttons: {
  388. ok: {
  389. btnClass: 'btn-red',
  390. action: function () {
  391. $http({
  392. method: 'POST',
  393. url: "/superadmin/unbindDevByAdmin",
  394. data: {logicalCode: entity.logicalCode}
  395. }).then(function (response) {
  396. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  397. toaster.pop("info", "提示", "解绑成功!");
  398. }, function (response) {
  399. toaster.pop("error", "提示", "操作失败!");
  400. });
  401. }
  402. },
  403. }
  404. });
  405. };
  406. // 清理缓存
  407. $scope.cleanCache = function (entity) {
  408. $.confirm({
  409. content: '确定清理?',
  410. buttons: {
  411. ok: {
  412. btnClass: 'btn-red',
  413. action: function () {
  414. $http({
  415. method: 'POST',
  416. url: "/superadmin/device/clearCache",
  417. data: {devNo: entity.devNo}
  418. }).then(function (response) {
  419. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  420. toaster.pop("info", "提示", "清理成功!");
  421. }, function (response) {
  422. toaster.pop("error", "提示", "清理失败!");
  423. });
  424. }
  425. },
  426. }
  427. });
  428. };
  429. //设置调试标记
  430. $scope.setDebugFlag = function (entity) {
  431. $(".devManageMain #deviceDebugPanel").modal();
  432. $scope.devNo = entity.devNo;
  433. };
  434. var dialogData = $scope.dialogData = {};
  435. $scope.devNo = "";
  436. //发送指令
  437. $scope.sendCommand = function (entity) {
  438. $scope.commandInfoPanel.$setPristine();
  439. $scope.commandInfoPanel.$setUntouched();
  440. $scope.devNo = entity.devNo;
  441. $http.get('/superadmin/getCommandByDevice', {
  442. params: {logicalCode: entity.logicalCode}
  443. }).then(function (data) {
  444. data = data.data
  445. if (data.result == 1) {
  446. dialogData.commandList = data.payload.dataList
  447. $scope.currentCmdIndex = -1
  448. $scope.currentCmd = null;
  449. }
  450. }).catch(function (data) {
  451. toaster.pop("error", "提示", "获取常用命令列表失败");
  452. });
  453. $(".devManageMain #commandInfoPanel").modal();
  454. };
  455. $scope.selectCommand = function (index, item) {
  456. $scope.currentCmdIndex = index
  457. $scope.currentCmd = item;
  458. };
  459. $scope.sendCommandConfirm = function () {
  460. if ($scope.commandInfoPanel.$invalid) {
  461. return;
  462. }
  463. var currentCmd = $scope.currentCmd
  464. if (!$scope.currentCmd.id) {
  465. toaster.pop("info", "提示", "请选择指令!");
  466. return
  467. }
  468. var params = []
  469. for (var index in currentCmd.params) {
  470. var item = currentCmd.params[index]
  471. params.push({
  472. id: item.id,
  473. default: item.default,
  474. })
  475. }
  476. $http({
  477. method: 'POST',
  478. url: '/superadmin/sendCommand',
  479. data: {id: currentCmd.id, devNo: $scope.devNo, params: params}
  480. }).then(function (response) {
  481. var data = response.data;
  482. if (data.result == 1) {
  483. toaster.pop("success", "提示", "操作成功!");
  484. $scope.currentResult = JSON.parse(data.data);
  485. }
  486. }, function (response) {
  487. toaster.pop("error", "提示", "操作失败!");
  488. });
  489. };
  490. $scope.closeCommandPanel = function () {
  491. $(".devManageMain #commandInfoPanel").modal("hide");
  492. delete dialogData.command;
  493. };
  494. $scope.leaseDev = function (entity) {
  495. $.confirm({
  496. content: '确定出租设备?',
  497. buttons: {
  498. ok: {
  499. btnClass: 'btn-red',
  500. action: function () {
  501. $http({
  502. method: 'POST',
  503. url: '/superadmin/rentDevice',
  504. data: {logicalCode: entity.logicalCode}
  505. }).then(function (response) {
  506. var data = response.data;
  507. if (data.result == 1) {
  508. toaster.pop("success", "提示", "操作成功!");
  509. }
  510. }, function () {
  511. toaster.pop("error", "提示", "操作失败!");
  512. });
  513. }
  514. },
  515. }
  516. });
  517. }
  518. $scope.sendDeviceDebugConfirm = function () {
  519. $http({
  520. method: 'POST',
  521. url: '/superadmin/device/setDebug',
  522. data: {devNo: $scope.devNo, debugFlag: dialogData.debugFlag}
  523. }).then(function (response) {
  524. $scope.devNo = "";
  525. var data = response.data;
  526. if (data.result == 1) {
  527. toaster.pop("success", "提示", "操作成功!");
  528. }
  529. }, function (response) {
  530. $scope.devNo = "";
  531. toaster.pop("error", "提示", "操作失败!");
  532. });
  533. };
  534. $scope.closeDeviceDebugPanel = function () {
  535. $(".devManageMain #deviceDebugPanel").modal("hide");
  536. delete dialogData.debugFlag;
  537. $scope.devNo = "";
  538. };
  539. //展示设备属主信息
  540. $scope.showDevOwnerInfo = function (title, content) {
  541. var owner = {
  542. dealer: content.dealer,
  543. agent: content.agent,
  544. manager: content.manager
  545. }
  546. $scope.infoDetail = {title: title, content: owner};
  547. $(".devManageMain #detailInfoPanel").modal();
  548. };
  549. //展示设备类型详情
  550. $scope.showDevTypeDetailInfo = function (title, content) {
  551. $scope.infoDetail = {title: title, content: content};
  552. $(".devManageMain #detailInfoPanel").modal();
  553. };
  554. //展示设备详情
  555. $scope.showDevDetailInfo = function (title, content) {
  556. var detail = {
  557. server: content.server,
  558. softVer: content.softVer,
  559. hwVer: content.hwVer,
  560. coreVer: content.coreVer,
  561. driverVersion: content.driverVersion,
  562. cycle: content.cycle,
  563. washConfig: content.washConfig,
  564. pulseInterval1: content.pulseInterval1,
  565. remarks: content.remarks,
  566. battery: content.battery,
  567. groupId: content.groupId,
  568. groupName: content.groupName,
  569. address: content.address,
  570. pulseWidth1: content.pulseWidth1,
  571. mcuVersion: content.mcuVersion,
  572. boardValid: content.boardValid,
  573. simStatus: content.simStatus,
  574. dateTimeBinded: content.dateTimeBinded,
  575. }
  576. $scope.infoDetail = {title: title, content: detail};
  577. $(".devManageMain #detailInfoPanel").modal();
  578. };
  579. //显示SIM卡信息
  580. $scope.showSimCard = function (iccid) {
  581. $http.get('/superadmin/sim/get', {
  582. params: {iccid: iccid}
  583. }).then(function (data) {
  584. data = data.data
  585. if (data.result == 1) {
  586. $scope.infoDetail = {title: 'SIM详细信息', content: data.payload};
  587. $(".devManageMain #detailInfoPanel").modal();
  588. }
  589. }).catch(function () {
  590. toaster.pop("error", "提示", "获取SIM卡信息失败");
  591. });
  592. };
  593. $scope.closeDetailPanel = function () {
  594. $(".devManageMain #detailInfoPanel").modal("hide");
  595. };
  596. // 信号趋势图
  597. var chartCondition = $scope.chartCondition = {
  598. "logicalCode": null,
  599. startTime: moment().format("YYYY-MM-DD"),
  600. endTime: moment().format("YYYY-MM-DD")
  601. };
  602. var signalChartPanel;
  603. $scope.showChart = function (entity, type) {
  604. $("#chartInfoPanel").modal();
  605. chartCondition.logicalCode = entity.logicalCode;
  606. //展示趋势图
  607. signalChartPanel = echarts.init(document.getElementById('signalChartPanel')); //resize事件绑定
  608. $(window).off("resize.signalChartPanel").on("resize.signalChartPanel", function () {
  609. signalChartPanel.resize();
  610. });
  611. loadChartData();
  612. };
  613. $scope.closeChart = function () {
  614. $("#chartInfoPanel").modal('hide');
  615. };
  616. $scope.closeChart = function () {
  617. $("#chartInfoPanel").modal('hide');
  618. };
  619. var loadChartData = $scope.loadChartData = function () {
  620. var params = chartCondition;
  621. let url = '/superadmin/getSignalTrendByDevice'
  622. //获取数据
  623. $http.get(url, {
  624. params: {
  625. logicalCode: params.logicalCode,
  626. startTime: params.startTime + ' 00:00:00',
  627. endTime: params.endTime + ' 23:59:59',
  628. }
  629. }).then(function (data) {
  630. var payload = data.data.payload
  631. var option = signalChartOption(payload.dataList);
  632. signalChartPanel.setOption(option);
  633. });
  634. };
  635. function signalChartOption(dataList) {
  636. var xData = [];
  637. var seriesData = [];
  638. function getColor(v) {
  639. if (v > 8 && v <= 20) {
  640. return '#FFC000'
  641. } else if (v > 20) {
  642. return '#07C160'
  643. } else {
  644. return '#ED6066'
  645. }
  646. }
  647. var min = 31;
  648. var max = 0;
  649. for (var index in dataList) {
  650. var item = dataList[index]
  651. xData.push(moment(item.dateStr).format("MM-DD HH:mm:ss"));
  652. seriesData.push(parseFloat(item.signal));
  653. if (min > item.signal) {
  654. min = item.signal
  655. }
  656. if (max < item.signal) {
  657. max = item.signal
  658. }
  659. }
  660. var option = {
  661. legend: {
  662. show: false
  663. },
  664. tooltip: {
  665. trigger: 'axis',
  666. axisPointer: {
  667. lineStyle: {
  668. color: '#108EE9',
  669. width: .3,
  670. }
  671. }
  672. },
  673. grid: {
  674. x: 40,
  675. x2: 15,
  676. y: 45,
  677. y2: 40,
  678. },
  679. xAxis: [
  680. {
  681. type: 'category',
  682. axisLabel: {
  683. textStyle: {
  684. color: "#aaa",
  685. fontSize: "12px"
  686. }
  687. },
  688. axisTick: {
  689. show: false,
  690. },
  691. axisLine: {
  692. show: false,
  693. },
  694. data: xData
  695. }
  696. ],
  697. yAxis: [
  698. {
  699. type: 'value',
  700. axisLabel: {
  701. textStyle: {
  702. color: "#aaa",
  703. fontSize: "12px"
  704. }
  705. },
  706. axisTick: {
  707. show: false,
  708. },
  709. axisLine: {
  710. show: false,
  711. },
  712. splitLine: {
  713. lineStyle: {
  714. color: '#ccc',
  715. width: 0.3,
  716. type: 'dotted'
  717. }
  718. },
  719. },
  720. ],
  721. series: []
  722. };
  723. option.yAxis[0].max = 31
  724. option.visualMap = {
  725. show: false,
  726. pieces: [{
  727. gt: 0,
  728. lte: 8,
  729. color: '#ED6066'
  730. }, {
  731. gt: 8,
  732. lte: 20,
  733. color: '#FFC000'
  734. }, {
  735. gt: 20,
  736. lte: 31,
  737. color: '#07C160'
  738. }]
  739. }
  740. option.series.push({
  741. name: '信号',
  742. stack: '信号',
  743. type: 'line',
  744. symbolSize: 0,
  745. markPoint: {
  746. data: [
  747. {type: 'max', name: '信号最强', itemStyle: {color: getColor(max)}},
  748. {
  749. type: 'min',
  750. name: '信号最差',
  751. symbolRotate: 180,
  752. label: {position: 'insideBottom', distance: 8},
  753. itemStyle: {color: getColor(min)}
  754. }
  755. ]
  756. },
  757. itemStyle: {
  758. normal: {
  759. color: "rgba(244,81,108,0.8)",
  760. }
  761. },
  762. data: seriesData,
  763. });
  764. return option
  765. }
  766. // 功率趋势图
  767. var powerChartCondition = $scope.powerChartCondition = {
  768. "logicalCode": null,
  769. "port": null,
  770. startTime: moment().format("YYYY-MM-DD"),
  771. endTime: moment().format("YYYY-MM-DD")
  772. };
  773. var powerChartPanel;
  774. $scope.showPowerChart = function (entity) {
  775. $("#powerChartInfoPanel").modal();
  776. powerChartCondition.logicalCode = entity.logicalCode;
  777. powerChartCondition.port = entity.port;
  778. //展示趋势图
  779. powerChartPanel = echarts.init(document.getElementById('powerChartPanel')); //resize事件绑定
  780. $(window).off("resize.powerChartPanel").on("resize.powerChartPanel", function () {
  781. powerChartPanel.resize();
  782. });
  783. loadPowerChartData();
  784. };
  785. $scope.closePowerChart = function () {
  786. $("#powerChartInfoPanel").modal('hide');
  787. };
  788. var loadPowerChartData = $scope.loadPowerChartData = function () {
  789. var params = powerChartCondition;
  790. let url = '/common/getPowerGraph'
  791. //获取数据
  792. $http.get(url, {
  793. params: {
  794. logicalCode: params.logicalCode,
  795. port: params.port,
  796. startTime: params.startTime + ' 00:00:00',
  797. endTime: params.endTime + ' 23:59:59',
  798. }
  799. }).then(function (data) {
  800. var payload = data.data.payload
  801. var option = powerChartOption(payload.dataList);
  802. powerChartPanel.setOption(option);
  803. });
  804. };
  805. function powerChartOption(dataList) {
  806. var xData = [];
  807. var seriesData = [];
  808. for (var index in dataList) {
  809. var item = dataList[index]
  810. xData.push(moment(item.dateStr).format("MM-DD HH:mm:ss"));
  811. seriesData.push(parseFloat(item.power));
  812. }
  813. var option = {
  814. legend: {
  815. show: false
  816. },
  817. tooltip: {
  818. trigger: 'axis',
  819. axisPointer: {
  820. lineStyle: {
  821. color: '#108EE9',
  822. width: .3,
  823. }
  824. }
  825. },
  826. grid: {
  827. x: 40,
  828. x2: 15,
  829. y: 45,
  830. y2: 40,
  831. },
  832. xAxis: [
  833. {
  834. type: 'category',
  835. axisLabel: {
  836. textStyle: {
  837. color: "#aaa",
  838. fontSize: "12px"
  839. }
  840. },
  841. axisTick: {
  842. show: false,
  843. },
  844. axisLine: {
  845. show: false,
  846. },
  847. data: xData
  848. }
  849. ],
  850. yAxis: [
  851. {
  852. type: 'value',
  853. axisLabel: {
  854. textStyle: {
  855. color: "#aaa",
  856. fontSize: "12px"
  857. }
  858. },
  859. axisTick: {
  860. show: false,
  861. },
  862. axisLine: {
  863. show: false,
  864. },
  865. splitLine: {
  866. lineStyle: {
  867. color: '#ccc',
  868. width: 0.3,
  869. type: 'dotted'
  870. }
  871. },
  872. },
  873. ],
  874. series: []
  875. };
  876. option.series.push({
  877. name: '功率',
  878. stack: '功率',
  879. type: 'line',
  880. symbolSize: 0,
  881. itemStyle: {
  882. normal: {
  883. color: "rgba(244,81,108,0.8)",
  884. }
  885. },
  886. data: seriesData,
  887. });
  888. return option
  889. }
  890. // 续费记录
  891. $scope.chargeRecord = [];
  892. // 查询记录
  893. $scope.queryChargeRecord = function (entity) {
  894. $scope.chargeRecord = entity.chargeRecord || []
  895. $("#chargeRecordForm").modal();
  896. }
  897. function getSelectRows() {
  898. var rows = $scope.gridApi.selection.getSelectedRows();
  899. if (rows.length === 0) {
  900. toaster.pop("info", "提示", "请选择数据!");
  901. return false;
  902. }
  903. var ids = [];
  904. for (var i = 0; i < rows.length; i++) {
  905. ids.push(rows[i].logicalCode);
  906. }
  907. $scope.selectedIds = ids;
  908. return ids
  909. }
  910. $scope.manualRechargeSimCard = function () {
  911. var ids = getSelectRows()
  912. if (!ids) {
  913. return
  914. }
  915. $.confirm({
  916. content: '您选择的设备为 ' + ids + ' ,确认手动续费?',
  917. buttons: {
  918. ok: {
  919. btnClass: 'btn-red',
  920. action: function () {
  921. $http({
  922. method: 'POST',
  923. url: '/superadmin/manualRechargeSimCard',
  924. data: {logicalCode: ids}
  925. }).then(function (response) {
  926. initDataGrid();
  927. }, function (response) {
  928. toaster.pop("error", "提示", "续费失败!");
  929. });
  930. }
  931. },
  932. }
  933. });
  934. }
  935. $scope.lockDeviceSimStatus = function () {
  936. var ids = getSelectRows()
  937. if (!ids) {
  938. return
  939. }
  940. $.confirm({
  941. content: '您选择的设备为 ' + ids + ' ,确认操作?',
  942. buttons: {
  943. ok: {
  944. btnClass: 'btn-red',
  945. text: '锁定',
  946. action: function () {
  947. $http({
  948. method: 'POST',
  949. url: '/superadmin/lockDeviceSimStatus',
  950. data: {logicalCode: ids}
  951. }).then(function (response) {
  952. initDataGrid(true);
  953. toaster.pop("success", "提示", "锁定成功!");
  954. }, function (response) {
  955. toaster.pop("error", "提示", "锁定失败!");
  956. });
  957. }
  958. },
  959. unlock: {
  960. btnClass: 'btn-green',
  961. text: '解锁',
  962. action: function () {
  963. $http({
  964. method: 'POST',
  965. url: '/superadmin/unlockDeviceSimStatus',
  966. data: {logicalCode: ids}
  967. }).then(function (response) {
  968. initDataGrid(true);
  969. toaster.pop("success", "提示", "解锁成功!");
  970. }, function (response) {
  971. toaster.pop("error", "提示", "解锁失败!");
  972. });
  973. }
  974. },
  975. close: {
  976. isHidden: true
  977. },
  978. }
  979. });
  980. }
  981. $scope.changeDevCode = function (entity) {
  982. $scope.changeDevCodeForm.$setPristine();
  983. $scope.changeDevCodeForm.$setUntouched();
  984. var ids = getSelectRows()
  985. if (!ids) {
  986. return
  987. }
  988. $scope.dialogData = {logicalCodeList: ids};
  989. $("#changeDevCodeForm").modal();
  990. }
  991. $scope.changeDevCodeSave = function () {
  992. if ($scope.changeDevCodeForm.$invalid) {
  993. return;
  994. }
  995. $.confirm({
  996. content: '您选择的设备为 ' + $scope.dialogData.logicalCodeList + ' ,确认修改Code?',
  997. buttons: {
  998. ok: {
  999. btnClass: 'btn-red',
  1000. action: function () {
  1001. $http({
  1002. method: 'POST',
  1003. url: '/superadmin/modifyDeviceCode',
  1004. data: {
  1005. logicalCodeList: $scope.dialogData.logicalCodeList,
  1006. code: $scope.dialogData.code
  1007. }
  1008. }).then(function (response) {
  1009. console.log(response.data.description, response.data.payload)
  1010. toaster.pop("success", "提示", response.data.description);
  1011. $('#changeDevCodeForm').modal('hide');
  1012. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  1013. }, function (response) {
  1014. toaster.pop("error", "提示", "修改Code失败!");
  1015. });
  1016. }
  1017. },
  1018. }
  1019. });
  1020. }
  1021. $scope.serviceSwitch = function (key, value) {
  1022. var ids = getSelectRows()
  1023. if (!ids) {
  1024. return
  1025. }
  1026. let data = {
  1027. logicalCode: ids,
  1028. }
  1029. data[key] = value
  1030. $.confirm({
  1031. content: '您选择的设备为 ' + ids + ' ,确认操作?',
  1032. buttons: {
  1033. ok: {
  1034. btnClass: 'btn-red',
  1035. action: function () {
  1036. $http({
  1037. method: 'POST',
  1038. url: '/superadmin/setServiceButtonStatus',
  1039. data: data
  1040. }).then(function (response) {
  1041. toaster.pop("success", "提示", '操作成功');
  1042. }, function (response) {
  1043. toaster.pop("error", "提示", "操作失败!");
  1044. });
  1045. }
  1046. },
  1047. }
  1048. });
  1049. }
  1050. }]);