123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 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"); //获取表的id
- self.get_ctype = sp.getUrlName("ctype"); //获取表的类型
- self.get_leftActive = sp.getUrlName("leftActive");
- self.get_leftActiveType = sp.getUrlName("leftActiveType");
- self.get_formName = ""; //获取表名
- self.btnGoBack = function () {
- window.location.href = "formlist-add.html?formid=" + self.get_formid + "&ctype=" + self.get_ctype + "&leftActive=" + self.get_leftActive + "&leftActiveType=" + self.get_leftActiveType;
- };
- var postCfg = {
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': "Bearer " + self.get_AccessToken
- }
- };
- $("#table").css("height", $("body").height() - 90)
- self.noDataTip = 1;
- self.codeArray = [];
- self.getCodeFormData = function () {
- self.codeArray = [];
- self.get_formName = "";
- 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));
- self.get_formName = res.data.CKEY;
- self.getThead()
- });
- }
-
- self.getThead = function () {
- var data = {
- tablename: self.get_formName,
- order: "sortid"
- }
- $http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data))
- self.thead = [];
- $.each(res.data, function (index, item) {
- if (item.code != "ID" && item.code != "ROUTEINFOID") {
- self.thead.push({ code: item.code, cname: item.cname })
- }
- })
- console.log(self.thead)
- self.thead = self.thead.sort(function (a, b) {
- if (a.code < b.code) {
- return -1;
- }
- if (a.code > b.code) {
- return 1;
- }
- return 0;
- })
- self.getData()
- })
- }
- self.getData = function () {
- var sendData = {
- ckey: self.get_formName,
- routeinfoid: 0
- }
- $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(sendData)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.data[self.get_formName].length == 1 && res.data[self.get_formName][0].ID == "0") {
- self.noDataTip = 0;
- self.codeArray = [];
- } else {
- self.noDataTip = 1;
- self.codeArray = res.data[self.get_formName];
- }
- });
- }
- self.getCodeFormData();
- self.itemCode = {
- ID: "0",
- TITLE: "",
- list: []
- }
- self.openAddLayer = function () {
- self.itemCode.ID = "0";
- self.itemCode.TITLE = "新增数据";
- self.itemCode.list = [];
- self.thead.forEach(function (item) {
- if (item.code != "SORTID") {
- var a = {
- code: item.code,
- name: item.cname
- }
- a[item.code] = "";
- self.itemCode.list.push(a)
- }
- })
- console.log(self.itemCode)
- sp.layer("#layer_codeData");
- };
- self.openEditLayer = function (item) {
- self.itemCode.ID = item.ID;
- self.itemCode.TITLE = "编辑数据";
- self.itemCode.list = [];
- self.thead.forEach(function (item1) {
- var a = {
- code: item1.code,
- name: item1.cname
- }
- a[item1.code] = item[item1.code];
- self.itemCode.list.push(a)
- })
- sp.layer("#layer_codeData");
- };
- self.delCodeData = function ($item) {
- // var getDelID = $item.PKID;
- var getDelID = $item.ID;
- var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
- var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
- 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>";
- $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
- sp.openCenter(".sp-dialog");
- ///取消按钮
- $('.sp-closeDialog').click(function (event) {
- sp.dialoghide();
- event.preventDefault();
- event.stopPropagation();
- });
- //post消息的id
- $("#delDataTrue").click(function () {
- var data = {
- ckey: self.get_formName,
- id: getDelID
- };
- $http.post(apiurljs.login + "g2app/abase/deleteDataCodeItem", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success) {
- self.getCodeFormData();
- sp.dialoghide();
- } else {
- sp.dialog(res.message);
- }
- });
- });
- };
- self.btnDataCancel = function () {
- sp.layerhide();
- };
- self.btnDataSave = function () {
- var valueArray = [];
- var a = {}
- self.itemCode.list.forEach(function (item) {
- a[item.code]=item[item.code]
- })
- valueArray.push(a)
- var postData = {
- ckey: self.get_formName,
- id: self.itemCode.ID,
- data: JSON.stringify(valueArray)
- }
- $http.post(apiurljs.login + "g2app/abase/saveDataCodeItem", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- sp.layerhide();
- if (res.success) {
- self.getCodeFormData();
- } else {
- sp.dialog(res.message);
- }
- });
- }
- }]);
|