devManage.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. angular.module('app')
  2. .directive('devManage', ['$filter', '$http', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'QRCodeOptions', '$rootScope', '$localStorage', function ($filter, $http, $stateParams, $timeout, uiGridConstants, i18nService, toaster, QRCodeOptions, $rootScope, $localStorage) {
  3. return {
  4. restrict: 'AEC',
  5. templateUrl: 'js/directives/tpl/devManage.html',
  6. // 独立作用域,并暴露配置属性
  7. scope: {},
  8. link: function ($scope, el, attrs) {
  9. i18nService.setCurrentLang("zh-cn");//汉化
  10. moment.locale('zh-cn');
  11. var dealerId = "";
  12. var searchKey = "";
  13. function initDevList() {
  14. //可能是由路由跳转,则获取url参数
  15. if ($stateParams.dealerId) {
  16. $scope.dealerId = dealerId = $stateParams.dealerId;
  17. }
  18. if ($stateParams.searchKey) {
  19. searchKey = $stateParams.searchKey;
  20. }
  21. // 更新查询条件到界面
  22. condition.searchKey = searchKey;
  23. setColumnDefs();
  24. initDataGrid();
  25. }
  26. $scope.$on('initDevList', function (evt, data) {
  27. //先获取广播参数
  28. if (data && data.dealerId) {
  29. $scope.dealerId = dealerId = data.dealerId;
  30. }
  31. if (data && data.searchKey) {
  32. searchKey = data.searchKey || "";
  33. }
  34. initDevList();
  35. });
  36. $scope.gridOptions = {
  37. data: 'myData',
  38. showGridFooter: true, //是否显示grid footer
  39. // rowHeight: 80,
  40. //-------- 分页属性 ----------------
  41. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  42. paginationCurrentPage: 1, //当前页码
  43. paginationPageSize: 10, //每页显示个数
  44. totalItems: 0,// 总数量
  45. useExternalPagination: true,//是否使用分页按钮
  46. //过滤
  47. // enableFiltering: true,
  48. columnDefs: [],
  49. //---------------api---------------------
  50. onRegisterApi: function (gridApi) {
  51. $scope.gridApi = gridApi;
  52. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  53. if ($scope.setPagingData) {
  54. $scope.getPagedDataAsync(newPage, pageSize);
  55. }
  56. });
  57. }
  58. };
  59. //查询条件
  60. var condition = $scope.condition = {
  61. searchKey: searchKey,
  62. startLogicalCode: '',
  63. endLogicalCode: '',
  64. };
  65. //枚举常量
  66. $scope.enum = {};
  67. //事件
  68. $scope.event = {
  69. search: function () {
  70. dealerId = "";//清空跳转带入的条件
  71. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  72. }
  73. };
  74. //截止日期选择
  75. $scope.dateOptions = {
  76. formatYear: 'yy',
  77. startingDay: 1,
  78. class: 'datepicker'
  79. };
  80. $scope.expireDate = null;
  81. $scope.format = 'yyyy-MM-dd';
  82. $scope.minDate = new Date();
  83. var maxDate = new Date();
  84. $scope.maxDate = maxDate.setFullYear(maxDate.getFullYear() + 10);
  85. $scope.opened = true;
  86. $scope.open = function ($event) {
  87. $event.preventDefault();
  88. $event.stopPropagation();
  89. $scope.opened = true;
  90. };
  91. function setColumnDefs() {
  92. var cols = $scope.gridOptions.columnDefs = [
  93. {field: 'logicalCode', displayName: '逻辑编号'},
  94. {field: 'devType', displayName: '设备类型'},
  95. {
  96. field: 'imei',
  97. displayName: '电子标签',
  98. minWidth: 160,
  99. cellTemplate: '<div class="temp-row" title="{{row.entity.imei}}" ng-bind="row.entity.imei"></div>'
  100. },
  101. {
  102. field: 'createdTime',
  103. displayName: '注册时间',
  104. width: 160,
  105. cellTemplate: '<div class="temp-row" ng-bind="row.entity.createdTime| date:\'yyyy-MM-dd HH:mm:ss\'"></div>'
  106. },
  107. {
  108. field: 'dealerName',
  109. displayName: '商户',
  110. minWidth: 160,
  111. cellTemplate: '<div class="temp-row" title="{{row.entity.dealerName}}" ng-bind="row.entity.dealerName"></div>'
  112. },
  113. {
  114. field: 'address',
  115. displayName: '设备地址',
  116. minWidth: 160,
  117. cellTemplate: '<div class="temp-row" title="{{row.entity.address}}" ng-bind="row.entity.address"></div>'
  118. },
  119. {
  120. field: 'serverAddress',
  121. displayName: '服务器',
  122. },
  123. {
  124. field: 'online', displayName: '设备状态',
  125. cellTemplate: '<div class="temp-row" ng-class="{\'text-dark\':row.entity.online==\'离线\',\'text-success\':row.entity.online==\'在线\'}" >{{row.entity.online}}</div>'
  126. },
  127. {
  128. field: 'lastOffTime', displayName: '最近离线时间',
  129. cellTemplate: '<div class="temp-row" ng-bind="row.entity.lastOffTime?(row.entity.lastOffTime| date:\'yyyy-MM-dd HH:mm:ss\'):\'无\'"></div>',
  130. width: 160
  131. },
  132. {
  133. field: 'signal', displayName: '信号',
  134. cellTemplate: '<div class="temp-row iconfont text-success" ng-click="grid.appScope.refreshSignal(row.entity)" style="cursor: pointer" ng-class="{' +
  135. '\'icon-refresh text-dark\':row.entity.signal==0,' +
  136. '\'icon-xinhao1\':row.entity.signal>0&&row.entity.signal<=6,' +
  137. '\'icon-xinhao2\':row.entity.signal>7&&row.entity.signal<=12,' +
  138. '\'icon-xinhao3\':row.entity.signal>13&&row.entity.signal<=18,' +
  139. '\'icon-xinhao4\':row.entity.signal>19&&row.entity.signal<=24,' +
  140. '\'icon-xinhao5\':row.entity.signal>24' +
  141. '}" ></div>'
  142. },
  143. {
  144. field: 'detail', displayName: '详细信息',
  145. cellTemplate: '<div class="temp-row" ng-click="grid.appScope.showInfoDetail(\'详细信息\',row.entity)" >{{row.entity.detail}}</div>'
  146. }
  147. ];
  148. var feature_map = $scope.feature_map = $localStorage.feature_map
  149. if (feature_map && feature_map.disableDevice) {
  150. cols.push(
  151. {
  152. field: 'disableDevice', displayName: '禁用状态',
  153. cellTemplate: '<div class="temp-row" >{{row.entity.disableDevice?\'已禁用\':\'已启用\'}}</div>'
  154. }
  155. )
  156. }
  157. cols.push({
  158. field: 'oper', displayName: '操作',
  159. enableFiltering: false,
  160. enableSorting: false,
  161. enableHiding: false,//禁止在列选择器中隐藏
  162. enableColumnMenu: false,// 是否显示列头部菜单按钮
  163. width: 450,
  164. cellTemplate: '<div class="grid-button">' +
  165. '<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>' +
  166. '<button class="btn btn-sm btn-rounded btn-info" ng-click="grid.appScope.onOpenPort(row.entity)"><i class="fa fa-file-code-o"></i> 端口信息</button>' +
  167. '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.code==100500" ng-click="grid.appScope.openDeviceFunctionParam(row.entity)"><i class="fa fa-gear"></i> 参数</button>' +
  168. '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.code==100210" ng-click="grid.appScope.showRealtimeData(row.entity)"><i class="fa fa-eye"></i> 数据监控</button>' +
  169. ((feature_map && feature_map.disableDevice) ? ('<button class="btn btn-sm btn-rounded " ng-class="{\'btn-info\':row.entity.disableDevice,\'btn-danger\':!row.entity.disableDevice}" ng-click="grid.appScope.disableDeviceToggle(row.entity)"><i class="fa fa-wrench"></i> {{row.entity.disableDevice?\'启用\':\'禁用\'}}</button>') : ('')) +
  170. '<button class="btn btn-sm btn-rounded btn-success" ng-click="grid.appScope.getQRCode(row.entity)"><i class="fa fa-qrcode"></i> 二维码</button>' +
  171. '</div>'
  172. })
  173. var fields = $scope.gridOptions.columnDefs;
  174. for (var index in fields) {
  175. var item = fields[index];
  176. if (item && item['minWidth'] == null) {
  177. item['minWidth'] = 100;
  178. }
  179. }
  180. }
  181. $scope.refreshSignal = function (entity) {
  182. $http.get('/device/sendSignal', {
  183. params: {logicalCode: entity.logicalCode}
  184. }).then(function (data) {
  185. data = data.data
  186. if (data.result == 1) {
  187. var signal = data.para;
  188. entity.signal = signal;
  189. if (entity.signal == 0) {
  190. toaster.pop("info", "设备离线!");
  191. }
  192. }
  193. }).catch(function (data) {
  194. toaster.pop("error", "提示", "操作失败!");
  195. });
  196. };
  197. $scope.setPagingData = function (data, curPage, pageSize) {
  198. var firstRow = (curPage - 1) * pageSize;
  199. var pagedData = data.data.dataList;
  200. $scope.myData = pagedData;
  201. $scope.gridOptions.totalItems = data.data.total;
  202. };
  203. $scope.getPagedDataAsync = function (curPage, pageSize) {
  204. if ($scope.gridOptionsLoading) {
  205. return;
  206. }
  207. var params = {
  208. pageSize: pageSize,
  209. pageIndex: curPage
  210. };
  211. if (condition.searchKey != "") {
  212. params.searchKey = condition.searchKey
  213. }
  214. if (condition.startLogicalCode != "") {
  215. params.startLogicalCode = condition.startLogicalCode
  216. }
  217. if (condition.endLogicalCode != "") {
  218. params.endLogicalCode = condition.endLogicalCode
  219. }
  220. if (dealerId) {
  221. params.dealerId = dealerId;
  222. }
  223. $scope.gridOptionsLoading = true;
  224. $http.get('/manager/getDevDetailList', {
  225. params: params
  226. }).then(function (data) {
  227. data = data.data
  228. $scope.gridOptionsLoading = false;
  229. $scope.setPagingData(data, curPage, pageSize);
  230. setTimeout(function () {
  231. $(window).trigger("resize");
  232. }, 50);
  233. }).catch(function (data) {
  234. toaster.pop("error", "提示", "获取数据列表失败");
  235. });
  236. };
  237. function initDataGrid() {
  238. //首次加载表格
  239. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  240. }
  241. if (attrs.autoInit !== "false") {
  242. initDevList();
  243. }
  244. //展示详情
  245. $scope.showInfoDetail = function (title, content) {
  246. var data = $.extend(true, {}, JSON.parse(content.detail))
  247. $scope.infoDetail = {
  248. title: title,
  249. content: data
  250. };
  251. $(".devManageMain #detailInfoPanel").modal();
  252. };
  253. $scope.closeDetailInfoPanel = function () {
  254. $(".devManageMain #detailInfoPanel").modal("hide");
  255. };
  256. var dialogData = $scope.dialogData = {};
  257. //发送指令
  258. $scope.sendCommand = function (entity) {
  259. $scope.commandInfoPanel.$setPristine();
  260. $scope.commandInfoPanel.$setUntouched();
  261. $http.get('/manager/getCommandByDevice', {
  262. params: {logicalCode: entity.logicalCode}
  263. }).then(function (data) {
  264. data = data.data
  265. if (data.result == 1) {
  266. dialogData.commandList = data.payload.dataList
  267. $scope.currentCmdIndex = -1
  268. $scope.currentCmd = null;
  269. }
  270. }).catch(function (data) {
  271. toaster.pop("error", "提示", "获取常用命令列表失败");
  272. });
  273. $(".devManageMain #commandInfoPanel").modal();
  274. };
  275. $scope.selectCommand = function (index, item) {
  276. $scope.currentCmdIndex = index
  277. $scope.currentCmd = item;
  278. };
  279. //确认发送指令
  280. $scope.sendCommandConfirm = function () {
  281. if ($scope.commandInfoPanel.$invalid) {
  282. return;
  283. }
  284. var currentCmd = $scope.currentCmd
  285. if(!$scope.currentCmd.id){
  286. toaster.pop("info", "提示", "请选择指令!");
  287. return
  288. }
  289. var params = []
  290. for(var index in currentCmd.params) {
  291. var item = currentCmd.params[index]
  292. params.push({
  293. id: item.id,
  294. default: item.default,
  295. })
  296. }
  297. $http({
  298. method: 'POST',
  299. url: '/manager/sendCommand',
  300. data: {id: currentCmd.id, devNo: currentCmd.IMEI, params: params}
  301. }).then(function (response) {
  302. var data = response.data;
  303. if (data.result == 1) {
  304. toaster.pop("success", "提示", "操作成功!");
  305. $scope.currentResult = JSON.parse(data.data);
  306. }
  307. }, function (response) {
  308. toaster.pop("error", "提示", "操作失败!");
  309. });
  310. };
  311. $scope.closeCommandPanel = function () {
  312. $(".devManageMain #commandInfoPanel").modal("hide");
  313. delete dialogData.command;
  314. };
  315. // 查看端口信息
  316. $scope.portList = [];
  317. $scope.onOpenPort = function (entity) {
  318. $(".devManageMain #portInfoPanel").modal();
  319. $http.get('/device/getDevicePort', {
  320. params: {logicalCode: entity.logicalCode}
  321. }).then(function (response) {
  322. let data = response.data;
  323. let payload = data.payload;
  324. $scope.portList = payload.portList || [];
  325. }).catch(function (data) {
  326. toaster.pop("error", "提示", "获取端口信息失败!");
  327. });
  328. };
  329. $scope.closePortInfoPanel = function () {
  330. $(".devManageMain #portInfoPanel").modal("hide");
  331. };
  332. $scope.qiangStatusMap = {
  333. yes: '是',
  334. no: '否',
  335. unknow: '未知'
  336. }
  337. $scope.getPayTypeEnum = function (item, type) {
  338. // 单位后台确定
  339. var payTypeEnum = {
  340. 'mobile': '扫码付费' + (item.coins || 0),
  341. 'mobile_vcard': '虚拟卡抵扣',
  342. 'monthlyPackage': '包月卡抵扣',
  343. 'coin': '投币' + (item.coins || 0),
  344. 'card': '刷卡' + (item.coins || 0),
  345. 'serverBilling': '后台计费',
  346. 'powerBilling': '功率计费',
  347. 'postpaid': '后付费',
  348. null: "未知"
  349. }
  350. return payTypeEnum[type]
  351. }
  352. $scope.getPortStatusDom = function (status) {
  353. var statusMap = {
  354. // 这三个状态根据配置来确定是否可用
  355. idle: {
  356. name: '空闲',
  357. style: 'text-success'
  358. },
  359. busy: {
  360. name: '繁忙',
  361. style: 'text-warning'
  362. },
  363. finished: {
  364. name: '完成',
  365. style: 'text-success'
  366. },
  367. connected: {
  368. name: '连接',
  369. style: 'text-warning'
  370. },
  371. // 以下两个状态 完全不能用
  372. fault: {
  373. name: '故障',
  374. style: 'text-danger'
  375. },
  376. ban: {
  377. name: '禁用',
  378. style: 'font-4'
  379. },
  380. estop: {
  381. name: '急停状态',
  382. style: 'text-danger'
  383. },
  384. ready: {
  385. name: '就绪',
  386. style: 'text-warning'
  387. },
  388. // 0:'空闲',
  389. // 1:'繁忙',
  390. // 2:'故障',
  391. // 3:'禁用',
  392. // 4:'暂停',
  393. // 5:'已连接',
  394. // 6:'充电完成',
  395. // 7:'维护中',
  396. // 8:'预约中',
  397. 0: {
  398. name: '空闲',
  399. style: 'text-success'
  400. },
  401. 1: {
  402. name: '繁忙',
  403. style: 'text-warning'
  404. },
  405. 2: {
  406. name: '故障',
  407. style: 'text-danger'
  408. },
  409. 3: {
  410. name: '禁用',
  411. style: 'text-danger'
  412. },
  413. 4: {
  414. name: '暂停',
  415. style: 'text-warning'
  416. },
  417. 5: {
  418. name: '已连接',
  419. style: 'text-success'
  420. },
  421. 6: {
  422. name: '充电完成',
  423. style: 'text-success'
  424. },
  425. 7: {
  426. name: '维护中',
  427. style: 'text-danger'
  428. },
  429. 8: {
  430. name: '预约中',
  431. style: 'text-danger'
  432. },
  433. 10: {
  434. name: '占位状态',
  435. style: 'text-warning'
  436. },
  437. 11: {
  438. name: '急停状态',
  439. style: 'text-danger'
  440. },
  441. 12: {
  442. name: '就绪',
  443. style: 'text-success'
  444. },
  445. 13: {
  446. name: '继电器粘连',
  447. style: 'text-danger'
  448. },
  449. }
  450. var item = statusMap[status]
  451. // 普通充电桩
  452. if (item) {
  453. return "<span class='" + item.style + "'>" + item.name + "</span>"
  454. } else {
  455. return "<span class='font-4'>未知</span>"
  456. }
  457. }
  458. // 切换禁用状态
  459. $scope.disableDeviceToggle = function (entity) {
  460. $http.get('/manager/disableDevice', {
  461. params: {logicalCode: entity.logicalCode, disable: !entity.disableDevice}
  462. }).then(function (data) {
  463. data = data.data
  464. if (data.result == 1) {
  465. entity.disableDevice = !entity.disableDevice
  466. toaster.pop("success", "操作成功!");
  467. }
  468. }).catch(function (data) {
  469. toaster.pop("error", "提示", "操作失败!");
  470. });
  471. };
  472. function getSelectRows() {
  473. var rows = $scope.gridApi.selection.getSelectedRows();
  474. if (rows.length === 0) {
  475. toaster.pop("info", "提示", "请选择数据!");
  476. return false;
  477. }
  478. var ids = [];
  479. for (var i = 0; i < rows.length; i++) {
  480. ids.push(rows[i].logicalCode);
  481. }
  482. $scope.selectedIds = ids;
  483. return ids
  484. }
  485. // 禁用启用选中设备
  486. $scope.disableDeviceSelected = function (target) {
  487. var ids = getSelectRows()
  488. if (ids) {
  489. $http.post('/manager/disableSelectedDevice', {
  490. logicalCode: ids, disable: target
  491. }).then(function (data) {
  492. toaster.pop("success", "操作成功!");
  493. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  494. }).catch(function (data) {
  495. toaster.pop("error", "提示", "操作失败!");
  496. });
  497. }
  498. };
  499. // 禁用启用全部设备
  500. $scope.disableAllDevice = function (target) {
  501. $http.post('/manager/disableAllDevice', {
  502. disable: target, dealerId: $scope.dealerId
  503. }).then(function (data) {
  504. toaster.pop("success", "操作成功!");
  505. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  506. }).catch(function (data) {
  507. toaster.pop("error", "提示", "操作失败!");
  508. });
  509. };
  510. $scope.getQRCode = function (entity) {
  511. $(".devManageMain #devQRCodePanel").modal();
  512. var currentDomain = location.protocol + "//" + location.host;
  513. var dataURL = QRCodeOptions.getQRCodeImageData({
  514. text: currentDomain + "/userLogin?l=" + entity.logicalCode,
  515. label: entity.logicalCode,
  516. // logoDom: $("#qrcodeOptPreviewLogo")[0]
  517. });
  518. $(".devManageMain #previewImg").attr({
  519. "width": 200,
  520. "height": 240,
  521. "src": dataURL
  522. });
  523. };
  524. $scope.closeQRCode = function () {
  525. $(".devManageMain #devQRCodePanel").modal('hide');
  526. };
  527. /*********设备参数配置*************/
  528. //弹窗内部折叠状态
  529. $scope.devParamDialogStatus = {
  530. open1: true,
  531. open2: true,
  532. open3: true,
  533. };
  534. var logicalCode;
  535. $scope.openDeviceFunctionParam = function (entity) {
  536. //重置表单状态
  537. $scope.devParamForm.$setPristine();
  538. $scope.devParamForm.$setUntouched();
  539. logicalCode = entity.logicalCode;
  540. //目前只有沥森 100500 需要这么设置
  541. $(".devManageMain #devParamPanel").modal();
  542. $scope.devParamDialogData = {}
  543. //非沥森 待实现 todo
  544. if (entity.code != 100500) {
  545. var url = "/device/getDeviceFunction";
  546. $http({
  547. method: 'POST',
  548. url: url,
  549. data: {id: entity.id}
  550. }).then(function (response) {
  551. var data = response.data
  552. if (data.result == 1) {
  553. $scope.devParamDialogData = data.payload;
  554. }
  555. }, function (response) {
  556. toaster.pop("error", "提示", "获取失败!");
  557. });
  558. }
  559. };
  560. $scope.getDevParam = function (key) {
  561. var url = "/device/getDeviceFunctionByKey";
  562. $http({
  563. method: 'POST',
  564. url: url,
  565. data: {key: key, logicalCode: logicalCode}
  566. }).then(function (response) {
  567. var data = response.data
  568. if (data.result == 1) {
  569. $scope.devParamDialogData[key] = data.payload[key];
  570. $(".devManageMain #devParamPanel").modal();
  571. }
  572. }, function (response) {
  573. toaster.pop("error", "提示", "获取失败!");
  574. });
  575. }
  576. $scope.setDevParam = function (key) {
  577. var url = "/device/setDeviceFunctionByKey";
  578. if ($scope.devParamDialogData[key] == null || $scope.devParamDialogData[key] == '') {
  579. toaster.pop("warning", "请填写正确的数据。");
  580. return
  581. }
  582. var data = {
  583. logicalCode: logicalCode, config: {}
  584. };
  585. data.config[key] = $scope.devParamDialogData[key]
  586. $http({
  587. method: 'POST',
  588. url: url,
  589. data: data
  590. }).then(function (response) {
  591. toaster.pop("success", "提示", "设置成功!");
  592. }, function (response) {
  593. toaster.pop("error", "提示", "保存失败!");
  594. });
  595. }
  596. $scope.closeDevParam = function () {
  597. $('.devManageMain #devParamPanel').modal('hide');
  598. }
  599. /********************设备端口充电状态变化曲线*****************************/
  600. $scope.realtimeConfig = {
  601. startTimeOpen: false,
  602. endTimeOpen: false,
  603. timeChange: function () {
  604. this.startTimeOpen = false
  605. this.endTimeOpen = false
  606. }
  607. }
  608. $scope.realtimeEnity = null;
  609. $scope.realtimeCondition = {
  610. // 默认今天,后台需要 智能采样 优化性能
  611. startTime: moment().format("YYYY-MM-DD"),
  612. endTime: moment().format("YYYY-MM-DD"),
  613. port: 1,// 默认为1
  614. logicalCode: null,
  615. }
  616. $scope.portList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // 暂时写死10路
  617. $scope.realtimeConditionChange = function (port) {
  618. $scope.realtimeCondition.port = port
  619. }
  620. var showRealtimeChart = echarts.init(document.getElementById('realtimeDataChart'));
  621. $scope.showRealtimeData = function (entity) {
  622. $scope.realtimeCondition.logicalCode = entity.logicalCode
  623. $(".devManageMain #realtimeDialog").modal();
  624. $scope.loadRealtimeData();
  625. }
  626. $scope.loadRealtimeData = function () {
  627. $http.get('/manager/getDeviceRealtimeData', {
  628. params: $scope.realtimeCondition
  629. }).then(function (data) {
  630. data = data.data
  631. var payload = data.payload;
  632. var dataList = payload.dataList
  633. var option = getRealtimeDataOption(dataList, {
  634. 'voltage': {
  635. name: "电压"
  636. },
  637. 'electricity': {
  638. name: "电流"
  639. },
  640. 'temperature': {
  641. name: "温度"
  642. },
  643. })
  644. showRealtimeChart.setOption(option)
  645. showRealtimeChart.resize();
  646. }).catch(function (data) {
  647. toaster.pop("error", "提示", "获取数据列表失败");
  648. });
  649. }
  650. function getRealtimeDataOption(list, dataConfig) {
  651. var xData = [];
  652. var seriesMap = {};
  653. var markAreaData = []
  654. var prevStatus = ''
  655. var leng = list.length
  656. for (var index in list) {
  657. var item = list[index];
  658. xData.push(item.dateStr);
  659. var status = item.status
  660. // 如果发现状态值变化 或是 循环已经结束,则结束上一轮的markArea
  661. if (prevStatus !== status || index === leng - 1) {
  662. prevStatus = status
  663. // 如果发现有上一轮的 markArea 则设置其结束坐标
  664. if (markAreaItem) {
  665. markAreaItem[1].xAxis = item.dateStr
  666. }
  667. var markAreaItem = [{
  668. xAxis: item.dateStr,
  669. itemStyle: {}
  670. }, {
  671. xAxis: null
  672. }]
  673. // 繁忙标记为绿色
  674. if (status === 'busy') {
  675. markAreaItem[0].itemStyle.color = 'rgba(7,193,96,.8)'
  676. }
  677. // 故障标记为红色
  678. else if (status === 'fault') {
  679. markAreaItem[0].itemStyle.color = 'rgba(255,82,76,.8)'
  680. } else {
  681. //空闲或其他状态暂时标记为白色
  682. markAreaItem[0].itemStyle.color = '#fff'
  683. }
  684. markAreaData.push(markAreaItem)
  685. }
  686. for (var key in dataConfig) {
  687. var value = item[key];
  688. if (!seriesMap[key]) {
  689. seriesMap[key] = [];
  690. }
  691. seriesMap[key].push(value);
  692. }
  693. }
  694. var option = {
  695. tooltip: {
  696. trigger: 'axis',
  697. axisPointer: {
  698. lineStyle: {
  699. color: '#108EE9',
  700. width: .3,
  701. }
  702. }
  703. },
  704. legend: {
  705. bottom: 0,
  706. data: []
  707. },
  708. grid: {
  709. x: 20,
  710. x2: 20,
  711. y: 20,
  712. y2: 45,
  713. },
  714. xAxis: [
  715. {
  716. type: 'category',
  717. axisLabel: {
  718. textStyle: {
  719. color: "#aaa",
  720. fontSize: "12px"
  721. }
  722. },
  723. axisTick: {
  724. show: false,
  725. },
  726. axisLine: {
  727. show: false,
  728. },
  729. data: xData
  730. }
  731. ],
  732. yAxis: [
  733. {
  734. type: 'value',
  735. axisLabel: {
  736. textStyle: {
  737. color: "#aaa",
  738. fontSize: "12px"
  739. }
  740. },
  741. axisTick: {
  742. show: false,
  743. },
  744. axisLine: {
  745. show: false,
  746. },
  747. splitLine: {
  748. show: false,
  749. },
  750. },
  751. ],
  752. series: []
  753. };
  754. var legend = []
  755. var index = 0;
  756. for (var key in seriesMap) {
  757. var dataList = seriesMap[key];
  758. var serie = {
  759. name: dataConfig[key].name,
  760. smooth: true,
  761. symbolSize: 0,
  762. type: 'line',
  763. data: dataList
  764. }
  765. // 只有电压一个坐标设置 markArea ,否则重复了
  766. if (key === 'voltage') {
  767. serie.markArea = {data: markAreaData}
  768. }
  769. option.series.push(serie);
  770. legend.push(dataConfig[key].name)
  771. index++;
  772. }
  773. option.legend.data = legend
  774. return option;
  775. }
  776. /********************查看设备上投放的广告*****************************/
  777. $scope.adGridOptions = {
  778. data: 'adGridData',
  779. showGridFooter: true, //是否显示grid footer
  780. //-------- 分页属性 ----------------
  781. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  782. paginationCurrentPage: 1, //当前页码
  783. paginationPageSize: 100, //每页显示个数
  784. totalItems: 0,// 总数量
  785. useExternalPagination: true,//是否使用分页按钮
  786. //过滤
  787. enableFiltering: true,
  788. columnDefs: [],
  789. // 菜单
  790. enableGridMenu: true,
  791. //---------------api---------------------
  792. onRegisterApi: function (gridApi) {
  793. $scope.adGridApi = gridApi;
  794. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  795. if ($scope.setAdGridPagingData) {
  796. $scope.getAdGridPagedData(newPage, pageSize);
  797. }
  798. });
  799. }
  800. };
  801. function setAdGridColumnDefs() {
  802. $scope.adGridOptions.columnDefs = [
  803. {
  804. field: 'adId',
  805. displayName: '编号', cellClass: "text-center"
  806. },
  807. {field: 'name', displayName: '名称'},
  808. {field: 'word', displayName: '广告词'},
  809. {field: 'startTime', enableFiltering: false, displayName: '开始时间'},
  810. {field: 'endTime', enableFiltering: false, displayName: '结束时间'},
  811. {
  812. field: 'img',
  813. displayName: '图片',
  814. enableFiltering: false,
  815. enableSorting: false,
  816. cellTemplate: '<img ng-src="{{row.entity.img}}" class="img-circle center-block" style="max-height: 100%"/>'
  817. },
  818. {
  819. field: 'status',
  820. displayName: '状态',
  821. enableSorting: false,
  822. cellTemplate: '<span ng-if="row.entity.status==true" class="text-success ui-grid-cell-contents">在线</span><span ng-if="row.entity.status==false" class="ui-grid-cell-contents">下线</span>' +
  823. ''
  824. },
  825. ];
  826. var fields = $scope.adGridOptions.columnDefs;
  827. for (var index in fields) {
  828. var item = fields[index];
  829. if (item && item['minWidth'] == null) {
  830. item['minWidth'] = 100;
  831. }
  832. }
  833. }
  834. setAdGridColumnDefs();
  835. $scope.getAdGridPagedData = function (curPage, pageSize) {
  836. var adByLogicalCode = $scope.adByLogicalCode;
  837. if (!adByLogicalCode) {
  838. toaster.pop("error", "提示", "设备逻辑码错误");
  839. return
  840. }
  841. var params = {
  842. pageSize: pageSize,
  843. pageIndex: curPage,
  844. logicalCode: adByLogicalCode
  845. };
  846. $http.get('/ad/getDeviceAllocatedAds', {
  847. params: params
  848. }).then(function (data) {
  849. data = data.data
  850. if (data.result == 1) {
  851. $scope.setAdGridPagingData(data, curPage, pageSize);
  852. setTimeout(function () {
  853. $(window).trigger("resize");
  854. }, 100);
  855. } else {
  856. toaster.pop("error", "提示", data.description);
  857. }
  858. }).catch(function (data) {
  859. toaster.pop("error", "提示", "获取数据列表失败");
  860. });
  861. };
  862. $scope.setAdGridPagingData = function (data, curPage, pageSize) {
  863. var pagedData = data.data.dataList;
  864. $scope.adGridData = pagedData;
  865. $scope.adGridOptions.totalItems = data.data.total;
  866. };
  867. function initAdDataGrid() {
  868. $scope.getAdGridPagedData($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  869. }
  870. $scope.openAdDataGrid = function (entity) {
  871. $scope.adByLogicalCode = entity.logicalCode;
  872. $(".devManageMain #adDataGrid").modal();
  873. initAdDataGrid()
  874. }
  875. $scope.closeAdDataGrid = function () {
  876. $(".devManageMain #adDataGrid").modal('hide')
  877. }
  878. /**end***/
  879. }
  880. };
  881. }]);