formlist-add.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. var app = angular.module('app', ["angularUtils.directives.dirPagination"]);
  2. app.controller("formlistAddCtrl", ["$scope", "$http", "$compile", "$timeout", function ($scope, $http, $compile, $timeout) {
  3. var self = this;
  4. var s4 = new SM4Util();
  5. sp.fitHeight("#formAddPart", 190);
  6. sp.fitHeight("#formTablePart", 80);
  7. self.userId = $.cookie("GlWorkPlatform-userid");
  8. self.userName = $.cookie("GlWorkPlatform-username");
  9. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  10. self.get_formid = sp.getUrlName("formid");
  11. self.get_ctype = sp.getUrlName("ctype");
  12. self.get_leftActive = sp.getUrlName("leftActive");
  13. self.get_leftActiveType = sp.getUrlName("leftActiveType");
  14. self.loading = false;
  15. self.btnGoBack = function () {
  16. ///返回上一级
  17. window.location.href = "formlist.html?leftActive=" + self.get_leftActive + "&leftActiveType=" + self.get_leftActiveType;
  18. };
  19. var postCfg = {
  20. headers: {
  21. 'Content-Type': 'application/json',
  22. 'Authorization': "Bearer " + self.get_AccessToken
  23. }
  24. };
  25. //列存储类型
  26. self.columnType = [
  27. {
  28. "cval": "varchar",
  29. "cname": "文本型",
  30. "set_cname": "文本型[varchar]",
  31. "set_length": 60,
  32. "set_deci": 0,
  33. "is_deci": false
  34. },
  35. {
  36. "cval": "number",
  37. "cname": "整数型",
  38. "set_cname": "整数型[number]",
  39. "set_length": 10,
  40. "set_deci": 0,
  41. "is_deci": false
  42. },
  43. {
  44. "cval": "decimal",
  45. "cname": "小数型",
  46. "set_cname": "小数型[decimal]",
  47. "set_length": 18,
  48. "set_deci": 2,
  49. "is_deci": true
  50. },
  51. {
  52. "cval": "datetime",
  53. "cname": "日期型",
  54. "set_cname": "日期型[datetime]",
  55. "set_length": 0,
  56. "set_deci": 0,
  57. "is_deci": false
  58. },
  59. {"cval": "image", "cname": "二进制", "set_cname": "二进制[image]", "set_length": 0, "set_deci": 0, "is_deci": false}
  60. ]
  61. ///控件类型
  62. self.controlType = [
  63. {"cval": "hidden", "cname": "隐藏列", "set_cname": "隐藏列[hidden]", "need_select": false},
  64. {"cval": "edit", "cname": "单行文本", "set_cname": "单行文本[edit]", "need_select": false},
  65. {"cval": "number", "cname": "数值控件", "set_cname": "数值控件[number]", "need_select": false},
  66. {"cval": "datetime", "cname": "日期控件", "set_cname": "日期控件[datetime]", "need_select": false},
  67. {"cval": "image", "cname": "图片控件", "set_cname": "图片控件[image]", "need_select": false},
  68. {"cval": "text", "cname": "多行文本", "set_cname": "多行文本[text]", "need_select": false},
  69. {"cval": "select", "cname": "下拉列表", "set_cname": "下拉列表[select]", "need_select": true},
  70. {"cval": "checkbox", "cname": "多选列", "set_cname": "多选列[checkbox]", "need_select": true},
  71. {"cval": "radiobox", "cname": "单选列", "set_cname": "单选列[radiobox]", "need_select": true},
  72. {"cval": "popchecks", "cname": "弹出多选列", "set_cname": "弹出多选列[popchecks]", "need_select": true},
  73. {"cval": "popradio", "cname": "弹出单选列", "set_cname": "弹出单选列[popradio]", "need_select": true},
  74. {"cval": "attachtree", "cname": "指定分类上传", "set_cname": "指定分类上传[attachtree]", "need_select": false},
  75. {"cval": "attachlist", "cname": "任意附件上传", "set_cname": "任意附件上传[attachlist]", "need_select": false},
  76. {"cval": "ordpasslist", "cname": "传阅记录列", "set_cname": "传阅记录列[ordpasslist]", "need_select": false},
  77. {"cval": "tongzhilist", "cname": "拟发通知书列", "set_cname": "拟发通知书列[tongzhilist]", "need_select": false},
  78. {"cval": "optionbox", "cname": "签写意见列", "set_cname": "签写意见列[optionbox]", "need_select": false},
  79. {"cval": "signabox", "cname": "留痕文本列", "set_cname": "留痕文本列[signabox]", "need_select": false},
  80. { "cval": "departbox", "cname": "部门选择列", "set_cname": "部门选择列[departbox]", "need_select": false },
  81. { "cval": "usersbox", "cname": "人员选择列", "set_cname": "人员选择列[usersbox]", "need_select": false },
  82. { "cval": "iconxing", "cname": "自定义图标", "set_cname": "自定义图标[iconxing]", "need_select": false },
  83. ]
  84. //初始值类型
  85. self.initValType = [
  86. {"cval": "", "cname": "[无]", "need_init": false, "need_auto": false},
  87. {"cval": "defined", "cname": "[自定义]", "need_init": true, "need_auto": false},
  88. {"cval": "autoadd", "cname": "自增编号", "need_init": false, "need_auto": true},
  89. {"cval": "currentuserid", "cname": "当前用户ID", "need_init": false, "need_auto": false},
  90. {"cval": "currentusername", "cname": "当前用户名称", "need_init": false, "need_auto": false },
  91. {"cval": "currentsectcode", "cname": "当前用户部门编码", "need_init": false, "need_auto": false},
  92. {"cval": "currentsectname", "cname": "当前用户部门名称", "need_init": false, "need_auto": false },
  93. {"cval": "currentdate", "cname": "当前时间", "need_init": false, "need_auto": false}
  94. ]
  95. //自增编码前缀选项
  96. self.autoCodeHeadArray = [
  97. {"cval": "当前年", "cname": "当前年"}
  98. ]
  99. ////初始化左侧效果--start--*****************************************
  100. // self.leftActive=0;
  101. self.active = {
  102. STATUS: 0,
  103. TYPE: ""
  104. };
  105. ///激活状态的设置,考虑上来就加载和从详情页面返回的两种情况
  106. self.setMsgActive = function () {
  107. alert(self.active.STATUS);
  108. $(".sp-msg-left-bottom .sp-msg-left-lh").removeClass("sp-msg-left-active");
  109. $(".sp-msg-left-bottom .sp-msg-left-lh:eq(" + self.active.STATUS + ")").addClass("sp-msg-left-active");
  110. };
  111. self.getMsgData = function (str, $item) {
  112. self.leftActive = str;
  113. self.active = {
  114. STATUS: str,
  115. TYPE: $item.BILLKEY
  116. };
  117. $(".sp-msg-left-bottom .sp-msg-left-lh").removeClass("sp-msg-left-active");
  118. $(".sp-msg-left-bottom .sp-msg-left-lh:eq(" + str + ")").addClass("sp-msg-left-active");
  119. self.getFormFieldData();///加载列数据
  120. };
  121. ////初始化左侧效果--end--*****************************************
  122. //加载左侧子表数据--start
  123. self.subFormData = [];
  124. self.getBasicAndSubForm = function () {
  125. self.loading = true;
  126. var postData = {
  127. formid: self.get_formid
  128. }
  129. $http.post(apiurljs.login + "g2work/bill/queryData", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  130. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  131. if (res.success) {
  132. if (sp.isval(res.data)) {
  133. self.subFormData = res.data;
  134. self.active.TYPE = self.subFormData[0].BILLKEY;
  135. self.getFormFieldData();
  136. } else {
  137. self.loading = false;
  138. self.subFormData = [];
  139. }
  140. } else {
  141. self.loading = false;
  142. sp.dialog(res.message);
  143. }
  144. });
  145. }
  146. self.getBasicAndSubForm();
  147. //获取编辑类型的选项数据
  148. self.optionEkind = []; //编辑类型的表选项
  149. self.optionEkindItem = []; //编辑类型的列选项
  150. self.getOtionEkindData = function () {
  151. $http.post(apiurljs.login + "g2work/billcol/queryDataEkind", {data: s4.encryptData_CBC("")}, postCfg).success(function (obj) {
  152. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  153. console.log(res.data[0]);
  154. if (res.success) {
  155. if (sp.isval(res.data)) {
  156. self.optionEkind = res.data;
  157. self.optionEkind.push({
  158. BILLKEY:"[NEWCHILD]",
  159. CNAME:"[创建同名代码表]",
  160. COLS:[{
  161. CKIND: "varchar",
  162. CNAME: "代码",
  163. CODE: "CODE",
  164. },{
  165. CKIND: "varchar",
  166. CNAME: "名称",
  167. CODE: "CNAME",
  168. }]
  169. })
  170. var newCols = [];
  171. res.data[0].COLS.forEach(function (item) {
  172. if (item.CKIND == "varchar") {
  173. newCols.push(item)
  174. }
  175. })
  176. self.optionEkindItem = newCols;
  177. } else {
  178. self.optionEkind = [];
  179. self.optionEkindItem = [];
  180. self.optionEkind.push({
  181. BILLKEY:"[NEWCHILD]",
  182. CNAME:"创建同名代码表",
  183. COLS:[{
  184. CKIND: "varchar",
  185. CNAME: "代码",
  186. CODE: "CODE",
  187. },{
  188. CKIND: "varchar",
  189. CNAME: "名称",
  190. CODE: "CNAME",
  191. }]
  192. })
  193. }
  194. } else {
  195. sp.dialog(res.message);
  196. }
  197. });
  198. }
  199. self.getOtionEkindData()//响应速度优化同步进行
  200. //获取初始值的选项数据
  201. self.optionInitval = []; //初始值的表选项
  202. self.optionInitvalItem = []; //初始值的列选项
  203. self.getOtionInitvalData = function () {
  204. //数据表和列分开加载
  205. $http.post(apiurljs.login + "g2work/billcol/queryDataInitvalT", {data: s4.encryptData_CBC("")}, postCfg).success(function (obj) {
  206. var res = strToJson(s4.decryptData_CBC(obj.data));
  207. if (res.success) {
  208. if (sp.isval(res.data)) {
  209. self.optionInitval = res.data;
  210. self.field.initable = res.data[0].BILLKEY;
  211. self.optionInitvalItem = [];
  212. self.changeOptionInitval()
  213. } else {
  214. self.optionInitval = [];
  215. self.optionInitvalItem = [];
  216. }
  217. } else {
  218. sp.dialog(res.message);
  219. }
  220. });
  221. }
  222. self.getOtionInitvalData()//响应速度优化同步进行
  223. //加载列数据
  224. self.formFieldData = [];
  225. self.getFormFieldData = function () {
  226. self.loading = true;
  227. var postData = {
  228. "billkey": self.active.TYPE
  229. };
  230. $http.post(apiurljs.login + "g2work/billcol/queryData", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  231. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  232. self.loading = false;
  233. if (res.success) {
  234. if (sp.isval(res.data)) {
  235. self.formFieldData = res.data;
  236. angular.forEach(self.formFieldData, function (item) {
  237. angular.forEach(self.controlType, function (item2) {
  238. if (item.EKIND == item2.cval) {
  239. item.EKIND_set = item2.cname;
  240. }
  241. });
  242. angular.forEach(self.initValType, function (item2) {
  243. if (item.INITVAL == item2.cval) {
  244. item.INITVAL_set = item2.cname;
  245. }
  246. });
  247. });
  248. } else {
  249. self.formFieldData = [];
  250. }
  251. } else {
  252. sp.dialog(res.message);
  253. }
  254. });
  255. };
  256. //**编辑基本表单**开始***** */
  257. self.formsingle = {};
  258. self.getFormSingle = function () {
  259. //检索单条表单数据
  260. var postData = {
  261. formid: self.get_formid
  262. }
  263. $http.post(apiurljs.login + "g2work/form/queryDataItem", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  264. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  265. if (res.success) {
  266. if (sp.isval(res.data)) {
  267. self.formsingle = res.data;
  268. } else {
  269. self.formsingle = {};
  270. }
  271. } else {
  272. sp.dialog(res.message);
  273. }
  274. });
  275. };
  276. self.getFormSingle();
  277. self.formTypeAray = [
  278. {"cval": "NORMAL", "cname": "一般表"},
  279. {"cval": "MDETAIL", "cname": "主细表"},
  280. {"cval": "FILETBL", "cname": "附件表"},
  281. {"cval": "CODETBL", "cname": "代码表"},
  282. {"cval": "TREESTAL", "cname": "树状表"},
  283. {"cval": "ENTITYTB", "cname": "实体表"}
  284. ];
  285. self.form = {
  286. ckey: "",
  287. cname: "",
  288. ctype: self.formTypeAray[0].cval,
  289. shortname: "",
  290. explain: "",
  291. formkinds: ""
  292. };
  293. self.editBasicForm = function () {
  294. var postData = {
  295. formid: self.get_formid
  296. }
  297. $http.post(apiurljs.login + "g2work/form/queryDataItem", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  298. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  299. if (res.success) {
  300. self.formsingle = res.data;
  301. var sendData = {
  302. pkid: self.formsingle.UNITID,
  303. includechildren: true
  304. }
  305. $http.post(apiurljs.login + "g2work/formkinds/queryData", {data: s4.encryptData_CBC(JSON.stringify(sendData))}, postCfg).success(function (obj) {
  306. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  307. if (res.success) {
  308. if (sp.isval(res.data)) {
  309. self.optionFormkinds = res.data;
  310. } else {
  311. self.optionFormkinds = [];
  312. }
  313. // console.log(self.optionFormkinds);
  314. self.form = {
  315. ckey: self.formsingle.CKEY,
  316. cname: self.formsingle.CNAME,
  317. ctype: self.formsingle.CTYPE,
  318. shortname: self.formsingle.SHORTNAME,
  319. explain: self.formsingle.EXPLAIN,
  320. formkinds: ""
  321. };
  322. setTimeout(function () {
  323. self.form.formkinds = self.formsingle.FORMKINDS;
  324. $scope.$apply();
  325. sp.layer("#layer_editBasicForm");
  326. }, 0)
  327. } else {
  328. sp.dialog(res.message);
  329. self.optionFormkinds = [];
  330. }
  331. });
  332. } else {
  333. sp.dialog(res.message);
  334. }
  335. });
  336. };
  337. self.editBasicFormTrue = function () {
  338. ///编辑基本表单-提交
  339. if (spngvld.submit("#layer_editBasicForm")) {
  340. var postData = {
  341. "formid": self.get_formid,
  342. "ckey": self.form.ckey,
  343. "cname": self.form.cname,
  344. "ctype": self.form.ctype,
  345. "explain": self.form.explain,
  346. "shortname": self.form.shortname,
  347. "formkinds": self.form.formkinds
  348. }
  349. $http.post(apiurljs.login + "g2work/form/updateDataByFormid", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  350. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  351. if (res.success) {
  352. self.getFormSingle();
  353. sp.layerhide();
  354. } else {
  355. sp.layerhide();
  356. sp.dialog(res.message);
  357. }
  358. });
  359. }
  360. };
  361. self.editBasicFormCancel = function () {
  362. ///编辑基本表单-取消
  363. self.form = {
  364. ckey: "",
  365. cname: "",
  366. ctype: self.formTypeAray[0].cval,
  367. shortname: "",
  368. explain: ""
  369. };
  370. sp.layerhide();
  371. };
  372. //**编辑基本表单**结束***** */
  373. //*** 新建、删除子表**************************************** */
  374. self.subForm = {
  375. edit: false,
  376. layertitle: "新建子表",
  377. billkey: "",
  378. cname: "",
  379. type: 'NORMAL'
  380. };
  381. self.openAddSubLayer = function () {
  382. self.subForm = {
  383. edit: false,
  384. layertitle: "新建子表",
  385. billkey: "",
  386. cname: "",
  387. type: 'SHW'
  388. };
  389. sp.layer("#layer_addSubForm");
  390. };
  391. self.editSubForm = function ($item) {
  392. self.subForm = {
  393. edit: true,
  394. layertitle: "更新子表",
  395. billkey: $item.BILLKEY,
  396. cname: $item.CNAME,
  397. type: $item.STYLE
  398. };
  399. sp.layer("#layer_addSubForm");
  400. };
  401. self.addSubFormTrue = function () {
  402. //新建子表单-提交事件
  403. if (spngvld.submit("#layer_addSubForm")) {
  404. if (!self.subForm.edit) {
  405. ///新建
  406. var postData = {
  407. formid: self.get_formid,
  408. cname: self.subForm.cname,
  409. style: self.subForm.type
  410. };
  411. $http.post(apiurljs.login + "g2work/bill/insertData", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  412. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  413. if (res.success) {
  414. if (sp.isval(res.data)) {
  415. self.getBasicAndSubForm();
  416. sp.layerhide();
  417. }
  418. } else {
  419. sp.layerhide();
  420. sp.dialog(res.message);
  421. }
  422. });
  423. } else {
  424. var postData = {
  425. billkey: self.subForm.billkey,
  426. cname: self.subForm.cname,
  427. style: self.subForm.type
  428. };
  429. $http.post(apiurljs.login + "g2work/bill/updateDataByBillKey", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  430. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  431. if (res.success) {
  432. if (sp.isval(res.data)) {
  433. self.getBasicAndSubForm();
  434. sp.layerhide();
  435. }
  436. } else {
  437. sp.layerhide();
  438. sp.dialog(res.message);
  439. }
  440. });
  441. }
  442. }
  443. };
  444. self.addSubFormCancel = function () {
  445. //新建子表单取消
  446. spngvld.clear("#layer_addSubForm")
  447. sp.layerhide();
  448. };
  449. self.delSubForm = function ($item) {
  450. ///删除子表单
  451. // var getDelID = $item.PKID;
  452. var getDelID = $item.BILLKEY;
  453. ;
  454. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  455. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  456. var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  457. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  458. sp.openCenter(".sp-dialog");
  459. ///取消按钮
  460. $('.sp-closeDialog').click(function (event) {
  461. sp.dialoghide();
  462. event.preventDefault();
  463. event.stopPropagation();
  464. });
  465. //post消息的id
  466. $("#delDataTrue").click(function () {
  467. var data = {
  468. billkey: getDelID///角色编码
  469. };
  470. $http.post(apiurljs.login + "g2work/bill/deleteByBillKey", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  471. .success(function (obj) {
  472. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  473. if (res.success) {
  474. self.getBasicAndSubForm();
  475. sp.dialoghide();
  476. } else {
  477. sp.dialog(res.message);
  478. }
  479. });
  480. });
  481. };
  482. //*** 新建子表**************************************** */
  483. //* 新建、编辑字段 **** */
  484. self.field = {
  485. edit: false,
  486. layertitle: "新建列",
  487. colid: "",
  488. code: "",
  489. cname: "",
  490. ckind: "",
  491. clength: "",
  492. deci: "",
  493. ekind: "",
  494. ekind_select: "",
  495. initval: "",
  496. initval_init: "",
  497. initval_auto: "",
  498. ismust: "否",
  499. tchild: "",
  500. tdata: "",
  501. tshow: "",
  502. twhere: "",
  503. initable: "",
  504. initcol: "",
  505. initc: 0,
  506. initm: "NEWITEM",
  507. rowall: "",
  508. colfunc: "",
  509. coltips: "",
  510. codehead: "",
  511. codebody: "",
  512. codetail: ""
  513. };
  514. self.addFormField = function () {
  515. self.field.edit = false;
  516. self.field.layertitle = "新建列";
  517. self.field.code = "";
  518. self.field.cname = "";
  519. self.field.colid = "";
  520. self.field.ckind = self.columnType[0].cval;
  521. self.field.clength = self.columnType[0].set_length;
  522. self.field.deci = (self.columnType[0].is_deci) ? self.columnType[0].set_deci : 0;
  523. self.field.ekind = self.controlType[1].cval;
  524. self.field.ekind_select = self.controlType[1].need_select;
  525. self.field.tchild = (self.optionEkind.length == 0) ? "" : self.optionEkind[0].BILLKEY;
  526. self.field.tdata = (self.optionEkindItem.length == 0) ? "" : self.optionEkindItem[0].CODE;
  527. self.field.tshow = (self.optionEkindItem.length == 0) ? "" : self.optionEkindItem[1].CODE;
  528. self.field.initval = self.initValType[0].cval;
  529. self.field.initval_init = self.initValType[0].need_init;
  530. self.field.initval_auto = self.initValType[0].need_auto;
  531. self.field.initable = (self.optionInitval.length == 0) ? "" : self.optionInitval[0].BILLKEY;
  532. self.field.initcol = (self.optionInitvalItem.length == 0) ? "" : self.optionInitvalItem[0].CODE;
  533. self.field.ismust = "否";
  534. self.field.initc = 0;
  535. self.field.initm = "NEWITEM";
  536. self.field.rowall = "";
  537. self.field.colfunc = "";
  538. self.field.coltips = "";
  539. self.field.twhere = "";
  540. self.field.codehead = self.autoCodeHeadArray[0].cval;
  541. self.field.codebody = "";
  542. self.field.codetail = "";
  543. sp.layer("#layer_formField");
  544. };
  545. self.changeColumnType = function () {
  546. self.columnType.forEach(function (item) {
  547. if (item.cval == self.field.ckind) {
  548. self.field.clength = item.set_length;
  549. self.field.deci = (item.is_deci) ? item.set_deci : 0;
  550. }
  551. })
  552. // console.log(self.field.ckind);
  553. if (self.field.ckind == "datetime") {
  554. self.field.ekind = self.controlType[3].cval;
  555. self.field.ekind_select = self.controlType[3].need_select;
  556. } else {
  557. self.field.ekind = self.controlType[1].cval;
  558. self.field.ekind_select = self.controlType[1].need_select;
  559. }
  560. }
  561. self.changeControlType = function () {
  562. self.controlType.forEach(function (item) {
  563. if (item.cval == self.field.ekind) {
  564. self.field.ekind_select = item.need_select;
  565. }
  566. })
  567. }
  568. self.changeOptionEkind = function () {
  569. self.optionEkind.forEach(function (item) {
  570. if (item.BILLKEY == self.field.tchild) {
  571. var newCols = [];
  572. item.COLS.forEach(function (item2) {
  573. if (item2.CKIND == "varchar") {
  574. newCols.push(item2);
  575. }
  576. })
  577. self.optionEkindItem = angular.copy(newCols);
  578. self.field.tdata = "";
  579. self.field.tshow = "";
  580. setTimeout(function () {
  581. self.field.tdata = (self.optionEkindItem.length == 0) ? "" : self.optionEkindItem[0].CODE;
  582. self.field.tshow = (self.optionEkindItem.length == 0) ? "" : self.optionEkindItem[1].CODE;
  583. $scope.$apply();
  584. },100)
  585. }
  586. })
  587. }
  588. self.changeInitValType = function () {
  589. self.initValType.forEach(function (item) {
  590. if (item.cval == self.field.initval) {
  591. self.field.initval_init = item.need_init;
  592. self.field.initval_auto = item.need_auto;
  593. }
  594. })
  595. }
  596. self.changeOptionInitval = function () {
  597. var data = {
  598. billkey: self.field.initable
  599. }
  600. $http.post(apiurljs.login + "g2work/billcol/queryDataByParam", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  601. .success(function (obj) {
  602. var res = strToJson(s4.decryptData_CBC(obj.data));
  603. // console.log(res.data[0])
  604. self.optionInitvalItem = res.data[0].COLS;
  605. self.field.initcol = (self.optionInitvalItem.length == 0) ? "" : self.optionInitvalItem[0].CODE;
  606. })
  607. //self.optionInitval.forEach(function (item) {
  608. // if (item.BILLKEY == self.field.initable) {
  609. // self.optionInitvalItem = item.COLS;
  610. // self.field.initcol = (self.optionInitvalItem.length == 0) ? "" : self.optionInitvalItem[0].CODE;
  611. // }
  612. //})
  613. }
  614. self.editFormField = function (obj) {
  615. // console.log(obj);
  616. self.field.edit = true;
  617. self.field.layertitle = "编辑列";
  618. self.field.colid = obj.COLID;
  619. self.field.code = obj.CODE;
  620. self.field.cname = obj.CNAME;
  621. self.field.ckind = obj.CKIND;
  622. self.field.clength = obj.CLENGTH;
  623. self.field.deci = obj.DECI;
  624. self.field.coltips = obj.COLTIPS;
  625. self.field.ekind = obj.EKIND;
  626. self.controlType.forEach(function (item) {
  627. if (self.field.ekind == item.cval) {
  628. self.field.ekind_select = item.need_select;
  629. }
  630. })
  631. self.field.tchild = obj.TCHILD;
  632. self.field.tdata = obj.TDATA;
  633. self.field.tshow = obj.TSHOW;
  634. self.field.twhere = obj.TWHERE;
  635. self.field.initval = obj.INITVAL;
  636. self.initValType.forEach(function (item) {
  637. if (item.cval == self.field.initval) {
  638. self.field.initval_init = item.need_init;
  639. self.field.initval_auto = item.need_auto;
  640. }
  641. })
  642. self.field.initable = obj.INITABLE;
  643. self.field.initcol = obj.INITCOL;
  644. self.field.ismust = obj.ISMUST;
  645. self.field.initc = obj.INITC;
  646. self.field.initm = obj.INITM;
  647. self.field.rowall = obj.ROWALL;
  648. self.field.colfunc = obj.COLFUNC;
  649. self.field.codehead = obj.CODEHEAD;
  650. self.field.codebody = obj.CODEBODY;
  651. self.field.codetail = obj.CODETAIL;
  652. sp.layer("#layer_formField");
  653. };
  654. self.addFormfieldTrue = function () {
  655. if (spngvld.submit("#layer_formField")) {
  656. if (!self.field.edit) {
  657. var postData = {
  658. billkey: self.active.TYPE,
  659. code: self.field.code,
  660. cname: self.field.cname,
  661. ckind: self.field.ckind,
  662. clength: self.field.clength + "",
  663. deci: self.field.deci + "",
  664. ekind: self.field.ekind,
  665. initval: self.field.initval,
  666. ismust: self.field.ismust,
  667. tchild: (self.field.ekind_select) ? self.field.tchild : "",
  668. tdata: (self.field.ekind_select) ? self.field.tdata : "",
  669. tshow: (self.field.ekind_select) ? self.field.tshow : "",
  670. twhere: (self.field.ekind_select) ? self.field.twhere : "",
  671. initable: (self.field.initval_init) ? self.field.initable : "",
  672. initcol: (self.field.initval_init) ? self.field.initcol : "",
  673. initc: (self.field.initval_init) ? self.field.initc : "",
  674. initm: (self.field.initval_init) ? self.field.initm : "",
  675. rowall: self.field.rowall,
  676. colfunc: self.field.colfunc,
  677. coltips: self.field.coltips,
  678. codehead: (self.field.initval_auto) ? self.field.codehead : "",
  679. codebody: (self.field.initval_auto) ? self.field.codebody : "",
  680. codetail: (self.field.initval_auto) ? self.field.codetail : "",
  681. }
  682. $http.post(apiurljs.login + "g2work/billcol/insertData", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  683. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  684. if (res.success) {
  685. if (sp.isval(res.data)) {
  686. self.getFormFieldData();
  687. self.getOtionEkindData();
  688. sp.layerhide();
  689. }
  690. } else {
  691. sp.layerhide();
  692. sp.dialog(res.message);
  693. }
  694. });
  695. } else {
  696. var postData = {
  697. colid: self.field.colid,
  698. code: self.field.code,
  699. cname: self.field.cname,
  700. ckind: self.field.ckind,
  701. clength: self.field.clength + "",
  702. deci: self.field.deci + "",
  703. ekind: self.field.ekind,
  704. initval: self.field.initval,
  705. ismust: self.field.ismust,
  706. tchild: (self.field.ekind_select) ? self.field.tchild : "",
  707. tdata: (self.field.ekind_select) ? self.field.tdata : "",
  708. tshow: (self.field.ekind_select) ? self.field.tshow : "",
  709. twhere: (self.field.ekind_select) ? self.field.twhere : "",
  710. initable: (self.field.initval_init) ? self.field.initable : "",
  711. initcol: (self.field.initval_init) ? self.field.initcol : "",
  712. initc: (self.field.initval_init) ? self.field.initc : "",
  713. initm: (self.field.initval_init) ? self.field.initm : "",
  714. rowall: self.field.rowall,
  715. colfunc: self.field.colfunc,
  716. coltips: self.field.coltips,
  717. codehead: (self.field.initval_auto) ? self.field.codehead : "",
  718. codebody: (self.field.initval_auto) ? self.field.codebody : "",
  719. codetail: (self.field.initval_auto) ? self.field.codetail : "",
  720. }
  721. $http.post(apiurljs.login + "g2work/billcol/updateDataByColId", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  722. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  723. if (res.success) {
  724. if (sp.isval(res.data)) {
  725. self.getFormFieldData();
  726. sp.layerhide();
  727. }
  728. } else {
  729. sp.layerhide();
  730. sp.dialog(res.message);
  731. }
  732. });
  733. }
  734. }
  735. //sp.layerhide();
  736. };
  737. self.addFormfieldCancel = function () {
  738. sp.layerhide();
  739. };
  740. self.delFormField = function (id) {
  741. var getDelID = id;
  742. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  743. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  744. var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  745. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  746. sp.openCenter(".sp-dialog");
  747. ///取消按钮
  748. $('.sp-closeDialog').click(function (event) {
  749. sp.closeCenter(".sp-dialog");
  750. event.preventDefault();
  751. event.stopPropagation();
  752. });
  753. //post消息的id
  754. $("#delDataTrue").click(function () {
  755. sp.dialoghide();
  756. var getid = $(this).attr("data-id");
  757. var data = {
  758. colid: getid
  759. };
  760. $http.post(apiurljs.login + "g2work/billcol/deleteByColId", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  761. .success(function (obj) {
  762. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  763. if (res.success) {
  764. self.getFormFieldData();
  765. sp.dialoghide();
  766. } else {
  767. sp.dialog(res.message);
  768. }
  769. });
  770. });
  771. };
  772. self.reBuildForm = function () {
  773. ///删除子表单
  774. // var getDelID = $item.PKID;
  775. var getDelID = self.get_formid;
  776. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  777. var dialogBody = "<div class=\"sp-dialog-body\">重建表单后数据将会被清空且不可恢复,您确认要重建吗?</div>";
  778. var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='reBuildForm' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  779. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  780. sp.openCenter(".sp-dialog");
  781. ///取消按钮
  782. $('.sp-closeDialog').click(function (event) {
  783. sp.dialoghide();
  784. event.preventDefault();
  785. event.stopPropagation();
  786. });
  787. //post消息的id
  788. $("#reBuildForm").click(function () {
  789. var data = {
  790. formid: self.get_formid
  791. }
  792. $http.post(apiurljs.login + "g2work/form/createTableByFormid", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg)
  793. .success(function (obj) {
  794. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  795. // console.log(res);
  796. sp.dialoghide();
  797. setTimeout(function () {
  798. sp.dialog(res.message);
  799. }, 1000)
  800. });
  801. });
  802. }
  803. self.previewForm = function () {
  804. window.location.href = "formlist-detail.html?formid=" + self.get_formid + "&ctype=" + self.get_ctype + "&leftActive=" + self.get_leftActive + "&leftActiveType=" + self.get_leftActiveType;
  805. }
  806. //另存为函数
  807. self.other = {
  808. formid: "",
  809. newformkinds: "",
  810. newckye: "",
  811. newformname: "",
  812. includeformedit: 0,
  813. optionformkinds: []
  814. }
  815. self.saveAs = function () {
  816. var postData = {
  817. formid: self.get_formid
  818. }
  819. $http.post(apiurljs.login + "g2work/form/queryDataItem", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) {
  820. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  821. if (res.success) {
  822. var sendData = {
  823. pkid: self.formsingle.UNITID,
  824. includechildren: true
  825. }
  826. $http.post(apiurljs.login + "g2work/formkinds/queryData", {data: s4.encryptData_CBC(JSON.stringify(sendData))}, postCfg).success(function (obj1) {
  827. var response = strToJson(s4.decryptData_CBC(obj1.data).slice(0, s4.decryptData_CBC(obj1.data).lastIndexOf("}") + 1));
  828. if (res.success) {
  829. self.other.formid = res.data.FORMID;
  830. self.other.newformkinds = res.data.FORMKINDS;
  831. self.other.newckye = res.data.CKEY + "1";
  832. self.other.newformname = res.data.CNAME + "1";
  833. self.other.optionformkinds = response.data;
  834. // console.log(self.other);
  835. } else {
  836. sp.dialog(response.message);
  837. }
  838. });
  839. } else {
  840. sp.dialog(res.message);
  841. }
  842. });
  843. sp.layer('#layer_saveAs')
  844. }
  845. self.saveAsSubmit = function () {
  846. var postData = {
  847. formid: self.other.formid,
  848. newformkinds: self.other.newformkinds,
  849. newckey: self.other.newckye,
  850. newformname: self.other.newformname,
  851. includeformedit: (self.other.includeformedit == "1") ? true : false
  852. }
  853. $http.post(apiurljs.login + "g2work/form/saveasByFormid", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg)
  854. .success(function (obj) {
  855. var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1));
  856. sp.layerhide();
  857. setTimeout(function () {
  858. sp.dialog(res.message);
  859. }, 1000)
  860. });
  861. }
  862. self.keyLogin = function (n) {
  863. if (event.keyCode == 13) //回车键的键值为13
  864. {
  865. if (n == 1) {
  866. self.addSubFormTrue()
  867. } else {
  868. self.addFormfieldTrue()
  869. }
  870. }
  871. }
  872. }]);