knowledgeform.js 53 KB

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