index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 'use strict';
  2. var app = angular.module('app', ["angularUtils.directives.dirPagination"]);
  3. app.controller("noticeCtrl", ["$http", "$scope", function ($http, $scope) {
  4. var self = this;
  5. self.userId = $.cookie("GlWorkPlatform-userid");
  6. self.userName = $.cookie("GlWorkPlatform-username");
  7. self.userChineseName = $.cookie("GlWorkPlatform-chineseName");
  8. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  9. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno") || 1; ///接收传过来的第几页
  10. var postCfg = {
  11. headers: {
  12. 'Content-Type': 'application/json',
  13. 'Authorization': "Bearer " + self.get_AccessToken
  14. }
  15. };
  16. //搜索,查询
  17. self.search = {
  18. proname: "",
  19. userid:""
  20. };
  21. //数据表格的控制器,动态加载table表格数据
  22. self.noDataTip = 1; //声明没有数据时变量
  23. self.rows = [];
  24. self.pageno = 1;
  25. self.total_count = 0;
  26. self.itemsPerPage = 8;
  27. self.pageOptions = [8, 12, 16, 20, 24, 26]; ////
  28. self.getData = function (pageno) {
  29. self.rows = [];
  30. self.pageno = pageno;
  31. setTimeout(function () {
  32. $scope.__default__currentPage = self.pageno; //设置页面样式在第几页
  33. })
  34. var postData = {
  35. proname: self.search.proname,
  36. pagesize: self.itemsPerPage,
  37. userid:self.search.userid,
  38. pageno: parseInt(self.pageno)
  39. };
  40. $http.post(apiurljs.login + "g2app/duchaduban/queryDataWithPage", postData, postCfg).success(function (res) {
  41. if (sp.isval(res.data)) {
  42. self.noDataTip = 1;
  43. res.data.forEach(function (item) {
  44. item.PRODATE = sp.dateFtt("yyyy-MM-dd", new Date(item.PRODATE));
  45. })
  46. self.rows = res.data;
  47. self.total_count = res.totalCount;
  48. } else {
  49. self.noDataTip = 0;
  50. }
  51. });
  52. };
  53. //删除功能
  54. self.btnDelDate = function (strId) {
  55. var getDelID = strId;
  56. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  57. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  58. 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>";
  59. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  60. sp.openCenter(".sp-dialog");
  61. //取消按钮
  62. $('.sp-closeDialog').click(function (event) {
  63. sp.closeCenter(".sp-dialog");
  64. event.preventDefault();
  65. event.stopPropagation();
  66. });
  67. //post消息的id
  68. $("#delDataTrue").click(function () {
  69. var getid = $(this).attr("data-id");
  70. sp.dialoghide();
  71. var data = {
  72. id:getid,
  73. tablename:"KEYPROJECT"
  74. };
  75. $http.post(apiurljs.login + "g2app/duchaduban/del", data, postCfg)
  76. .success(function (res) {
  77. sp.dialoghide();
  78. if (res.success) {
  79. self.getData(self.pageno);
  80. } else {
  81. sp.dialog("删除失败,请联系管理员!");
  82. }
  83. });
  84. });
  85. };
  86. //点击 筛选 打开弹出层
  87. self.openLayer = function () {
  88. sp.layer('#layer_search');
  89. };
  90. //搜索
  91. self.btnSearch = function () {
  92. sp.closeCenter('#layer_search');
  93. self.getData(1);
  94. };
  95. //刷新
  96. self.refresh = function () {
  97. self.search = {
  98. TITLE: "",
  99. };
  100. self.getData(1);
  101. }
  102. self.openSearchLayer = function () {
  103. sp.layer("#layer_search");
  104. }
  105. self.doSearch = function () {
  106. sp.layerhide();
  107. self.getData(1);
  108. }
  109. //先判断当前登录用户的角色
  110. self.getUserRole=function () {
  111. var data = {
  112. userid: self.userId
  113. };
  114. $http.post(apiurljs.login + "g2app/duchaduban/queryRole", data, postCfg)
  115. .success(function (res) {
  116. if(res.data.ADMIN=="ADMIN"){
  117. self.search.userid="";
  118. }else{
  119. self.search.userid=self.userId;
  120. }
  121. if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
  122. self.getData(1);// 初始化 当前页为 1
  123. } else {
  124. self.getData(self.get_lastReturnPageno); ///加载接收页码的数据
  125. }
  126. });
  127. }
  128. self.getUserRole();
  129. }]);