jry_ceshiCtrl.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. var sysFormly = angular.module('formlySystem', [
  2. 'formly', 'formlyBootstrap', 'ui.bootstrap',
  3. 'ngSanitize', 'ui.select', 'ui.grid'
  4. ]);
  5. app.requires.push('formlySystem');
  6. // var appFormly = angular.module('formlyExample', [
  7. // 'formly', 'formlyBootstrap','ui.bootstrap',
  8. // 'ngSanitize','ui.select','ui.grid'],
  9. sysFormly.config(
  10. function config(formlyConfigProvider) {
  11. //格式转换方法 XXX-XXX转驼峰命名
  12. });
  13. // 'use strict';
  14. sysFormly.controller('jry_ceshiFormCtrl', ['$rootScope', '$scope', '$parse', '$filter', '$injector', '$http', '$q', '$state', '$stateParams', '$modal', '$timeout', '$interval', 'SweetAlert', 'FileUploader', 'i18nService', 'moment', 'Restangular', 'UserRestangular', 'BpmRestangular', 'api_configure_form', 'api_bpm_domain', 'api_bpm_data', 'api_user_data', 'api_apply',
  15. function($rootScope, $scope, $parse, $filter, $injector, $http, $q, $state, $stateParams, $modal, $timeout, $interval, SweetAlert, FileUploader, i18nService, moment, Restangular, UserRestangular, BpmRestangular, api_configure_form, api_bpm_domain, api_bpm_data, api_user_data, api_apply) {
  16. // $scope.ceshi="哈哈"
  17. //console.log($stateParams);
  18. var vm = this;
  19. vm.options = {};
  20. vm.exampleTitle = ['expressionProperties', 'model property'];
  21. vm.fields = [];
  22. vm.model = {};
  23. $scope.langs = i18nService.getAllLangs();
  24. $scope.lang = 'zh-cn';
  25. //alert($rootScope.user.id,null,2);
  26. vm.model["loginUser"] = $rootScope.user;
  27. var that = $injector;
  28. var parse = $parse;
  29. var modelWatch = "";
  30. var fieldsWatch = [];
  31. var serviceWatch = null;
  32. var formWatch = {};
  33. if (angular.isDefined($stateParams.model) && $stateParams.model != "") {
  34. modelWatch = JSON.parse($stateParams.model);
  35. console.log(modelWatch);
  36. // console.log("modelWatch:"+ JSON.stringify(modelWatch));
  37. }
  38. if (angular.isDefined($stateParams.fields) && $stateParams.fields != "") {
  39. fieldsWatch = JSON.parse($stateParams.fields);
  40. }
  41. if (angular.isDefined($stateParams.extjson) && $stateParams.extjson != "") {
  42. formWatch.extjson = JSON.parse($stateParams.extjson);
  43. }
  44. if (angular.isDefined($stateParams.cancelUrl) && $stateParams.cancelUrl != "") {
  45. formWatch.cancelUrl = $stateParams.cancelUrl;
  46. }
  47. if (angular.isDefined($stateParams.url) && $stateParams.url != "") {
  48. formWatch.url = $stateParams.url;
  49. }
  50. if (angular.isDefined($stateParams.service) && $stateParams.service != "") {
  51. if (that.has($stateParams.service)) {
  52. serviceWatch = that.get($stateParams.service);
  53. } else {
  54. serviceWatch = $stateParams.service;
  55. }
  56. }
  57. //用户测试数据,后续从header的auth中获取
  58. var userId = 2;
  59. userId = $rootScope.user.id;
  60. //==============处理表单设计数据 开始====================
  61. //处理组件加载后台数据选项的方法
  62. function refreshSelectOptions(searchVal, field) {
  63. //todo
  64. console.log(field);
  65. if (field.key == 'id' && field.templateOptions.pkey == 'change.source') {
  66. field.templateOptions.options = [{ "id": 1, "name": "事件", "code": 1 }, { "id": 2, "name": "问题", "code": 2 }, { "id": 3, "name": "配置", "code": 3 }, { "id": 4, "name": "服务级别", "code": 4 }, { "id": 5, "name": "内部需求", "code": 5 }];
  67. } else if (field.templateOptions.optionsUrl) {
  68. var process = BpmRestangular.all("");
  69. if (field.templateOptions.ApiService) {
  70. process = UserRestangular.all("");
  71. }
  72. process.customPOST({ "idx": 0, "sum": 1000 }, field.templateOptions.optionsUrl).then(function(result) {
  73. if (!field.templateOptions.options) {
  74. field.templateOptions.options = [];
  75. }
  76. if (field.templateOptions.optionsDataKey) {
  77. field.templateOptions.options = result[field.templateOptions.optionsDataKey];
  78. } else {
  79. field.templateOptions.options = result;
  80. }
  81. });
  82. }
  83. }
  84. //解析自定义表单设计数据
  85. function decodeVMForm(vmForm) {
  86. var result = { model: {}, fields: [] };
  87. //设置模型实体数据 begin
  88. // var mdata = vmForm.model;
  89. //解析数据实体
  90. var mdata = angular.fromJson(vmForm.model); //JSON.parse(field.extjson);
  91. angular.extend(result.model, mdata);
  92. if (modelWatch != null && modelWatch != '') {
  93. //angular.extend(result.model.incident,modelWatch.incident);
  94. //result.model.alarmType = modelWatch.alarmType;
  95. // vmForm.cancelUrl = modelWatch.cancelUrl;
  96. for (var index in modelWatch.model) {
  97. console.log(JSON.stringify(index + " " + JSON.stringify(modelWatch.model[index])));
  98. if (result.model[index] != null) {
  99. angular.extend(result.model[index], modelWatch.model[index]);
  100. } else {
  101. result.model[index] = modelWatch.model[index];
  102. }
  103. }
  104. }
  105. //设置模型实体数据 end
  106. //解析设计数据生成表单项 begin
  107. var fields = [];
  108. //处理修改设计数据中展示设置
  109. angular.forEach(vmForm.fields, function(field) {
  110. if (field.key == "") {
  111. delete field.key;
  112. }
  113. if (angular.isDefined(field.extjson)) {
  114. var extObj = angular.fromJson(field.extjson); //JSON.parse(field.extjson);
  115. angular.extend(field.templateOptions, extObj.templateOptions);
  116. delete extObj.templateOptions;
  117. for (var prop in extObj) {
  118. if (new RegExp("Expression").test(prop)) {
  119. //var obj = $scope.$eval(extObj[prop]);
  120. //extObj[prop] = $scope.$eval(extObj[prop]);
  121. if (extObj[prop] != null) {
  122. if (new RegExp("function").test(extObj[prop])) {
  123. var propValue = eval(extObj[prop]);
  124. extObj[prop] = propValue;
  125. } else {
  126. //console.log(extObj[prop]);
  127. var obj = $scope.$eval(extObj[prop]);
  128. extObj[prop] = obj;
  129. //console.log(obj);
  130. }
  131. }
  132. } else if (new RegExp("expressionProperties").test(prop)) {
  133. for (var p in extObj[prop]) {
  134. if (new RegExp("function").test(extObj[prop][p])) {
  135. var propValue = eval(extObj[prop][p]);
  136. extObj[prop][p] = propValue;
  137. } else {
  138. }
  139. }
  140. } else if ("watcher" == prop) {
  141. if (angular.isArray(extObj[prop])) {
  142. angular.forEach(extObj[prop], function(item, index) {
  143. for (var p in item) {
  144. if (new RegExp("function").test(item[p])) {
  145. var propValue = eval(item[p]);
  146. extObj[prop][index][p] = propValue;
  147. }
  148. }
  149. });
  150. } else if (angular.isObject(extObj[prop])) {
  151. for (var p in extObj[prop]) {
  152. if (new RegExp("function").test(extObj[prop][p])) {
  153. var propValue = eval(extObj[prop][p]);
  154. extObj[prop][p] = propValue;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. angular.extend(field, extObj);
  161. delete field.extjson;
  162. }
  163. if (angular.isDefined(field.templateOptions)) {
  164. var templateOs = field.templateOptions;
  165. for (var property in templateOs) {
  166. //console.log(property);
  167. if (angular.isString(templateOs[property]) && !(new RegExp("[\u4e00-\u9fa5]").test(templateOs[property]))) {
  168. if (new RegExp("function").test(templateOs[property])) {
  169. var propValue = eval(templateOs[property]);
  170. field.templateOptions[property] = propValue;
  171. } else {
  172. if (that.has(templateOs[property])) {
  173. field.templateOptions[property] = that.get(templateOs[property]);
  174. } else {
  175. field.templateOptions[property] = templateOs[property];
  176. }
  177. }
  178. } else if (templateOs[property] == null) {
  179. //delete field.templateOptions[property];
  180. } else {}
  181. }
  182. }
  183. //console.log(field);
  184. if (angular.isDefined(field.templateOptions) && angular.isDefined(field.templateOptions.extjson)) {
  185. var extObj = angular.fromJson(field.templateOptions.extjson); //JSON.parse(field.extjson);
  186. angular.extend(field.templateOptions, extObj);
  187. delete field.templateOptions.extjson;
  188. }
  189. //...
  190. if (field.templateOptions) {
  191. //处理远程获取数据控件方法调用
  192. if (field.templateOptions.optionsUrl) {
  193. field.templateOptions.refresh = refreshSelectOptions;
  194. }
  195. //处理嵌套属性数据绑定/
  196. if (field.templateOptions.pkey) {
  197. var pmodel, i = 0;
  198. angular.forEach(field.templateOptions.pkey.split("."), function(p) {
  199. if (i == 0) {
  200. if (result.model[p] == null) {
  201. result.model[p] = {};
  202. }
  203. pmodel = result.model[p];
  204. i++;
  205. } else {
  206. if (pmodel[p] == null) {
  207. pmodel[p] = {};
  208. }
  209. pmodel = pmodel[p];
  210. }
  211. });
  212. if (pmodel != null) {
  213. field.model = pmodel;
  214. if (pmodel[field.key] == null) {
  215. pmodel[field.key] = null;
  216. }
  217. }
  218. } else {
  219. if (result.model[field.key] == null) {
  220. result.model[field.key] = null;
  221. }
  222. }
  223. //处理弹出框组件初始化
  224. if (field.type == "ui-input-selectmodal") {
  225. field.templateOptions.modal = $modal;
  226. //field.templateOptions.Restangular = Restangular;
  227. } else if (field.type == "ui-requesterselect") {
  228. //field.templateOptions.language = $scope.lang;
  229. field.templateOptions.modal = $modal;
  230. field.templateOptions.UserService = api_user_data;
  231. } else if (field.type == "ui-userselect") {
  232. field.templateOptions.modal = $modal;
  233. //field.templateOptions.Restangular = Restangular;
  234. } else if (field.type == "ui-multiuserselect") {
  235. field.templateOptions.modal = $modal;
  236. } else if (field.type == "ui-search") {
  237. field.templateOptions.modal = $modal;
  238. } else if (field.type == "ui-modelselect") {
  239. field.templateOptions.modal = $modal;
  240. //console.log("$rootScope.user:" + JSON.stringify($rootScope.user));
  241. field.templateOptions.loginUser = $rootScope.user;
  242. //field.templateOptions.Restangular = Restangular;
  243. } else if (field.type == "ui-dropfile") {
  244. $scope.fileUploader = field.templateOptions.fileUploader = new FileUploader({
  245. url: '/uploader'
  246. });
  247. field.templateOptions.taskId = $stateParams.taskId;
  248. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  249. field.templateOptions.userId = $rootScope.user.id;
  250. //field.ApiService=api_bpm_domain;
  251. } else if (field.type == "ui-dropfiletable") {
  252. if (field.templateOptions.processInstanceId) {
  253. } else {
  254. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  255. }
  256. } else if (field.type == "ui-repeatSection") {
  257. var repeatForm = {
  258. model: {
  259. },
  260. fields: field.templateOptions.fields
  261. };
  262. repeatForm.model[field.key] = [];
  263. decodeVMForm(repeatForm);
  264. } else if (field.type == "ui-currentuser") {
  265. field.templateOptions.user = vm.model["loginUser"];
  266. }
  267. }
  268. // console.log(field);
  269. result.fields.push(field);
  270. });
  271. angular.extend($scope.vm.fields, result.fields);
  272. angular.extend($scope.vm.model, result.model);
  273. // console.log($rootScope.user);
  274. //vm.model["loginUser"] = $rootScope.user;
  275. if (modelWatch != null && modelWatch != '' && modelWatch.cancelUrl != null && modelWatch.cancelUrl != '') {
  276. vmForm.cancelUrl = modelWatch.cancelUrl;
  277. }
  278. $scope.formData = vmForm;
  279. //console.log($scope.vm);
  280. //解析设计数据生成表单项 end
  281. return result;
  282. }
  283. //======================处理表单设计数据 结束========================
  284. $scope.ldloading = {};
  285. function filter(obj) {
  286. angular.forEach(obj, function(key, value) {
  287. if (value === "" || value === null) {
  288. delete obj[key];
  289. } else if (Object.prototype.toString.call(value) === '[object Object]') {
  290. filter(value);
  291. } else if (angular.isArray(value)) {
  292. angular.forEach(value, function(item) {
  293. filter(item);
  294. });
  295. }
  296. });
  297. }
  298. $scope.closeModel = function() {
  299. $state.go('app.desk.jry_emergency', {});
  300. // console.log("$stateParams.formKey="+JSON.stringify($stateParams.formKey))
  301. // if (angular.isDefined($stateParams.formKey) && $stateParams.formKey != "") {
  302. // if ($stateParams.formKey == "system_edit") {
  303. // $state.go('app.system.user.user', {});
  304. // } else if ($stateParams.formKey == "system_edit_role") {
  305. // $state.go('app.system.user.role', {});
  306. // } else if ($stateParams.formKey == "system_edit_roletype") {
  307. // $state.go('app.system.user.role', {});
  308. // } else if ($stateParams.formKey == "system_edit_navmanager") {
  309. // $state.go('app.system.navmanager', {});
  310. // } else if ($stateParams.formKey == "system_edit_requester") {
  311. // $state.go('app.system.userdesign.requester', {});
  312. // } else if ($stateParams.formKey == "noticeEditor") {
  313. // $state.go('app.system.notice.list', {});
  314. // } else if ($stateParams.formKey == "noticeDetail") {
  315. // $state.go('app.system.notice.list', {});
  316. // } else if ($stateParams.formKey == "desk_detail") {
  317. // $state.go('app.desk.chart', {});
  318. // } else if ($stateParams.formKey == "system_add_service") {
  319. // $state.go('app.system.navmanager', {});
  320. // } else if ($stateParams.formKey == "system_add_menu") {
  321. // // $state.go('app.system.user.power', {});
  322. // $state.go('app.system.navmanager', {});
  323. // } else if ($stateParams.formKey == "system_add_service") {
  324. // $state.go('app.system.navmanager', {});
  325. // }
  326. // event.preventDefault();
  327. // }
  328. }
  329. $scope.submit = function(model) {
  330. if (model.rejectRemark && model.rejectRemark != "") {
  331. api_apply.wxIncidentReject(model.incident.id, { "rejectRemark": model.rejectRemark }).then(function(data) {
  332. if (data && data.state == 200) {
  333. SweetAlert.swal({
  334. title: "提交成功",
  335. text: '不受理提交成功',
  336. type: "success"
  337. }, function() {
  338. $state.go('app.desk.chart', {});
  339. });
  340. } else {
  341. SweetAlert.swal({
  342. title: "提交失败",
  343. text: '不受理提交失败',
  344. type: "error"
  345. });
  346. }
  347. });
  348. } else {
  349. SweetAlert.swal({
  350. title: "提交错误",
  351. text: "请填写不受理原因!",
  352. type: "error",
  353. confirmButtonColor: "#DD6B55"
  354. });
  355. }
  356. }
  357. vm.submit = function(data, style) {
  358. if ($stateParams.formKey == "system_edit" || $stateParams.formKey == "system_edit_requester" || $stateParams.formKey == "system_add_menu" || $stateParams.formKey == "system_add_service" || $stateParams.formKey == "noticeEditor") {
  359. // console.log("roleid="+$scope.roleid);
  360. if (vm.form.$valid) {
  361. vm.options.updateInitialValue();
  362. $scope.ldloading[style.replace('-', '_')] = true;
  363. // alert(JSON.stringify(vm.model), null, 2);
  364. var _ = window._;
  365. vm.model = (function filter(obj) { //过滤
  366. var dateTransKeys = [];
  367. var filtered = _.pick(obj, function(v, k, obj) {
  368. if (_.isDate(v)) {
  369. dateTransKeys.push(k);
  370. }
  371. return angular.isDefined(v) && v !== null && (angular.isArray(v) ? v.length > 0 : true) && (_.isPlainObject(v) ? (!_.isEmpty(v)) : true);
  372. });
  373. return _.cloneDeep(filtered, function(v, index, object) {
  374. if (angular.isArray(dateTransKeys) && dateTransKeys.length > 0) {
  375. angular.forEach(dateTransKeys, function(item) {
  376. v[item] = moment(v[item]).format('YYYY-MM-DD HH:mm:ss');
  377. });
  378. dateTransKey = [];
  379. return v;
  380. }
  381. return !(_.isEmpty(filtered)) && v !== filtered && _.isPlainObject(v) ? filter(v) : undefined;
  382. });
  383. })(vm.model);
  384. if ($scope.formData.modelName) {
  385. if (vm.model[$scope.formData.modelName]) {
  386. for (var key in vm.model[$scope.formData.modelName]) {
  387. if (vm.model[$scope.formData.modelName][key] &&
  388. (vm.model[$scope.formData.modelName][key] == null || vm.model[$scope.formData.modelName][key] == undefined || JSON.stringify(vm.model[$scope.formData.modelName][key]) == "{}")) {
  389. delete vm.model[$scope.formData.modelName][key];
  390. }
  391. }
  392. }
  393. }
  394. switch ($scope.formData.url) {
  395. case "create":
  396. //vm.model["initUser"]=$rootScope.user.id;
  397. //addData
  398. // if (vm.model.id) {
  399. // if ($stateParams.formKey == "system_add_menu") {
  400. // vm.model.parent = vm.model.menu.parent;
  401. // delete vm.model.menu;
  402. // }
  403. // serviceWatch.updData($scope.formData.modelName, vm.model).then(function(response) {
  404. // if (response && response.status == 200) {
  405. // SweetAlert.swal({
  406. // title: "修改成功!",
  407. // confirmButtonColor: "#007AFF"
  408. // }, function() {
  409. // // $state.go($scope.formData.cancelUrl);
  410. // });
  411. // } else {
  412. // SweetAlert.swal({
  413. // title: "系统错误",
  414. // text: "系统错误,请稍后重试!",
  415. // type: "error",
  416. // confirmButtonColor: "#DD6B55"
  417. // });
  418. // }
  419. // $scope.ldloading[style.replace('-', '_')] = false;
  420. // });
  421. // } else {
  422. if ($stateParams.formKey == "system_add_menu" && vm.model.menu) {
  423. vm.model.parent = vm.model.menu.parent;
  424. delete vm.model.menu;
  425. }
  426. if ($stateParams.formKey == "system_add_service") {
  427. if (vm.model.menu) {
  428. vm.model.menu = vm.model.menu.menu;
  429. delete vm.model.menu.menu;
  430. }
  431. serviceWatch.addData("linkConfigure", vm.model).then(function(response) {
  432. if (response) {
  433. var resData = Restangular.stripRestangular(response);
  434. if (resData && resData.status == 200) {
  435. SweetAlert.swal({
  436. title: "提交成功!",
  437. type: "success",
  438. confirmButtonColor: "#007AFF"
  439. }, function() {
  440. $state.go($scope.formData.cancelUrl);
  441. });
  442. } else {
  443. SweetAlert.swal({
  444. title: "系统错误",
  445. text: "系统错误,请稍后重试!",
  446. type: "error",
  447. confirmButtonColor: "#DD6B55"
  448. });
  449. }
  450. } else {
  451. SweetAlert.swal({
  452. title: "系统错误",
  453. text: "系统错误,请稍后重试!",
  454. type: "error",
  455. confirmButtonColor: "#DD6B55"
  456. });
  457. }
  458. $scope.ldloading[style.replace('-', '_')] = false;
  459. });
  460. } else {
  461. serviceWatch.addData($scope.formData.modelName, vm.model).then(function(response) {
  462. if (response) {
  463. var resData = Restangular.stripRestangular(response);
  464. if (resData && resData.status == 200) {
  465. SweetAlert.swal({
  466. title: "提交成功!",
  467. type: "success",
  468. confirmButtonColor: "#007AFF"
  469. }, function() {
  470. $state.go($scope.formData.cancelUrl);
  471. });
  472. } else {
  473. SweetAlert.swal({
  474. title: "系统错误",
  475. text: "系统错误,请稍后重试!",
  476. type: "error",
  477. confirmButtonColor: "#DD6B55"
  478. });
  479. }
  480. } else {
  481. SweetAlert.swal({
  482. title: "系统错误",
  483. text: "系统错误,请稍后重试!",
  484. type: "error",
  485. confirmButtonColor: "#DD6B55"
  486. });
  487. }
  488. $scope.ldloading[style.replace('-', '_')] = false;
  489. });
  490. }
  491. // }
  492. break;
  493. case "save":
  494. //addData
  495. // if ($scope.formData.name == "system_edit" && !vm.model.user.role) {
  496. // vm.form.$valid = false;
  497. // SweetAlert.swal({
  498. // title: "校验错误",
  499. // text: "请填写必填项!",
  500. // type: "error",
  501. // confirmButtonColor: "#DD6B55"
  502. // });
  503. // angular.forEach(vm.form.$error.required, function(item) {
  504. // angular.forEach(vm.fields, function(f) {
  505. // if (f.name == item.$name) {
  506. // f.validation.show = true;
  507. // }
  508. // });
  509. // })
  510. // } else {
  511. if ($scope.formData.name == "system_edit") {
  512. if (vm.model.user.dept) {
  513. delete vm.model.user.dept.children;
  514. }
  515. }
  516. serviceWatch.addData($scope.formData.modelName, vm.model).then(function(response) {
  517. if (response) {
  518. var resData = Restangular.stripRestangular(response);
  519. if (resData && resData.status == 200) {
  520. if ($scope.formData.name == "system_edit") {
  521. if (!response.data.account) {
  522. SweetAlert.swal({
  523. title: "提交失败",
  524. text: "工号已存在,请重新填写!",
  525. type: "error",
  526. confirmButtonColor: "#DD6B55"
  527. }, function() {
  528. renderform();
  529. });
  530. } else if (!response.data.name) {
  531. SweetAlert.swal({
  532. title: "提交失败",
  533. text: "用户名已存在,请重新填写!",
  534. type: "error",
  535. confirmButtonColor: "#DD6B55"
  536. }, function() {
  537. renderform();
  538. });
  539. } else {
  540. SweetAlert.swal({
  541. title: "提交成功!",
  542. type: "success",
  543. confirmButtonColor: "#007AFF"
  544. }, function() {
  545. $state.go($scope.formData.cancelUrl);
  546. });
  547. }
  548. } else {
  549. SweetAlert.swal({
  550. title: "提交成功!",
  551. type: "success",
  552. confirmButtonColor: "#007AFF"
  553. }, function() {
  554. $state.go($scope.formData.cancelUrl);
  555. });
  556. }
  557. } else {
  558. SweetAlert.swal({
  559. title: "系统错误",
  560. text: "系统错误,请稍后重试!",
  561. type: "error",
  562. confirmButtonColor: "#DD6B55"
  563. });
  564. }
  565. } else {
  566. SweetAlert.swal({
  567. title: "系统错误",
  568. text: "系统错误,请稍后重试!",
  569. type: "error",
  570. confirmButtonColor: "#DD6B55"
  571. });
  572. }
  573. $scope.ldloading[style.replace('-', '_')] = false;
  574. });
  575. // }
  576. break;
  577. case "close":
  578. $state.go($scope.formData.cancelUrl);
  579. break;
  580. default:
  581. $scope.ldloading[style.replace('-', '_')] = false;
  582. break;
  583. }
  584. } else {
  585. SweetAlert.swal({
  586. title: "校验错误",
  587. text: "请填写必填项!",
  588. type: "error",
  589. confirmButtonColor: "#DD6B55"
  590. });
  591. angular.forEach(vm.form.$error.required, function(item) {
  592. angular.forEach(vm.fields, function(f) {
  593. if (f.name == item.$name) {
  594. f.validation.show = true;
  595. }
  596. });
  597. })
  598. }
  599. } else {
  600. var role = {};
  601. var data1 = {};
  602. // console.log("data.role="+JSON.stringify(data.role));
  603. role['rolecode'] = data.role.rolecode;
  604. role['id'] = data.role.id;
  605. // console.log("role="+JSON.stringify(role));
  606. data1['role'] = role;
  607. // console.log("data1="+JSON.stringify(data1));
  608. api_user_data.validate(data1, 'role').then(function(response) {
  609. var resData = Restangular.stripRestangular(response);
  610. // console.log("resData11="+JSON.stringify(resData));
  611. if (resData.status == 200 && resData.data == "false" && vm.form.$valid) {
  612. // if (vm.form.$valid ) {
  613. vm.options.updateInitialValue();
  614. $scope.ldloading[style.replace('-', '_')] = true;
  615. // alert(JSON.stringify(vm.model), null, 2);
  616. var _ = window._;
  617. vm.model = (function filter(obj) {
  618. var dateTransKeys = [];
  619. var filtered = _.pick(obj, function(v, k, obj) {
  620. if (_.isDate(v)) {
  621. dateTransKeys.push(k);
  622. }
  623. return angular.isDefined(v) && v !== null && (angular.isArray(v) ? v.length > 0 : true) && (_.isPlainObject(v) ? (!_.isEmpty(v)) : true);
  624. });
  625. return _.cloneDeep(filtered, function(v, index, object) {
  626. if (angular.isArray(dateTransKeys) && dateTransKeys.length > 0) {
  627. angular.forEach(dateTransKeys, function(item) {
  628. v[item] = moment(v[item]).format('YYYY-MM-DD HH:mm:ss');
  629. });
  630. dateTransKey = [];
  631. return v;
  632. }
  633. return !(_.isEmpty(filtered)) && v !== filtered && _.isPlainObject(v) ? filter(v) : undefined;
  634. });
  635. })(vm.model);
  636. // console.log("$scope.formData="+$scope.formData);
  637. switch ($scope.formData.url) {
  638. case "create":
  639. //vm.model["initUser"]=$rootScope.user.id;
  640. //addData
  641. serviceWatch.addData($scope.formData.modelName, vm.model).then(function(response) {
  642. if (response) {
  643. var resData = Restangular.stripRestangular(response);
  644. if (resData && resData.status == 200) {
  645. SweetAlert.swal({
  646. title: "提交成功!",
  647. type: "success",
  648. confirmButtonColor: "#007AFF"
  649. }, function() {
  650. $state.go($scope.formData.cancelUrl);
  651. });
  652. } else {
  653. SweetAlert.swal({
  654. title: "系统错误",
  655. text: "系统错误,请稍后重试!",
  656. type: "error",
  657. confirmButtonColor: "#DD6B55"
  658. });
  659. }
  660. } else {
  661. SweetAlert.swal({
  662. title: "系统错误",
  663. text: "系统错误,请稍后重试!",
  664. type: "error",
  665. confirmButtonColor: "#DD6B55"
  666. });
  667. }
  668. $scope.ldloading[style.replace('-', '_')] = false;
  669. });
  670. break;
  671. case "save":
  672. //addData
  673. serviceWatch.addData($scope.formData.modelName, vm.model).then(function(response) {
  674. if (response) {
  675. var resData = Restangular.stripRestangular(response);
  676. // console.log("resData="+JSON.stringify(resData.data));
  677. // console.log("modelWatch.model="+JSON.stringify(modelWatch.model));
  678. if (resData && resData.status == 200) {
  679. SweetAlert.swal({
  680. title: "提交成功!",
  681. type: "success",
  682. confirmButtonColor: "#007AFF"
  683. }, function() {
  684. $state.go($scope.formData.cancelUrl);
  685. });
  686. } else {
  687. SweetAlert.swal({
  688. title: "系统错误",
  689. text: "系统错误,请稍后重试!",
  690. type: "error",
  691. confirmButtonColor: "#DD6B55"
  692. });
  693. }
  694. } else {
  695. SweetAlert.swal({
  696. title: "系统错误",
  697. text: "系统错误,请稍后重试!",
  698. type: "error",
  699. confirmButtonColor: "#DD6B55"
  700. });
  701. }
  702. $scope.ldloading[style.replace('-', '_')] = false;
  703. });
  704. break;
  705. case "close":
  706. $state.go($scope.formData.cancelUrl);
  707. break;
  708. default:
  709. $scope.ldloading[style.replace('-', '_')] = false;
  710. break;
  711. }
  712. } else if (resData.status == 200 && resData.data == "true" && vm.form.$valid) {
  713. SweetAlert.swal({
  714. title: "角色代码以存在",
  715. text: "请重新填写角色代码!",
  716. type: "error",
  717. confirmButtonColor: "#DD6B55"
  718. });
  719. } else {
  720. SweetAlert.swal({
  721. title: "校验错误",
  722. text: "请填写必填项!",
  723. type: "error",
  724. confirmButtonColor: "#DD6B55"
  725. });
  726. angular.forEach(vm.form.$error.required, function(item) {
  727. angular.forEach(vm.fields, function(f) {
  728. if (f.name == item.$name) {
  729. f.validation.show = true;
  730. }
  731. });
  732. })
  733. }
  734. })
  735. }
  736. };
  737. $scope.vm = vm;
  738. function renderform() {
  739. api_configure_form.renderForm($stateParams.formKey, '00000').then(function(responseData) {
  740. if (responseData) {
  741. //console.log("responseData>>>");console.log(responseData);
  742. var vmForm = Restangular.stripRestangular(responseData);
  743. if (vmForm) {
  744. //console.log("vmForm>>>");console.log(vmForm);
  745. var modelData = {};
  746. //modelData=myData.data;
  747. decodeVMForm(vmForm);
  748. }
  749. }
  750. });
  751. }
  752. if (angular.isDefined($stateParams.formKey) && $stateParams.formKey != "") {
  753. renderform();
  754. // api_configure_form.renderForm($stateParams.formKey, '00000').then(function(responseData) {
  755. // if (responseData) {
  756. // //console.log("responseData>>>");console.log(responseData);
  757. // var vmForm = Restangular.stripRestangular(responseData);
  758. // if (vmForm) {
  759. // //console.log("vmForm>>>");console.log(vmForm);
  760. // var modelData = {};
  761. // //modelData=myData.data;
  762. // decodeVMForm(vmForm);
  763. // }
  764. // }
  765. // });
  766. } else {
  767. //
  768. if (angular.isDefined(fieldsWatch) && fieldsWatch.length > 0) {
  769. var vmForm = {
  770. fields: fieldsWatch,
  771. model: modelWatch
  772. }
  773. angular.extend(vmForm, formWatch);
  774. //$scope.formData = vmForm;
  775. if (vmForm) {
  776. decodeVMForm(vmForm);
  777. }
  778. } else { //for form
  779. //TODO
  780. //测试数据 开始
  781. var testJson = {
  782. fields: [{
  783. key: 'formtitle',
  784. type: 'ui-title',
  785. noFormControl: true,
  786. templateOptions: {
  787. label: 'title is ',
  788. placeholder: 'Formly is terrific!'
  789. }
  790. },
  791. {
  792. key: 'b',
  793. type: 'ui-input',
  794. className: 'col-xs-4',
  795. templateOptions: {
  796. type: 'input',
  797. label: 'input a',
  798. placeholder: 'search a...',
  799. rBtn: {
  800. icon: 'fa fa-phone',
  801. onClick: function(val, opt, el, ev, model) { alert(val); }
  802. },
  803. lAddon: '<i class="fa fa-phone"/>'
  804. }
  805. },
  806. {
  807. key: 'id',
  808. type: 'ui-select',
  809. //initialValue:"false",
  810. templateOptions: {
  811. label: "测试默认值",
  812. optionsUrl: "abc",
  813. //options:[{"id":"false","name":"不取消"},{"id":"true","name":"取消"}],
  814. // refresh:function(){
  815. // return [{"id":1,"name":"事件","code":1},{"id":2,"name":"问题","code":2},{"id":3,"name":"配置","code":3},{"id":4,"name":"服务级别","code":4},{"id":5,"name":"内部需求","code":5}];
  816. // },
  817. //options:[{"id":1,"name":"事件","code":1},{"id":2,"name":"问题","code":2},{"id":3,"name":"配置","code":3},{"id":4,"name":"服务级别","code":4},{"id":5,"name":"内部需求","code":5}],
  818. valueProp: "id",
  819. labelProp: "name",
  820. pkey: "change.source"
  821. }
  822. },
  823. {
  824. key: 'systemType',
  825. type: 'ui-multiselect',
  826. className: 'col-xs-4',
  827. templateOptions: {
  828. label: "所属系统类型",
  829. pkey: "change",
  830. valueProp: "id",
  831. labelProp: "source",
  832. optionsUrl: "data/fetchDataList/changesystemtype",
  833. optionsDataKey: "list",
  834. onChange: function(value, options, that, event, model) {
  835. var field = null;
  836. angular.forEach(that.$parent.fields, function(item) {
  837. if (item.key == 'influenceDepartment') {
  838. field = item;
  839. }
  840. if (item.key == 'notificationDepartment') {
  841. notifyField = item;
  842. }
  843. })
  844. if (field != null) {
  845. field.templateOptions.optionsPostData = {
  846. 'systemIds': []
  847. }
  848. angular.forEach(value, function(vue) {
  849. field.templateOptions.optionsPostData['systemIds'].push({ 'id': vue });
  850. })
  851. field.value([]);
  852. if (value.length > 0) {
  853. field.templateOptions.refreshData(null, field);
  854. }
  855. }
  856. if (notifyField != null) {
  857. notifyField.templateOptions.optionsPostData = {
  858. 'systemIds': []
  859. }
  860. angular.forEach(value, function(vue) {
  861. notifyField.templateOptions.optionsPostData['systemIds'].push({ 'id': vue });
  862. })
  863. notifyField.value([]);
  864. if (value.length > 0) {
  865. notifyField.templateOptions.refreshData(null, notifyField);
  866. }
  867. }
  868. }
  869. }
  870. },
  871. {
  872. key: 'influenceDepartment',
  873. type: 'ui-multiselectplus',
  874. className: 'col-xs-4',
  875. templateOptions: {
  876. label: '所影响的应用系统、科室',
  877. pkey: "change",
  878. valueProp: '', //对应value
  879. labelProp: 'dept', //对应key
  880. optionsUrl: 'dept/findBySystemType', //对应后台地址,api/之前的部分省略
  881. optionsDataKey: 'list', //对应返回数组数据的键值,
  882. optionsPostData: function(options, model, scope) {
  883. return { "systemIds": [] };
  884. },
  885. refreshData: function(search, options, model, that) {
  886. options.templateOptions.options = [{ "id": 13, "dept": "村镇银行管理部" }, { "id": 14, "dept": "电子银行部" }];
  887. options.value(options.templateOptions.options);
  888. },
  889. optionsChecked: true,
  890. required: true,
  891. ApiService: UserRestangular
  892. }
  893. },
  894. {
  895. key: 'notificationDepartment',
  896. type: 'ui-multiselectplus',
  897. className: 'col-xs-4',
  898. templateOptions: {
  899. label: '需通知科室',
  900. pkey: "change",
  901. valueProp: 'id', //对应value
  902. labelProp: 'dept', //对应key
  903. optionsUrl: 'dept/findBySystemType', //对应后台地址,api/之前的部分省略
  904. optionsDataKey: 'list', //对应返回数组数据的键值,
  905. optionsPostData: function(options, model, scope) {
  906. return { "systemIds": [] };
  907. },
  908. optionsChecked: true,
  909. required: true,
  910. ApiService: UserRestangular
  911. }
  912. },
  913. {
  914. type: 'ui-label',
  915. key: 'arrayData',
  916. className: 'col-xs-4',
  917. templateOptions: {
  918. label: '数组label数据',
  919. labelProp: 'dept'
  920. }
  921. },
  922. {
  923. key: 'selectUser',
  924. type: 'ui-requesterselect',
  925. className: 'col-xs-12',
  926. templateOptions: {
  927. label: '请求人信息',
  928. modalTitle: '请求人列表',
  929. fetchItems: function(filterData, APIService) {
  930. return APIService.fetchDataList('requester', filterData);
  931. },
  932. Restangular: Restangular,
  933. ApiService: api_user_data
  934. // onClick:function(val, options, field, event , model){
  935. // console.log(options);
  936. // }
  937. }
  938. },
  939. {
  940. key: 'cabUser',
  941. type: 'ui-multiuserselect',
  942. className: 'col-xs-12',
  943. templateOptions: {
  944. label: 'CAB评审成员',
  945. modalTitle: 'CAB成员列表',
  946. fetchItems: function(filterData, APIService) {
  947. return APIService.fetchDataList('user', filterData);
  948. },
  949. Restangular: Restangular,
  950. ApiService: api_user_data,
  951. onClick: function(val, options, field, event, model) {
  952. console.log(model);
  953. }
  954. }
  955. },
  956. // {
  957. // key:'incident',
  958. // type:'ui-modelselect',
  959. // className:'col-xs-3',
  960. // templateOptions:{
  961. // label:'关联事件工单',
  962. // modalTitle:'工单列表',
  963. // fetchItems:function(filterData,APIService){
  964. // return APIService.fetchDataList('incident',filterData);
  965. // },
  966. // Restangular:"Restangular",
  967. // ApiService:"api_bpm_data",
  968. // columnDefs:[
  969. // { name:'id', width:80, enableFiltering:false},
  970. // { name:'title', displayName:'事件主题', width:140},
  971. // { name:'type.name', displayName:'事件类型', width:140},
  972. // { name:'emergency.name', displayName:'紧急度', width:80},
  973. // { name:'state.name', displayName:'状态', width:100},
  974. // { name:'emergency.name', displayName:'紧急度', width:80},
  975. // { name:'influence.name', displayName:'影响度', width:80},
  976. // { name:'priority.name', displayName:'优先级', width:80},
  977. // { name:'handlerUser.name', displayName:'当前处理人', width:100},
  978. // { name:'acceptDate', displayName:'创建时间', width:100}
  979. // ],
  980. // displayName:'title',
  981. // onClick:function(val, options, field, event , model){
  982. // //model.start_code++;
  983. // console.log(options);
  984. // }
  985. // }
  986. // },
  987. // {
  988. // key: 'worknumber',
  989. // type: 'ui-workernumber',
  990. // className:'col-xs-3',
  991. // templateOptions: {
  992. // label: 'work number',
  993. // Restangular:Restangular,
  994. // ApiService:api_bpm_domain,
  995. // getWorkernumber: function(APIService){
  996. // return APIService.workernumber('bg');
  997. // }
  998. // }
  999. // },
  1000. // {
  1001. // key: 'chkme',
  1002. // type: 'ui-checkbox',
  1003. // className:'col-xs-3',
  1004. // templateOptions: {
  1005. // label: 'Check me out'
  1006. // }
  1007. // },
  1008. // {
  1009. // key: 'droplink',
  1010. // type: 'ui-link',
  1011. // className: 'col-xs-3',
  1012. // templateOptions:{
  1013. // label:'添加附件',
  1014. // onClick:function(val, options, field, event ,model){
  1015. // if(angular.isUndefined(field.form.dropState)){
  1016. // field.form.dropState=false;
  1017. // }
  1018. // field.form.dropState=!field.form.dropState;
  1019. // console.log(field);
  1020. // }
  1021. // }
  1022. // },
  1023. // {
  1024. // key: 'dropfile',
  1025. // type: 'ui-dropfile',
  1026. // className: 'col-xs-12',
  1027. // templateOptions:{
  1028. // label:'附件',
  1029. // uploadUrl:'http://127.0.0.1:9008/saveAttachments'
  1030. // }
  1031. // },
  1032. // {
  1033. // type: 'ui-label',
  1034. // key: 'changesign',
  1035. // className: 'col-xs-4',
  1036. // templateOptions: {
  1037. // label:'变更请求单号',
  1038. // pkey:'change'
  1039. // }
  1040. // },
  1041. // {
  1042. // type: 'ui-label',
  1043. // key: 'title',
  1044. // className: 'col-xs-4',
  1045. // templateOptions: {
  1046. // label:'变更标题',
  1047. // pkey:'change'
  1048. // }
  1049. // },
  1050. // //关联发布单号
  1051. // //新建发布
  1052. // {
  1053. // key: 'droplist',
  1054. // type: 'ui-dropfiletable',
  1055. // className: 'col-xs-12',
  1056. // templateOptions:{
  1057. // label:'附件下载列表',
  1058. // Restangular:Restangular,
  1059. // processInstanceId:'250033',
  1060. // ApiService:api_bpm_domain
  1061. // }
  1062. // },
  1063. // {
  1064. // type: 'ui-repeatSection',
  1065. // key: 'investments',
  1066. // className: 'col-xs-12',
  1067. // templateOptions: {
  1068. // btnText: '新增变更施工单',
  1069. // fields: [
  1070. // {
  1071. // className: 'col-xs-3',
  1072. // type: 'ui-input',
  1073. // key: 'aboutci',
  1074. // templateOptions: {
  1075. // label: '关联的配置项',
  1076. // required: true
  1077. // }
  1078. // },
  1079. // {
  1080. // className: 'col-xs-3',
  1081. // type: 'ui-datepicker',
  1082. // key: 'planbegintime',
  1083. // templateOptions: {
  1084. // label: '计划开始时间',
  1085. // required: true
  1086. // }
  1087. // },
  1088. // {
  1089. // className: 'col-xs-3',
  1090. // type: 'ui-datepicker',
  1091. // key: 'planendtime',
  1092. // templateOptions: {
  1093. // label: '计划完成时间',
  1094. // required: true
  1095. // }
  1096. // },
  1097. // {
  1098. // className: 'col-xs-12',
  1099. // type: 'ui-userselect',
  1100. // key: 'handleruser',
  1101. // templateOptions: {
  1102. // label: '实施人员信息',
  1103. // modalTitle:'实施人列表',
  1104. // required: true,
  1105. // fetchItems:function(filterData, APIService){
  1106. // return APIService.fetchDataList('user',filterData);
  1107. // },
  1108. // Restangular:Restangular,
  1109. // ApiService:api_user_data,
  1110. // onClick:function(val, options, field, event , model){
  1111. // //model.start_code++;
  1112. // console.log(options);
  1113. // }
  1114. // }
  1115. // },
  1116. // {
  1117. // className: 'col-xs-8',
  1118. // type: 'ui-textarea',
  1119. // key: 'handlerContent',
  1120. // templateOptions: {
  1121. // label: '实施内容',
  1122. // required: true,
  1123. // row:10
  1124. // }
  1125. // },{
  1126. // noFormControl: true,
  1127. // template:'<hr>'
  1128. // }]
  1129. // }
  1130. // },
  1131. // {
  1132. // key: 'droplist',
  1133. // type: 'ui-dropfiletable',
  1134. // className: 'col-xs-12',
  1135. // templateOptions:{
  1136. // label:'附件下载列表',
  1137. // Restangular:Restangular,
  1138. // processInstanceId:'250033',
  1139. // ApiService:api_bpm_domain
  1140. // }
  1141. // },
  1142. // {
  1143. // key: 'start_code',
  1144. // className:'col-xs-6',
  1145. // type: 'ui-hidden'
  1146. // },
  1147. // {
  1148. // key:'remark',
  1149. // type:'ui-textarea',
  1150. // className:'col-xs-12',
  1151. // templateOptions:{
  1152. // label:'remark is ',
  1153. // rows:3
  1154. // }
  1155. // },
  1156. // {
  1157. // key:'setStartCode',
  1158. // type:'ui-button',
  1159. // className:'col-xs-4',
  1160. // templateOptions:{
  1161. // label:'升级为变更',
  1162. // onClick:function(val, options, field, event ,model){
  1163. // console.log(options);
  1164. // event.preventDefault();
  1165. // //model.start_code++;
  1166. // //console.log(options);
  1167. // }
  1168. // }
  1169. // }
  1170. ],
  1171. model: {
  1172. username: "robin lau",
  1173. password: "123456",
  1174. change: { source: { id: 5 } },
  1175. chkme: false,
  1176. start_code: 0,
  1177. arrayData: [{ "id": 13, "dept": "村镇银行管理部" }, { "id": 14, "dept": "电子银行部" }],
  1178. formtitle: "Hey!I am title value!",
  1179. name: {
  1180. first: "robin",
  1181. last: "lau"
  1182. },
  1183. multiselectItem: []
  1184. //date:"2015-09-15 00:00:00"
  1185. }
  1186. };
  1187. setTimeout(function() {
  1188. decodeVMForm(testJson);
  1189. $scope.$apply();
  1190. }, 500);
  1191. //测试数据结束
  1192. }
  1193. }
  1194. console.log("end decode");
  1195. }
  1196. ]);
  1197. // 'use strict';
  1198. // app.controller('jry_ceshiFormCtrl', ['$rootScope', '$scope', '$parse', '$filter', '$injector', '$http', '$q', '$state', '$stateParams', '$modal', '$timeout', '$interval', 'SweetAlert', 'FileUploader', 'i18nService', 'moment', 'Restangular', 'UserRestangular', 'BpmRestangular', 'api_configure_form', 'api_bpm_domain', 'api_bpm_data', 'api_user_data', 'api_apply',
  1199. // function($rootScope, $scope, $parse, $filter, $injector, $http, $q, $state, $stateParams, $modal, $timeout, $interval, SweetAlert, FileUploader, i18nService, moment, Restangular, UserRestangular, BpmRestangular, api_configure_form, api_bpm_domain, api_bpm_data, api_user_data, api_apply) {
  1200. // $scope.ceshi="哈哈"
  1201. // }
  1202. // ]);