customformDetailCtrl.js 47 KB

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