customformDetailCtrl.js 43 KB

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