123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- 'use strict';
- var app = angular.module('app', [
- 'angularUtils.directives.dirPagination'
- ]);
- app.controller("indexCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
- var self = this;
- var s4 = new SM4Util();
- self.userId = $.cookie("GlWorkPlatform-userid");
- self.userName = $.cookie("GlWorkPlatform-chineseName");
- self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
- self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
- self.get_type = sp.getUrlName("type");
- var postCfg = {
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': "Bearer " + self.get_AccessToken
- }
- }
- //根据选择的底稿目录获取当前目录下的文件
- self.noDataTip = 1;
- self.rows = [];
- self.pageno = 1;
- self.total_count = 0;
- self.itemsPerPage = 10;
- self.pageOptions = [10, 15, 20, 25, 30];
- self.type = 1;
- self.search = {
- CNAME: "",
- ZHIWU: ""
- }
- self.getData = function (pageno) {
- self.pageno = pageno;
- $scope.__default__currentPage = self.pageno;
- var postData = {
- tablename: "SX_ZHIBANRYGL",
- pagesize: self.itemsPerPage,
- pageno: self.pageno,
- colums: "*",
- order: "SORTID",
- sqlwhere: { MANMARK: self.type == 1 ? "C01" : self.type == 2 ? "C02" : "C03" },
- sqlorwhere: "",
- sqlinwhere: "",
- sqllikewhere: {
- CNAME: self.search.CNAME,
- ZHIWU: self.search.ZHIWU
- }
- }
- $http.post(apiurljs.login + "g2app/dataabase/queryDataByColWithPage", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
- .success(function (res) {
- var res = strToJson(s4.decryptData_CBC(res.data));
- if (sp.isval(res.data)) {
- self.noDataTip = 1;
- self.rows = res.data;
- self.total_count = res.totalCount;
- } else {
- self.rows = [];
- self.noDataTip = 0;
- }
- }).error(function (err) {
- sp.dialog(JSON.stringify(err));
- });
- }
- self.getData(1);
- //弹出筛选框
- self.openSearchLayer = function () {
- sp.layer("#layer_search");
- }
- self.doSearch = function () {
- sp.closeCenter('.sp-layer');
- self.pageno = 1; // 初始化 当前页为 1
- self.getData(self.pageno);
- }
- //新增数据
- self.insertData = [];
- self.opneInsertLayer = function () {
- self.insertData = [];
- sp.layer('#layer_insert');
- }
- self.addItemData = function () {
- if (self.type == 1) {
- self.insertData.push({
- CNAME: "",
- SEX: "",
- ZHIWU: "",
- TEL: "",
- MOBILEPHONE: ""
- });
- } else {
- self.insertData.push({
- CNAME: "",
- SEX: "",
- ZHIWU: "",
- DPNAME: "",
- REMARK: ""
- });
- }
- }
- self.deleteItem = function (index) {
- self.insertData.splice(index, 1);
- }
- self.saveInsertData = function () {
- if (spngvld.submit("#layer_insert")) {
- var postData = {
- "tablename": "SX_ZHIBANRYGL",
- "data": []
- }
- if (self.type == 1) {
- self.insertData.forEach(function (item) {
- postData.data.push({
- CNAME: item.CNAME,
- SEX: item.SEX,
- ZHIWU: item.ZHIWU,
- TEL: item.TEL,
- MOBILEPHONE: item.MOBILEPHONE,
- MANMARK: "C01",
- CUSERID: self.userId,
- CDATE: sp.getLocalDate()
- });
- });
- } else {
- self.insertData.forEach(function (item) {
- postData.data.push({
- CNAME: item.CNAME,
- SEX: item.SEX,
- ZHIWU: item.ZHIWU,
- DPNAME: item.DPNAME,
- REMARK: item.REMARK,
- MANMARK: self.type == 2 ? "C02" : "C03",
- CUSERID: self.userId,
- CDATE: sp.getLocalDate()
- });
- });
- }
- $http.post(apiurljs.login + "g2app/dataabase/insertDataList", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
- .success(function (obj) {
- sp.closeCenter('.sp-layer');
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success) {
- self.getData(1);
- } else {
- sp.dialog(res.message);
- }
- })
- .error(function (XMLHttpRequest, textStatus, errorThrown) {
- })
- }
- }
- self.deleteData = function ($item) {
- 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.closeCenter(".sp-dialog");
- event.preventDefault();
- event.stopPropagation();
- });
- //post消息的id
- $("#delDataTrue").click(function () {
- var getid = $(this).attr("data-id");
- sp.dialoghide();
- var data = { "id": $item.ID, "tablename": "SX_ZHIBANRYGL" }
- //console.log(data);
- $http.post(apiurljs.login + "g2app/richang/delDataById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success) {
- self.getData(1);
- } else {
- sp.dialog(res.message);
- }
- })
- .error(function (XMLHttpRequest, textStatus, errorThrown) {
- })
- });
- }
- self.itemObj = {
- ID: "",
- CNAME: "",
- SEX: "",
- ZHIWU: ""
- }
- self.itemDataEdit = function ($item) {
- self.itemObj.ID = $item.ID;
- self.itemObj.CNAME = $item.CNAME;
- self.itemObj.SEX = $item.SEX;
- self.itemObj.ZHIWU = $item.ZHIWU;
- if (self.type == 1) {
- self.itemObj.TEL = $item.TEL;
- self.itemObj.MOBILEPHONE = $item.MOBILEPHONE;
- } else {
- self.itemObj.DPNAME = $item.DPNAME;
- self.itemObj.REMARK = $item.REMARK;
- }
- sp.layer('#layer_edit');
- };
- self.editBtn = function () {
- if (spngvld.submit("#layer_edit")) {
- var postData = {
- "entity": "SX_ZHIBANRYGL",
- "data": {
- CNAME: self.itemObj.CNAME,
- SEX: self.itemObj.SEX,
- ZHIWU: self.itemObj.ZHIWU
- },
- "setwhere": " WHERE id=" + self.itemObj.ID + ""
- }
- if (self.type == 1) {
- postData.data.TEL = self.itemObj.TEL;
- postData.data.MOBILEPHONE = self.itemObj.MOBILEPHONE;
- } else {
- postData.data.DPNAME = self.itemObj.DPNAME;
- postData.data.REMARK = self.itemObj.REMARK;
- }
- $http.post(apiurljs.login + "g2app/dataabase/UpdataBySql", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
- .success(function (obj) {
- sp.closeCenter('.sp-layer');
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success) {
- self.getData(1);
- } else {
- sp.dialog(res.message);
- }
- })
- .error(function (XMLHttpRequest, textStatus, errorThrown) {
- })
- } else {
- }
- }
- self.openSortLayer = function () {
- var postData = {
- tablename: "SX_ZHIBANRYGL",
- colums: "*",
- order: "SORTID",
- sqlwhere: { MANMARK: self.type == 1 ? "C01" : self.type == 2 ? "C02" : "C03" },
- sqlorwhere: "",
- sqlinwhere: "",
- sqllikewhere: ""
- }
- $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
- .success(function (res) {
- var res = strToJson(s4.decryptData_CBC(res.data));
- self.sortList = res.data;
- $("#sortList tbody").sortable({
- cursor: "move",
- stop: function (event, ui) {
- var index = 1;
- $("#sortList tbody").children().each(function (x) {
- $(this).attr("index", index)
- $(this).children().eq(0).html(index)
- index++
- })
- }
- }).disableSelection();
- sp.layer("#sortWin")
- })
- }
- self.btnSortBtn = function () {
- var IDS = [], SORTIDS = [];
- self.sortList.forEach(function (item) {
- $("#sortList tbody").children().each(function (index) {
- if ($(this).attr("data-col") == item.ID) {
- IDS.push({ ID: item.ID })
- SORTIDS.push({ SORTID: index + 1 })
- }
- })
- })
- var data = {
- entity: "SX_ZHIBANRYGL",
- data: SORTIDS,
- setwhere: IDS
- }
- $http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success == true) {
- self.getData(1);
- sp.closeCenter("#sortWin")
- }
- })
- }
- }])
|