customformDetailCtrl.js 46 KB

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