controllers.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
  1. starter.controller('PayCtrl', function ($rootScope, $scope, $state, $ionicPopover, global, Member, Pay, Tool) {
  2. beforeEnter = $scope.$on("$ionicView.beforeEnter", function (event, data) {
  3. global.fetch_user().then(function () {
  4. if ($scope.recordlist == undefined) getpaydata();
  5. set_step_data();
  6. });
  7. });
  8. Member.selectedemplst = [];
  9. $scope.goBack = function () {
  10. global.goBack();
  11. };
  12. $scope.toman = function () {
  13. $state.go('payman');
  14. };
  15. $scope.torecord = function (record) {
  16. if (record) {
  17. Pay.recordItem = _.clone(record);
  18. $state.go('pay-record', {
  19. id: record.id
  20. });
  21. } else {
  22. $scope.popover.hide();
  23. $state.go('pay-record', {
  24. id: -1
  25. });
  26. }
  27. };
  28. $scope.addpaybill = function () {
  29. $scope.popover.hide();
  30. $state.go('pay-bill', {
  31. type: 0,
  32. id: -1
  33. })
  34. };
  35. $scope.toauditstep = function () {
  36. $scope.popover.hide();
  37. Member.customerop = null;
  38. if ($scope.is_have_step) {
  39. $state.go('auditstep', {
  40. "id": 0
  41. });
  42. } else {
  43. Member.selectedemplst.push({
  44. "user_id": global.user.usrid,
  45. "username": global.user.usrname
  46. });
  47. Member.dialogresult = 1;
  48. Member.customerop = 1;
  49. $state.go('auditstep', {
  50. "id": -1
  51. });
  52. }
  53. };
  54. $ionicPopover.fromTemplateUrl('templates/paymenu.html', {
  55. scope: $scope
  56. }).then(function (popover) {
  57. $scope.popover = popover;
  58. });
  59. $scope.doRefresh = function () {
  60. global.refresh = true;
  61. getpaydata();
  62. };
  63. $scope.loadMore = function () {
  64. if ($scope.recordlist != undefined && $scope.recordlist.next != null) {
  65. Tool.get($scope.recordlist.next).then(function (data) {
  66. _.each(data.results, function (item) {
  67. $scope.recordlist.results.push(item);
  68. });
  69. $scope.recordlist.next = data.next;
  70. $scope.recordlist.previous = data.previous;
  71. }).finally(function () {
  72. $scope.$broadcast('scroll.infiniteScrollComplete');
  73. $scope.loading = false;
  74. });
  75. } else {
  76. $scope.$broadcast('scroll.infiniteScrollComplete');
  77. }
  78. };
  79. $scope.moreCanBeLoaded = function () {
  80. return $scope.recordlist != undefined && $scope.recordlist.next != null;
  81. };
  82. function getpaydata() {
  83. if (global.user.token != "") {
  84. if ($scope.recordlist == undefined) {
  85. $scope.loading = true;
  86. }
  87. Pay.record.get(function (res) {
  88. Pay.recordList = _.clone(res.results);
  89. $scope.recordlist = res;
  90. $scope.roleid = global.user.roleid;
  91. }, function (err) {
  92. alert(JSON.stringify(err));
  93. }).$promise.finally(function () {
  94. $scope.$broadcast('scroll.refreshComplete');
  95. $scope.loading = false;
  96. });
  97. }
  98. }
  99. enter = $scope.$on("$ionicView.enter", function (event, data) {
  100. if (data.fromCache && $rootScope.commons.refresh) {
  101. $rootScope.commons.refresh = false;
  102. getpaydata();
  103. }
  104. });
  105. $scope.is_have_step = false;
  106. function set_step_data() {
  107. Pay.auditstep.query({"userid": global.user.usrid}, function (data) {
  108. Pay.personstepdata = data;
  109. $scope.is_have_step = data.length > 0;
  110. }, function (err) {
  111. alert(JSON.stringify(err));
  112. })
  113. }
  114. $scope.$on("$destroy", function () {
  115. enter = null;
  116. Pay.auditstepdata = [];
  117. $scope.popover.remove();
  118. });
  119. })
  120. .controller('TypeSetCtrl', function ($rootScope, $scope, $state, $ionicHistory, global, showPopup, Pay, Tool) {
  121. $scope.ordering = false;
  122. global.fetch_user().then(function () {
  123. gettypedata();
  124. });
  125. $scope.toaddtype = function () {
  126. $state.go("addtype", {
  127. "id": -1
  128. });
  129. };
  130. $scope.toedittype = function (item) {
  131. Pay.typeItem = _.clone(item);
  132. $state.go("addtype", {
  133. "id": item.id
  134. });
  135. };
  136. $scope.reorderItem = function (item, fromIndex, toIndex) {
  137. $scope.types.splice(fromIndex, 1);
  138. $scope.types.splice(toIndex, 0, item);
  139. };
  140. $scope.ok = function () {
  141. $scope.ordering = !$scope.ordering;
  142. if (!$scope.ordering) {
  143. var data = [];
  144. for (var i = 0; i < $scope.types.length; i++) {
  145. data.push({
  146. 'id': $scope.types[i].id,
  147. 'ordering': i
  148. });
  149. }
  150. Pay.type.patch(data, function (data) {
  151. $scope.doRefresh();
  152. })
  153. }
  154. };
  155. $scope.doRefresh = function () {
  156. global.refresh = true;
  157. gettypedata();
  158. }
  159. function gettypedata() {
  160. if (global.user.token != "") {
  161. if ($scope.types == undefined) {
  162. $scope.loading = true;
  163. }
  164. Pay.type.get(function (res) {
  165. $scope.types = res;
  166. Pay.typeList = res;
  167. }, function (err) {
  168. alert(JSON.stringify(err));
  169. }).$promise.finally(function () {
  170. $scope.$broadcast('scroll.refreshComplete');
  171. $scope.loading = false;
  172. });
  173. }
  174. }
  175. enter = $scope.$on("$ionicView.enter", function (event, data) {
  176. if (data.fromCache && $rootScope.commons.refresh) {
  177. $rootScope.commons.refresh = false;
  178. gettypedata();
  179. }
  180. });
  181. $scope.$on("$destroy", function () {
  182. enter = null;
  183. });
  184. })
  185. .controller('AuditStepSetCtrl', function ($rootScope, $scope, $state, $ionicPopover, $timeout, $location, $ionicScrollDelegate, $ionicHistory, global, showPopup, Member, Pay) {
  186. $ionicPopover.fromTemplateUrl('templates/add.html', {
  187. scope: $scope
  188. }).then(function (popover) {
  189. $scope.popover = popover;
  190. });
  191. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  192. getPayStepMflist();
  193. });
  194. $scope.sortchars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '#'];
  195. $scope.sortchar = 'A';
  196. $scope.is_show_middle = false;
  197. $scope.is_show_delete = false;
  198. $scope.sortByChar = function (char, id) {
  199. $scope.sortchar = char;
  200. $scope.is_show_middle = true;
  201. $location.hash(id);
  202. $ionicScrollDelegate.anchorScroll();
  203. $timeout(function () {
  204. $scope.is_show_middle = false;
  205. }, 200);
  206. };
  207. $scope.displayremove = function () {
  208. $scope.is_show_delete = !$scope.is_show_delete;
  209. $scope.popover.hide();
  210. };
  211. $scope.ok = function () {
  212. $scope.popover.hide();
  213. $scope.is_show_delete = false;
  214. var data = {"U": [], "D": delete_data, "C": []};
  215. if (delete_data.length > 0) {
  216. Pay.auditstep.patch(data, function (data) {
  217. console.log(data);
  218. }, function (err) {
  219. // alert('delete error');
  220. }).$promise.finally(function (f) {
  221. delete_data = [];
  222. });
  223. Pay.auditstepdata = _.filter(Pay.auditstepdata, function (item) {
  224. return !_.contains(delete_data, item.id);
  225. });
  226. }
  227. };
  228. $scope.toadd = function () {
  229. Member.resourcemember = [];
  230. Member.selectedemplst = [];
  231. Member.disabled = true;
  232. Member.resourcemember = _.map(_.pluck(Pay.auditstepdata, 'create_user'), function (m) {
  233. return {"user_id": m.id, "username": m.username};
  234. });
  235. Member.showall = false;
  236. Member.showgroup = false;
  237. Member.customerop = 1;
  238. Member.titlename = "选择添加的成员";
  239. Member.routename = "auditstep";
  240. Member.routeparams = {
  241. "id": -1
  242. };
  243. $scope.popover.hide();
  244. $state.go('selectmember');
  245. };
  246. var delete_data = [];
  247. $scope.removeItem = function (user, _char) {
  248. var ids = _.pluck(_.filter(Pay.auditstepdata, function (item) {
  249. return item.create_user.id == user.id;
  250. }), 'id');
  251. delete_data = delete_data.concat(ids);
  252. for (var i = 0; i < $scope.resultdata.length; i++) {
  253. if ($scope.resultdata[i].sortchar == _char) {
  254. for (var j = 0; j < $scope.resultdata[i].persons.length; j++) {
  255. if ($scope.resultdata[i].persons[j].emp.id == user.id) {
  256. $scope.resultdata[i].persons.splice(j, 1);
  257. if ($scope.resultdata[i].persons.length == 0) {
  258. $scope.resultdata.splice(i, 1);
  259. }
  260. break;
  261. }
  262. }
  263. break;
  264. }
  265. }
  266. };
  267. $scope.toedit = function (usrid) {
  268. Member.customerop = null;
  269. $state.go('auditstep', {
  270. "id": usrid
  271. });
  272. };
  273. $scope.doRefresh = function () {
  274. getPayStepMflist();
  275. };
  276. function getPayStepMflist() {
  277. if ($scope.resultdata == undefined) {
  278. showPopup.showLoading(1, '正在加载', false);
  279. }
  280. Pay.auditstep.query(function (data) {
  281. Pay.auditstepdata = angular.copy(data);
  282. $scope.resultdata = [];
  283. var chars = _.map(data, function (item) {
  284. return _.indexOf($scope.sortchars, getCamelChar(item.create_user.username)) >= 0 ? getCamelChar(item.create_user.username) : '#';
  285. });
  286. chars = _.sortBy(_.uniq(chars));
  287. for (var i = 0; i < chars.length; i++) {
  288. var d = {
  289. "sortchar": chars[i],
  290. "persons": []
  291. };
  292. var users = _.map(_.uniq(_.map(_.pluck(data, 'create_user'), JSON.stringify)), JSON.parse);
  293. for (var j = 0; j < users.length; j++) {
  294. var char = _.indexOf($scope.sortchars, getCamelChar(users[j].username)) >= 0 ? getCamelChar(users[j].username) : '#';
  295. if (char == chars[i]) {
  296. var p = {"emp": users[j], "checknames": ""};
  297. var steps = _.sortBy(_.filter(data, function (v) {
  298. return v.create_user.id == users[j].id && !v.is_teller;
  299. }), 'ordering');
  300. var newsteps = steps.length > 3 ? steps.slice(0, 3) : steps;
  301. p.checknames = _.pluck(_.pluck(newsteps, 'verifier'), 'username').join('→');
  302. if (steps.length > 3) p.checknames += '...';
  303. d.persons.push(p)
  304. }
  305. }
  306. $scope.resultdata.push(d);
  307. }
  308. var index = _.pluck($scope.resultdata, 'sortchar').indexOf('#');
  309. if (index >= 0) {
  310. var item = $scope.resultdata[index];
  311. $scope.resultdata.splice(index, 1);
  312. $scope.resultdata.push(item);
  313. }
  314. showPopup.hideLoading();
  315. }, function (err) {
  316. showPopup.hideLoading();
  317. }).$promise.finally(function (f) {
  318. $scope.$broadcast('scroll.refreshComplete');
  319. });
  320. }
  321. function getCamelChar(str) {
  322. return pinyin.getCamelChars(str).toUpperCase().charAt(0)
  323. }
  324. })
  325. .controller('AddTypeCtrl', function ($rootScope, $scope, $state, $ionicHistory, global, showPopup, Pay, Tool) {
  326. var icon = {icon: null}, iconcolor = null, isModified = false;
  327. $scope.typeid = $state.params['id'];
  328. $scope.data = {
  329. "name": "",
  330. "icon": "",
  331. "icon_color": "",
  332. "ordering": 0
  333. };
  334. $scope.iconcolordata = [{
  335. 'background': "#FCB232",
  336. 'isacitve': false
  337. }, {
  338. 'background': "#F89E79",
  339. 'isacitve': false
  340. }, {
  341. 'background': "#FB7B7A",
  342. 'isacitve': false
  343. }, {
  344. 'background': "#F393C3",
  345. 'isacitve': false
  346. }, {
  347. 'background': "#DF9FF3",
  348. 'isacitve': false
  349. }, {
  350. 'background': "#C08CCE",
  351. 'isacitve': false
  352. }, {
  353. 'background': "#609BF5",
  354. 'isacitve': false
  355. }, {
  356. 'background': "#4BB1FB",
  357. 'isacitve': false
  358. }, {
  359. 'background': "#89cff0",
  360. 'isacitve': false
  361. }, {
  362. 'background': "#68D3C9",
  363. 'isacitve': false
  364. }, {
  365. 'background': "#87CC79",
  366. 'isacitve': false
  367. }, {
  368. 'background': "#4AD592",
  369. 'isacitve': false
  370. }, {
  371. 'background': "#C8BEBD",
  372. 'isacitve': false
  373. }, {
  374. 'background': "#CBA7AB",
  375. 'isacitve': false
  376. }, {
  377. 'background': "#868CA6",
  378. 'isacitve': false
  379. }, {
  380. 'background': "#8299CF",
  381. 'isacitve': false
  382. }, {
  383. 'background': "#A0C7E6",
  384. 'isacitve': false
  385. }, {
  386. 'background': "#90B1B6",
  387. 'isacitve': false
  388. }];
  389. $scope.icondata = [{
  390. 'background': "#fff",
  391. 'icon': "ion-android-bus",
  392. 'isacitve': false
  393. }, {
  394. 'background': "#fff",
  395. 'icon': "ion-ios-cart",
  396. 'isacitve': false
  397. }, {
  398. 'background': "#fff",
  399. 'icon': "ion-ios-telephone",
  400. 'isacitve': false
  401. }, {
  402. 'background': "#fff",
  403. 'icon': "ion-ios-home",
  404. 'isacitve': false
  405. }, {
  406. 'background': "#fff",
  407. 'icon': "ion-fork",
  408. 'isacitve': false
  409. }, {
  410. 'background': "#fff",
  411. 'icon': "icon-money",
  412. 'isacitve': false
  413. }, {
  414. 'background': "#fff",
  415. 'icon': "ion-android-film",
  416. 'isacitve': false
  417. }, {
  418. 'background': "#fff",
  419. 'icon': "ion-umbrella",
  420. 'isacitve': false
  421. }, {
  422. 'background': "#fff",
  423. 'icon': "ion-ios-game-controller-b",
  424. 'isacitve': false
  425. }, {
  426. 'background': "#fff",
  427. 'icon': "ion-android-print",
  428. 'isacitve': false
  429. }, {
  430. 'background': "#fff",
  431. 'icon': "ion-tshirt",
  432. 'isacitve': false
  433. }, {
  434. 'background': "#fff",
  435. 'icon': "ion-ios-medkit",
  436. 'isacitve': false
  437. }, {
  438. 'background': "#fff",
  439. 'icon': "ion-outlet",
  440. 'isacitve': false
  441. }, {
  442. 'background': "#fff",
  443. 'icon': "ion-android-bicycle",
  444. 'isacitve': false
  445. }, {
  446. 'background': "#fff",
  447. 'icon': "ion-ios-pulse-strong",
  448. 'isacitve': false
  449. }, {
  450. 'background': "#fff",
  451. 'icon': "ion-trophy",
  452. 'isacitve': false
  453. }, {
  454. 'background': "#fff",
  455. 'icon': "ion-android-favorite",
  456. 'isacitve': false
  457. }, {
  458. 'background': "#fff",
  459. 'icon': "ion-ios-cloud-download",
  460. 'isacitve': false
  461. }, {
  462. 'background': "#fff",
  463. 'icon': "ion-plane",
  464. 'isacitve': false
  465. }, {
  466. 'background': "#fff",
  467. 'icon': "ion-android-bar",
  468. 'isacitve': false
  469. }, {
  470. 'background': "#fff",
  471. 'icon': "ion-nuclear",
  472. 'isacitve': false
  473. }, {
  474. 'background': "#fff",
  475. 'icon': "ion-film-marker",
  476. 'isacitve': false
  477. }, {
  478. 'background': "#fff",
  479. 'icon': "ion-icecream",
  480. 'isacitve': false
  481. }, {
  482. 'background': "#fff",
  483. 'icon': "ion-flag",
  484. 'isacitve': false
  485. }];
  486. global.fetch_user().then(function () {
  487. if ($scope.typeid > 0) {
  488. $scope.data = Tool.cloneObj(Pay.typeItem);
  489. iconcolor = _.find($scope.iconcolordata, function (item) {
  490. if (item.background == $scope.data.icon_color) {
  491. item.isacitve = true;
  492. return item;
  493. }
  494. });
  495. iconcolor = iconcolor.background;
  496. icon = _.find($scope.icondata, function (item) {
  497. if (item.icon == $scope.data.icon) {
  498. item.isacitve = true;
  499. item.background = $scope.data.icon_color;
  500. return item;
  501. }
  502. });
  503. } else {
  504. $scope.data.ordering = Pay.typeList.length;
  505. $scope.iconcolordata[0].isacitve = true;
  506. $scope.icondata[0].background = '#FCB232';
  507. $scope.icondata[0].isacitve = true;
  508. iconcolor = $scope.iconcolordata[0].background;
  509. icon.icon = $scope.icondata[0].icon;
  510. }
  511. });
  512. if ($scope.typeid > 0) {
  513. watch = $scope.$watch('data', function (n, o) {
  514. if (n == o)
  515. return;
  516. isModified = true;
  517. }, true);
  518. }
  519. $scope.selecticon = function (iconitem) {
  520. _.find($scope.icondata, function (item) {
  521. if (item.isacitve) {
  522. item.isacitve = false;
  523. item.background = '#fff';
  524. return item;
  525. }
  526. });
  527. iconitem.isacitve = true;
  528. iconitem.background = iconcolor;
  529. icon = iconitem;
  530. };
  531. $scope.selectcolor = function (coloritem) {
  532. _.find($scope.iconcolordata, function (item) {
  533. if (item.isacitve) {
  534. item.isacitve = false;
  535. return item;
  536. }
  537. });
  538. coloritem.isacitve = true;
  539. icon.background = coloritem.background;
  540. iconcolor = coloritem.background;
  541. };
  542. $scope.ok = function () {
  543. if ($scope.data.name == "") {
  544. return showPopup.PopupWindow(0, '类型名称不能为空!');
  545. }
  546. $scope.data.icon = icon.icon;
  547. $scope.data.icon_color = iconcolor;
  548. var type = null;
  549. if ($scope.typeid > 0) {
  550. if (isModified) {
  551. type = _.find(Pay.typeList, function (item) {
  552. if (item.id != $scope.typeid && item.name == $scope.data.name) {
  553. showPopup.PopupWindow(0, '类型名称不能重复!');
  554. return item;
  555. }
  556. });
  557. if (!type) {
  558. showPopup.showLoading(1, '正在上传');
  559. Pay.type.update($scope.data, function () {
  560. $rootScope.commons.refresh = true;
  561. showPopup.hideLoading();
  562. $scope.back();
  563. });
  564. }
  565. } else {
  566. $scope.back();
  567. }
  568. } else {
  569. type = _.find(Pay.typeList, function (item) {
  570. if (item.name == $scope.data.name) {
  571. showPopup.PopupWindow(0, '类型名称不能重复!');
  572. return item;
  573. }
  574. });
  575. if (!type) {
  576. showPopup.showLoading(1, '正在上传');
  577. Pay.type.save($scope.data, function () {
  578. $rootScope.commons.refresh = true;
  579. showPopup.hideLoading();
  580. $scope.back();
  581. });
  582. }
  583. }
  584. };
  585. $scope.deltype = function () {
  586. showPopup.confirm('确定删除该类型吗?', '确定', '取消').then(function (res) {
  587. if (res) {
  588. showPopup.showLoading(1, '正在删除');
  589. Pay.type.delete({'id': $scope.typeid}, function () {
  590. $rootScope.commons.refresh = true;
  591. showPopup.hideLoading();
  592. $scope.back();
  593. });
  594. }
  595. });
  596. };
  597. $scope.back = function () {
  598. $ionicHistory.goBack();
  599. };
  600. $scope.$on('$destroy', function () {
  601. if ($scope.typeid > 0) {
  602. watch();
  603. }
  604. })
  605. })
  606. .controller('AuditStepCtrl', function ($rootScope, $scope, $state, $ionicHistory, $timeout, global, Member, showPopup, Pay, Tool) {
  607. $scope.create_users = [];
  608. $scope.step_users = [];
  609. $scope.teller = null;
  610. $scope.op_id = 0;
  611. var beforeEnter = $scope.$on("$ionicView.enter", function () {
  612. $scope.op_id = $state.params['id'];
  613. if ($scope.op_id != 0) Tool.removeBackView(['selectmember', 'selectsinglemember', 'auditstep']);
  614. var back = $ionicHistory.backView();
  615. if ($scope.op_id > 0) {
  616. $scope.titlename = "编辑审批步骤";
  617. if (Member.customerop == null) {
  618. $scope.create_users = [_.find(Pay.auditstepdata, function (item) {
  619. return item.create_user.id == $scope.op_id;
  620. }).create_user];
  621. setusers(Pay.auditstepdata, $scope.op_id);
  622. } else seteditdata();
  623. } else if ($scope.op_id < 0) {
  624. $scope.titlename = "添加审批步骤";
  625. setdata();
  626. if (back.stateName == 'pay' && Member.customerop == null && Pay.personstepdata.length > 0) setusers(Pay.personstepdata, Pay.personstepdata[0].create_user.id);
  627. } else if ($scope.op_id == 0) { //修改当前登录人的审批步骤
  628. $scope.titlename = "编辑审批步骤";
  629. if (Member.customerop == null) {
  630. if (Pay.personstepdata.length == 0) {
  631. Pay.auditstep.query({"userid": global.user.usrid}, function (data) {
  632. $scope.step_data = angular.copy(data);
  633. $scope.create_users.push({"id": global.user.usrid, "username": global.user.usrname});
  634. setusers(data, global.user.usrid);
  635. });
  636. } else {
  637. $scope.create_users = [{"id": global.user.usrid, "username": global.user.usrname}];
  638. setusers(Pay.personstepdata, Pay.personstepdata[0].create_user.id);
  639. }
  640. } else setdata();
  641. $scope.showbar = true;
  642. }
  643. $scope.is_current_user = (global.user.usrid == formatusers($scope.create_users)[0].user_id && back.stateName == "pay");
  644. });
  645. $scope.$on("$destroy", function () {
  646. Pay.personstepdata = [];
  647. Member.selectedemplst = [];
  648. Member.unenabledata = [];
  649. beforeEnter = null;
  650. });
  651. $scope.add_teller = function () {
  652. set_member_option(false, $scope.teller == null ? [] : [$scope.teller], 3, "选择出纳人员", "selectsinglemember");
  653. };
  654. $scope.add_step_user = function () {
  655. set_member_option(true, $scope.step_users, 2, "选择审批人", "selectsinglemember");
  656. };
  657. $scope.add_create_user = function () {
  658. set_member_option(false, $scope.create_users, 1, "选择添加的成员", "selectmember");
  659. Member.unenabledata = formatusers(_.pluck(Pay.auditstepdata, "create_user"));
  660. };
  661. $scope.ok = function () {
  662. if ($scope.step_users.length == 0) {
  663. showPopup.PopupWindow(0, "请选择审批人!", false);
  664. return;
  665. }
  666. if ($scope.teller == null) {
  667. showPopup.PopupWindow(0, "请选择出纳人!", false);
  668. return;
  669. }
  670. showPopup.showLoading(1, '正在提交', false);
  671. if ($scope.op_id >= 0) {//edit
  672. Pay.auditstep.patch({"C": [], "D": [], "U": get_upload_data()}, function (data) {
  673. showPopup.hideLoading();
  674. $ionicHistory.goBack();
  675. }, function (err) {
  676. showPopup.hideLoading();
  677. // alert(JSON.stringify(err))
  678. $ionicHistory.goBack();
  679. })
  680. } else if ($scope.op_id < 0) { //add
  681. Pay.auditstep.save(get_upload_data(), function (data) {
  682. showPopup.hideLoading();
  683. $ionicHistory.goBack();
  684. }, function (err) {
  685. alert(JSON.stringify(err));
  686. })
  687. }
  688. };
  689. $scope.goback = function () {
  690. $ionicHistory.goBack();
  691. };
  692. $scope.toSeeList = function () {
  693. $state.go("seestepmflist");
  694. };
  695. function set_member_option(is_disabled, data, op, titlename, route) {
  696. Member.selectedemplst = [];
  697. Member.disabled = is_disabled;
  698. Member.resourcemember = formatusers(data);
  699. Member.customerop = op;
  700. Member.titlename = titlename;
  701. $state.go(route);
  702. }
  703. function seteditdata() {
  704. $scope.titlename = "编辑审批步骤";
  705. if (Member.customerop == null) $scope.create_users = Member.selectedemplst;
  706. setdata();
  707. }
  708. function setdata() {
  709. if (Member.customerop == 1) { //申请
  710. if (Member.dialogresult == 1) $scope.create_users = Member.selectedemplst;
  711. } else if (Member.customerop == 2) { //审核
  712. if (Member.selectedemplst.length > 0) $scope.step_users.push(Member.selectedemplst[0])
  713. } else if (Member.customerop == 3) {//出纳
  714. if (Member.selectedemplst.length > 0) $scope.teller = Member.selectedemplst[0]
  715. }
  716. }
  717. function get_upload_data() {
  718. var data = [];
  719. _.each($scope.create_users, function (c_user) {
  720. data = data.concat(_.map($scope.step_users, function (s_user, index) {
  721. return {"create_user": getuserid(c_user), "verifier": getuserid(s_user), "is_teller": false, "ordering": index + 1};
  722. }));
  723. data.push({"create_user": getuserid(c_user), "verifier": getuserid($scope.teller), "is_teller": true, "ordering": $scope.step_users.length + 1})
  724. });
  725. return data;
  726. }
  727. function getuserid(user) {
  728. return _.has(user, 'id') ? user.id : user.user_id;
  729. }
  730. function setusers(data, userid) {
  731. $scope.step_users = _.pluck(_.sortBy(_.filter(data, function (item) {
  732. return item.create_user.id == userid && !item.is_teller;
  733. }), "ordering"), 'verifier');
  734. $scope.teller = _.find(data, function (item) {
  735. return item.create_user.id == userid && item.is_teller;
  736. }).verifier;
  737. }
  738. function formatusers(data) {
  739. return _.map(data, function (item) {
  740. return {"user_id": _.has(item, 'id') ? item.id : item.user_id, "username": item.username}
  741. })
  742. }
  743. })
  744. .controller('SeeStepMfListCtrl', function ($rootScope, $scope, $state, $ionicHistory, $cordovaDatePicker, $timeout, global, Pay, Member, showPopup) {
  745. doRefresh();
  746. $scope.usestep = function (step) {
  747. Member.customerop = null;
  748. Pay.personstepdata = _.filter($scope.step_data_copy, function (item) {
  749. return item.create_user.id == step.create_user.id;
  750. });
  751. $ionicHistory.goBack();
  752. };
  753. $scope.doRefresh = function () {
  754. doRefresh();
  755. };
  756. function doRefresh() {
  757. if ($scope.step_datas == undefined) showPopup.showLoading(1, '正在加载', false);
  758. Pay.auditstep.query(function (data) {
  759. $scope.step_datas = [];
  760. $scope.step_data_copy = angular.copy(data);
  761. var users = _.map(_.uniq(_.map(_.pluck(data, 'create_user'), JSON.stringify)), JSON.parse);
  762. _.each(users, function (user) {
  763. if (user.id != global.user.usrid) {
  764. var step_users = _.pluck(_.sortBy(_.filter(data, function (item) {
  765. return item.create_user.id == user.id && !item.is_teller;
  766. }), 'ordering'), 'verifier');
  767. var step_usernames = _.pluck(step_users, 'username').join('→');
  768. var teller = _.find(data, function (item) {
  769. return item.create_user.id == user.id && item.is_teller;
  770. }).verifier;
  771. $scope.step_datas.push({"create_user": user, "step_users": step_users, "teller": teller, "step_usernames": step_usernames})
  772. }
  773. })
  774. }, function (err) {
  775. showPopup.hideLoading();
  776. alert(JSON.stringify(err));
  777. }).$promise.finally(function () {
  778. $scope.$broadcast('scroll.refreshComplete');
  779. showPopup.hideLoading();
  780. });
  781. }
  782. $scope.goback = function () {
  783. $ionicHistory.goBack();
  784. };
  785. })
  786. .controller('PayRecordCtrl', function ($rootScope, $scope, $state, $cordovaDatePicker, $timeout, $ionicModal, $ionicHistory, $q, ImageManage, global, showPopup, Pay, Tool) {
  787. showPopup.modalTemplate('templates/modal-paytype.html', 'slide-in-right', $scope).then(function (modal) {
  788. $scope.select_pay_type = modal;
  789. });
  790. $scope.recordid = $state.params['id'];
  791. $scope.titleArr = ['新建', '编辑'];
  792. $scope.popup = {
  793. isPopup: false
  794. };
  795. $scope.record = {
  796. "amount": null,
  797. "pay_type": null,
  798. "type_modal": null,
  799. "spend_date": null,
  800. "description": null,
  801. "files": []
  802. };
  803. var isModified = false;
  804. Pay.type.get(function (res) {
  805. $scope.types = res;
  806. Pay.typeList = res;
  807. _.each($scope.types, function (type) {
  808. type.color = {
  809. 'color': type.icon_color
  810. };
  811. type.selected = false;
  812. });
  813. }, function (err) {
  814. alert(JSON.stringify(err));
  815. });
  816. if ($scope.recordid > 0) {
  817. $scope.record = Tool.cloneObj(Pay.recordItem);
  818. $scope.record.amount = parseFloat($scope.record.amount);
  819. }
  820. $scope.ok = function () {
  821. if ($scope.record.amount == null) {
  822. showPopup.PopupWindow(0, "请填写金额", false);
  823. return
  824. } else if ($scope.record.type_modal == null) {
  825. showPopup.PopupWindow(0, "请选择消费类型", false);
  826. return
  827. } else if ($scope.record.spend_date == null) {
  828. showPopup.PopupWindow(0, "请选择消费日期", false);
  829. return
  830. }
  831. showPopup.showLoading(1, '正在提交', true);
  832. if ($scope.recordid > 0) {
  833. if (isModified) {
  834. Pay.record.update($scope.record, function () {
  835. $rootScope.commons.refresh = true;
  836. _.each($scope.deleteimage_list, function (imageID) {
  837. Pay.recordfile.delete({id: imageID});
  838. });
  839. var imagefiles = [];
  840. _.each($scope.record.files, function (image) {
  841. if (!image.id)
  842. imagefiles.push(image.file_full_path);
  843. });
  844. if (imagefiles.length > 0) {
  845. postimg(imagefiles, $scope.recordid);
  846. } else {
  847. showPopup.hideLoading();
  848. $ionicHistory.goBack();
  849. }
  850. });
  851. }
  852. } else {
  853. Pay.record.save($scope.record, function (data) {
  854. $rootScope.commons.refresh = true;
  855. var imagefiles = [];
  856. _.each($scope.record.files, function (image) {
  857. if (!image.id)
  858. imagefiles.push(image.file_full_path);
  859. });
  860. if (imagefiles.length > 0) {
  861. postimg(imagefiles, data.id);
  862. } else {
  863. showPopup.hideLoading();
  864. $ionicHistory.goBack();
  865. }
  866. }, function (err) {
  867. alert('post Record error' + err);
  868. });
  869. }
  870. }
  871. $scope.selectSpendDate = function (spend_date) {
  872. var options = {
  873. mode: 'date',
  874. date: spend_date ? new Date(spend_date) : new Date(),
  875. androidTheme: 3
  876. };
  877. $cordovaDatePicker.show(options).then(function (date) {
  878. if (date == undefined) return;
  879. $scope.record.spend_date = date;
  880. });
  881. }
  882. $scope.selectPayType = function () {
  883. $scope.select_pay_type.show();
  884. $rootScope.commons.modal = $scope.select_pay_type;
  885. }
  886. $scope.cancel = function (op) {
  887. $rootScope.commons.modal.hide();
  888. }
  889. $scope.checkType = function (type) {
  890. $scope.pay_type = type.id;
  891. $scope.record.type_modal = type;
  892. $rootScope.commons.modal.hide();
  893. }
  894. $scope.deleteRecord = function () {
  895. showPopup.confirm("是否删除该消费记录?", '是', '否').then(function (res) {
  896. if (res) {
  897. Pay.record.delete({id: $scope.recordid}, function () {
  898. $rootScope.commons.refresh = true;
  899. $ionicHistory.goBack();
  900. });
  901. }
  902. });
  903. }
  904. $scope.addphoto = function () {
  905. if ($scope.record.files.length < 5) {
  906. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  907. $scope.popup.isPopup = true;
  908. } else {
  909. showPopup.PopupWindow(0, "上传图片数量需小于等于5!", false);
  910. }
  911. };
  912. var ImagePicker = function () { //打开相册
  913. $scope.popup.optionsPopup.close();
  914. ImageManage.ImagePicker_getPictures(5).then(function (result) {
  915. _.each(result, function (imageUrl) {
  916. $scope.record.files.push({
  917. "file_thumbnail_path": imageUrl,
  918. "file_full_path": imageUrl
  919. });
  920. })
  921. });
  922. };
  923. var Camera = function () {
  924. $scope.popup.optionsPopup.close();
  925. ImageManage.Camera_getPicture(true).then(function (result) {
  926. $scope.record.files.push({
  927. "file_thumbnail_path": result,
  928. "file_full_path": result
  929. });
  930. });
  931. };
  932. function postimg(imgfiles, id) {
  933. ImageManage.uploadImage(imgfiles, 'pay', id, 'payrecordfile').then(function (res) {
  934. $q.all(res).then(function (data) {
  935. showPopup.hideLoading();
  936. $ionicHistory.goBack();
  937. })
  938. }, function (err) {
  939. alert(JSON.stringify(error));
  940. showPopup.PopupWindow(0, 'upload image fail');
  941. })
  942. }
  943. $scope.deleteimage_list = [];
  944. $scope.shouBigImage = function (imageUrl) {
  945. $scope.Url = imageUrl;
  946. $rootScope.commons.bigImage = true;
  947. };
  948. $rootScope.commons.bigImage = false;
  949. $scope.hideBigImage = function () {
  950. $rootScope.commons.bigImage = false;
  951. };
  952. $scope.deleteimage = function () {
  953. var img = _.find($scope.record.files, function (image) {
  954. return image.file_full_path == $scope.Url;
  955. });
  956. if (img) {
  957. $scope.record.files.splice(_.indexOf($scope.record.files, img), 1);
  958. if (img.id)
  959. $scope.deleteimage_list.push(img.id);
  960. }
  961. $rootScope.commons.bigImage = false;
  962. };
  963. if ($scope.recordid > 0) {
  964. watch = $scope.$watch('record', function (n, o) {
  965. if (n == o)
  966. return;
  967. isModified = true;
  968. }, true);
  969. }
  970. $scope.$on("$destroy", function () {
  971. $scope.select_pay_type.remove();
  972. if ($scope.recordid > 0) {
  973. watch();
  974. }
  975. });
  976. })
  977. .controller('PayBillCtrl', function ($rootScope, $scope, $state, $ionicHistory, $ionicModal, global, showPopup, Pay, Tool) {
  978. $scope.select_record = showPopup.modalTemplate('templates/modal-selectrecord.html', 'slide-in-right', $scope);
  979. var isFirst = false;
  980. $scope.type = $state.params['type'];
  981. $scope.billid = $state.params['id']
  982. $scope.titleArr = ['新建', '编辑'];
  983. $scope.amountSum = 0;
  984. $scope.bill = {
  985. "title": null,
  986. "note": null,
  987. "status": null,
  988. "record": [],
  989. "record_old": []
  990. }
  991. $scope.records = [];
  992. global.fetch_user().then(function () {
  993. Pay.auditstep.get({userid: global.user.usrid}, function (data) {
  994. $scope.checkusrdata = data;
  995. });
  996. if ($scope.billid < 0) {
  997. $scope.recordlist = Tool.cloneObj(Pay.recordList);
  998. $scope.select_record.then(function (modal) {
  999. $scope.select_record = modal;
  1000. $rootScope.commons.modal = modal;
  1001. $scope.select_record.show();
  1002. });
  1003. isFirst = true;
  1004. } else {
  1005. $scope.select_record.then(function (modal) {
  1006. $scope.select_record = modal;
  1007. $rootScope.commons.modal = modal;
  1008. });
  1009. $scope.bill = Tool.cloneObj(Pay.detailItem);
  1010. $scope.recordlist = Tool.cloneObj(Pay.recordList);
  1011. $scope.records = $scope.bill.record;
  1012. $scope.bill.record_old = _.map($scope.bill.record, function (record) {
  1013. return record.id;
  1014. });
  1015. _.each($scope.records.reverse(), function (record) {
  1016. record.selected = true;
  1017. $scope.recordlist.splice(0, 0, record);
  1018. });
  1019. $scope.amountSum = $scope.bill.total_amount;
  1020. }
  1021. });
  1022. $scope.selectRecord = function (recorditem) {
  1023. if (recorditem.selected) {
  1024. $scope.amountSum = parseFloat($scope.amountSum) + parseFloat(recorditem.amount);
  1025. } else {
  1026. $scope.amountSum = parseFloat($scope.amountSum) - parseFloat(recorditem.amount);
  1027. }
  1028. $scope.amountSum = $scope.amountSum.toFixed(2);
  1029. };
  1030. $scope.toEditRecord = function () {
  1031. $scope.select_record.show();
  1032. $rootScope.commons.modal = $scope.select_record;
  1033. };
  1034. $scope.cancel = function (op) {
  1035. if (op == 'm') {
  1036. if (isFirst) {
  1037. $ionicHistory.goBack();
  1038. }
  1039. $rootScope.commons.modal.hide();
  1040. $rootScope.commons.modal = undefined;
  1041. } else {
  1042. $ionicHistory.goBack();
  1043. }
  1044. };
  1045. $scope.ok = function (op) {
  1046. if (op == 'bill') {
  1047. if ($scope.bill.title == null) {
  1048. showPopup.PopupWindow(0, "请填写标题", false);
  1049. return;
  1050. }
  1051. $scope.bill.record = _.map($scope.records, function (item) {
  1052. return item.id;
  1053. });
  1054. showPopup.showLoading(1, '正在提交', false);
  1055. if ($scope.billid < 0) {
  1056. Pay.billdetail.save($scope.bill, function (data) {
  1057. showPopup.hideLoading();
  1058. $state.go('paybilldetails', {
  1059. id: data.id
  1060. });
  1061. }, function (err) {
  1062. alert(JSON.stringify(err))
  1063. });
  1064. } else {
  1065. $scope.bill = _.pick($scope.bill, 'id', 'title', 'note', 'status', 'record', 'record_old');
  1066. Pay.billdetail.update($scope.bill, function (data) {
  1067. showPopup.hideLoading();
  1068. $state.go('paybilldetails', {
  1069. id: data.id
  1070. });
  1071. }, function (err) {
  1072. alert(JSON.stringify(err))
  1073. });
  1074. }
  1075. } else {
  1076. $scope.records = _.filter($scope.recordlist, function (item) {
  1077. return item.selected;
  1078. });
  1079. $rootScope.commons.modal.hide();
  1080. }
  1081. }
  1082. $scope.$on("$destroy", function () {
  1083. $scope.select_record.remove();
  1084. });
  1085. })
  1086. .controller('BillListCtrl', function ($rootScope, $scope, $state, global, Pay) {
  1087. var type = $state.params['type'];
  1088. global.fetch_user().then(function () {
  1089. getpaylistdata();
  1090. });
  1091. $scope.doRefresh = function () {
  1092. global.refresh = true;
  1093. getpaylistdata();
  1094. };
  1095. $scope.loadMore = function () {
  1096. if ($scope.bills != undefined && $scope.bills.next != null) {
  1097. Tool.get($scope.bills.next).then(function (data) {
  1098. _.each(data.results, function (item) {
  1099. $scope.bills.results.push(item);
  1100. });
  1101. $scope.bills.next = data.next;
  1102. $scope.bills.previous = data.previous;
  1103. }).finally(function () {
  1104. $scope.$broadcast('scroll.infiniteScrollComplete');
  1105. $scope.loading = false;
  1106. });
  1107. } else {
  1108. $scope.$broadcast('scroll.infiniteScrollComplete');
  1109. }
  1110. };
  1111. $scope.moreCanBeLoaded = function () {
  1112. return $scope.bills != undefined && $scope.bills.next != null;
  1113. };
  1114. function getpaylistdata() {
  1115. if (global.user.token != "") {
  1116. if ($scope.bills == undefined) {
  1117. $scope.loading = true;
  1118. }
  1119. Pay.bill.get({type: type}, function (data) {
  1120. $scope.bills = data;
  1121. }, function (err) {
  1122. alert(JSON.stringify(err));
  1123. }).$promise.finally(function () {
  1124. $scope.$broadcast('scroll.refreshComplete');
  1125. $scope.loading = false;
  1126. });
  1127. }
  1128. }
  1129. })
  1130. .controller('BillApproveCtrl', function ($rootScope, $scope, $state, global, Pay) {
  1131. var type = $state.params['type'];
  1132. global.fetch_user().then(function () {
  1133. getpaylistdata();
  1134. });
  1135. $scope.doRefresh = function () {
  1136. global.refresh = true;
  1137. getpaylistdata();
  1138. };
  1139. $scope.loadMore = function () {
  1140. if ($scope.bills != undefined && $scope.bills.next != null) {
  1141. Tool.get($scope.bills.next).then(function (data) {
  1142. _.each(data.results, function (item) {
  1143. $scope.bills.results.push(item);
  1144. });
  1145. $scope.bills.next = data.next;
  1146. $scope.bills.previous = data.previous;
  1147. }).finally(function () {
  1148. $scope.$broadcast('scroll.infiniteScrollComplete');
  1149. $scope.loading = false;
  1150. });
  1151. } else {
  1152. $scope.$broadcast('scroll.infiniteScrollComplete');
  1153. }
  1154. };
  1155. $scope.moreCanBeLoaded = function () {
  1156. return $scope.bills != undefined && $scope.bills.next != null;
  1157. };
  1158. function getpaylistdata() {
  1159. if (global.user.token != "") {
  1160. if ($scope.bills == undefined) {
  1161. $scope.loading = true;
  1162. }
  1163. Pay.bill.get({type: type}, function (data) {
  1164. $scope.bills = data;
  1165. }, function (err) {
  1166. alert(JSON.stringify(err));
  1167. }).$promise.finally(function () {
  1168. $scope.$broadcast('scroll.refreshComplete');
  1169. $scope.loading = false;
  1170. });
  1171. }
  1172. }
  1173. })
  1174. .controller('BillApprovedCtrl', function ($rootScope, $scope, $state, global, Pay, Member, Tool) {
  1175. var type = $state.params['type'];
  1176. $scope.centerdata = [
  1177. {"key": null, "name": "全部状态", "check": true},
  1178. {"key": 0, "name": "已驳回", "check": false},
  1179. {"key": 1, "name": "已支付", "check": false},
  1180. {"key": 2, "name": "未支付", "check": false},
  1181. {"key": 3, "name": "处理中", "check": false}];
  1182. var beforeenter = $scope.$on('$ionicView.beforeEnter', function () {
  1183. $scope.user_id = Member.selectedemplst.length > 0 ? Member.selectedemplst[0].user_id : 0;
  1184. });
  1185. global.fetch_user().then(function () {
  1186. getpaylistdata(null, null, null, null);
  1187. });
  1188. $scope.doRefresh = function () {
  1189. global.refresh = true;
  1190. getpaylistdata();
  1191. };
  1192. $scope.loadMore = function () {
  1193. if ($scope.bills != undefined && $scope.bills.next != null) {
  1194. Tool.get($scope.bills.next).then(function (data) {
  1195. _.each(data.results, function (item) {
  1196. $scope.bills.results.push(item);
  1197. });
  1198. $scope.bills.next = data.next;
  1199. $scope.bills.previous = data.previous;
  1200. }).finally(function () {
  1201. $scope.$broadcast('scroll.infiniteScrollComplete');
  1202. $scope.loading = false;
  1203. });
  1204. } else {
  1205. $scope.$broadcast('scroll.infiniteScrollComplete');
  1206. }
  1207. };
  1208. $scope.moreCanBeLoaded = function () {
  1209. return $scope.bills != undefined && $scope.bills.next != null;
  1210. };
  1211. $scope.selectClick = function (date, status, user_id) {
  1212. var year = date == null ? date : (date.length > 4 ? date.substr(0, 4) : date);
  1213. var month = date == null ? date : (date.length == 4 ? null : date.substr(5, date.length - 5));
  1214. getpaylistdata(status == null ? status : parseInt(status), year, month, user_id);
  1215. };
  1216. $scope.setUser = function () {
  1217. $scope.user_id = 0;
  1218. };
  1219. function getpaylistdata(status, year, month, create_user) {
  1220. if (global.user.token != "") {
  1221. if ($scope.bills == undefined) {
  1222. $scope.loading = true;
  1223. }
  1224. Pay.bill.get({"type": type, "status": status, "year": year, "month": month, "create_user": create_user}, function (data) {
  1225. $scope.bills = data;
  1226. }, function (err) {
  1227. alert(JSON.stringify(err));
  1228. }).$promise.finally(function () {
  1229. $scope.$broadcast('scroll.refreshComplete');
  1230. $scope.loading = false;
  1231. });
  1232. }
  1233. }
  1234. $scope.$on('$destroy', function () {
  1235. beforeenter = null;
  1236. Member.selectedemplst = [];
  1237. });
  1238. })
  1239. .controller('BillPayCtrl', function ($rootScope, $scope, $state, global, Pay) {
  1240. var type = $state.params['type'];
  1241. global.fetch_user().then(function () {
  1242. getpaylistdata();
  1243. });
  1244. $scope.doRefresh = function () {
  1245. global.refresh = true;
  1246. getpaylistdata();
  1247. };
  1248. $scope.toAnalyse = function () {
  1249. $state.go('pay-analyse');
  1250. }
  1251. $scope.loadMore = function () {
  1252. if ($scope.bills != undefined && $scope.bills.next != null) {
  1253. Tool.get($scope.bills.next).then(function (data) {
  1254. _.each(data.results, function (item) {
  1255. $scope.bills.results.push(item);
  1256. });
  1257. $scope.bills.next = data.next;
  1258. $scope.bills.previous = data.previous;
  1259. }).finally(function () {
  1260. $scope.$broadcast('scroll.infiniteScrollComplete');
  1261. $scope.loading = false;
  1262. });
  1263. } else {
  1264. $scope.$broadcast('scroll.infiniteScrollComplete');
  1265. }
  1266. };
  1267. $scope.moreCanBeLoaded = function () {
  1268. return $scope.bills != undefined && $scope.bills.next != null;
  1269. };
  1270. function getpaylistdata() {
  1271. if (global.user.token != "") {
  1272. if ($scope.bills == undefined) {
  1273. $scope.loading = true;
  1274. }
  1275. Pay.bill.get({type: type}, function (data) {
  1276. $scope.bills = data;
  1277. }, function (err) {
  1278. alert(JSON.stringify(err));
  1279. }).$promise.finally(function () {
  1280. $scope.$broadcast('scroll.refreshComplete');
  1281. $scope.loading = false;
  1282. });
  1283. }
  1284. }
  1285. })
  1286. .controller('PayBillDetailsCtrl', function ($rootScope, $scope, $state, $ionicPopup, $ionicHistory, $cordovaDialogs, global, Pay, showPopup, Tool) {
  1287. showPopup.modalTemplate('templates/modal-stepReject.html', 'slide-in-right', $scope).then(function (modal) {
  1288. $scope.step_reject = modal;
  1289. });
  1290. $scope.index = null;
  1291. var paybillid = $state.params["id"];
  1292. Tool.removeBackView('pay-bill');
  1293. global.fetch_user().then(function () {
  1294. $scope.user = global.user.usrid;
  1295. getbilldata();
  1296. });
  1297. $scope.toedit = function () {
  1298. $state.go('pay-bill', {
  1299. type: 1,
  1300. id: paybillid
  1301. });
  1302. }
  1303. $scope.deleteBill = function () {
  1304. $cordovaDialogs.confirm('是否撤销该报销单', '提示', ['是', '否']).then(function (buttonIndex) {
  1305. if (buttonIndex == 1) {
  1306. showPopup.showLoading(1, '撤销中');
  1307. Pay.billdetail.delete({id: paybillid}, function () {
  1308. showPopup.hideLoading();
  1309. $ionicHistory.goBack();
  1310. });
  1311. }
  1312. });
  1313. }
  1314. $scope.audit = function (op) {
  1315. $scope.data = {};
  1316. if (op == 0) {
  1317. setPopup('驳回', '请输入驳回理由(必填)', op);
  1318. } else if (op == 1) {
  1319. setPopup('同意', '请输入备注(选填)', op);
  1320. } else if (op == 2) {
  1321. showPopup.showLoading(1, '提交中');
  1322. Pay.billdetail.update({id: paybillid, status: 2}, function (data) {
  1323. getbilldata();
  1324. showPopup.hideLoading();
  1325. });
  1326. }
  1327. }
  1328. $scope.ok = function () {
  1329. console.log($scope.index);
  1330. $scope.data.ordering = $scope.index;
  1331. postHistory($scope.data);
  1332. $scope.cancel();
  1333. }
  1334. $scope.cancel = function () {
  1335. $rootScope.commons.modal.hide();
  1336. }
  1337. $scope.changeIndex = function (index) {
  1338. $scope.index = index;
  1339. }
  1340. function getbilldata() {
  1341. if (global.user.token != "") {
  1342. if ($scope.bill == undefined) {
  1343. $scope.loading = true;
  1344. }
  1345. Pay.billdetail.get({id: paybillid}, function (res) {
  1346. $scope.loading = false;
  1347. $scope.bill = res;
  1348. Pay.detailItem = _.clone(res);
  1349. console.log(res);
  1350. $scope.billhistorydata = [];
  1351. _.each(res.history, function (item) {
  1352. var historyitem = {};
  1353. historyitem.date = item.create_date;
  1354. historyitem.title = item.create_user.username;
  1355. historyitem.profilePicture = "../../../img/panda.png";
  1356. historyitem.text = item.content;
  1357. historyitem.icon = item.status == 0 ? "ion-ios-undo assertive" : "ion-ios-checkmark balanced"
  1358. $scope.billhistorydata.push(historyitem);
  1359. });
  1360. if (!$scope.bill.verifier.is_teller) {
  1361. $scope.billhistorydata.push({
  1362. icon: 'ion-load-c task-create-member-p',
  1363. title: $scope.bill.status == 0 ? $scope.user == $scope.bill.create_user.id ? '等待我处理' : '当前处理人:' + $scope.bill.create_user.username : $scope.user == $scope.bill.verifier.verifier_id ? '等待我处理' : '当前处理人:' + $scope.bill.verifier.verifier__username,
  1364. profilePicture: "../../../img/panda.png"
  1365. });
  1366. }
  1367. $scope.billhistorydata.reverse();
  1368. })
  1369. }
  1370. }
  1371. function setPopup(title, placeholdertext, op) {
  1372. $cordovaDialogs.prompt(placeholdertext, title, ['确定', '取消']).then(function (result) {
  1373. var input = result.input1;
  1374. var btnIndex = result.buttonIndex;
  1375. if (btnIndex == 1) {
  1376. if (input == '' && op == 0) {
  1377. $cordovaDialogs.alert('请填写驳回理由', '提示', '确定');
  1378. } else {
  1379. $scope.data = {
  1380. status: op,
  1381. content: input == '' ? null : input,
  1382. pay_bill_id: paybillid,
  1383. ordering: null
  1384. }
  1385. if (op == 1) {
  1386. postHistory($scope.data);
  1387. } else if (op == 0) {
  1388. $scope.step = getStep($scope.bill.step);
  1389. if ($scope.step.length >= 1) {
  1390. $scope.step.reverse();
  1391. $scope.step.push({
  1392. ordering: 0,
  1393. verifier: {
  1394. username: $scope.bill.create_user.username
  1395. }
  1396. });
  1397. $scope.index = $scope.step[0].ordering;
  1398. $scope.step_reject.show();
  1399. $rootScope.commons.modal = $scope.step_reject;
  1400. } else {
  1401. postHistory($scope.data);
  1402. }
  1403. }
  1404. }
  1405. }
  1406. });
  1407. }
  1408. function postHistory(data) {
  1409. showPopup.showLoading(1, '提交中');
  1410. Pay.billhistory.save(data, function (data) {
  1411. getbilldata();
  1412. showPopup.hideLoading();
  1413. })
  1414. }
  1415. function getStep(step) {
  1416. return _.filter(step, function (item) {
  1417. return item.is_approved;
  1418. });
  1419. }
  1420. $scope.$on("$destroy", function () {
  1421. $scope.step_reject.remove();
  1422. });
  1423. })
  1424. .controller('PayAnalyseCtrl', function ($rootScope, $scope, $filter, $state, global, Pay) {
  1425. global.fetch_user().then(function () {
  1426. getanalysedata();
  1427. });
  1428. function getanalysedata() {
  1429. if (global.user.token != "") {
  1430. if ($scope.data == undefined) {
  1431. $scope.loading = true;
  1432. }
  1433. Pay.analyse.get(function (res) {
  1434. $scope.loading = false;
  1435. $scope.data = res;
  1436. _.each($scope.data.result, function (item) {
  1437. item.percentage = $filter('percentage')(item.count / $scope.data.count, 2, "%");
  1438. })
  1439. })
  1440. }
  1441. }
  1442. })