consumablesCtrl.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. 'use strict';
  2. app.controller('hc_consumablesCtrl', ["$scope", "$http", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_text", "api_bpm_data", "api_user_data", "api_cmdb", "api_cmdb2", "api_cmdb3", "api_cmdb4","api_wechatfile","api_sysinfo", function($scope, $http, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_text, api_bpm_data, api_user_data, api_cmdb, api_cmdb2, api_cmdb3, api_cmdb4,api_wechatfile,api_sysinfo) {
  3. $scope.ceshi = "耗材系统";
  4. $scope.langs = i18nService.getAllLangs();
  5. $scope.lang = 'zh-cn';
  6. i18nService.setCurrentLang($scope.lang);
  7. $scope.myData = [];
  8. var loginUser = $rootScope.user;
  9. // 监听编辑在库数量
  10. $scope.$watch('hc_eject_inventoryNum', function(val, oldval) {
  11. var zhengze = /^\w{0,5}$/;
  12. if (!zhengze.exec(val)) {
  13. $scope.hc_eject_inventoryNum = oldval;
  14. }
  15. });
  16. $scope.fileData={
  17. "idx":0,
  18. "sum":10,
  19. "consumable":{}
  20. }
  21. // 监听下拉框搜索
  22. $scope.$watch('select_val.search_data', function(val) {
  23. // if (val == undefined) {
  24. // $scope.wt_data_display = true;
  25. // } else if (val.name == '全部') {
  26. // wt_data = { consumable: {} };
  27. // $scope.wt_data_display = false;
  28. // if ($scope.fenye == undefined) {
  29. // $scope.fenye = 0
  30. // };
  31. // $scope.memoryfilterData = {
  32. // idx: $scope.fenye,
  33. // sum: 10
  34. // }
  35. // //获取列表数据
  36. // $scope.refreshData = function(style, filterData) {
  37. // // var data1={idx: 0, sum: 10};
  38. // var pdKey = "consumable";
  39. // $scope.myData = [];
  40. // api_cmdb3.fetchDataList(pdKey, filterData).then(function(data) {
  41. // // console.log(data.list);
  42. // if (data.list) {
  43. // var myData = Restangular.stripRestangular(data);
  44. // var list = [];
  45. // $scope.gridOptions['totalItems'] = myData.totalNum;
  46. // $scope.myData = myData.list;
  47. // for (var i = 0; i < $scope.myData.length; i++) {
  48. // $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  49. // }
  50. // } else {
  51. // SweetAlert.swal({
  52. // title: "系统错误",
  53. // text: "请稍后再试!",
  54. // type: "error"
  55. // });
  56. // }
  57. // $scope.ldloading[style.replace('-', '_')] = false;
  58. // }, function() {
  59. // $scope.ldloading[style.replace('-', '_')] = false;
  60. // });
  61. // };
  62. // $scope.refreshData('expand-right', $scope.memoryfilterData);
  63. // } else {
  64. // wt_data = { consumable: { "name": val.name } };
  65. // $scope.wt_data_display = false;
  66. // if ($scope.fenye == undefined) {
  67. // $scope.fenye = 0
  68. // };
  69. // $scope.memoryfilterData = {
  70. // idx: $scope.fenye,
  71. // sum: 10,
  72. // consumable: { "name": val.name }
  73. // }
  74. // //获取列表数据
  75. // $scope.refreshData = function(style, filterData) {
  76. // var pdKey = "consumable";
  77. // $scope.myData = [];
  78. // // $scope.gridOptions['sum'] = filterData.sum;
  79. // api_cmdb3.fetchDataList(pdKey, filterData).then(function(data) {
  80. // // console.log(data.list);
  81. // if (data.list) {
  82. // var myData = Restangular.stripRestangular(data);
  83. // var list = [];
  84. // $scope.gridOptions['totalItems'] = myData.totalNum;
  85. // $scope.myData = myData.list;
  86. // for (var i = 0; i < $scope.myData.length; i++) {
  87. // $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  88. // }
  89. // } else {
  90. // SweetAlert.swal({
  91. // title: "系统错误",
  92. // text: "请稍后再试!",
  93. // type: "error"
  94. // });
  95. // }
  96. // $scope.ldloading[style.replace('-', '_')] = false;
  97. // }, function() {
  98. // $scope.ldloading[style.replace('-', '_')] = false;
  99. // });
  100. // };
  101. // $scope.refreshData('expand-right', $scope.memoryfilterData);
  102. // }
  103. if(val){
  104. $scope.fileData.consumable["name"]=val.name;
  105. $scope.refreshData('expand-right', $scope.fileData);
  106. }
  107. })
  108. $scope.new_data = function() {
  109. $scope.myData = [];
  110. $scope.refreshData('expand-right', $scope.memoryfilterData);
  111. }
  112. var pdKey = $state.current.pdKey;
  113. $rootScope.hc_eject_big = false; //编辑弹出框
  114. $rootScope.hc_eject_sma = false; //编辑弹出框
  115. $rootScope.hc_toedit = "new_top";
  116. // 关闭编辑弹出框
  117. $scope.close = function() {
  118. $rootScope.hc_eject_big = false; //编辑弹出框
  119. $rootScope.hc_eject_sma = false; //编辑弹出框
  120. $rootScope.hc_toedit = "new_top";
  121. $scope.select_updata_name = {}; //编辑下拉框名称
  122. $scope.select_updata_guige = {}; //编辑下拉框规格
  123. $scope.select_updata_pinpai = {}; //编辑下拉框品牌
  124. }
  125. $scope.select_updata_name = {}; //编辑下拉框名称
  126. $scope.select_updata_guige = {}; //编辑下拉框规格
  127. $scope.select_updata_pinpai = {}; //编辑下拉框品牌
  128. // 名称
  129. $scope.$watch('hc_eject_name_caozuo', function(val) {
  130. if (val != undefined) {
  131. // console.log(val);
  132. $scope.hc_eject_name = val;
  133. }
  134. })
  135. // 下拉框名称
  136. $scope.$watch('select_updata_name.updata_name', function(val) {
  137. // console.log(val);
  138. if (val == undefined) {
  139. } else {
  140. // $scope.hc_eject_name = val.name;
  141. // // 耗材查询品牌
  142. // $scope.refreshDat_pinpai = function() {
  143. // var dat = {
  144. // "key": "pinpai",
  145. // parent: val.id
  146. // }
  147. // api_cmdb4.fetchDataList(dat).then(function(data) {
  148. // $scope.updata_pinpai = data;
  149. // });
  150. // }
  151. // $scope.refreshDat_pinpai();
  152. // // 耗材查询规格
  153. // $scope.refreshDat_guige = function() {
  154. // var dat = {
  155. // "key": "guige",
  156. // parent: val.id
  157. // }
  158. // api_cmdb4.fetchDataList(dat).then(function(data) {
  159. // $scope.updata_guige = data;
  160. // });
  161. // }
  162. // $scope.refreshDat_guige();
  163. $scope.hc_eject_name = val.name;
  164. // 耗材查询品牌
  165. $scope.refreshDat_pinpai = function() {
  166. var dat = {
  167. "dictionaryTree":{
  168. "key": "pinpai",
  169. parent: val.id
  170. },
  171. "idx":0,
  172. "sum":999
  173. }
  174. api_sysinfo.fetchDataList("dictionaryTree",dat).then(function(data) {
  175. $scope.updata_pinpai = data;
  176. });
  177. }
  178. $scope.refreshDat_pinpai();
  179. // 耗材查询规格
  180. $scope.refreshDat_guige = function() {
  181. // var dat = {
  182. // "key": "guige",
  183. // parent: val.id,
  184. // "type":"tree"
  185. // }
  186. // api_wechatfile.getDictionary(dat).then(function(data) {
  187. // $scope.updata_guige = data;
  188. // });
  189. var dat = {
  190. "dictionaryTree":{
  191. "key": "guige",
  192. parent: val.id
  193. },
  194. "idx":0,
  195. "sum":999
  196. }
  197. api_sysinfo.fetchDataList("dictionaryTree",dat).then(function(data) {
  198. $scope.updata_pinpai = data;
  199. });
  200. }
  201. $scope.refreshDat_guige();
  202. }
  203. })
  204. // 规格
  205. $scope.$watch('hc_eject_specification_caozuo', function(val) {
  206. $scope.hc_eject_specification = val;
  207. })
  208. // 下拉框规格
  209. $scope.$watch('select_updata_guige.updata_guige', function(val) {
  210. // console.log(val);
  211. if (val == undefined) {
  212. } else {
  213. $scope.hc_eject_specification = val.name;
  214. }
  215. })
  216. // 品牌
  217. $scope.$watch('hc_eject_brandModel_caozuo', function(val) {
  218. $scope.hc_eject_brandModel = val;
  219. })
  220. // 下拉框品牌
  221. $scope.$watch('select_updata_pinpai.updata_pinpai', function(val) {
  222. // console.log(val);
  223. if (val == undefined) {
  224. } else {
  225. $scope.hc_eject_brandModel = val.name;
  226. }
  227. })
  228. // 在库数量
  229. $scope.$watch('hc_eject_inventoryNum_caozuo', function(val) {
  230. $scope.hc_eject_inventoryNum = val;
  231. })
  232. // 入库数量
  233. $scope.$watch('hc_eject_inventorySum_caozuo', function(val) {
  234. $scope.hc_eject_inventorySum = val;
  235. })
  236. $scope.reset=function(){
  237. $scope.select_val={};
  238. $scope.fileData.consumable={};
  239. $scope.refreshData('expand-right', $scope.fileData);
  240. }
  241. // 编辑保存按钮
  242. $scope.preservation = function() {
  243. if ($scope.add_virtualMachinesNum == '') {
  244. SweetAlert.swal({
  245. title: "保存失败",
  246. text: "必填数据不能为空!",
  247. type: "error"
  248. });
  249. } else {
  250. var pdKey = "consumable";
  251. var edit_data = {
  252. "consumable": {
  253. "name": $scope.hc_eject_name,
  254. "brandModel": $scope.hc_eject_brandModel,
  255. "specification": $scope.hc_eject_specification,
  256. "inventoryNum": $scope.hc_eject_inventoryNum,
  257. "inventorySum": $scope.hc_eject_inventorySum,
  258. "id": $rootScope.hc_eject_id_caozuo
  259. }
  260. };
  261. api_cmdb3.preservation(pdKey, edit_data).then(function(data) {
  262. if (data.status == 200) {
  263. // $scope.refreshData = function(style, filterData) {
  264. // var pdKey = "consumable";
  265. // $scope.myData = [];
  266. // $scope.gridOptions['sum'] = filterData.sum;
  267. // api_cmdb3.fetchDataList(pdKey, filterData).then(function(data) {
  268. // // console.log(data.list);
  269. // if (data.list) {
  270. // var myData = Restangular.stripRestangular(data);
  271. // var list = [];
  272. // $scope.gridOptions['totalItems'] = myData.totalNum;
  273. // $scope.myData = myData.list;
  274. // for (var i = 0; i < $scope.myData.length; i++) {
  275. // $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  276. // }
  277. // } else {
  278. // SweetAlert.swal({
  279. // title: "系统错误",
  280. // text: "请稍后再试!",
  281. // type: "error"
  282. // });
  283. // }
  284. // $scope.ldloading[style.replace('-', '_')] = false;
  285. // }, function() {
  286. // $scope.ldloading[style.replace('-', '_')] = false;
  287. // });
  288. // };
  289. $scope.refreshData('expand-right', $scope.fileData);
  290. SweetAlert.swal({
  291. title: "修改成功",
  292. confirmButtonColor: "#007AFF",
  293. type: "success"
  294. });
  295. $rootScope.hc_eject_big = false; //编辑弹出框
  296. $rootScope.hc_eject_sma = false; //编辑弹出框
  297. $rootScope.hc_toedit = "new_top";
  298. $scope.select_updata_name = {}; //编辑下拉框名称
  299. $scope.select_updata_guige = {}; //编辑下拉框规格
  300. $scope.select_updata_pinpai = {}; //编辑下拉框品牌
  301. }
  302. })
  303. }
  304. }
  305. $scope.gridOptions = {};
  306. $scope.gridOptions.data = 'myData';
  307. $scope.gridOptions.enableColumnResizing = true;
  308. $scope.gridOptions.enableFiltering = false;
  309. $scope.gridOptions.enableGridMenu = true;
  310. $scope.gridOptions.enableSelectAll = true;
  311. $scope.gridOptions.enableRowSelection = true;
  312. $scope.gridOptions.showGridFooter = true;
  313. $scope.gridOptions.showColumnFooter = false;
  314. $scope.gridOptions.fastWatch = true;
  315. $scope.gridOptions.enableSorting = true;
  316. $scope.gridOptions.useExternalSorting = true;
  317. $scope.gridOptions.useExternalFiltering = false;
  318. $scope.gridOptions.useExternalPagination = true;
  319. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  320. $scope.gridOptions.paginationPageSize = 10;
  321. $scope.gridOptions.multiSelect = true;
  322. var mun = $scope.gridOptions.paginationPageSize;
  323. $scope.gridOptions.rowTemplate = "<div ng-click=\"onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
  324. $scope.gridOptions.rowIdentity = function(row) {
  325. return row.id;
  326. };
  327. $scope.gridOptions.getRowIdentity = function(row) {
  328. return row.id;
  329. };
  330. $scope.transferColor = function(item) {
  331. var color = "icon iconfont icon-zhengchang greenfont";
  332. if (item.colourInfo) {
  333. if (item.colourInfo.id == 1) {
  334. color = "icon iconfont icon-yiyuqi redfont";
  335. } else if (item.colourInfo.id == 2) {
  336. color = "iconfont icon-yuqixinxiu yellofont";
  337. }
  338. } else {
  339. // color = "white";
  340. }
  341. return color;
  342. }
  343. $scope.transfertip = function(item) {
  344. var tip = "正常";
  345. if (item.colourInfo) {
  346. if (item.colourInfo.id == 1) {
  347. tip = "逾期";
  348. } else if (item.colourInfo.id == 2) {
  349. tip = "即将逾期";
  350. }
  351. } else {
  352. // color = "white";
  353. }
  354. return tip;
  355. }
  356. $scope.transferstatus = function(item) {
  357. var statecolor = "#fc4c58";
  358. if (item.id == 2) { //待处理
  359. statecolor = "#fc4c58";
  360. } else if (item.id == 7) { //待审核
  361. statecolor = "#fcb44c";
  362. } else if (item.id == 3) { //请求重新指派
  363. statecolor = "#ebf902";
  364. } else if (item.id == 4) { //处理中
  365. statecolor = "#0aa5f5";
  366. } else if (item.id == 5) { //已解决
  367. statecolor = "#2edbb8";
  368. } else if (item.id == 6) { //已关闭
  369. statecolor = "#bbbbbb";
  370. }
  371. return statecolor;
  372. }
  373. // 双击查看
  374. $scope.onDblClick=function(row){
  375. $state.go('app.means.consumables_see', { idd: row.entity.id })
  376. }
  377. $scope.gridOptions.columnDefs = [{
  378. name: 'item',
  379. displayName: '序号',
  380. width: 49,
  381. cellTemplate: '<div>' +
  382. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  383. '</div>'
  384. },
  385. {
  386. name: 'name',
  387. displayName: '耗材分类',
  388. width: '14%',
  389. cellTemplate: '<div>' +
  390. '<div class="ui-grid-cell-contents">{{row.entity.name}}</div>' +
  391. '</div>'
  392. },
  393. {
  394. name: 'brandModel',
  395. displayName: '品牌型号',
  396. width: '14%',
  397. cellTemplate: '<div>' +
  398. '<div class="ui-grid-cell-contents">{{row.entity.brandModel}}</div>' +
  399. '</div>'
  400. },
  401. {
  402. name: 'specification',
  403. displayName: '规格',
  404. width: '14%',
  405. cellTemplate: '<div>' +
  406. '<div class="ui-grid-cell-contents">{{row.entity.specification}}</div>' +
  407. '</div>'
  408. },
  409. {
  410. name: 'inventoryNum',
  411. displayName: '在库数量',
  412. width: '12%',
  413. minWidth: '120',
  414. cellTemplate: '<div>' +
  415. '<div class="ui-grid-cell-contents">{{row.entity.inventoryNum}}</div>' +
  416. '</div>'
  417. },
  418. {
  419. name: 'inventorySum',
  420. displayName: '入库总数量',
  421. width: '14%',
  422. minWidth: '120',
  423. cellTemplate: '<div>' +
  424. '<div class="ui-grid-cell-contents">{{row.entity.inventorySum}}</div>' +
  425. '</div>'
  426. },
  427. {
  428. name: 'updateTime',
  429. displayName: '最后更新时间',
  430. width: '14%',
  431. minWidth: '160',
  432. cellTemplate: '<div>' +
  433. '<div class="ui-grid-cell-contents">{{grid.appScope.transferTime(row.entity.updateTime)}}</div>' +
  434. '</div>'
  435. },
  436. {
  437. name: '操作',
  438. enableSorting: false,
  439. minWidth: 120,
  440. cellTemplate: '<wtt style="background-color:{{row.entity.colourInfo.rgb}}" item="row.entity" colobject="col">',
  441. enableFiltering: false
  442. },
  443. ];
  444. $scope.value = 10;
  445. $scope.decrement = function() {
  446. $scope.value = $scope.value - 1;
  447. };
  448. $scope.transferTime = function(time) {
  449. return moment(time).format('YYYY-MM-DD HH:mm');
  450. }
  451. $scope.record = function() {
  452. api_text.record($rootScope.takes).then(function(data) {
  453. if (data.errno == 0) {
  454. $scope.busy = false;
  455. }
  456. })
  457. };
  458. $scope.parameters = null;
  459. $scope.open = function($event) {
  460. $event.preventDefault();
  461. $event.stopPropagation();
  462. $scope.opened = !$scope.opened;
  463. };
  464. $scope.endOpen = function($event) {
  465. $event.preventDefault();
  466. $event.stopPropagation();
  467. $scope.startOpened = false;
  468. $scope.endOpened = !$scope.endOpened;
  469. };
  470. $scope.startOpen = function($event) {
  471. $event.preventDefault();
  472. $event.stopPropagation();
  473. $scope.endOpened = false;
  474. $scope.startOpened = !$scope.startOpened;
  475. };
  476. $scope.othcode = {};
  477. var items = [];
  478. $scope.selected = {
  479. items: []
  480. };
  481. $scope.select_val = {}; //下拉框查询
  482. //列表排序
  483. $scope.gridOptions.onRegisterApi = function(gridApi) {
  484. $scope.gridApi = gridApi;
  485. var index = 0;
  486. var oldheader = {};
  487. gridApi.grid.sortColumn = function(gridApi) {
  488. if (oldheader.field) {
  489. if (oldheader.field == gridApi.field) {
  490. // index = 0;
  491. } else {
  492. index = 0;
  493. }
  494. }
  495. index++;
  496. oldheader = gridApi;
  497. var fildata = $scope.memoryfilterData;
  498. if (index % 3 == 0) {
  499. delete $scope.memoryfilterData.incident;
  500. fildata = $scope.memoryfilterData;
  501. } else if (index % 3 == 1) {
  502. if (fildata.incident) {
  503. if (gridApi.field == "acceptDate") {
  504. angular.extend(fildata.incident, { "sort": gridApi.field });
  505. } else {
  506. angular.extend(fildata.incident, { "sort": gridApi.field + " desc , _incident.acceptDate" });
  507. }
  508. } else {
  509. if (gridApi.field == "acceptDate") {
  510. angular.extend(fildata, { 'incident': { "sort": gridApi.field } });
  511. } else {
  512. angular.extend(fildata, { 'incident': { "sort": gridApi.field + " desc , _incident.acceptDate" } });
  513. }
  514. }
  515. } else if (index % 3 == 2) {
  516. if (fildata.incident) {
  517. if (gridApi.field == "acceptDate") {
  518. angular.extend(fildata.incident, { "sort": gridApi.field, "order": "asc" });
  519. } else {
  520. angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
  521. }
  522. } else {
  523. if (gridApi.field == "acceptDate") {
  524. angular.extend(fildata, { 'incident': { "sort": gridApi.field, "order": "asc" } });
  525. } else {
  526. angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
  527. }
  528. }
  529. }
  530. $scope.refreshData('expand-right', $scope.fileData);
  531. }
  532. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  533. var filtersData = $scope.memoryfilterData;
  534. $scope.fenye = newPage - 1;
  535. filtersData.idx = newPage - 1;
  536. $scope.fileData.idx=newPage - 1;
  537. filtersData.sum = pageSize;
  538. $scope.fileData.sum=pageSize;
  539. $scope.refreshData('expand-right', $scope.fileData);
  540. });
  541. gridApi.core.on.filterChanged($scope, function() {
  542. var grid = this.grid;
  543. if ($rootScope.user.group) {
  544. var filtersData = {
  545. idx: 0,
  546. sum: mun
  547. };
  548. } else {
  549. var filtersData = {
  550. idx: 0,
  551. sum: mun
  552. };
  553. }
  554. angular.forEach(grid.columns, function(item) {
  555. if (item.enableFiltering) {
  556. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  557. filtersData = $scope.memoryfilterData
  558. if (angular.isUndefined(filtersData['incident'])) {
  559. filtersData['incident'] = {};
  560. }
  561. if (item.field == 'requester.name') {
  562. filtersData['incident']['requester'] = {};
  563. filtersData.incident.requester['accountName'] = item.filters[0].term;
  564. } else if (item.field == 'handlingPersonnelUser.name') {
  565. filtersData['incident']['handlingPersonnelUser'] = {};
  566. filtersData.incident.handlingPersonnelUser['name'] = item.filters[0].term;
  567. } else if (item.field == 'requester.account') {
  568. filtersData['incident']['requester'] = {};
  569. filtersData.incident.requester['account'] = item.filters[0].term;
  570. } else if (item.field == 'acceptUser.name') {
  571. filtersData['incident']['acceptUser'] = {};
  572. filtersData.incident.acceptUser['name'] = item.filters[0].term;
  573. } else {
  574. filtersData['incident'][item.field] = item.filters[0].term;
  575. }
  576. }
  577. }
  578. });
  579. filtersData.idx = 0;
  580. $scope.memoryfilterData = filtersData;
  581. $scope.refreshData('expand-right', $scope.fileData);
  582. });
  583. };
  584. var items = [];
  585. //当前人是否分组
  586. if ($rootScope.user.group) {
  587. if ($rootScope.user.group.length == 0) {
  588. SweetAlert.swal("访问失败!", "当前登录人未分配工作组,无权限访问,请添加工作组后重试。", "error");
  589. } else {
  590. $scope.memoryfilterData = defaultFilterData = {
  591. "idx": 0,
  592. "sum": mun
  593. };
  594. }
  595. } else {
  596. $scope.memoryfilterData = defaultFilterData = {
  597. "idx": 0,
  598. "sum": mun
  599. };
  600. }
  601. var wt_data = {};
  602. //导出
  603. $scope.hc_export = function() {
  604. if ($scope.wt_data_display == true) {
  605. SweetAlert.swal({
  606. title: "导出失败",
  607. text: "请选择分类!",
  608. type: "error"
  609. });
  610. } else {
  611. var filadata = angular.copy($scope.memoryfilterData);
  612. filadata.sum = 10000;
  613. var wt_url = api_cmdb3.exportData("downDataModel/consumable/1", wt_data).getRequestedUrl()
  614. $http({
  615. url: wt_url,
  616. method: 'POST',
  617. data: JSON.stringify(wt_data),
  618. headers: {
  619. 'Accept': '*/*'
  620. },
  621. responseType: 'arraybuffer'
  622. }).success(function(data, status, headers, config) {
  623. // $scope.ldloading.zoom_in = false;
  624. var file = new Blob([data], {
  625. type: 'application/vnd.ms-excel'
  626. });
  627. var fileURL = URL.createObjectURL(file);
  628. var a = document.createElement('a');
  629. a.href = fileURL;
  630. a.target = '_blank';
  631. a.download = '耗材列表.xls';
  632. document.body.appendChild(a);
  633. a.click();
  634. }).error(function(data, status, headers, config) {
  635. // $scope.ldloading.zoom_in = false;
  636. console.log(data);
  637. });
  638. }
  639. };
  640. if ($stateParams.model) {
  641. if (JSON.parse($stateParams.model).searchType && JSON.parse($stateParams.model).searchType != null) {
  642. $scope.searchTypes = JSON.parse($stateParams.model).searchType;
  643. } else {
  644. $scope.searchTypes = "todo";
  645. }
  646. } else {
  647. $scope.searchTypes = "todo";
  648. }
  649. if ($rootScope.user.group) {
  650. var defaultFilterData = {
  651. "idx": 0,
  652. "sum": mun
  653. };
  654. } else {
  655. var defaultFilterData = {
  656. "idx": 0,
  657. "sum": mun
  658. };
  659. }
  660. if (angular.isDefined($rootScope.search) && angular.isDefined($rootScope.search.incident)) {
  661. defaultFilterData['searchType'] = $rootScope.search.incident;
  662. $scope.searchTypes = $rootScope.search.incident;
  663. }
  664. if ($rootScope['cmdbs'] != 'incident') { $rootScope.idx = 1 }
  665. if (angular.isDefined($rootScope.idx) && $rootScope.cmdbs != "false") {
  666. $rootScope['cmdbs'] = 'incident';
  667. defaultFilterData.idx = $rootScope.idx - 1;
  668. } else { $rootScope.cmdbs = ""; }
  669. $scope.ldloading = {};
  670. //获取列表数据
  671. var pdKey = "consumable";
  672. $scope.refreshData = function(style, filterData) {
  673. // var pdKey = "consumable";
  674. $scope.myData = [];
  675. $scope.gridOptions['sum'] = filterData.sum;
  676. api_cmdb3.fetchDataList(pdKey, filterData).then(function(data) {
  677. // console.log(data.list);
  678. if (data.list) {
  679. var myData = Restangular.stripRestangular(data);
  680. var list = [];
  681. $scope.gridOptions['totalItems'] = myData.totalNum;
  682. $scope.myData = myData.list;
  683. for (var i = 0; i < $scope.myData.length; i++) {
  684. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
  685. }
  686. } else {
  687. SweetAlert.swal({
  688. title: "系统错误",
  689. text: "请稍后再试!",
  690. type: "error"
  691. });
  692. }
  693. $scope.ldloading[style.replace('-', '_')] = false;
  694. }, function() {
  695. $scope.ldloading[style.replace('-', '_')] = false;
  696. });
  697. };
  698. $scope.refreshData2 = function(style, filterData) {
  699. // var pdKey = "consumable";
  700. // $scope.myData = [];
  701. $scope.gridOptions['sum'] = filterData.sum;
  702. api_cmdb3.fetchDataList(pdKey, filterData).then(function(data) {
  703. // console.log(data.list);
  704. if (data.list) {
  705. var myData = Restangular.stripRestangular(data);
  706. var list = [];
  707. $scope.gridOptions['totalItems'] = myData.totalNum;
  708. $scope.myData = myData.list;
  709. for (var i = 0; i < $scope.myData.length; i++) {
  710. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
  711. }
  712. } else {
  713. SweetAlert.swal({
  714. title: "系统错误",
  715. text: "请稍后再试!",
  716. type: "error"
  717. });
  718. }
  719. $scope.ldloading[style.replace('-', '_')] = false;
  720. }, function() {
  721. $scope.ldloading[style.replace('-', '_')] = false;
  722. });
  723. };
  724. // 耗材查询分类
  725. $scope.refreshDat_name = function() {
  726. // var dat = {
  727. // "key": "haocaifenlei",
  728. // }
  729. // api_cmdb4.fetchDataList(dat).then(function(data) {
  730. // $scope.search_data = data;
  731. // $scope.search_data.unshift({ 'name': '全部' });
  732. // });
  733. var dat = {
  734. "key": "haocaifenlei",
  735. "type":"tree"
  736. }
  737. api_wechatfile.getDictionary(dat).then(function(data) {
  738. $scope.search_data = data;
  739. // $scope.search_data.unshift({ 'name': '全部' });
  740. });
  741. };
  742. // 耗材查询分类修改
  743. $scope.refreshDat_name_updata = function() {
  744. var dat = {
  745. "key": "haocaifenlei",
  746. "type":"tree"
  747. }
  748. api_wechatfile.getDictionary(dat).then(function(data) {
  749. $scope.updata_name = data;
  750. });
  751. };
  752. $scope.refreshDat_name();
  753. $scope.refreshDat_name_updata();
  754. // $scope.refreshDat_pinpai();
  755. // $scope.refreshDat_guige();
  756. $scope.refreshData('expand-right', $scope.fileData);
  757. $scope.timer=$interval(function(){
  758. $scope.refreshData2('expand-right', $scope.fileData);
  759. },$rootScope.refreshTime);
  760. $scope.$on('$destroy',function(){
  761. $interval.cancel($scope.timer)
  762. });
  763. }]);
  764. //操作按钮权限控制
  765. app.controller('hc_caozuoCtrl', ['$rootScope', '$http', '$scope', '$modal', '$state', function($rootScope, $http, $scope, $modal, $state) {
  766. // 编辑按钮
  767. $scope.edit = function() {
  768. $rootScope.hc_eject_name_caozuo = $scope.item.name; //耗材名称
  769. $rootScope.hc_eject_brandModel_caozuo = $scope.item.brandModel; //耗材品牌型号
  770. $rootScope.hc_eject_specification_caozuo = $scope.item.specification; //耗材规格
  771. $rootScope.hc_eject_inventoryNum_caozuo = $scope.item.inventoryNum; //耗材在库数量
  772. $rootScope.hc_eject_inventorySum_caozuo = $scope.item.inventorySum; //耗材入库数量
  773. $rootScope.hc_eject_id_caozuo = $scope.item.id; //耗材id
  774. $rootScope.hc_eject_big = true; //编辑弹出框
  775. $rootScope.hc_eject_sma = true; //编辑弹出框
  776. $rootScope.hc_toedit = "new_after";
  777. };
  778. //查看按钮
  779. $scope.see = function() {
  780. // console.log($scope.item.id);
  781. // idd=$scope.item.id;
  782. $state.go('app.means.consumables_see', { idd: $scope.item.id })
  783. }
  784. }]);
  785. //操作
  786. app.directive('wtt', function() {
  787. return {
  788. restrict: 'E',
  789. scope: {
  790. item: '=',
  791. colobject: '='
  792. },
  793. controller: 'hc_caozuoCtrl',
  794. template: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  795. // '<a class="handlefont" ng-click="see()">查看</a>' +
  796. '<a class="bianjifont" ng-click="edit()">编辑</a>' +
  797. '</div></div>'
  798. };
  799. });