systemFormCtrl.js 49 KB

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