consumablesCtrl.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. $scope.searchData = function(){
  10. $scope.refreshData('expand-right', $scope.fileData);
  11. }
  12. // 修改供货公司
  13. $scope.changeCompany = function(e){
  14. console.log(e)
  15. $scope.companyIds = e;
  16. }
  17. //修改开始价格和结束价格
  18. $scope.changePrice = function(val,type){
  19. $scope[type] = val?Math.abs(parseFloat(val.toFixed(2), 10)):val;
  20. }
  21. // 监听编辑在库数量
  22. $scope.$watch('hc_eject_inventoryNum', function (val, oldval) {
  23. var zhengze = /^\w{0,5}$/;
  24. if (!zhengze.exec(val)) {
  25. $scope.hc_eject_inventoryNum = oldval;
  26. }
  27. });
  28. $scope.fileData = {
  29. "idx": 0,
  30. "sum": 10,
  31. "consumable": {}
  32. }
  33. // 清空表单
  34. $scope.clearForm = function(){
  35. $rootScope.hc_eject_unit = '';
  36. $rootScope.hc_eject_name_caozuo = '';
  37. $rootScope.hc_eject_brandModel_caozuo = '';
  38. $rootScope.hc_eject_specification_caozuo = '';
  39. $rootScope.hc_eject_companyIds_caozuo = [];
  40. $rootScope.hc_eject_startPrice_caozuo = '';
  41. $rootScope.hc_eject_endPrice_caozuo = '';
  42. $rootScope.hc_eject_isWarehousing_caozuo = 0;
  43. $rootScope.hc_eject_inventoryNum_caozuo = '';
  44. $rootScope.hc_eject_inventorySum_caozuo = '';
  45. delete $rootScope.hc_eject_id_caozuo;
  46. // -------------------
  47. $scope.hc.unit = ''
  48. $scope.select_updata_name.updata_name = {name:''};
  49. $scope.select_updata_pinpai.updata_pinpai = {name:''};
  50. $scope.select_updata_guige.updata_guige = {name:''};
  51. $scope.hc_eject_inventoryNum = '';
  52. $scope.hc_eject_inventorySum = '';
  53. $scope.isWarehousing = 0;
  54. $scope.startPrice = '';
  55. $scope.endPrice = '';
  56. $scope.companyIds = null;
  57. }
  58. //新增
  59. $rootScope.isAdds = false;//是否是新增
  60. $scope.addData = function () {
  61. $scope.clearForm();
  62. $rootScope.isAdds = true;
  63. $rootScope.hc_eject_big = true; //编辑弹出框
  64. $rootScope.hc_eject_sma = true; //编辑弹出框
  65. // $rootScope.hc_toedit = "new_after";
  66. }
  67. // 监听下拉框搜索
  68. // $scope.$watch('select_val.search_data', function (val) {
  69. // if (val) {
  70. // $scope.fileData.consumable["keyWord"] = val.name;
  71. // $scope.refreshData('expand-right', $scope.fileData);
  72. // }
  73. // })
  74. $scope.new_data = function () {
  75. $scope.myData = [];
  76. $scope.refreshData('expand-right', $scope.memoryfilterData);
  77. }
  78. var pdKey = $state.current.pdKey;
  79. $rootScope.hc_eject_big = false; //编辑弹出框
  80. $rootScope.hc_eject_sma = false; //编辑弹出框
  81. // $rootScope.hc_toedit = "new_top";
  82. // 关闭编辑弹出框
  83. $scope.close = function () {
  84. $rootScope.hc_eject_unit = '';
  85. $rootScope.hc_eject_name_caozuo = '';
  86. $rootScope.hc_eject_brandModel_caozuo = '';
  87. $rootScope.hc_eject_specification_caozuo = '';
  88. $rootScope.hc_eject_companyIds_caozuo = [];
  89. $rootScope.hc_eject_startPrice_caozuo = '';
  90. $rootScope.hc_eject_endPrice_caozuo = '';
  91. $rootScope.hc_eject_isWarehousing_caozuo = 0;
  92. $rootScope.hc_eject_inventoryNum_caozuo = '';
  93. $rootScope.hc_eject_inventorySum_caozuo = '';
  94. delete $rootScope.hc_eject_id_caozuo;
  95. // ----------------------------------
  96. $rootScope.hc_eject_big = false; //编辑弹出框
  97. $rootScope.hc_eject_sma = false; //编辑弹出框
  98. // $rootScope.hc_toedit = "new_top";
  99. $scope.select_updata_name = {}; //编辑下拉框名称
  100. $scope.select_updata_guige = {}; //编辑下拉框规格
  101. $scope.select_updata_pinpai = {}; //编辑下拉框品牌
  102. }
  103. $scope.select_updata_name = {}; //编辑下拉框名称
  104. $scope.select_updata_guige = {}; //编辑下拉框规格
  105. $scope.select_updata_pinpai = {}; //编辑下拉框品牌
  106. // 名称
  107. $scope.$watch('hc_eject_name_caozuo', function (val) {
  108. if (val != undefined) {
  109. console.log(val);
  110. // $scope.hc_eject_name = val;
  111. var dat = {
  112. "key": "haocaifenlei",
  113. "type": "tree"
  114. }
  115. api_wechatfile.getDictionary(dat).then(function (data) {
  116. data = data || [];
  117. $scope.select_updata_name.updata_name = data.find(v=>v.name == val);
  118. });
  119. }
  120. })
  121. // 下拉框名称
  122. $scope.$watch('select_updata_name.updata_name', function (val) {
  123. // console.log(val);
  124. val = val || {name:''};
  125. if (!val.name) {
  126. } else {
  127. $scope.hc_eject_name = val.name;
  128. // 耗材查询品牌
  129. $scope.refreshDat_pinpai = function () {
  130. var dat = {
  131. "dictionaryTree": {
  132. "key": "pinpai",
  133. parent: val.id
  134. },
  135. "idx": 0,
  136. "sum": 999
  137. }
  138. api_sysinfo.fetchDataList("dictionaryTree", dat).then(function (data) {
  139. if (data.status == 200) {
  140. $scope.updata_pinpai = data.list;
  141. var flag = data.list.find(v=>v.name == $scope.select_updata_pinpai.updata_pinpai.name);
  142. if(!flag){
  143. $scope.select_updata_pinpai.updata_pinpai.name = '';
  144. $scope.hc_eject_brandModel = '';
  145. }
  146. }
  147. });
  148. }
  149. $scope.refreshDat_pinpai();
  150. // 耗材查询规格
  151. $scope.refreshDat_guige = function () {
  152. // var dat = {
  153. // "key": "guige",
  154. // parent: val.id,
  155. // "type":"tree"
  156. // }
  157. // api_wechatfile.getDictionary(dat).then(function(data) {
  158. // $scope.updata_guige = data;
  159. // });
  160. var dat = {
  161. "dictionaryTree": {
  162. "key": "guige",
  163. parent: val.id
  164. },
  165. "idx": 0,
  166. "sum": 999
  167. }
  168. api_sysinfo.fetchDataList("dictionaryTree", dat).then(function (data) {
  169. if (data.status == 200) {
  170. $scope.updata_guige = data.list;
  171. var flag = data.list.find(v=>v.name == $scope.select_updata_guige.updata_guige.name);
  172. if(!flag){
  173. $scope.select_updata_guige.updata_guige.name = '';
  174. $scope.hc_eject_specification = '';
  175. }
  176. }
  177. });
  178. }
  179. $scope.refreshDat_guige();
  180. }
  181. })
  182. $scope.selected = {
  183. items: []
  184. }
  185. //删除
  186. $scope.removeData = function () {
  187. var modalInstance = $modal.open({
  188. templateUrl: 'assets/views/delete.html',
  189. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  190. var rmvList = [];
  191. $scope.title = '耗材删除';
  192. $scope.connect = '确定要删除此耗材?';
  193. angular.forEach(scope.selected.items, function (item) {
  194. rmvList.push(item.id);
  195. });
  196. $scope.ok = function () {
  197. $modalInstance.close(rmvList);
  198. };
  199. $scope.cancel = function () {
  200. $modalInstance.dismiss('cancel');
  201. };
  202. },
  203. size: 'sm',
  204. resolve: {
  205. scope: function () {
  206. return $scope;
  207. }
  208. }
  209. });
  210. modalInstance.result.then(function (selectedItem) {
  211. if (selectedItem) {
  212. if (selectedItem.length > 0) {
  213. api_user_data.rmvData('consumable', selectedItem).then(function (response) {
  214. if (response.data) {
  215. SweetAlert.swal({
  216. title: "删除成功!",
  217. type: "success",
  218. confirmButtonColor: "#007AFF"
  219. }, function () {
  220. $scope.myData = _.reject($scope.myData, function (o) {
  221. return _.includes(selectedItem, o.id);
  222. });
  223. $scope.selected = {
  224. items: []
  225. };
  226. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
  227. $scope.gridApi.grid.selection.selectedCount = 0;
  228. $scope.refreshData('expand-right', $scope.fileData);
  229. });
  230. } else {
  231. SweetAlert.swal({
  232. title: "操作异常!",
  233. text: "系统异常,请稍后重试,或者联系管理员!",
  234. type: "error"
  235. });
  236. }
  237. })
  238. }
  239. }
  240. })
  241. }
  242. // 第三方公司查询
  243. $scope.refreshDat_company = function (name,companyIds=[]) {
  244. $scope.updata_company = [];
  245. name = name || "";
  246. companyIds = companyIds || [];
  247. var dat = {
  248. "company": {
  249. serviceTypeIds:"1709",
  250. name:name
  251. },
  252. "idx": 0,
  253. "sum": 999
  254. }
  255. api_sysinfo.fetchDataList("company", dat).then(function (data) {
  256. if (data.status == 200) {
  257. if(companyIds.length){
  258. companyIds.forEach(v=>{
  259. data.list.forEach((v1,i)=>{
  260. if(v.id == v1.id){
  261. data.list.splice(i,1)
  262. }
  263. })
  264. })
  265. }
  266. $scope.updata_company = data.list;
  267. }
  268. });
  269. }
  270. $scope.refreshDat_company();
  271. // 规格
  272. $scope.$watch('hc_eject_specification_caozuo', function (val) {
  273. // $scope.hc_eject_specification = val;
  274. $scope.select_updata_guige.updata_guige = {name:val}
  275. })
  276. // 下拉框规格
  277. $scope.$watch('select_updata_guige.updata_guige', function (val) {
  278. // console.log(val);
  279. if (val == undefined) {
  280. } else {
  281. $scope.hc_eject_specification = val.name;
  282. }
  283. })
  284. // 品牌
  285. $scope.$watch('hc_eject_brandModel_caozuo', function (val) {
  286. // $scope.hc_eject_brandModel = val;
  287. $scope.select_updata_pinpai.updata_pinpai = {name:val}
  288. })
  289. // 下拉框品牌
  290. $scope.$watch('select_updata_pinpai.updata_pinpai', function (val) {
  291. console.log(val);
  292. if (val == undefined) {
  293. } else {
  294. $scope.hc_eject_brandModel = val.name;
  295. }
  296. })
  297. //供货公司hc_eject_companyIds_caozuo
  298. $scope.$watch('hc_eject_companyIds_caozuo', function (ids) {
  299. ids = ids || [];
  300. var dat = {
  301. "company": {
  302. serviceTypeIds:"1709",
  303. },
  304. "idx": 0,
  305. "sum": 999
  306. }
  307. api_sysinfo.fetchDataList("company", dat).then(function (data) {
  308. if (data.status == 200) {
  309. var arr = [];
  310. data.list.forEach(v=>{
  311. ids.forEach(v1=>{
  312. if(v.id == v1){
  313. arr.push(v);
  314. }
  315. })
  316. })
  317. $scope.companyIds = arr;
  318. }
  319. });
  320. })
  321. // 单位hc_eject_unit
  322. $scope.$watch('hc_eject_unit', function (val) {
  323. $scope.hc.unit = val;
  324. })
  325. // 费用区间开始hc_eject_startPrice_caozuo
  326. $scope.$watch('hc_eject_startPrice_caozuo', function (val) {
  327. $scope.startPrice = val;
  328. })
  329. // 费用区间开始hc_eject_endPrice_caozuo
  330. $scope.$watch('hc_eject_endPrice_caozuo', function (val) {
  331. $scope.endPrice = val;
  332. })
  333. // 是否库存hc_eject_isWarehousing_caozuo
  334. $scope.$watch('hc_eject_isWarehousing_caozuo', function (val) {
  335. $scope.isWarehousing = val;
  336. })
  337. // 在库数量
  338. $scope.$watch('hc_eject_inventoryNum_caozuo', function (val) {
  339. $scope.hc_eject_inventoryNum = val;
  340. })
  341. // 入库数量
  342. $scope.$watch('hc_eject_inventorySum_caozuo', function (val) {
  343. $scope.hc_eject_inventorySum = val;
  344. })
  345. $scope.reset = function () {
  346. $scope.select_val = {};
  347. $scope.fileData.consumable = {};
  348. $scope.refreshData('expand-right', $scope.fileData);
  349. }
  350. // 是否库存
  351. $scope.changeWarehousing = function(type){
  352. $scope.isWarehousing = type;
  353. }
  354. // 编辑保存按钮
  355. $scope.companyIds = null;
  356. $scope.startPrice = '';
  357. $scope.endPrice = '';
  358. $scope.isWarehousing = 0;
  359. $scope.hc_eject_inventorySum = '';
  360. $scope.updata_company = [];
  361. $scope.hc = {
  362. unit: '',//单位
  363. }
  364. $scope.preservation = function () {
  365. if (!$scope.select_updata_name.updata_name.name
  366. ||!$scope.select_updata_pinpai.updata_pinpai.name
  367. ||!$scope.select_updata_guige.updata_guige.name
  368. ||!$scope.companyIds
  369. ||(!$scope.startPrice&&$scope.startPrice!==0)
  370. ||(!$scope.endPrice&&$scope.endPrice!==0)
  371. ||($scope.isWarehousing == 1&&($scope.hc_eject_inventorySum===null||$scope.hc_eject_inventoryNum===null))
  372. ) {
  373. SweetAlert.swal({
  374. title: "保存失败",
  375. text: "必填数据不能为空!",
  376. type: "error"
  377. });
  378. } else {
  379. var pdKey = "consumable";
  380. var edit_data = {
  381. "consumable": {
  382. "name": $scope.select_updata_name.updata_name.name,
  383. "unit": $scope.hc.unit,
  384. "brandModel": $scope.select_updata_pinpai.updata_pinpai.name,
  385. "specification": $scope.select_updata_guige.updata_guige.name,
  386. isInventory:$scope.isWarehousing,
  387. startPrice:$scope.startPrice,
  388. endPrice:$scope.endPrice,
  389. companyIds:$scope.companyIds.map(v=>v.id).toString()
  390. }
  391. };
  392. if($scope.isWarehousing == 1){
  393. edit_data.consumable.inventoryNum = $scope.hc_eject_inventoryNum;
  394. edit_data.consumable.inventorySum = $scope.hc_eject_inventorySum;
  395. }
  396. if($rootScope.isAdds){
  397. edit_data.consumable.inOutInventory = 1;//入库1,出库2
  398. }else{
  399. edit_data.consumable.id = $rootScope.hc_eject_id_caozuo;
  400. }
  401. api_cmdb3[$rootScope.isAdds?'addData':'preservation'](pdKey, edit_data).then(function (data) {
  402. if (data.status == 200) {
  403. $scope.refreshData('expand-right', $scope.fileData);
  404. SweetAlert.swal({
  405. title: ($rootScope.isAdds?'新增':'修改')+"成功",
  406. confirmButtonColor: "#007AFF",
  407. type: "success"
  408. });
  409. $rootScope.hc_eject_big = false; //编辑弹出框
  410. $rootScope.hc_eject_sma = false; //编辑弹出框
  411. // $rootScope.hc_toedit = "new_top";
  412. }
  413. })
  414. }
  415. }
  416. $scope.gridOptions = {};
  417. $scope.gridOptions.data = 'myData';
  418. $scope.gridOptions.enableColumnResizing = true;
  419. $scope.gridOptions.enableFiltering = false;
  420. $scope.gridOptions.enableGridMenu = true;
  421. $scope.gridOptions.enableSelectAll = true;
  422. $scope.gridOptions.enableRowSelection = true;
  423. $scope.gridOptions.showGridFooter = true;
  424. $scope.gridOptions.showColumnFooter = false;
  425. $scope.gridOptions.fastWatch = true;
  426. $scope.gridOptions.enableSorting = true;
  427. $scope.gridOptions.useExternalSorting = true;
  428. $scope.gridOptions.useExternalFiltering = false;
  429. $scope.gridOptions.useExternalPagination = true;
  430. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  431. $scope.gridOptions.paginationPageSize = 10;
  432. $scope.gridOptions.multiSelect = true;
  433. var mun = $scope.gridOptions.paginationPageSize;
  434. $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>";
  435. $scope.gridOptions.rowIdentity = function (row) {
  436. return row.id;
  437. };
  438. $scope.gridOptions.getRowIdentity = function (row) {
  439. return row.id;
  440. };
  441. $scope.transferColor = function (item) {
  442. var color = "icon iconfont icon-zhengchang greenfont";
  443. if (item.colourInfo) {
  444. if (item.colourInfo.id == 1) {
  445. color = "icon iconfont icon-yiyuqi redfont";
  446. } else if (item.colourInfo.id == 2) {
  447. color = "iconfont icon-yuqixinxiu yellofont";
  448. }
  449. } else {
  450. // color = "white";
  451. }
  452. return color;
  453. }
  454. $scope.transfertip = function (item) {
  455. var tip = "正常";
  456. if (item.colourInfo) {
  457. if (item.colourInfo.id == 1) {
  458. tip = "逾期";
  459. } else if (item.colourInfo.id == 2) {
  460. tip = "即将逾期";
  461. }
  462. } else {
  463. // color = "white";
  464. }
  465. return tip;
  466. }
  467. $scope.transferstatus = function (item) {
  468. var statecolor = "#fc4c58";
  469. if (item.id == 2) { //待处理
  470. statecolor = "#fc4c58";
  471. } else if (item.id == 7) { //待审核
  472. statecolor = "#fcb44c";
  473. } else if (item.id == 3) { //请求重新指派
  474. statecolor = "#ebf902";
  475. } else if (item.id == 4) { //处理中
  476. statecolor = "#0aa5f5";
  477. } else if (item.id == 5) { //已解决
  478. statecolor = "#2edbb8";
  479. } else if (item.id == 6) { //已关闭
  480. statecolor = "#bbbbbb";
  481. }
  482. return statecolor;
  483. }
  484. // 双击查看
  485. $scope.onDblClick = function (row) {
  486. $state.go('app.means.consumables_see', { idd: row.entity.id })
  487. }
  488. $scope.gridOptions.columnDefs = [{
  489. name: 'item',
  490. displayName: '序号',
  491. width: 49,
  492. cellTemplate: '<div>' +
  493. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  494. '</div>'
  495. },
  496. {
  497. name: 'spdCode',
  498. displayName: '耗材编码',
  499. minWidth: '120',
  500. },
  501. {
  502. name: 'name',
  503. displayName: '耗材名称',
  504. minWidth: '120',
  505. cellTemplate: '<div>' +
  506. '<div class="ui-grid-cell-contents">{{row.entity.name}}</div>' +
  507. '</div>'
  508. },
  509. {
  510. name: 'brandModel',
  511. displayName: '品牌型号',
  512. minWidth: '120',
  513. cellTemplate: '<div>' +
  514. '<div class="ui-grid-cell-contents">{{row.entity.brandModel}}</div>' +
  515. '</div>'
  516. },
  517. {
  518. name: 'specification',
  519. displayName: '规格',
  520. minWidth: '120',
  521. cellTemplate: '<div>' +
  522. '<div class="ui-grid-cell-contents">{{row.entity.specification}}</div>' +
  523. '</div>'
  524. },
  525. {
  526. name: 'unit',
  527. displayName: '单位',
  528. minWidth: '120',
  529. },
  530. {
  531. name: 'price',
  532. displayName: '价格区间',
  533. minWidth: '120',
  534. cellTemplate: '<div>' +
  535. '<div class="ui-grid-cell-contents">{{row.entity.startPrice}} ~ {{row.entity.endPrice}}</div>' +
  536. '</div>'
  537. },
  538. {
  539. name: 'companyIds',
  540. displayName: '供货公司',
  541. minWidth: '120',
  542. cellTemplate: '<div>' +
  543. '<div class="ui-grid-cell-contents">{{row.entity.companyNames}}</div>' +
  544. '</div>'
  545. },
  546. // {
  547. // name: 'isInventory',
  548. // displayName: '是否库存',
  549. // width: '10%',
  550. // minWidth: '120',
  551. // cellTemplate: '<div>' +
  552. // '<div class="ui-grid-cell-contents">{{row.entity.isInventory == 1 ? "是" : "否"}}</div>' +
  553. // '</div>'
  554. // },
  555. // {
  556. // name: 'inventorySum',
  557. // displayName: '入库总数量',
  558. // width: '11%',
  559. // minWidth: '120',
  560. // cellTemplate: '<div>' +
  561. // '<div class="ui-grid-cell-contents">{{row.entity.inventorySum}}</div>' +
  562. // '</div>'
  563. // },
  564. {
  565. name: 'inventoryNum',
  566. displayName: '在库数量',
  567. minWidth: '120',
  568. cellTemplate: '<div>' +
  569. '<div class="ui-grid-cell-contents">{{row.entity.inventoryNum}}</div>' +
  570. '</div>'
  571. },
  572. // {
  573. // name: 'updateTime',
  574. // displayName: '最后更新时间',
  575. // width: '14%',
  576. // minWidth: '160',
  577. // cellTemplate: '<div>' +
  578. // '<div class="ui-grid-cell-contents">{{grid.appScope.transferTime(row.entity.updateTime)}}</div>' +
  579. // '</div>'
  580. // },
  581. {
  582. name: '操作',
  583. enableSorting: false,
  584. minWidth: 120,
  585. cellTemplate: '<wtt style="background-color:{{row.entity.colourInfo.rgb}}" item="row.entity" colobject="col">',
  586. enableFiltering: false
  587. },
  588. ];
  589. $scope.value = 10;
  590. $scope.decrement = function () {
  591. $scope.value = $scope.value - 1;
  592. };
  593. $scope.transferTime = function (time) {
  594. return moment(time).format('YYYY-MM-DD HH:mm');
  595. }
  596. $scope.record = function () {
  597. api_text.record($rootScope.takes).then(function (data) {
  598. if (data.errno == 0) {
  599. $scope.busy = false;
  600. }
  601. })
  602. };
  603. $scope.parameters = null;
  604. $scope.open = function ($event) {
  605. $event.preventDefault();
  606. $event.stopPropagation();
  607. $scope.opened = !$scope.opened;
  608. };
  609. $scope.endOpen = function ($event) {
  610. $event.preventDefault();
  611. $event.stopPropagation();
  612. $scope.startOpened = false;
  613. $scope.endOpened = !$scope.endOpened;
  614. };
  615. $scope.startOpen = function ($event) {
  616. $event.preventDefault();
  617. $event.stopPropagation();
  618. $scope.endOpened = false;
  619. $scope.startOpened = !$scope.startOpened;
  620. };
  621. $scope.othcode = {};
  622. var items = [];
  623. $scope.selected = {
  624. items: []
  625. };
  626. $scope.select_val = {}; //下拉框查询
  627. //列表排序
  628. $scope.gridOptions.onRegisterApi = function (gridApi) {
  629. $scope.gridApi = gridApi;
  630. var index = 0;
  631. var oldheader = {};
  632. gridApi.grid.sortColumn = function (gridApi) {
  633. if (oldheader.field) {
  634. if (oldheader.field == gridApi.field) {
  635. // index = 0;
  636. } else {
  637. index = 0;
  638. }
  639. }
  640. index++;
  641. oldheader = gridApi;
  642. var fildata = $scope.memoryfilterData;
  643. if (index % 3 == 0) {
  644. delete $scope.memoryfilterData.incident;
  645. fildata = $scope.memoryfilterData;
  646. } else if (index % 3 == 1) {
  647. if (fildata.incident) {
  648. if (gridApi.field == "acceptDate") {
  649. angular.extend(fildata.incident, { "sort": gridApi.field });
  650. } else {
  651. angular.extend(fildata.incident, { "sort": gridApi.field + " desc , _incident.acceptDate" });
  652. }
  653. } else {
  654. if (gridApi.field == "acceptDate") {
  655. angular.extend(fildata, { 'incident': { "sort": gridApi.field } });
  656. } else {
  657. angular.extend(fildata, { 'incident': { "sort": gridApi.field + " desc , _incident.acceptDate" } });
  658. }
  659. }
  660. } else if (index % 3 == 2) {
  661. if (fildata.incident) {
  662. if (gridApi.field == "acceptDate") {
  663. angular.extend(fildata.incident, { "sort": gridApi.field, "order": "asc" });
  664. } else {
  665. angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
  666. }
  667. } else {
  668. if (gridApi.field == "acceptDate") {
  669. angular.extend(fildata, { 'incident': { "sort": gridApi.field, "order": "asc" } });
  670. } else {
  671. angular.extend(fildata.incident, { "sort": gridApi.field + " asc , _incident.acceptDate" });
  672. }
  673. }
  674. }
  675. $scope.refreshData('expand-right', $scope.fileData);
  676. }
  677. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  678. $scope.fenye = newPage - 1;
  679. $scope.fileData.idx = newPage - 1;
  680. $scope.fileData.sum = pageSize;
  681. $scope.refreshData('expand-right', $scope.fileData);
  682. });
  683. gridApi.core.on.filterChanged($scope, function () {
  684. var grid = this.grid;
  685. if ($rootScope.user.group) {
  686. var filtersData = {
  687. idx: 0,
  688. sum: mun
  689. };
  690. } else {
  691. var filtersData = {
  692. idx: 0,
  693. sum: mun
  694. };
  695. }
  696. angular.forEach(grid.columns, function (item) {
  697. if (item.enableFiltering) {
  698. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  699. filtersData = $scope.memoryfilterData
  700. if (angular.isUndefined(filtersData['incident'])) {
  701. filtersData['incident'] = {};
  702. }
  703. if (item.field == 'requester.name') {
  704. filtersData['incident']['requester'] = {};
  705. filtersData.incident.requester['accountName'] = item.filters[0].term;
  706. } else if (item.field == 'handlingPersonnelUser.name') {
  707. filtersData['incident']['handlingPersonnelUser'] = {};
  708. filtersData.incident.handlingPersonnelUser['name'] = item.filters[0].term;
  709. } else if (item.field == 'requester.account') {
  710. filtersData['incident']['requester'] = {};
  711. filtersData.incident.requester['account'] = item.filters[0].term;
  712. } else if (item.field == 'acceptUser.name') {
  713. filtersData['incident']['acceptUser'] = {};
  714. filtersData.incident.acceptUser['name'] = item.filters[0].term;
  715. } else {
  716. filtersData['incident'][item.field] = item.filters[0].term;
  717. }
  718. }
  719. }
  720. });
  721. filtersData.idx = 0;
  722. $scope.memoryfilterData = filtersData;
  723. $scope.refreshData('expand-right', $scope.fileData);
  724. });
  725. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  726. var j = 0;
  727. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  728. if (scope.grid.appScope.selected.items[i] == scope.entity) {
  729. j++;
  730. break;
  731. }
  732. }
  733. // console.log("j="+j)
  734. if (j == 1) {
  735. scope.grid.appScope.selected.items.splice(i, 1);
  736. } else {
  737. scope.grid.appScope.selected.items.push(scope.entity)
  738. }
  739. });
  740. };
  741. var items = [];
  742. //当前人是否分组
  743. // if ($rootScope.user.group) {
  744. // if ($rootScope.user.group.length == 0) {
  745. // SweetAlert.swal("访问失败!", "当前登录人未分配工作组,无权限访问,请添加工作组后重试。", "error");
  746. // } else {
  747. // $scope.memoryfilterData = defaultFilterData = {
  748. // "idx": 0,
  749. // "sum": mun
  750. // };
  751. // }
  752. // } else {
  753. // $scope.memoryfilterData = defaultFilterData = {
  754. // "idx": 0,
  755. // "sum": mun
  756. // };
  757. // }
  758. var wt_data = {};
  759. //导出
  760. $scope.hc_export = function () {
  761. if ($scope.wt_data_display == true) {
  762. SweetAlert.swal({
  763. title: "导出失败",
  764. text: "请选择分类!",
  765. type: "error"
  766. });
  767. } else {
  768. var filadata = angular.copy($scope.memoryfilterData);
  769. filadata.sum = 10000;
  770. var wt_url = api_cmdb3.exportData("downDataModel/consumable/1", wt_data).getRequestedUrl()
  771. $http({
  772. url: wt_url,
  773. method: 'POST',
  774. data: JSON.stringify(wt_data),
  775. headers: {
  776. 'Accept': '*/*'
  777. },
  778. responseType: 'arraybuffer'
  779. }).success(function (data, status, headers, config) {
  780. // $scope.ldloading.zoom_in = false;
  781. var file = new Blob([data], {
  782. type: 'application/vnd.ms-excel'
  783. });
  784. var fileURL = URL.createObjectURL(file);
  785. var a = document.createElement('a');
  786. a.href = fileURL;
  787. a.target = '_blank';
  788. a.download = '耗材列表.xls';
  789. document.body.appendChild(a);
  790. a.click();
  791. }).error(function (data, status, headers, config) {
  792. // $scope.ldloading.zoom_in = false;
  793. console.log(data);
  794. });
  795. }
  796. };
  797. if ($stateParams.model) {
  798. if (JSON.parse($stateParams.model).searchType && JSON.parse($stateParams.model).searchType != null) {
  799. $scope.searchTypes = JSON.parse($stateParams.model).searchType;
  800. } else {
  801. $scope.searchTypes = "todo";
  802. }
  803. } else {
  804. $scope.searchTypes = "todo";
  805. }
  806. if ($rootScope.user.group) {
  807. var defaultFilterData = {
  808. "idx": 0,
  809. "sum": mun
  810. };
  811. } else {
  812. var defaultFilterData = {
  813. "idx": 0,
  814. "sum": mun
  815. };
  816. }
  817. if (angular.isDefined($rootScope.search) && angular.isDefined($rootScope.search.incident)) {
  818. defaultFilterData['searchType'] = $rootScope.search.incident;
  819. $scope.searchTypes = $rootScope.search.incident;
  820. }
  821. if ($rootScope['cmdbs'] != 'incident') { $rootScope.idx = 1 }
  822. if (angular.isDefined($rootScope.idx) && $rootScope.cmdbs != "false") {
  823. $rootScope['cmdbs'] = 'incident';
  824. defaultFilterData.idx = $rootScope.idx - 1;
  825. } else { $rootScope.cmdbs = ""; }
  826. $scope.ldloading = {};
  827. //获取列表数据
  828. var pdKey = "consumable";
  829. $scope.refreshData = function (style, filterData) {
  830. // var pdKey = "consumable";
  831. $scope.myData = [];
  832. $scope.gridOptions['sum'] = filterData.sum;
  833. api_cmdb3.fetchDataList(pdKey, filterData).then(function (data) {
  834. // console.log(data.list);
  835. if (data.list) {
  836. var myData = Restangular.stripRestangular(data);
  837. $scope.gridOptions['totalItems'] = myData.totalNum;
  838. for (var i = 0; i < myData.list.length; i++) {
  839. myData.list[i]['item'] = i + 1 + filterData.idx * filterData.sum;
  840. }
  841. // ------------------
  842. var dat = {
  843. "company": {
  844. serviceTypeIds:"1709",
  845. },
  846. "idx": 0,
  847. "sum": 999
  848. }
  849. api_sysinfo.fetchDataList("company", dat).then(function (data) {
  850. if (data.status == 200) {
  851. // data.list
  852. $scope.myData = myData.list;
  853. myData.list.map(v=>{
  854. var ids = v.companyIds?v.companyIds.split(','):[];
  855. var strArr = [];
  856. ids.forEach(v1=>{
  857. data.list.forEach(v2=>{
  858. if(v1 == v2.id){
  859. strArr.push(v2.name);
  860. }
  861. })
  862. })
  863. v.companyNames = strArr.toString();
  864. return v;
  865. })
  866. }
  867. });
  868. } else {
  869. SweetAlert.swal({
  870. title: "系统错误",
  871. text: "请稍后再试!",
  872. type: "error"
  873. });
  874. }
  875. $scope.ldloading[style.replace('-', '_')] = false;
  876. }, function () {
  877. $scope.ldloading[style.replace('-', '_')] = false;
  878. });
  879. };
  880. $scope.refreshData2 = function (style, filterData) {
  881. // var pdKey = "consumable";
  882. // $scope.myData = [];
  883. $scope.gridOptions['sum'] = filterData.sum;
  884. api_cmdb3.fetchDataList(pdKey, filterData).then(function (data) {
  885. // console.log(data.list);
  886. if (data.list) {
  887. var myData = Restangular.stripRestangular(data);
  888. var list = [];
  889. $scope.gridOptions['totalItems'] = myData.totalNum;
  890. $scope.myData = myData.list;
  891. for (var i = 0; i < $scope.myData.length; i++) {
  892. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum;
  893. }
  894. } else {
  895. SweetAlert.swal({
  896. title: "系统错误",
  897. text: "请稍后再试!",
  898. type: "error"
  899. });
  900. }
  901. $scope.ldloading[style.replace('-', '_')] = false;
  902. }, function () {
  903. $scope.ldloading[style.replace('-', '_')] = false;
  904. });
  905. };
  906. // 耗材查询分类
  907. // $scope.refreshDat_name = function () {
  908. // // var dat = {
  909. // // "key": "haocaifenlei",
  910. // // }
  911. // // api_cmdb4.fetchDataList(dat).then(function(data) {
  912. // // $scope.search_data = data;
  913. // // $scope.search_data.unshift({ 'name': '全部' });
  914. // // });
  915. // var dat = {
  916. // "key": "haocaifenlei",
  917. // "type": "tree"
  918. // }
  919. // api_wechatfile.getDictionary(dat).then(function (data) {
  920. // $scope.search_data = data;
  921. // // $scope.search_data.unshift({ 'name': '全部' });
  922. // });
  923. // };
  924. // 耗材查询分类修改
  925. $scope.refreshDat_name_updata = function () {
  926. var dat = {
  927. "key": "haocaifenlei",
  928. "type": "tree"
  929. }
  930. api_wechatfile.getDictionary(dat).then(function (data) {
  931. $scope.updata_name = data;
  932. });
  933. };
  934. // $scope.refreshDat_name();
  935. $scope.refreshDat_name_updata();
  936. // $scope.refreshDat_pinpai();
  937. // $scope.refreshDat_guige();
  938. $scope.refreshData('expand-right', $scope.fileData);
  939. $scope.timer = $interval(function () {
  940. $scope.refreshData2('expand-right', $scope.fileData);
  941. }, $rootScope.refreshTime);
  942. $scope.$on('$destroy', function () {
  943. $interval.cancel($scope.timer)
  944. });
  945. }]);
  946. //操作按钮权限控制
  947. app.controller('hc_caozuoCtrl', ['$rootScope', '$http', '$scope', '$modal', '$state', function ($rootScope, $http, $scope, $modal, $state) {
  948. // 编辑按钮
  949. $scope.edit = function () {
  950. // --------------------------------
  951. console.log($scope.item)
  952. $rootScope.isAdds = false;
  953. $rootScope.hc_eject_big = true; //编辑弹出框
  954. $rootScope.hc_eject_sma = true; //编辑弹出框
  955. $rootScope.hc_eject_unit = $scope.item.unit;//单位
  956. $rootScope.hc_eject_name_caozuo = $scope.item.name; //耗材名称
  957. $rootScope.hc_eject_brandModel_caozuo = $scope.item.brandModel; //耗材品牌型号
  958. $rootScope.hc_eject_specification_caozuo = $scope.item.specification; //耗材规格
  959. $rootScope.hc_eject_companyIds_caozuo = $scope.item.companyIds.split(','); //供货公司
  960. $rootScope.hc_eject_startPrice_caozuo = $scope.item.startPrice; //费用区间开始
  961. $rootScope.hc_eject_endPrice_caozuo = $scope.item.endPrice; //费用区间结束
  962. $rootScope.hc_eject_isWarehousing_caozuo = $scope.item.isInventory || 0; //是否库存
  963. $rootScope.hc_eject_inventoryNum_caozuo = $scope.item.inventoryNum; //耗材在库数量
  964. $rootScope.hc_eject_inventorySum_caozuo = $scope.item.inventorySum; //耗材入库数量
  965. $rootScope.hc_eject_id_caozuo = $scope.item.id; //耗材id
  966. };
  967. //查看按钮
  968. $scope.see = function () {
  969. // console.log($scope.item.id);
  970. // idd=$scope.item.id;
  971. $state.go('app.means.consumables_see', { idd: $scope.item.id })
  972. }
  973. }]);
  974. //操作
  975. app.directive('wtt', function () {
  976. return {
  977. restrict: 'E',
  978. scope: {
  979. item: '=',
  980. colobject: '='
  981. },
  982. controller: 'hc_caozuoCtrl',
  983. template: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  984. '<a class="handlefont" ng-click="see()">查看</a>' +
  985. '<a class="bianjifont" ng-click="edit()">编辑</a>' +
  986. '</div></div>'
  987. };
  988. });