customformDetailCtrl.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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',
  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) {
  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-uploadFile") {
  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-dropfiletable") {
  279. if (field.templateOptions.processInstanceId) {
  280. } else {
  281. field.templateOptions.processInstanceId = $stateParams.processInstanceId;
  282. }
  283. } else if (field.type == "ui-repeatSection") {
  284. var repeatForm = {
  285. model: {
  286. },
  287. fields: field.templateOptions.fields
  288. };
  289. repeatForm.model[field.key] = [];
  290. decodeVMForm(repeatForm);
  291. } else if (field.type == "ui-currentuser") {
  292. field.templateOptions.user = vm.model["loginUser"];
  293. } else if (field.type == "ui-workernumbersign") {
  294. field.templateOptions.user = vm.model["loginUser"];
  295. }
  296. }
  297. }
  298. //解析自定义表单设计数据
  299. $scope.oldfromtype = true;
  300. function decodeVMForm(vmForm) {
  301. if (vmForm.formType == "1") {
  302. $scope.oldfromtype = false;
  303. } else {
  304. $scope.oldfromtype = true;
  305. }
  306. var result = { model: {}, fields: [] };
  307. //设置模型实体数据 begin
  308. // var mdata = vmForm.model;
  309. //解析数据实体
  310. var mdata = angular.fromJson(vmForm.model); //JSON.parse(field.extjson);
  311. angular.extend(result.model, mdata);
  312. if (modelWatch != null && modelWatch != '') {
  313. //angular.extend(result.model.incident,modelWatch.incident);
  314. //result.model.alarmType = modelWatch.alarmType;
  315. // vmForm.cancelUrl = modelWatch.cancelUrl;
  316. // console.log(modelWatch.cancelUrl)
  317. for (var index in modelWatch.model) {
  318. //console.log(JSON.stringify(index+" " +JSON.stringify( modelWatch.model[index])));
  319. if (result.model[index] != null) {
  320. angular.extend(result.model[index], modelWatch.model[index]);
  321. } else {
  322. result.model[index] = modelWatch.model[index];
  323. }
  324. }
  325. }
  326. //设置模型实体数据 end
  327. //解析设计数据生成表单项 begin
  328. var fields = [];
  329. //处理修改设计数据中展示设置
  330. angular.forEach(vmForm.fields, function(fields) {
  331. if (vmForm.formType == "1") {
  332. angular.forEach(fields.fields, function(field) {
  333. formfield(field, result);
  334. });
  335. } else {
  336. formfield(fields, result);
  337. }
  338. // console.log(field);
  339. result.fields.push(fields);
  340. });
  341. // $scope.vm.tabs = [];
  342. // angular.forEach(result.fields, function(item, index) {
  343. // if (index == 0) {
  344. // $scope.vm.tabs.push({ "fields": [item] })
  345. // } else if (index == 1 || index == 2 || index == 3) {
  346. // $scope.vm.tabs.push({ "fields": [item] })
  347. // } else if (index == 4) {
  348. // $scope.vm.tabs.push({ "fields": [item] })
  349. // }
  350. // })
  351. angular.extend($scope.vm.fields, result.fields);
  352. angular.extend($scope.vm.model, result.model);
  353. // angular.extend($scope.vm.formType, result.formType);
  354. // $scope.vm.tabs[0] = { "fields": $scope.vm.fields };
  355. // angular.extend($scope.vm.tabs[0].fields, result.fields);
  356. // angular.extend($scope.vm.tabs[0].model, result.model);
  357. // console.log("$scope.vm.model="+JSON.stringify($scope.vm.model));
  358. vm.model["loginUser"] = $rootScope.user;
  359. if (modelWatch != null && modelWatch != '' && modelWatch.cancelUrl != null && modelWatch.cancelUrl != '') {
  360. vmForm.cancelUrl = modelWatch.cancelUrl;
  361. }
  362. $scope.formData = vmForm;
  363. // console.log("$scope.formData="+JSON.stringify($scope.formData.url));
  364. if ($scope.formData.url == "start") {
  365. $scope.Reset = true;
  366. $scope.close = false;
  367. } else if ($scope.formData.url == "complete") {
  368. $scope.Reset = false;
  369. $scope.close = true;
  370. }
  371. // $scope.formData = vmForm;
  372. //console.log($scope.vm);
  373. //解析设计数据生成表单项 end
  374. return result;
  375. }
  376. //======================处理表单设计数据 结束========================
  377. $scope.closeModel = function() {
  378. $state.go($scope.formData.cancelUrl);
  379. event.preventDefault();
  380. };
  381. vm.submit = function(data, style) {
  382. if (vm.form.$valid) {
  383. // $scope.ldloading[style.replace('-', '_')] = true;
  384. vm.options.updateInitialValue();
  385. var _ = window._;
  386. vm.model = (function filter(obj) {
  387. var dateTransKeys = [];
  388. var filtered = _.pick(obj, function(v, k, obj) {
  389. if (_.isDate(v)) {
  390. dateTransKeys.push(k);
  391. }
  392. return angular.isDefined(v) && v !== null && (angular.isArray(v) ? v.length > 0 : true) && (_.isPlainObject(v) ? (!_.isEmpty(v)) : true);
  393. });
  394. return _.cloneDeep(filtered, function(v, index, object) {
  395. if (angular.isArray(dateTransKeys) && dateTransKeys.length > 0) {
  396. angular.forEach(dateTransKeys, function(item) {
  397. v[item] = moment(v[item]).format('YYYY-MM-DD HH:mm:ss');
  398. })
  399. dateTransKey = [];
  400. return v;
  401. }
  402. return !(_.isEmpty(filtered)) && v !== filtered && _.isPlainObject(v) ? filter(v) : undefined;
  403. });
  404. })(vm.model);
  405. if (pdKey != "") {
  406. if (pdKey == "incident") { //修改
  407. vm.model.incident.category = { id: vm.model.incident.category.id };
  408. api_bpm_data.updData("incident", { "incident": vm.model.incident }).then(function(response) {
  409. if (response) {
  410. var resData = Restangular.stripRestangular(response);
  411. SweetAlert.swal({
  412. title: "保存成功!",
  413. type: "success",
  414. confirmButtonColor: "#007AFF"
  415. }, function() {
  416. $state.go($scope.formData.cancelUrl);
  417. });
  418. } else {
  419. SweetAlert.swal({
  420. title: "系统错误",
  421. text: "系统错误,请稍后重试!",
  422. type: "error",
  423. confirmButtonColor: "#DD6B55"
  424. });
  425. }
  426. // $scope.ldloading[style.replace('-', '_')] = false;
  427. });
  428. }
  429. }
  430. } else {
  431. var i = Number((vm.form.$error.required[0].$name).split("_")[4]);
  432. if (vm.fields[i].name == vm.form.$error.required[0].$name) {
  433. SweetAlert.swal({
  434. title: vm.fields[i].templateOptions.label + '未填',
  435. text: "请填写此项!",
  436. type: "error",
  437. confirmButtonColor: "#DD6B55"
  438. });
  439. }
  440. }
  441. };
  442. $scope.vm = vm;
  443. var dataId = $stateParams.dataId;
  444. var pdKey = $stateParams.pdKey;
  445. var detailFormKey = $stateParams.formKey;
  446. var processInstanceId = $stateParams.processInstanceId;
  447. if (angular.isDefined(detailFormKey) && detailFormKey != "") {
  448. var dataId = parseInt(dataId);
  449. if (angular.isDefined(processInstanceId) && processInstanceId != "") {
  450. api_configure_form.renderForm(detailFormKey, '00000', processInstanceId).then(function(responseData) {
  451. if (responseData) {
  452. var vmForm = Restangular.stripRestangular(responseData);
  453. if (vmForm) {
  454. var modelData = {};
  455. modelData[pdKey] = vmForm.model;
  456. decodeVMForm(vmForm, modelData);
  457. }
  458. }
  459. });
  460. } else if (angular.isDefined(dataId) && dataId != "") {
  461. api_bpm_data.fetchData(pdKey, dataId).then(function(response) {
  462. if (response) {
  463. var myData = Restangular.stripRestangular(response);
  464. var processInstanceId = myData.data.processInstanceId;
  465. //$scope.vm.model[pdKey]=myData.data;
  466. api_configure_form.renderForm(detailFormKey, '00000', processInstanceId).then(function(responseData) {
  467. if (responseData) {
  468. // console.log("responseData>>>");console.log(responseData);
  469. var vmForm = Restangular.stripRestangular(responseData);
  470. if (!processInstanceId) {
  471. vmForm.model[pdKey] = myData.data;
  472. }
  473. if (vmForm) {
  474. //console.log("vmForm>>>");console.log(vmForm);
  475. var modelData = {};
  476. modelData[pdKey] = vmForm.model;
  477. decodeVMForm(vmForm, modelData);
  478. }
  479. }
  480. });
  481. }
  482. })
  483. }
  484. } else {
  485. // create process instance
  486. if (pdKey != "") { //for process
  487. api_bpm_domain.startformkey(pdKey).then(function(response) {
  488. if (response) {
  489. var myData = Restangular.stripRestangular(response);
  490. api_configure_form.renderForm(myData.data).then(function(responseData) {
  491. if (responseData) {
  492. var vmForm = Restangular.stripRestangular(responseData);
  493. if (vmForm) {
  494. decodeVMForm(vmForm);
  495. console.log($scope);
  496. }
  497. }
  498. });
  499. }
  500. });
  501. } else { //for form
  502. //TODO
  503. //测试数据 开始
  504. var testJson = {
  505. fields: [{
  506. key: 'formtitle',
  507. type: 'ui-title',
  508. noFormControl: true,
  509. templateOptions: {
  510. label: 'title is ',
  511. placeholder: 'Formly is terrific!'
  512. }
  513. },
  514. {
  515. key: 'a',
  516. type: 'ui-input',
  517. className: 'col-xs-4',
  518. templateOptions: {
  519. type: 'input',
  520. label: 'input a',
  521. placeholder: 'search a...',
  522. lBtn: {
  523. label: 'input',
  524. onClick: function(val, opt, el, ev, model) { alert(val); }
  525. },
  526. rAddon: '@111.cc'
  527. }
  528. },
  529. {
  530. key: 'b',
  531. type: 'ui-input',
  532. className: 'col-xs-4',
  533. templateOptions: {
  534. type: 'input',
  535. label: 'input a',
  536. placeholder: 'search a...',
  537. rBtn: {
  538. icon: 'glyphicon-search',
  539. onClick: function(val, opt, el, ev, model) { alert(val); }
  540. },
  541. lAddon: '@'
  542. }
  543. },
  544. {
  545. key: 'first',
  546. type: 'ui-input',
  547. className: 'col-xs-2',
  548. templateOptions: {
  549. type: 'input',
  550. label: 'first name',
  551. pkey: 'name'
  552. }
  553. },
  554. {
  555. key: 'last',
  556. type: 'ui-input',
  557. className: 'col-xs-2',
  558. templateOptions: { type: 'input', label: 'last name', pkey: 'name' }
  559. },
  560. {
  561. key: 'username',
  562. type: 'ui-input',
  563. className: 'col-xs-6',
  564. templateOptions: {
  565. type: 'input',
  566. label: 'User Name',
  567. placeholder: 'Enter name',
  568. required: true,
  569. maxLength: 10
  570. }
  571. },
  572. {
  573. key: 'password',
  574. type: 'ui-input',
  575. className: 'col-xs-6',
  576. templateOptions: {
  577. type: 'password',
  578. label: 'Password',
  579. placeholder: 'Password',
  580. required: true
  581. },
  582. expressionProperties: {
  583. 'templateOptions.disabled': '!model.username'
  584. }
  585. },
  586. {
  587. key: 'selectmodal',
  588. type: 'ui-input-selectmodal',
  589. className: 'col-xs-6',
  590. templateOptions: {
  591. label: 'selectmodal',
  592. btnLabel: 'search',
  593. btnClassName: 'btn-o',
  594. modalParam: {
  595. items: function() {
  596. return ['a', 'b', 'c', 'd'];
  597. },
  598. title: function() {
  599. return '测试标题';
  600. }
  601. }
  602. }
  603. },
  604. {
  605. key: 'email',
  606. type: 'ui-input',
  607. className: 'col-xs-6',
  608. templateOptions: {
  609. type: 'email',
  610. maxlength: 10,
  611. minlength: 6,
  612. label: 'EMail'
  613. }
  614. },
  615. {
  616. key: 'date',
  617. type: 'ui-datepicker',
  618. className: 'col-xs-6',
  619. templateOptions: {
  620. label: 'Date',
  621. type: 'text',
  622. datepickerPopup: 'yyyy-MM-dd hh:mm:ss',
  623. initDate: function() {
  624. return new Date();
  625. }
  626. }
  627. },
  628. {
  629. key: 'multiselectItem',
  630. type: 'ui-multi-select-tree',
  631. className: 'col-xs-6',
  632. templateOptions: {
  633. label: 'multiSelect',
  634. placeholder: '请选择...',
  635. isMultiSelect: false,
  636. selLeafs: false, //只选叶子节点
  637. refreshData: function(APIService) {
  638. return APIService.fetchDataList('changeclassify', { 'idx': 0, 'sum': 100 });
  639. },
  640. APIService: api_bpm_data,
  641. optionsDataKey: 'list',
  642. refreshDelay: 1000,
  643. onDataCallback: function(item, selectItems, options, field, model) {
  644. model[options.key] = { id: item.id };
  645. }
  646. }
  647. },
  648. {
  649. key: 'selectItem',
  650. type: 'ui-select',
  651. className: 'col-xs-4',
  652. templateOptions: {
  653. label: 'ui-select',
  654. valueProp: 'code', //对应value
  655. labelProp: 'source', //对应key
  656. optionsUrl: 'data/fetchDataList/incidentsource', //对应后台地址,api/之前的部分省略
  657. optionsDataKey: 'list', //对应返回数组数据的键值,
  658. required: true,
  659. onChange: function(val, options, field, event, model) {
  660. model.start_code = val;
  661. }
  662. }
  663. },
  664. {
  665. key: 'multiselectItem',
  666. type: 'ui-multiselect',
  667. className: 'col-xs-4',
  668. templateOptions: {
  669. label: 'multi-select',
  670. valueProp: 'code', //对应value
  671. labelProp: 'source', //对应key
  672. optionsUrl: 'data/fetchDataList/incidentsource', //对应后台地址,api/之前的部分省略
  673. optionsDataKey: 'list', //对应返回数组数据的键值,
  674. required: true,
  675. onChange: function(val, options, field, event, model) {
  676. console.log(val);
  677. console.log(model);
  678. //model.start_code = val;
  679. }
  680. }
  681. },
  682. {
  683. key: 'checklistItem',
  684. type: 'ui-checklist',
  685. className: 'col-xs-4',
  686. templateOptions: {
  687. label: 'checklistItem',
  688. options: [
  689. { name: 'Iron Man', value: 'iron_man' },
  690. { name: 'Captain America', value: 'captain_america' },
  691. { name: 'Black Widow', value: 'black_widow' },
  692. { name: 'Hulk', value: 'hulk' },
  693. { name: 'Captain Marvel', value: 'captain_marvel' }
  694. ]
  695. }
  696. },
  697. {
  698. key: 'radioItem',
  699. type: 'ui-radio',
  700. className: 'col-xs-4',
  701. templateOptions: {
  702. label: 'radioItem',
  703. options: [
  704. { name: 'Iron Man', value: 'iron_man' },
  705. { name: 'Captain America', value: 'captain_america' },
  706. { name: 'Black Widow', value: 'black_widow' },
  707. { name: 'Hulk', value: 'hulk' },
  708. { name: 'Captain Marvel', value: 'captain_marvel' }
  709. ],
  710. type: 'number'
  711. }
  712. },
  713. {
  714. key: 'selectUser',
  715. type: 'ui-userselect',
  716. className: 'col-xs-12',
  717. templateOptions: {
  718. label: '请求人信息',
  719. modalTitle: '请求人列表',
  720. fetchItems: function(filterData, APIService) {
  721. return APIService.fetchDataList('user', filterData);
  722. },
  723. Restangular: Restangular,
  724. ApiService: api_user_data,
  725. onClick: function(val, options, field, event, model) {
  726. //model.start_code++;
  727. console.log(options);
  728. }
  729. }
  730. },
  731. {
  732. key: 'cabUser',
  733. type: 'ui-multiuserselect',
  734. className: 'col-xs-12',
  735. templateOptions: {
  736. label: 'CAB评审成员',
  737. modalTitle: 'CAB成员列表',
  738. fetchItems: function(filterData, APIService) {
  739. return APIService.fetchDataList('user', filterData);
  740. },
  741. Restangular: Restangular,
  742. ApiService: api_user_data,
  743. onClick: function(val, options, field, event, model) {
  744. console.log(model);
  745. }
  746. }
  747. },
  748. {
  749. key: 'incident',
  750. type: 'ui-modelselect',
  751. className: 'col-xs-3',
  752. templateOptions: {
  753. label: '关联事件工单',
  754. modalTitle: '事件列表',
  755. fetchItems: function(filterData, APIService) {
  756. return APIService.fetchDataList('incident', filterData);
  757. },
  758. Restangular: "Restangular",
  759. ApiService: "api_bpm_data",
  760. columnDefs: [
  761. { name: 'id', width: 80, enableFiltering: false },
  762. { name: 'title', displayName: '事件主题', width: 140 },
  763. { name: 'type.name', displayName: '事件类型', width: 140 },
  764. { name: 'emergency.name', displayName: '紧急度', width: 80 },
  765. { name: 'state.name', displayName: '状态', width: 100 },
  766. { name: 'emergency.name', displayName: '紧急度', width: 80 },
  767. { name: 'influence.name', displayName: '影响度', width: 80 },
  768. { name: 'priority.name', displayName: '优先级', width: 80 },
  769. { name: 'handlerUser.name', displayName: '当前处理人', width: 100 },
  770. { name: 'acceptDate', displayName: '创建时间', width: 100 }
  771. ],
  772. displayName: 'title',
  773. onClick: function(val, options, field, event, model) {
  774. //model.start_code++;
  775. console.log(options);
  776. }
  777. }
  778. },
  779. {
  780. key: 'worknumber',
  781. type: 'ui-workernumber',
  782. className: 'col-xs-3',
  783. templateOptions: {
  784. label: 'work number',
  785. Restangular: Restangular,
  786. ApiService: api_bpm_domain,
  787. getWorkernumber: function(APIService) {
  788. return APIService.workernumber('bg');
  789. }
  790. }
  791. },
  792. {
  793. key: 'chkme',
  794. type: 'ui-checkbox',
  795. className: 'col-xs-3',
  796. templateOptions: {
  797. label: 'Check me out'
  798. }
  799. },
  800. {
  801. key: 'droplink',
  802. type: 'ui-link',
  803. className: 'col-xs-3',
  804. templateOptions: {
  805. label: '添加附件',
  806. onClick: function(val, options, field, event, model) {
  807. if (angular.isUndefined(field.form.dropState)) {
  808. field.form.dropState = false;
  809. }
  810. field.form.dropState = !field.form.dropState;
  811. console.log(field);
  812. }
  813. }
  814. },
  815. {
  816. key: 'dropfile',
  817. type: 'ui-dropfile',
  818. className: 'col-xs-12',
  819. templateOptions: {
  820. label: '附件',
  821. uploadUrl: 'http://127.0.0.1:9008/saveAttachments'
  822. }
  823. },
  824. {
  825. key: 'droplist',
  826. type: 'ui-dropfiletable',
  827. className: 'col-xs-12',
  828. templateOptions: {
  829. label: '附件下载列表',
  830. Restangular: Restangular,
  831. ApiService: api_bpm_domain
  832. }
  833. },
  834. {
  835. key: 'start_code',
  836. className: 'col-xs-6',
  837. type: 'ui-hidden'
  838. },
  839. {
  840. key: 'remark',
  841. type: 'ui-textarea',
  842. className: 'col-xs-12',
  843. templateOptions: {
  844. label: 'remark is ',
  845. rows: 3
  846. }
  847. },
  848. {
  849. key: 'setStartCode',
  850. type: 'ui-button',
  851. className: 'col-xs-4',
  852. templateOptions: {
  853. label: 'customButton',
  854. onClick: function(val, options, field, event, model) {
  855. model.start_code++;
  856. console.log(options);
  857. }
  858. }
  859. }
  860. ],
  861. model: {
  862. username: "robin lau",
  863. password: "123456",
  864. chkme: false,
  865. start_code: 0,
  866. formtitle: "Hey!I am title value!",
  867. name: {
  868. first: "robin",
  869. last: "lau"
  870. },
  871. multiselectItem: []
  872. //date:"2015-09-15 00:00:00"
  873. }
  874. };
  875. setTimeout(function() {
  876. decodeVMForm(testJson);
  877. $scope.$apply();
  878. }, 500);
  879. //测试数据结束
  880. }
  881. }
  882. }
  883. ]);