customformDetailCtrl.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. var appFormly = angular.module('formlyDetail', ['formlyExample']);
  2. app.requires.push('formlyDetail');
  3. appFormly.controller('CustomformDetailCtrl', ['$scope', 'i18nService', '$rootScope', '$parse', '$injector', '$http', '$q', '$state', '$stateParams', '$modal', '$timeout', '$interval', 'SweetAlert', 'FileUploader', 'Restangular', 'BpmRestangular', 'UserRestangular', 'api_configure_form', 'api_bpm_domain', 'api_bpm_data', 'api_user_data', 'up_down_file','WechatRestangular',
  4. function($scope, i18nService, $rootScope, $parse, $injector, $http, $q, $state, $stateParams, $modal, $timeout, $interval, SweetAlert, FileUploader, Restangular, BpmRestangular, UserRestangular, api_configure_form, api_bpm_domain, api_bpm_data, api_user_data, up_down_file,WechatRestangular) {
  5. //console.log($parse('Restangular')($scope));
  6. //console.log($injector.get('Restangular'));
  7. //保存报修主体
  8. $scope.repairMain = JSON.parse(sessionStorage.getItem("repair_main"));
  9. var vm = this;
  10. vm.options = {
  11. formState: {
  12. horizontalLabelClass: 'col-sm-5',
  13. horizontalFieldClass: 'col-sm-5',
  14. readOnly: true
  15. }
  16. };
  17. vm.exampleTitle = ['expressionProperties', 'model property'];
  18. vm.fields = [];
  19. vm.model = {};
  20. $scope.langs = i18nService.getAllLangs();
  21. $scope.lang = 'zh-cn';
  22. i18nService.setCurrentLang($scope.lang);
  23. $scope.backFunction = function(data) {
  24. $state.go('app.incident', {});
  25. };
  26. var that = $injector;
  27. var parse = $parse;
  28. var formKey = "";
  29. var pdKey = "";
  30. var modelWatch = "";
  31. if (angular.isDefined($state.current.pdKey) && $state.current.pdKey != "") {
  32. pdKey = $state.current.pdKey;
  33. // console.log("pdKey::"+$state.current.pdKey);
  34. } else if ($stateParams.pdKey) {
  35. pdKey = $stateParams.pdKey;
  36. };
  37. if (angular.isDefined($stateParams.formKey) && $stateParams.formKey != "") {
  38. formKey = $stateParams.formKey;
  39. // console.log("formKey::"+$stateParams.formKey);
  40. }
  41. if (angular.isDefined($stateParams.model) && $stateParams.model != "") {
  42. modelWatch = JSON.parse($stateParams.model);
  43. // console.log("modelWatch:"+ JSON.stringify(modelWatch));
  44. }
  45. //用户测试数据,后续从header的auth中获取
  46. var userId = 2;
  47. //==============处理表单设计数据 开始====================
  48. //处理组件加载后台数据选项的方法
  49. // function refreshSelectOptions(searchVal, field) {
  50. // if (field.templateOptions.optionsUrl) {
  51. // var process = BpmRestangular.all("");
  52. // process.customPOST({ "assignee": 2, "idx": 0, "sum": 1000 }, field.templateOptions.optionsUrl).then(function(result) {
  53. // if (!field.templateOptions.options) {
  54. // field.templateOptions.options = [];
  55. // }
  56. // if (field.templateOptions.optionsDataKey) {
  57. // field.templateOptions.options = result[field.templateOptions.optionsDataKey];
  58. // } else {
  59. // field.templateOptions.options = result;
  60. // }
  61. // });
  62. // }
  63. // }
  64. //处理组件加载后台数据选项的方法
  65. function refreshSelectOptions(searchVal, field) {
  66. if (field.templateOptions.optionsUrl && !field.templateOptions.isnosearch) {
  67. var process = BpmRestangular.all("");
  68. if (field.templateOptions.ApiService) {
  69. process = UserRestangular.all("");
  70. }
  71. if (field.templateOptions.Apicommon) {
  72. process = WechatRestangular.all("");
  73. }
  74. var datakey = { "idx": 0, "sum": 1000 };
  75. if (field.templateOptions.modelreasondata) {
  76. datakey = field.templateOptions.modelreasondata
  77. }
  78. process.customPOST(datakey, field.templateOptions.optionsUrl).then(function(result) {
  79. if (!field.templateOptions.options) {
  80. field.templateOptions.options = [];
  81. }
  82. if (field.templateOptions.optionsDataKey) {
  83. field.templateOptions.options = result[field.templateOptions.optionsDataKey];
  84. } else {
  85. field.templateOptions.options = result;
  86. }
  87. });
  88. }
  89. }
  90. //获取表单后数据处理
  91. function formfield(field, result) {
  92. // angular.forEach(fields.fields, function(field) {
  93. if (field.key == "") {
  94. delete field.key;
  95. }
  96. if (angular.isDefined(field.extjson)) {
  97. var extObj = angular.fromJson(field.extjson); //JSON.parse(field.extjson);
  98. angular.extend(field.templateOptions, extObj.templateOptions);
  99. delete extObj.templateOptions;
  100. for (var prop in extObj) {
  101. if (new RegExp("Expression").test(prop)) {
  102. //var obj = $scope.$eval(extObj[prop]);
  103. //extObj[prop] = $scope.$eval(extObj[prop]);
  104. if (extObj[prop] != null) {
  105. if (new RegExp("function").test(extObj[prop])) {
  106. var propValue = eval(extObj[prop]);
  107. extObj[prop] = propValue;
  108. } else {
  109. //console.log(extObj[prop]);
  110. var obj = $scope.$eval(extObj[prop]);
  111. extObj[prop] = obj;
  112. //console.log(obj);
  113. }
  114. }
  115. } else if (new RegExp("expressionProperties").test(prop)) {
  116. for (var p in extObj[prop]) {
  117. if (new RegExp("function").test(extObj[prop][p])) {
  118. var propValue = eval(extObj[prop][p]);
  119. extObj[prop][p] = propValue;
  120. } else {
  121. //if(p.indexOf("'")>=0){
  122. // var obj = $scope.$eval(extObj[prop][p]);
  123. // extObj[prop][$scope.$eval(p)]=obj;
  124. //}
  125. }
  126. }
  127. } else if ("watcher" == prop) {
  128. if (angular.isArray(extObj[prop])) {
  129. angular.forEach(extObj[prop], function(item, index) {
  130. for (var p in item) {
  131. if (new RegExp("function").test(item[p])) {
  132. var propValue = eval(item[p]);
  133. extObj[prop][index][p] = propValue;
  134. }
  135. }
  136. });
  137. } else if (angular.isObject(extObj[prop])) {
  138. for (var p in extObj[prop]) {
  139. if (new RegExp("function").test(extObj[prop][p])) {
  140. var propValue = eval(extObj[prop][p]);
  141. extObj[prop][p] = propValue;
  142. }
  143. }
  144. }
  145. }
  146. }
  147. angular.extend(field, extObj);
  148. delete field.extjson;
  149. }
  150. if (angular.isDefined(field.templateOptions)) {
  151. var templateOs = field.templateOptions;
  152. for (var property in templateOs) {
  153. //console.log(angular.isString(templateOs[property]) +" "+property + " " + (!(new RegExp("[\u4e00-\u9fa5]").test(templateOs[property]))));
  154. if (angular.isString(templateOs[property])) { //&& !(new RegExp("[\u4e00-\u9fa5]").test(templateOs[property]))
  155. if (new RegExp("function").test(templateOs[property])) {
  156. var propValue = eval(templateOs[property]);
  157. field.templateOptions[property] = propValue;
  158. } else {
  159. if (that.has(templateOs[property])) {
  160. field.templateOptions[property] = that.get(templateOs[property]);
  161. } else {
  162. field.templateOptions[property] = templateOs[property];
  163. }
  164. }
  165. } else if (templateOs[property] == null) {
  166. //delete field.templateOptions[property];
  167. } else {}
  168. }
  169. }
  170. if (angular.isDefined(field.templateOptions) && angular.isDefined(field.templateOptions.extjson)) {
  171. var extObj = angular.fromJson(field.templateOptions.extjson); //JSON.parse(field.extjson);
  172. angular.extend(field.templateOptions, extObj);
  173. delete field.templateOptions.extjson;
  174. }
  175. // ...
  176. if (field.templateOptions) {
  177. //处理远程获取数据控件方法调用
  178. if (field.templateOptions.optionsUrl) {
  179. field.templateOptions.refresh = refreshSelectOptions;
  180. }
  181. //处理嵌套属性数据绑定/
  182. if (field.templateOptions.pkey) {
  183. var pmodel, i = 0;
  184. angular.forEach(field.templateOptions.pkey.split("."), function(p) {
  185. if (i == 0) {
  186. if (result.model[p] == null) {
  187. result.model[p] = {};
  188. }
  189. pmodel = result.model[p];
  190. i++;
  191. } else {
  192. if (pmodel[p] == null) {
  193. pmodel[p] = {};
  194. }
  195. pmodel = pmodel[p];
  196. }
  197. });
  198. if (pmodel != null) {
  199. field.model = pmodel;
  200. if (pmodel[field.key] == null) {
  201. pmodel[field.key] = null;
  202. }
  203. }
  204. } else {
  205. if (result.model[field.key] == null) {
  206. result.model[field.key] = null;
  207. }
  208. }
  209. //处理弹出框组件初始化
  210. if (field.type == "ui-input-selectmodal") {
  211. field.templateOptions.modal = $modal;
  212. //field.templateOptions.Restangular = Restangular;
  213. } else if (field.type == "ui-requesterselect") {
  214. //field.templateOptions.language = $scope.lang;
  215. field.templateOptions.modal = $modal;
  216. field.templateOptions.UserService = api_user_data;
  217. } else if (field.type == "ui-deptinformation") {
  218. field.templateOptions.modal = $modal;
  219. field.templateOptions.UserService = api_user_data;
  220. } else if (field.type == "ui-requesterinformation") {
  221. field.templateOptions.modal = $modal;
  222. field.templateOptions.UserService = api_user_data;
  223. } else if (field.type == "ui-requesterselect-old") {
  224. //field.templateOptions.language = $scope.lang;
  225. field.templateOptions.modal = $modal;
  226. field.templateOptions.UserService = api_user_data;
  227. } else if (field.type == "ui-userselect") {
  228. field.templateOptions.modal = $modal;
  229. //field.templateOptions.Restangular = Restangular;
  230. } else if (field.type == "ui-multiuserselect") {
  231. field.templateOptions.modal = $modal;
  232. } else if (field.type == "ui-stringuserselect") {
  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-incidentmodelselect") {
  242. field.templateOptions.modal = $modal;
  243. //console.log("$rootScope.user:" + JSON.stringify($rootScope.user));
  244. field.templateOptions.loginUser = $rootScope.user;
  245. //field.templateOptions.Restangular = Restangular;
  246. } else if (field.type == "ui-dropfile") {
  247. $scope.fileUploader = field.templateOptions.fileUploader = new FileUploader({
  248. url: '/uploader'
  249. });
  250. field.templateOptions.taskId = $stateParams.taskId;
  251. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  252. field.templateOptions.userId = $rootScope.user.id;
  253. } else if (field.type == "ui-dropimage") {
  254. $scope.fileUploader = field.templateOptions.fileUploader = new FileUploader({
  255. url: '/uploader'
  256. });
  257. field.templateOptions.taskId = $stateParams.taskId;
  258. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  259. field.templateOptions.userId = $rootScope.user.id;
  260. } else if (field.type == "ui-dropfielknow") {
  261. $scope.fileUploader = field.templateOptions.fileUploader = new FileUploader({
  262. url: '/uploader'
  263. });
  264. field.templateOptions.taskId = $stateParams.taskId;
  265. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  266. field.templateOptions.userId = $rootScope.user.id;
  267. } else if (field.type == "ui-dropfilenotup") {
  268. $scope.fileUploader = field.templateOptions.fileUploader = new FileUploader({
  269. url: '/uploader'
  270. });
  271. field.templateOptions.taskId = $stateParams.taskId;
  272. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  273. field.templateOptions.userId = $rootScope.user.id;
  274. //field.ApiService=api_bpm_domain;
  275. }else if (field.type == "ui-uploadFile") {
  276. $scope.fileUploader = field.templateOptions.fileUploader = new FileUploader({
  277. url: '/uploader'
  278. });
  279. field.templateOptions.taskId = $stateParams.taskId;
  280. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  281. field.templateOptions.userId = $rootScope.user.id;
  282. //field.ApiService=api_bpm_domain;
  283. } else if (field.type == "ui-dropfiletable") {
  284. if (field.templateOptions.processInstanceId) {
  285. } else {
  286. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  287. }
  288. }else if (field.type == "ui-dropFiles") {
  289. if (field.templateOptions.processInstanceId) {
  290. } else {
  291. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  292. }
  293. }else if (field.type == "ui-showImgs") {
  294. if (field.templateOptions.processInstanceId) {
  295. } else {
  296. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  297. }
  298. } else if (field.type == "ui-repeatSection") {
  299. var repeatForm = {
  300. model: {
  301. },
  302. fields: field.templateOptions.fields
  303. };
  304. repeatForm.model[field.key] = [];
  305. decodeVMForm(repeatForm);
  306. } else if (field.type == "ui-currentuser") {
  307. field.templateOptions.user = vm.model["loginUser"];
  308. } else if (field.type == "ui-workernumbersign") {
  309. field.templateOptions.user = vm.model["loginUser"];
  310. } else if (field.type == "ui-repair-photos") {
  311. field.templateOptions.user = vm.model["loginUser"];
  312. }
  313. }
  314. }
  315. //解析自定义表单设计数据
  316. $scope.oldfromtype = true;
  317. function decodeVMForm(vmForm) {
  318. if (vmForm.formType == "1") {
  319. $scope.oldfromtype = false;
  320. } else {
  321. $scope.oldfromtype = true;
  322. }
  323. var result = { model: {}, fields: [] };
  324. //设置模型实体数据 begin
  325. // var mdata = vmForm.model;
  326. //解析数据实体
  327. var mdata = angular.fromJson(vmForm.model); //JSON.parse(field.extjson);
  328. angular.extend(result.model, mdata);
  329. if (modelWatch != null && modelWatch != '') {
  330. //angular.extend(result.model.incident,modelWatch.incident);
  331. //result.model.alarmType = modelWatch.alarmType;
  332. // vmForm.cancelUrl = modelWatch.cancelUrl;
  333. // console.log(modelWatch.cancelUrl)
  334. for (var index in modelWatch.model) {
  335. //console.log(JSON.stringify(index+" " +JSON.stringify( modelWatch.model[index])));
  336. if (result.model[index] != null) {
  337. angular.extend(result.model[index], modelWatch.model[index]);
  338. } else {
  339. result.model[index] = modelWatch.model[index];
  340. }
  341. }
  342. }
  343. //设置模型实体数据 end
  344. //解析设计数据生成表单项 begin
  345. var fields = [];
  346. //处理修改设计数据中展示设置
  347. angular.forEach(vmForm.fields, function(fields) {
  348. if (vmForm.formType == "1") {
  349. angular.forEach(fields.fields, function(field) {
  350. formfield(field, result);
  351. });
  352. } else {
  353. formfield(fields, result);
  354. }
  355. // console.log(field);
  356. result.fields.push(fields);
  357. });
  358. // $scope.vm.tabs = [];
  359. // angular.forEach(result.fields, function(item, index) {
  360. // if (index == 0) {
  361. // $scope.vm.tabs.push({ "fields": [item] })
  362. // } else if (index == 1 || index == 2 || index == 3) {
  363. // $scope.vm.tabs.push({ "fields": [item] })
  364. // } else if (index == 4) {
  365. // $scope.vm.tabs.push({ "fields": [item] })
  366. // }
  367. // })
  368. angular.extend($scope.vm.fields, result.fields);
  369. angular.extend($scope.vm.model, result.model);
  370. // angular.extend($scope.vm.formType, result.formType);
  371. // $scope.vm.tabs[0] = { "fields": $scope.vm.fields };
  372. // angular.extend($scope.vm.tabs[0].fields, result.fields);
  373. // angular.extend($scope.vm.tabs[0].model, result.model);
  374. // console.log("$scope.vm.model="+JSON.stringify($scope.vm.model));
  375. vm.model["loginUser"] = $rootScope.user;
  376. //增加识别报修主体seimin
  377. vm.model.repairType = $scope.repairMain.valueconfig;
  378. console.log(vm, 'repairType')//lmm
  379. if (modelWatch != null && modelWatch != '' && modelWatch.cancelUrl != null && modelWatch.cancelUrl != '') {
  380. vmForm.cancelUrl = modelWatch.cancelUrl;
  381. }
  382. $scope.formData = vmForm;
  383. // console.log("$scope.formData="+JSON.stringify($scope.formData.url));
  384. if ($scope.formData.url == "start") {
  385. $scope.Reset = true;
  386. $scope.close = false;
  387. } else if ($scope.formData.url == "complete") {
  388. $scope.Reset = false;
  389. $scope.close = true;
  390. }
  391. // $scope.formData = vmForm;
  392. //console.log($scope.vm);
  393. //解析设计数据生成表单项 end
  394. return result;
  395. }
  396. //======================处理表单设计数据 结束========================
  397. $scope.closeModel = function() {
  398. if($stateParams.isChart){
  399. $state.go('app.desk.chart');
  400. }else if($stateParams.isRecord){
  401. $state.go('app.desk.record');
  402. }else{
  403. $state.go($scope.formData.cancelUrl);
  404. }
  405. event.preventDefault();
  406. };
  407. vm.submit = function(data, style) {
  408. if (vm.form.$valid) {
  409. // $scope.ldloading[style.replace('-', '_')] = true;
  410. vm.options.updateInitialValue();
  411. var _ = window._;
  412. vm.model = (function filter(obj) {
  413. var dateTransKeys = [];
  414. var filtered = _.pick(obj, function(v, k, obj) {
  415. if (_.isDate(v)) {
  416. dateTransKeys.push(k);
  417. }
  418. return angular.isDefined(v) && v !== null && (angular.isArray(v) ? v.length > 0 : true) && (_.isPlainObject(v) ? (!_.isEmpty(v)) : true);
  419. });
  420. return _.cloneDeep(filtered, function(v, index, object) {
  421. if (angular.isArray(dateTransKeys) && dateTransKeys.length > 0) {
  422. angular.forEach(dateTransKeys, function(item) {
  423. v[item] = moment(v[item]).format('YYYY-MM-DD HH:mm:ss');
  424. })
  425. dateTransKey = [];
  426. return v;
  427. }
  428. return !(_.isEmpty(filtered)) && v !== filtered && _.isPlainObject(v) ? filter(v) : undefined;
  429. });
  430. })(vm.model);
  431. if (pdKey != "") {
  432. if (pdKey == "incident") { //修改
  433. vm.model.incident.category = { id: vm.model.incident.category.id };
  434. api_bpm_data.addData("incident", { "incident": vm.model.incident }).then(function(response) {
  435. if (response) {
  436. var resData = Restangular.stripRestangular(response);
  437. SweetAlert.swal({
  438. title: "保存成功!",
  439. type: "success",
  440. confirmButtonColor: "#007AFF"
  441. }, function() {
  442. $state.go($scope.formData.cancelUrl);
  443. });
  444. } else {
  445. SweetAlert.swal({
  446. title: "系统错误",
  447. text: "系统错误,请稍后重试!",
  448. type: "error",
  449. confirmButtonColor: "#DD6B55"
  450. });
  451. }
  452. // $scope.ldloading[style.replace('-', '_')] = false;
  453. });
  454. }
  455. }
  456. } else {
  457. var i = Number((vm.form.$error.required[0].$name).split("_")[4]);
  458. if (vm.fields[i].name == vm.form.$error.required[0].$name) {
  459. SweetAlert.swal({
  460. title: vm.fields[i].templateOptions.label + '未填',
  461. text: "请填写此项!",
  462. type: "error",
  463. confirmButtonColor: "#DD6B55"
  464. });
  465. }
  466. }
  467. };
  468. $scope.vm = vm;
  469. var dataId = $stateParams.dataId;
  470. var pdKey = $stateParams.pdKey;
  471. var detailFormKey = $stateParams.formKey;
  472. var processInstanceId = $stateParams.processInstanceId;
  473. // var idx=$stateParams.id
  474. if (angular.isDefined(detailFormKey) && detailFormKey != "") {
  475. var dataId = parseInt(dataId);
  476. if (angular.isDefined(processInstanceId) && processInstanceId != "") {
  477. api_configure_form.renderForm(detailFormKey, '00000', processInstanceId,dataId).then(function(responseData) {
  478. if (responseData) {
  479. var vmForm = Restangular.stripRestangular(responseData);
  480. if (vmForm) {
  481. var modelData = {};
  482. modelData[pdKey] = vmForm.model;
  483. decodeVMForm(vmForm, modelData);
  484. }
  485. }
  486. });
  487. } else if (angular.isDefined(dataId) && dataId != "") {
  488. api_bpm_data.fetchData(pdKey, dataId).then(function(response) {
  489. if (response) {
  490. var myData = Restangular.stripRestangular(response);
  491. var processInstanceId = myData.data.processInstanceId;
  492. //$scope.vm.model[pdKey]=myData.data;
  493. api_configure_form.renderForm(detailFormKey, '00000', processInstanceId).then(function(responseData) {
  494. if (responseData) {
  495. // console.log("responseData>>>");console.log(responseData);
  496. var vmForm = Restangular.stripRestangular(responseData);
  497. if (!processInstanceId) {
  498. vmForm.model[pdKey] = myData.data;
  499. }
  500. if (vmForm) {
  501. //console.log("vmForm>>>");console.log(vmForm);
  502. var modelData = {};
  503. modelData[pdKey] = vmForm.model;
  504. decodeVMForm(vmForm, modelData);
  505. }
  506. }
  507. });
  508. }
  509. })
  510. }
  511. } else {
  512. // create process instance
  513. if (pdKey != "") { //for process
  514. api_bpm_domain.startformkey(pdKey).then(function(response) {
  515. if (response) {
  516. var myData = Restangular.stripRestangular(response);
  517. api_configure_form.renderForm(myData.data).then(function(responseData) {
  518. if (responseData) {
  519. var vmForm = Restangular.stripRestangular(responseData);
  520. if (vmForm) {
  521. decodeVMForm(vmForm);
  522. console.log($scope);
  523. }
  524. }
  525. });
  526. }
  527. });
  528. } else { //for form
  529. //TODO
  530. //测试数据 开始
  531. var testJson = {
  532. fields: [{
  533. key: 'formtitle',
  534. type: 'ui-title',
  535. noFormControl: true,
  536. templateOptions: {
  537. label: 'title is ',
  538. placeholder: 'Formly is terrific!'
  539. }
  540. },
  541. {
  542. key: 'a',
  543. type: 'ui-input',
  544. className: 'col-xs-4',
  545. templateOptions: {
  546. type: 'input',
  547. label: 'input a',
  548. placeholder: 'search a...',
  549. lBtn: {
  550. label: 'input',
  551. onClick: function(val, opt, el, ev, model) { alert(val); }
  552. },
  553. rAddon: '@111.cc'
  554. }
  555. },
  556. {
  557. key: 'b',
  558. type: 'ui-input',
  559. className: 'col-xs-4',
  560. templateOptions: {
  561. type: 'input',
  562. label: 'input a',
  563. placeholder: 'search a...',
  564. rBtn: {
  565. icon: 'glyphicon-search',
  566. onClick: function(val, opt, el, ev, model) { alert(val); }
  567. },
  568. lAddon: '@'
  569. }
  570. },
  571. {
  572. key: 'first',
  573. type: 'ui-input',
  574. className: 'col-xs-2',
  575. templateOptions: {
  576. type: 'input',
  577. label: 'first name',
  578. pkey: 'name'
  579. }
  580. },
  581. {
  582. key: 'last',
  583. type: 'ui-input',
  584. className: 'col-xs-2',
  585. templateOptions: { type: 'input', label: 'last name', pkey: 'name' }
  586. },
  587. {
  588. key: 'username',
  589. type: 'ui-input',
  590. className: 'col-xs-6',
  591. templateOptions: {
  592. type: 'input',
  593. label: 'User Name',
  594. placeholder: 'Enter name',
  595. required: true,
  596. maxLength: 10
  597. }
  598. },
  599. {
  600. key: 'password',
  601. type: 'ui-input',
  602. className: 'col-xs-6',
  603. templateOptions: {
  604. type: 'password',
  605. label: 'Password',
  606. placeholder: 'Password',
  607. required: true
  608. },
  609. expressionProperties: {
  610. 'templateOptions.disabled': '!model.username'
  611. }
  612. },
  613. {
  614. key: 'selectmodal',
  615. type: 'ui-input-selectmodal',
  616. className: 'col-xs-6',
  617. templateOptions: {
  618. label: 'selectmodal',
  619. btnLabel: 'search',
  620. btnClassName: 'btn-o',
  621. modalParam: {
  622. items: function() {
  623. return ['a', 'b', 'c', 'd'];
  624. },
  625. title: function() {
  626. return '测试标题';
  627. }
  628. }
  629. }
  630. },
  631. {
  632. key: 'email',
  633. type: 'ui-input',
  634. className: 'col-xs-6',
  635. templateOptions: {
  636. type: 'email',
  637. maxlength: 10,
  638. minlength: 6,
  639. label: 'EMail'
  640. }
  641. },
  642. {
  643. key: 'date',
  644. type: 'ui-datepicker',
  645. className: 'col-xs-6',
  646. templateOptions: {
  647. label: 'Date',
  648. type: 'text',
  649. datepickerPopup: 'yyyy-MM-dd hh:mm:ss',
  650. initDate: function() {
  651. return new Date();
  652. }
  653. }
  654. },
  655. {
  656. key: 'multiselectItem',
  657. type: 'ui-multi-select-tree',
  658. className: 'col-xs-6',
  659. templateOptions: {
  660. label: 'multiSelect',
  661. placeholder: '请选择...',
  662. isMultiSelect: false,
  663. selLeafs: false, //只选叶子节点
  664. refreshData: function(APIService) {
  665. return APIService.fetchDataList('changeclassify', { 'idx': 0, 'sum': 100 });
  666. },
  667. APIService: api_bpm_data,
  668. optionsDataKey: 'list',
  669. refreshDelay: 1000,
  670. onDataCallback: function(item, selectItems, options, field, model) {
  671. model[options.key] = { id: item.id };
  672. }
  673. }
  674. },
  675. {
  676. key: 'selectItem',
  677. type: 'ui-select',
  678. className: 'col-xs-4',
  679. templateOptions: {
  680. label: 'ui-select',
  681. valueProp: 'code', //对应value
  682. labelProp: 'source', //对应key
  683. optionsUrl: 'data/fetchDataList/incidentsource', //对应后台地址,api/之前的部分省略
  684. optionsDataKey: 'list', //对应返回数组数据的键值,
  685. required: true,
  686. onChange: function(val, options, field, event, model) {
  687. model.start_code = val;
  688. }
  689. }
  690. },
  691. {
  692. key: 'multiselectItem',
  693. type: 'ui-multiselect',
  694. className: 'col-xs-4',
  695. templateOptions: {
  696. label: 'multi-select',
  697. valueProp: 'code', //对应value
  698. labelProp: 'source', //对应key
  699. optionsUrl: 'data/fetchDataList/incidentsource', //对应后台地址,api/之前的部分省略
  700. optionsDataKey: 'list', //对应返回数组数据的键值,
  701. required: true,
  702. onChange: function(val, options, field, event, model) {
  703. console.log(val);
  704. console.log(model);
  705. //model.start_code = val;
  706. }
  707. }
  708. },
  709. {
  710. key: 'checklistItem',
  711. type: 'ui-checklist',
  712. className: 'col-xs-4',
  713. templateOptions: {
  714. label: 'checklistItem',
  715. options: [
  716. { name: 'Iron Man', value: 'iron_man' },
  717. { name: 'Captain America', value: 'captain_america' },
  718. { name: 'Black Widow', value: 'black_widow' },
  719. { name: 'Hulk', value: 'hulk' },
  720. { name: 'Captain Marvel', value: 'captain_marvel' }
  721. ]
  722. }
  723. },
  724. {
  725. key: 'radioItem',
  726. type: 'ui-radio',
  727. className: 'col-xs-4',
  728. templateOptions: {
  729. label: 'radioItem',
  730. options: [
  731. { name: 'Iron Man', value: 'iron_man' },
  732. { name: 'Captain America', value: 'captain_america' },
  733. { name: 'Black Widow', value: 'black_widow' },
  734. { name: 'Hulk', value: 'hulk' },
  735. { name: 'Captain Marvel', value: 'captain_marvel' }
  736. ],
  737. type: 'number'
  738. }
  739. },
  740. {
  741. key: 'selectUser',
  742. type: 'ui-userselect',
  743. className: 'col-xs-12',
  744. templateOptions: {
  745. label: '请求人信息',
  746. modalTitle: '请求人列表',
  747. fetchItems: function(filterData, APIService) {
  748. return APIService.fetchDataList('user', filterData);
  749. },
  750. Restangular: Restangular,
  751. ApiService: api_user_data,
  752. onClick: function(val, options, field, event, model) {
  753. //model.start_code++;
  754. console.log(options);
  755. }
  756. }
  757. },
  758. {
  759. key: 'cabUser',
  760. type: 'ui-multiuserselect',
  761. className: 'col-xs-12',
  762. templateOptions: {
  763. label: 'CAB评审成员',
  764. modalTitle: 'CAB成员列表',
  765. fetchItems: function(filterData, APIService) {
  766. return APIService.fetchDataList('user', filterData);
  767. },
  768. Restangular: Restangular,
  769. ApiService: api_user_data,
  770. onClick: function(val, options, field, event, model) {
  771. console.log(model);
  772. }
  773. }
  774. },
  775. {
  776. key: 'incident',
  777. type: 'ui-modelselect',
  778. className: 'col-xs-3',
  779. templateOptions: {
  780. label: '关联事件工单',
  781. modalTitle: '事件列表',
  782. fetchItems: function(filterData, APIService) {
  783. return APIService.fetchDataList('incident', filterData);
  784. },
  785. Restangular: "Restangular",
  786. ApiService: "api_bpm_data",
  787. columnDefs: [
  788. { name: 'id', width: 80, enableFiltering: false },
  789. { name: 'title', displayName: '事件主题', width: 140 },
  790. { name: 'type.name', displayName: '事件类型', width: 140 },
  791. { name: 'emergency.name', displayName: '紧急度', width: 80 },
  792. { name: 'state.name', displayName: '状态', width: 100 },
  793. { name: 'emergency.name', displayName: '紧急度', width: 80 },
  794. { name: 'influence.name', displayName: '影响度', width: 80 },
  795. { name: 'priority.name', displayName: '优先级', width: 80 },
  796. { name: 'handlerUser.name', displayName: '当前处理人', width: 100 },
  797. { name: 'acceptDate', displayName: '创建时间', width: 100 }
  798. ],
  799. displayName: 'title',
  800. onClick: function(val, options, field, event, model) {
  801. //model.start_code++;
  802. console.log(options);
  803. }
  804. }
  805. },
  806. {
  807. key: 'worknumber',
  808. type: 'ui-workernumber',
  809. className: 'col-xs-3',
  810. templateOptions: {
  811. label: 'work number',
  812. Restangular: Restangular,
  813. ApiService: api_bpm_domain,
  814. getWorkernumber: function(APIService) {
  815. return APIService.workernumber('bg');
  816. }
  817. }
  818. },
  819. {
  820. key: 'chkme',
  821. type: 'ui-checkbox',
  822. className: 'col-xs-3',
  823. templateOptions: {
  824. label: 'Check me out'
  825. }
  826. },
  827. {
  828. key: 'droplink',
  829. type: 'ui-link',
  830. className: 'col-xs-3',
  831. templateOptions: {
  832. label: '添加附件',
  833. onClick: function(val, options, field, event, model) {
  834. if (angular.isUndefined(field.form.dropState)) {
  835. field.form.dropState = false;
  836. }
  837. field.form.dropState = !field.form.dropState;
  838. console.log(field);
  839. }
  840. }
  841. },
  842. {
  843. key: 'dropfile',
  844. type: 'ui-dropfile',
  845. className: 'col-xs-12',
  846. templateOptions: {
  847. label: '附件',
  848. uploadUrl: 'http://127.0.0.1:9008/saveAttachments'
  849. }
  850. },
  851. {
  852. key: 'droplist',
  853. type: 'ui-dropfiletable',
  854. className: 'col-xs-12',
  855. templateOptions: {
  856. label: '附件下载列表',
  857. Restangular: Restangular,
  858. ApiService: api_bpm_domain
  859. }
  860. },
  861. {
  862. key: 'start_code',
  863. className: 'col-xs-6',
  864. type: 'ui-hidden'
  865. },
  866. {
  867. key: 'remark',
  868. type: 'ui-textarea',
  869. className: 'col-xs-12',
  870. templateOptions: {
  871. label: 'remark is ',
  872. rows: 3
  873. }
  874. },
  875. {
  876. key: 'setStartCode',
  877. type: 'ui-button',
  878. className: 'col-xs-4',
  879. templateOptions: {
  880. label: 'customButton',
  881. onClick: function(val, options, field, event, model) {
  882. model.start_code++;
  883. console.log(options);
  884. }
  885. }
  886. }
  887. ],
  888. model: {
  889. username: "robin lau",
  890. password: "123456",
  891. chkme: false,
  892. start_code: 0,
  893. formtitle: "Hey!I am title value!",
  894. name: {
  895. first: "robin",
  896. last: "lau"
  897. },
  898. multiselectItem: []
  899. //date:"2015-09-15 00:00:00"
  900. }
  901. };
  902. setTimeout(function() {
  903. decodeVMForm(testJson);
  904. $scope.$apply();
  905. }, 500);
  906. //测试数据结束
  907. }
  908. }
  909. }
  910. ]);