controllers.js 53 KB

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