StoreQualificationCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. define([ 'app/app' ], function(app) {
  2. //品牌审批
  3. app.register.controller('StoreQualificationCtrl', ['$scope', '$stateParams', 'toaster', 'StoreInfo', '$state', '$timeout', '$q', 'BrandActiveAPI', '$modal', function ($scope, $stateParams, toaster, StoreInfo, $state, $timeout, $q, BrandActiveAPI, $modal) {
  4. //------------------------------------------------- 常量
  5. // 资质类型
  6. $scope.qType = {
  7. taxPayer: 'TAX_PAYER',
  8. taxRegistration: 'TAX_REGISTRATION',
  9. businessLicense: 'BUSINESS_LICENSE'
  10. };
  11. //------------------------------------------------- 变量
  12. // 资质信息
  13. $scope.qualifications = {};
  14. // 设置默认选择资质类型为大陆
  15. $scope.tab = 'MAINLAND';
  16. $scope.switchTab = switchTab;
  17. // 设置公司资质信息
  18. $scope.enQualification = { status: '正常'};
  19. $scope.showQualification = showQualification;
  20. $scope.showBrandInfo = showBrandInfo;
  21. // 是否可以修改
  22. $scope.canUpdate = false;
  23. // 更新状态
  24. $scope.updateState = false;
  25. $scope.enQualificationBuckup = null;
  26. $scope.brandsBuckup = null;
  27. $scope.audit = audit;
  28. $scope.auditUnpass = auditUnpass;
  29. $scope.changeToUpdate = changeToUpdate;
  30. $scope.saveUpdate = saveUpdate;
  31. $scope.isPdf = isPdf;
  32. $scope.createShowUrl = createShowUrl;
  33. activate();
  34. //------------------------------------------------- Method
  35. /**
  36. * 切换公司资质类型时,清除数据
  37. */
  38. function clearData(type) {
  39. if (type === 'MAINLAND') {
  40. $scope.enQualification = { status: '正常'};
  41. }
  42. if (type === 'HK') {
  43. $scope.enQualification = { status: '正常'};
  44. }
  45. }
  46. /**
  47. * 根据品牌UUID查询品牌信息
  48. *
  49. * @param brandUuid 品牌UUID
  50. */
  51. function findBrandByUuid(brandUuid) {
  52. var deffer = $q.defer();
  53. BrandActiveAPI.getBrand({uuid: brandUuid}, function (result) {
  54. deffer.resolve(result);
  55. }, function (error) {
  56. deffer.reject(error);
  57. });
  58. return deffer.promise;
  59. }
  60. /**
  61. * 提交审核后的申请信息到后台
  62. *
  63. * @param isPass 是否通过审核
  64. * @param apply 请求传递数据
  65. */
  66. function handlerApply(isPass, apply) {
  67. var status = 'UNPASS';
  68. if (isPass) {
  69. status = 'PASS';
  70. }
  71. var param = {
  72. uuid : $scope.application.uuid,
  73. status : status
  74. };
  75. var deffer = $q.defer();
  76. StoreInfo.handlerApply(param, apply || null, function (data) {
  77. deffer.resolve(data);
  78. }, function (error) {
  79. deffer.reject(error);
  80. });
  81. return deffer.promise;
  82. }
  83. /**
  84. * 保存店铺申请信息
  85. *
  86. * @param apply 待保存店铺申请信息
  87. */
  88. function saveUpdateOfApply(apply) {
  89. var param = {
  90. uuid : $scope.application.uuid
  91. };
  92. var deffer = $q.defer();
  93. StoreInfo.saveUpdateOfApply(param, apply || null, function (data) {
  94. deffer.resolve(data);
  95. }, function (error) {
  96. deffer.reject(error);
  97. });
  98. return deffer.promise;
  99. }
  100. /**
  101. * 打开审核不通过原因模态框
  102. */
  103. function openReasonModal() {
  104. return $modal.open({
  105. templateUrl: 'static/view/admin/modal/application_unpass_reason.html',
  106. controller: 'unpassReasonController',
  107. size : 'lg'
  108. }).result;
  109. }
  110. //------------------------------------------------- 初始化操作
  111. /**
  112. * 初始化数据获取
  113. */
  114. function activate() {
  115. var applyUuid = $stateParams.applyUuid;
  116. if (!applyUuid) {
  117. toaster.pop('error', '店铺申请编号UUID不能为空');
  118. return ;
  119. }
  120. StoreInfo.findApplyByUuid({uuid : applyUuid}, {}, function (apply) {
  121. $scope.application = apply || {};
  122. //初始化时备份一遍数据
  123. var qualifications = apply.qualifications || [];
  124. $scope.brands = apply.brands || [];
  125. $scope.brandsBackup = angular.copy($scope.brands);
  126. /**
  127. * 判断品牌图片是否是PDF
  128. *
  129. */
  130. angular.forEach($scope.brands, function (brand) {
  131. brand.isPdf = isPdf(brand.url);
  132. });
  133. // 处理店铺资质信息
  134. angular.forEach(qualifications, function (qualification) {
  135. if (qualification.type === $scope.qType.taxPayer || qualification.type === $scope.qType.taxRegistration
  136. || qualification.type === $scope.qType.businessLicense) {
  137. $scope.qualifications[qualification.type] = qualification;
  138. }
  139. });
  140. // 处理店铺的品牌信息
  141. if ($scope.brands && $scope.brands.length > 0) {
  142. var promises = new Array($scope.brands.length);
  143. for (var i = 0; i < $scope.brands.length; i++) {
  144. promises[i] = findBrandByUuid($scope.brands[i].brandUuid);
  145. }
  146. $q.all(promises).then(function (result) {
  147. for (var i = 0; i < result.length; i++) {
  148. $scope.brands[i].logoUrl = result[i].logoUrl;
  149. $scope.brands[i].nameCn = result[i].nameCn;
  150. $scope.brands[i].nameEn = result[i].nameEn;
  151. $scope.brands[i].website = result[i].url;
  152. // 初始化品牌证明文件
  153. if ($scope.application.type === 'ORIGINAL_FACTORY') {
  154. $scope.brands[i].certificate = '大陆商标注册证';
  155. if ($scope.brands[i].status =='' || !$scope.brands[i].status) {
  156. $scope.brands[i].status = '正常';
  157. }
  158. }
  159. if ($scope.application.type === 'AGENCY') {
  160. $scope.brands[i].certificate = '代理证明书';
  161. if ($scope.brands[i].authorizedStatus =='' || !$scope.brands[i].authorizedStatus) {
  162. $scope.brands[i].authorizedStatus = '正常';
  163. }
  164. }
  165. }
  166. })['catch'](function () {
  167. $scope.brands = [];
  168. });
  169. }
  170. if ($scope.application.status === 'PASS' || $scope.application.status === 'UNPASS') {
  171. // 设置编辑状态
  172. $scope.canUpdate = true;
  173. // 设置公司资质信息
  174. $scope.tab = $scope.application.enType;
  175. $scope.enQualificationBackup = angular.copy($scope.enQualification);
  176. }
  177. $scope.enQualification = $scope.application.enQualification && JSON.parse($scope.application.enQualification) || {}
  178. }, function () {
  179. toaster.pop('error', '获取店铺申请信息失败');
  180. });
  181. }
  182. //------------------------------------------------- 交互操作
  183. /**
  184. * 切换资质类型
  185. *
  186. * @param tab 资质类型
  187. */
  188. function switchTab(tab) {
  189. $scope.tab = tab;
  190. clearData(tab);
  191. }
  192. /**
  193. * 预览资质图片
  194. *
  195. * @param qualification 资质信息
  196. * @param isShow 是否展示资质信息
  197. */
  198. function showQualification(qualification, isShow) {
  199. qualification.isShow = isShow;
  200. }
  201. /**
  202. * 预览品牌图片信息
  203. *
  204. * @param brand 品牌信息
  205. * @param isShow 是否展示品牌信息
  206. */
  207. function showBrandInfo(brand, isShow) {
  208. brand.isShow = isShow;
  209. }
  210. /**
  211. * 验证企业信息
  212. */
  213. function validateEnQualification() {
  214. console.log('验证企业信息-' + $scope.tab);
  215. var props = ['name', 'type', 'address', 'representative', 'creditCode', 'capital', 'setUpDate', 'businessScope', 'status'];
  216. if ($scope.tab === 'HK') {
  217. props = ['name', 'address', 'businessNature', 'legalStatus', 'effectiveDate', 'expiryDate', 'status'];
  218. }
  219. var flag = true;
  220. angular.forEach(props, function (prop) {
  221. if ($scope.enQualification.hasOwnProperty(prop)) {
  222. if (!$scope.enQualification[prop] || $scope.enQualification[prop] === '') {
  223. console.log(prop + '不能为空');
  224. // TODO 记录验证信息
  225. flag = false;
  226. }
  227. } else {
  228. console.log(prop + '不能为空');
  229. flag = false;
  230. }
  231. });
  232. if ($scope.enQualification['status'] === '其他' && (!$scope.enQualification['reason'] || $scope.enQualification['reason'] === '')) {
  233. flag = false;
  234. }
  235. return flag;
  236. }
  237. /**
  238. * 验证单个品牌信息
  239. *
  240. * @param brand 品牌信息
  241. */
  242. function validateBrand(brand) {
  243. if (!brand) return false;
  244. if ($scope.application.type ==='ORIGINAL_FACTORY') {
  245. var props = ['certificate', 'status', 'registrant', 'number', 'address', 'registrationDate', 'effectiveDate', 'approvalUnit'];
  246. var flag = true;
  247. angular.forEach(props, function (prop) {
  248. if (brand.hasOwnProperty(prop)) {
  249. if (!brand[prop] || brand[prop] === '') {
  250. console.log(prop + '不能为空');
  251. // TODO 记录验证信息
  252. flag = false;
  253. }
  254. } else {
  255. console.log(prop + '不能为空');
  256. flag = false;
  257. }
  258. });
  259. if (brand['status'] === '其他' && (!brand['reason'] || brand['reason'] === '')) {
  260. flag = false;
  261. }
  262. }
  263. if ($scope.application.type ==='AGENCY'){
  264. var props = ['authorizedDate', 'authorizedStatus', 'authorizedFrom'];
  265. var flag = true;
  266. angular.forEach(props, function (prop) {
  267. if (brand.hasOwnProperty(prop)) {
  268. if (!brand[prop] || brand[prop] === '') {
  269. console.log(prop + '不能为空');
  270. // TODO 记录验证信息
  271. flag = false;
  272. }
  273. } else {
  274. console.log(prop + '不能为空');
  275. flag = false;
  276. }
  277. });
  278. if (brand['authorizedStatus'] === '其他' && (!brand['authorizedReason'] || brand['authorizedReason'] === '')) {
  279. flag = false;
  280. }
  281. }
  282. return flag;
  283. }
  284. /**
  285. * 验证品牌信息
  286. */
  287. function validateBrands() {
  288. console.log('验证品牌信息');
  289. var flag = true;
  290. for (var i = 0; i < $scope.brands.length; i++) {
  291. if (!validateBrand($scope.brands[i])) {
  292. flag = false;
  293. }
  294. }
  295. return flag;
  296. }
  297. /**
  298. * 审核店铺申请信息
  299. *
  300. * @param isPass 是否通过审核
  301. */
  302. function audit(isPass) {
  303. // 如果审核通过,验证企业信息
  304. if (isPass) {
  305. var qualificationFlag = validateEnQualification();
  306. var brandsFlag = validateBrands();
  307. if (!qualificationFlag || !brandsFlag) {
  308. toaster.pop('error', '请补充完信息后再次提交');
  309. return ;
  310. }
  311. } else {
  312. if (!$scope.reason || $scope.reason === '') {
  313. toaster.pop('error', '请填写不通过原因在提交');
  314. return ;
  315. }
  316. }
  317. var apply = {};
  318. apply.enType = $scope.tab;
  319. apply.enQualification = $scope.enQualification;
  320. apply.brands = $scope.brands || null;
  321. apply.reason = $scope.reason;
  322. /*
  323. * 初审
  324. * */
  325. if ($scope.application.status === 'PREPARE') {
  326. StoreInfo.storeCheck({uuid: $scope.application.uuid}, apply || null, function (data) {
  327. if (data.success) {
  328. toaster.pop('success', "审核完成");
  329. $scope.updateState = false;
  330. activate();
  331. } else {
  332. toaster.pop('error', data.message);
  333. }
  334. }, function (error) {
  335. console.log(error);
  336. toaster.pop('error', '审核操作失败');
  337. });
  338. }
  339. else {
  340. /*
  341. * 终审
  342. * */
  343. handlerApply(isPass, apply).then(function (data) {
  344. if (data.success) {
  345. toaster.pop('success', "审核完成");
  346. $scope.updateState = false;
  347. activate();
  348. } else {
  349. toaster.pop('error', data.message);
  350. }
  351. })['catch'](function (error) {
  352. console.log(error);
  353. toaster.pop('error', '审核操作失败');
  354. });
  355. }
  356. }
  357. /**
  358. * 审核未通过开铺申请
  359. */
  360. function auditUnpass() {
  361. openReasonModal().then(function (reason) {
  362. $scope.reason = reason;
  363. $scope.audit(false);
  364. }, function (error) {
  365. console.log(error);
  366. });
  367. }
  368. /**
  369. * 变更到更新状态
  370. */
  371. function changeToUpdate(isUpdate) {
  372. $scope.updateState = isUpdate;
  373. if ($scope.updateState == false){
  374. $scope.enQualification = angular.copy($scope.enQualificationBackup);
  375. $scope.brands = angular.copy($scope.brandsBackup);
  376. }
  377. }
  378. /**
  379. * 保存店铺申请信息
  380. */
  381. function saveUpdate() {
  382. // 先检查信息是否为空
  383. var qualificationFlag = validateEnQualification();
  384. var brandsFlag = validateBrands();
  385. if (!qualificationFlag || !brandsFlag) {
  386. toaster.pop('error', '请补充完信息后再次提交');
  387. return ;
  388. }
  389. var apply = {};
  390. apply.enType = $scope.tab;
  391. apply.enQualification = $scope.enQualification;
  392. apply.brands = $scope.brands || null;
  393. if (apply.enQualification.status !=='其他'){
  394. apply.enQualification.reason = '' ;
  395. }
  396. angular.forEach(apply.brands, function (brand) {
  397. if (brand.status !=='其他'){
  398. brand.reason = '';
  399. }
  400. if (brand.authorizedStatus !=='其他'){
  401. brand.authorizedReason = '';
  402. }
  403. });
  404. saveUpdateOfApply(apply).then(function (data) {
  405. if (data.success) {
  406. toaster.pop('success', "保存修改完成");
  407. angular.copy($scope.enQualificationBackup,$scope.enQualification);
  408. angular.copy($scope.brandsBackup,$scope.brands);
  409. $scope.updateState = false;
  410. activate();
  411. } else {
  412. toaster.pop('error', data.message);
  413. }
  414. })['catch'](function (error) {
  415. console.log(error);
  416. toaster.pop('error', '修改操作失败');
  417. });
  418. }
  419. /**
  420. * 根据path文件名来判断文件是否是PDF文件
  421. *
  422. * @param path 文件名称
  423. */
  424. function isPdf(path) {
  425. if(path) {
  426. var str = path.slice(path.lastIndexOf('.')).toLowerCase();
  427. return str === '.pdf';
  428. }
  429. return false;
  430. }
  431. /**
  432. * 根据文件的URL生成预览文件URL
  433. *
  434. * @param url 文件URL
  435. */
  436. function createShowUrl(url) {
  437. return isPdf(url) ? 'static/img/vendor/store/timg.png' : url;
  438. }
  439. }]);
  440. app.register.controller('unpassReasonController', ['$scope', '$modalInstance', 'toaster', function ($scope, $modalInstance, toaster) {
  441. $scope.saveReason = saveReason;
  442. $scope.dismiss = dismiss;
  443. $scope.reason = null;
  444. /**
  445. * 保存不通过原因
  446. */
  447. function saveReason() {
  448. if (!$scope.reason || $scope.reason === '') {
  449. toaster.pop('error', '请填写审核不通过原因');
  450. return ;
  451. }
  452. $modalInstance.close($scope.reason);
  453. }
  454. /**
  455. * 关闭模态框
  456. */
  457. function dismiss() {
  458. $modalInstance.dismiss();
  459. }
  460. }]);
  461. });