var app = angular.module('app', ["angularUtils.directives.dirPagination"]); app.controller("formlistAddCtrl", ["$scope", "$http", "$compile", "$timeout", function ($scope, $http, $compile, $timeout) { var self = this; var s4 = new SM4Util(); sp.fitHeight("#formAddPart", 190); sp.fitHeight("#formTablePart", 80); self.userId = $.cookie("GlWorkPlatform-userid"); self.userName = $.cookie("GlWorkPlatform-username"); self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken"); self.get_formid = sp.getUrlName("formid"); self.get_ctype = sp.getUrlName("ctype"); self.get_leftActive = sp.getUrlName("leftActive"); self.get_leftActiveType = sp.getUrlName("leftActiveType"); self.loading = false; self.btnGoBack = function () { ///返回上一级 window.location.href = "formlist.html?leftActive=" + self.get_leftActive + "&leftActiveType=" + self.get_leftActiveType; }; var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; //列存储类型 self.columnType = [ { "cval": "varchar", "cname": "文本型", "set_cname": "文本型[varchar]", "set_length": 60, "set_deci": 0, "is_deci": false }, { "cval": "number", "cname": "整数型", "set_cname": "整数型[number]", "set_length": 10, "set_deci": 0, "is_deci": false }, { "cval": "decimal", "cname": "小数型", "set_cname": "小数型[decimal]", "set_length": 18, "set_deci": 2, "is_deci": true }, { "cval": "datetime", "cname": "日期型", "set_cname": "日期型[datetime]", "set_length": 0, "set_deci": 0, "is_deci": false }, {"cval": "image", "cname": "二进制", "set_cname": "二进制[image]", "set_length": 0, "set_deci": 0, "is_deci": false} ] ///控件类型 self.controlType = [ {"cval": "hidden", "cname": "隐藏列", "set_cname": "隐藏列[hidden]", "need_select": false}, {"cval": "edit", "cname": "单行文本", "set_cname": "单行文本[edit]", "need_select": false}, {"cval": "number", "cname": "数值控件", "set_cname": "数值控件[number]", "need_select": false}, {"cval": "datetime", "cname": "日期控件", "set_cname": "日期控件[datetime]", "need_select": false}, {"cval": "image", "cname": "图片控件", "set_cname": "图片控件[image]", "need_select": false}, {"cval": "text", "cname": "多行文本", "set_cname": "多行文本[text]", "need_select": false}, {"cval": "select", "cname": "下拉列表", "set_cname": "下拉列表[select]", "need_select": true}, {"cval": "checkbox", "cname": "多选列", "set_cname": "多选列[checkbox]", "need_select": true}, {"cval": "radiobox", "cname": "单选列", "set_cname": "单选列[radiobox]", "need_select": true}, {"cval": "popchecks", "cname": "弹出多选列", "set_cname": "弹出多选列[popchecks]", "need_select": true}, {"cval": "popradio", "cname": "弹出单选列", "set_cname": "弹出单选列[popradio]", "need_select": true}, {"cval": "attachtree", "cname": "指定分类上传", "set_cname": "指定分类上传[attachtree]", "need_select": false}, {"cval": "attachlist", "cname": "任意附件上传", "set_cname": "任意附件上传[attachlist]", "need_select": false}, {"cval": "ordpasslist", "cname": "传阅记录列", "set_cname": "传阅记录列[ordpasslist]", "need_select": false}, {"cval": "tongzhilist", "cname": "拟发通知书列", "set_cname": "拟发通知书列[tongzhilist]", "need_select": false}, {"cval": "optionbox", "cname": "签写意见列", "set_cname": "签写意见列[optionbox]", "need_select": false}, {"cval": "signabox", "cname": "留痕文本列", "set_cname": "留痕文本列[signabox]", "need_select": false}, { "cval": "departbox", "cname": "部门选择列", "set_cname": "部门选择列[departbox]", "need_select": false }, { "cval": "usersbox", "cname": "人员选择列", "set_cname": "人员选择列[usersbox]", "need_select": false }, { "cval": "iconxing", "cname": "自定义图标", "set_cname": "自定义图标[iconxing]", "need_select": false }, ] //初始值类型 self.initValType = [ {"cval": "", "cname": "[无]", "need_init": false, "need_auto": false}, {"cval": "defined", "cname": "[自定义]", "need_init": true, "need_auto": false}, {"cval": "autoadd", "cname": "自增编号", "need_init": false, "need_auto": true}, {"cval": "currentuserid", "cname": "当前用户ID", "need_init": false, "need_auto": false}, {"cval": "currentusername", "cname": "当前用户名称", "need_init": false, "need_auto": false }, {"cval": "currentsectcode", "cname": "当前用户部门编码", "need_init": false, "need_auto": false}, {"cval": "currentsectname", "cname": "当前用户部门名称", "need_init": false, "need_auto": false }, {"cval": "currentdate", "cname": "当前时间", "need_init": false, "need_auto": false} ] //自增编码前缀选项 self.autoCodeHeadArray = [ {"cval": "当前年", "cname": "当前年"} ] ////初始化左侧效果--start--***************************************** // self.leftActive=0; self.active = { STATUS: 0, TYPE: "" }; ///激活状态的设置,考虑上来就加载和从详情页面返回的两种情况 self.setMsgActive = function () { alert(self.active.STATUS); $(".sp-msg-left-bottom .sp-msg-left-lh").removeClass("sp-msg-left-active"); $(".sp-msg-left-bottom .sp-msg-left-lh:eq(" + self.active.STATUS + ")").addClass("sp-msg-left-active"); }; self.getMsgData = function (str, $item) { self.leftActive = str; self.active = { STATUS: str, TYPE: $item.BILLKEY }; $(".sp-msg-left-bottom .sp-msg-left-lh").removeClass("sp-msg-left-active"); $(".sp-msg-left-bottom .sp-msg-left-lh:eq(" + str + ")").addClass("sp-msg-left-active"); self.getFormFieldData();///加载列数据 }; ////初始化左侧效果--end--***************************************** //加载左侧子表数据--start self.subFormData = []; self.getBasicAndSubForm = function () { self.loading = true; var postData = { formid: self.get_formid } $http.post(apiurljs.login + "g2work/bill/queryData", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); if (res.success) { if (sp.isval(res.data)) { self.subFormData = res.data; self.active.TYPE = self.subFormData[0].BILLKEY; self.getFormFieldData(); } else { self.loading = false; self.subFormData = []; } } else { self.loading = false; sp.dialog(res.message); } }); } self.getBasicAndSubForm(); //获取编辑类型的选项数据 self.optionEkind = []; //编辑类型的表选项 self.optionEkindItem = []; //编辑类型的列选项 self.getOtionEkindData = function () { $http.post(apiurljs.login + "g2work/billcol/queryDataEkind", {data: s4.encryptData_CBC("")}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); console.log(res.data[0]); if (res.success) { if (sp.isval(res.data)) { self.optionEkind = res.data; self.optionEkind.push({ BILLKEY:"[NEWCHILD]", CNAME:"[创建同名代码表]", COLS:[{ CKIND: "varchar", CNAME: "代码", CODE: "CODE", },{ CKIND: "varchar", CNAME: "名称", CODE: "CNAME", }] }) var newCols = []; res.data[0].COLS.forEach(function (item) { if (item.CKIND == "varchar") { newCols.push(item) } }) self.optionEkindItem = newCols; } else { self.optionEkind = []; self.optionEkindItem = []; self.optionEkind.push({ BILLKEY:"[NEWCHILD]", CNAME:"创建同名代码表", COLS:[{ CKIND: "varchar", CNAME: "代码", CODE: "CODE", },{ CKIND: "varchar", CNAME: "名称", CODE: "CNAME", }] }) } } else { sp.dialog(res.message); } }); } self.getOtionEkindData()//响应速度优化同步进行 //获取初始值的选项数据 self.optionInitval = []; //初始值的表选项 self.optionInitvalItem = []; //初始值的列选项 self.getOtionInitvalData = function () { //数据表和列分开加载 $http.post(apiurljs.login + "g2work/billcol/queryDataInitvalT", {data: s4.encryptData_CBC("")}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { if (sp.isval(res.data)) { self.optionInitval = res.data; self.field.initable = res.data[0].BILLKEY; self.optionInitvalItem = []; self.changeOptionInitval() } else { self.optionInitval = []; self.optionInitvalItem = []; } } else { sp.dialog(res.message); } }); } self.getOtionInitvalData()//响应速度优化同步进行 //加载列数据 self.formFieldData = []; self.getFormFieldData = function () { self.loading = true; var postData = { "billkey": self.active.TYPE }; $http.post(apiurljs.login + "g2work/billcol/queryData", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); self.loading = false; if (res.success) { if (sp.isval(res.data)) { self.formFieldData = res.data; angular.forEach(self.formFieldData, function (item) { angular.forEach(self.controlType, function (item2) { if (item.EKIND == item2.cval) { item.EKIND_set = item2.cname; } }); angular.forEach(self.initValType, function (item2) { if (item.INITVAL == item2.cval) { item.INITVAL_set = item2.cname; } }); }); } else { self.formFieldData = []; } } else { sp.dialog(res.message); } }); }; //**编辑基本表单**开始***** */ self.formsingle = {}; self.getFormSingle = function () { //检索单条表单数据 var postData = { formid: self.get_formid } $http.post(apiurljs.login + "g2work/form/queryDataItem", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); if (res.success) { if (sp.isval(res.data)) { self.formsingle = res.data; } else { self.formsingle = {}; } } else { sp.dialog(res.message); } }); }; self.getFormSingle(); self.formTypeAray = [ {"cval": "NORMAL", "cname": "一般表"}, {"cval": "MDETAIL", "cname": "主细表"}, {"cval": "FILETBL", "cname": "附件表"}, {"cval": "CODETBL", "cname": "代码表"}, {"cval": "TREESTAL", "cname": "树状表"}, {"cval": "ENTITYTB", "cname": "实体表"} ]; self.form = { ckey: "", cname: "", ctype: self.formTypeAray[0].cval, shortname: "", explain: "", formkinds: "" }; self.editBasicForm = function () { var postData = { formid: self.get_formid } $http.post(apiurljs.login + "g2work/form/queryDataItem", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); if (res.success) { self.formsingle = res.data; var sendData = { pkid: self.formsingle.UNITID, includechildren: true } $http.post(apiurljs.login + "g2work/formkinds/queryData", {data: s4.encryptData_CBC(JSON.stringify(sendData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); if (res.success) { if (sp.isval(res.data)) { self.optionFormkinds = res.data; } else { self.optionFormkinds = []; } // console.log(self.optionFormkinds); self.form = { ckey: self.formsingle.CKEY, cname: self.formsingle.CNAME, ctype: self.formsingle.CTYPE, shortname: self.formsingle.SHORTNAME, explain: self.formsingle.EXPLAIN, formkinds: "" }; setTimeout(function () { self.form.formkinds = self.formsingle.FORMKINDS; $scope.$apply(); sp.layer("#layer_editBasicForm"); }, 0) } else { sp.dialog(res.message); self.optionFormkinds = []; } }); } else { sp.dialog(res.message); } }); }; self.editBasicFormTrue = function () { ///编辑基本表单-提交 if (spngvld.submit("#layer_editBasicForm")) { var postData = { "formid": self.get_formid, "ckey": self.form.ckey, "cname": self.form.cname, "ctype": self.form.ctype, "explain": self.form.explain, "shortname": self.form.shortname, "formkinds": self.form.formkinds } $http.post(apiurljs.login + "g2work/form/updateDataByFormid", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); if (res.success) { self.getFormSingle(); sp.layerhide(); } else { sp.layerhide(); sp.dialog(res.message); } }); } }; self.editBasicFormCancel = function () { ///编辑基本表单-取消 self.form = { ckey: "", cname: "", ctype: self.formTypeAray[0].cval, shortname: "", explain: "" }; sp.layerhide(); }; //**编辑基本表单**结束***** */ //*** 新建、删除子表**************************************** */ self.subForm = { edit: false, layertitle: "新建子表", billkey: "", cname: "", type: 'NORMAL' }; self.openAddSubLayer = function () { self.subForm = { edit: false, layertitle: "新建子表", billkey: "", cname: "", type: 'SHW' }; sp.layer("#layer_addSubForm"); }; self.editSubForm = function ($item) { self.subForm = { edit: true, layertitle: "更新子表", billkey: $item.BILLKEY, cname: $item.CNAME, type: $item.STYLE }; sp.layer("#layer_addSubForm"); }; self.addSubFormTrue = function () { //新建子表单-提交事件 if (spngvld.submit("#layer_addSubForm")) { if (!self.subForm.edit) { ///新建 var postData = { formid: self.get_formid, cname: self.subForm.cname, style: self.subForm.type }; $http.post(apiurljs.login + "g2work/bill/insertData", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); if (res.success) { if (sp.isval(res.data)) { self.getBasicAndSubForm(); sp.layerhide(); } } else { sp.layerhide(); sp.dialog(res.message); } }); } else { var postData = { billkey: self.subForm.billkey, cname: self.subForm.cname, style: self.subForm.type }; $http.post(apiurljs.login + "g2work/bill/updateDataByBillKey", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg).success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data).slice(0, s4.decryptData_CBC(obj.data).lastIndexOf("}") + 1)); if (res.success) { if (sp.isval(res.data)) { self.getBasicAndSubForm(); sp.layerhide(); } } else { sp.layerhide(); sp.dialog(res.message); } }); } } }; self.addSubFormCancel = function () { //新建子表单取消 spngvld.clear("#layer_addSubForm") sp.layerhide(); }; self.delSubForm = function ($item) { ///删除子表单 // var getDelID = $item.PKID; var getDelID = $item.BILLKEY; ; var dialogHead = "温馨提示×"; var dialogBody = "