inspectForm.js 51 KB

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