StoreApplicationCtrl.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. define([ 'app/app' ], function(app) {
  2. //品牌审批
  3. app.register.controller('StoreApplicationCtrl', ['$scope', '$anchorScroll', '$location', '$modal', 'BaseService', 'SessionService', 'toaster', 'ngTableParams', 'StoreInfo', '$state', function ($scope, $anchorScroll, $location, $modal, BaseService, SessionService, toaster, ngTableParams, StoreInfo, $state) {
  4. // 店铺类型常量
  5. $scope.storeType = {
  6. AGENCY: {
  7. name: 'AGENCY',
  8. message: '代理商'
  9. },
  10. DISTRIBUTION: {
  11. name: 'DISTRIBUTION',
  12. message: '经销商'
  13. },
  14. ORIGINAL_FACTORY: {
  15. name: 'ORIGINAL_FACTORY',
  16. message: '原厂'
  17. }
  18. };
  19. // 开店申请的审核类型
  20. $scope.authType = {
  21. PREPARE: {
  22. name: 'PREPARE',
  23. message: '待审核'
  24. },
  25. PASS: {
  26. name: 'PASS',
  27. message: '已通过'
  28. },
  29. UNPASS: {
  30. name: 'UNPASS',
  31. message: '未通过'
  32. }
  33. };
  34. $scope.ngPageInfo = {
  35. page : 1,
  36. count : 10,
  37. sorting : {
  38. createTime: 'DESC'
  39. }
  40. };
  41. // 保存查询店铺申请的状态
  42. $scope.status = $scope.authType.PREPARE.name;
  43. // 保存查询店铺类型的状态
  44. $scope.type = 'ALL_TYPE';
  45. // 保存店铺搜索类型
  46. $scope.search = 'STORE_NAME';
  47. // 保存店铺搜索类型所传参数
  48. $scope.searchParams = 'authPage';
  49. $scope.showSearch = false
  50. /**
  51. * 切换Tab
  52. *
  53. * @param tab tab标签
  54. * @param type TAB类型
  55. */
  56. $scope.switchTab = function (tab, type) {
  57. if (type === 'status') {
  58. $scope.status = tab;
  59. if ($scope.type !== 'ALL_TYPE') {
  60. $scope.type = 'ALL_TYPE';
  61. }
  62. }
  63. if (type === 'type') {
  64. $scope.type = tab;
  65. }
  66. $scope.refreshTableData();
  67. };
  68. $scope.isShowSearch = function (flag) {
  69. $scope.showSearch = flag
  70. };
  71. /**
  72. * 切换搜索类型
  73. *
  74. * @param type 店铺类型
  75. *
  76. */
  77. $scope.placeValue = $scope.search === 'STORE_NAME' ? '请输入公司名称' : '请输入审核人姓名';
  78. $scope.switchSearch = function (type, flag) {
  79. if (type === 'STORE_NAME') {
  80. $scope.search = 'STORE_NAME';
  81. $scope.searchParams = 'authPage';
  82. }
  83. if (type === 'AUDITOR') {
  84. $scope.search = 'AUDITOR';
  85. $scope.searchParams = 'authorPage';
  86. }
  87. $scope.showSearch = flag
  88. $scope.placeValue = $scope.search === 'STORE_NAME' ? '请输入公司名称' : '请输入审核人姓名';
  89. };
  90. $scope.applicationTableParams = new ngTableParams($scope.ngPageInfo, {
  91. total : 0,
  92. counts: [5, 10, 25, 50, 100],
  93. getData : function($defer, params) {
  94. $scope.loading = true;
  95. var param = BaseService.parseParams(params.url());
  96. param.status = $scope.status === 'ALL' ? null : $scope.status;
  97. param.type = $scope.type === 'ALL_TYPE' ? null : $scope.type;
  98. param.keyword = $scope.keyword && $scope.keyword !== '' ? $scope.keyword : null;
  99. param.operate = $scope.searchParams;
  100. StoreInfo.pageStoreApplications(param, function (data) {
  101. console.log(data);
  102. params.total(data.totalElements);
  103. if (data.content) {
  104. $defer.resolve(data.content);
  105. var date = new Date();
  106. console.log('TIMESTAMP', date.getTime());
  107. angular.forEach(data.content, function (application) {
  108. if (application.status === $scope.authType.PREPARE.name) {
  109. var time = date - application.createTime;
  110. // 计算相差天数
  111. var days = Math.floor(time / (24 * 3600 * 1000));
  112. // 计算相差小时数
  113. var leave1 = time % (24 * 3600 * 1000);
  114. var hours = Math.floor(leave1 / (3600 * 1000));
  115. application.time = {
  116. hour: hours,
  117. day: days
  118. };
  119. }
  120. })
  121. } else {
  122. $defer.resolve([]);
  123. }
  124. });
  125. }
  126. });
  127. $scope.changeShorting = function () {
  128. if($scope.ngPageInfo.sorting.createTime == 'DESC'){
  129. $scope.ngPageInfo.sorting.createTime = 'ASC';
  130. } else {
  131. $scope.ngPageInfo.sorting.createTime = 'DESC';
  132. }
  133. $scope.refreshTableData();
  134. };
  135. /**
  136. * 刷新表格数据
  137. */
  138. $scope.refreshTableData = function () {
  139. if ($scope.applicationTableParams.page() != 1) {
  140. $scope.applicationTableParams.page(1);
  141. }
  142. $scope.applicationTableParams.reload();
  143. };
  144. /**
  145. * 审核通过
  146. */
  147. $scope.auditSuccess = function (application) {
  148. var param = {
  149. uuid : application.uuid,
  150. status : 'PASS'
  151. };
  152. handlerApplication(param);
  153. };
  154. /**
  155. * 审核失败
  156. */
  157. $scope.auditFail = function (application) {
  158. var param = {
  159. uuid : application.uuid,
  160. status : 'UNPASS'
  161. };
  162. handlerApplication(param);
  163. };
  164. /**
  165. * 审核申请
  166. */
  167. var handlerApplication = function (param) {
  168. console.log(param);
  169. StoreInfo.handlerApply(param, null, function (data) {
  170. if (data.success) {
  171. if (data.data) {
  172. toaster.pop('success', "审核通过,店铺UUID:" + data.data);
  173. } else {
  174. toaster.pop('success', "审核不通过");
  175. }
  176. $scope.refreshTableData();
  177. } else {
  178. toaster.pop('error', data.message);
  179. }
  180. })
  181. };
  182. /**
  183. * 审核资质信息
  184. *
  185. * @param application 店铺申请信息
  186. */
  187. $scope.auditQualification = function (application) {
  188. if (application && application.uuid) {
  189. $state.go('store_qualification_auth', { applyUuid : application.uuid });
  190. } else {
  191. toaster.pop('error', '店铺审核信息不能为空');
  192. }
  193. }
  194. }]);
  195. });