You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

454 lines
22 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. allMembers = [],
  4. /**
  5. * 目的設置公司成員list
  6. * @param{Array} list 人員資料
  7. * @param{String} flag 是否在線
  8. * @return{String} sHtml 人員列表html
  9. */
  10. fnSetMemberList = function (list, flag) {
  11. var sHtml = '';
  12. $.each(list, function (i, item) {
  13. var html = '<div class="team-member">'
  14. + '<div id="team-' + item.MemberID.replace('.', '') + '" class="online ' + (flag ? 'on' : 'off') + '"></div>'
  15. + '<img src="/Controller.ashx?action=getimg&folder=Members&id=' + item.MemberPic + '&orgid=' + parent.UserInfo.OrgID + '" width="40" height="40">'
  16. + '<span class="member-name">' + item.MemberID + '(' + item.MemberName + ')</span>'
  17. + '</div>';
  18. sHtml += html;
  19. });
  20. return sHtml;
  21. },
  22. /**
  23. * 目的設置在線成員
  24. */
  25. fnSetUserOnline = function () {
  26. var allOnlineUsers = parent.online_Users,
  27. onlines = [],
  28. offlines = [],
  29. sHtml = '';
  30. $.grep(allMembers, function (user) {
  31. var current = $.grep(allOnlineUsers, function (item) { return item.UserId === user.MemberID; });
  32. if (current.length > 0) {
  33. onlines.push(user);
  34. }
  35. else {
  36. offlines.push(user);
  37. }
  38. });
  39. sHtml += fnSetMemberList(onlines, true);
  40. sHtml += fnSetMemberList(offlines, false);
  41. $(".team").html(sHtml);
  42. },
  43. fnPageInit = function () {
  44. var oGrid1 = null,
  45. oGrid2 = null,
  46. sBackgroundImg = parent.OrgID + parent.UserID,
  47. sBackgroundImgFileId = '',
  48. Ann_imer = null,
  49. /*
  50. * 獲取背景圖片
  51. * @return{Object} ajax 對象
  52. */
  53. fnGetBackgroundImg = function () {
  54. return CallAjax(ComFn.W_Com, ComFn.GetOne, {
  55. Type: '',
  56. Params: {
  57. files: {
  58. ParentID: sBackgroundImg,
  59. OrgID: parent.OrgID
  60. }
  61. }
  62. }, function (res) {
  63. if (res.d) {
  64. var oData = $.parseJSON(res.d);
  65. $('.profile-cover').css({ 'background': "url('../../" + (oData.FilePath || '').replace(/\\/g, "\/") + "')" });
  66. sBackgroundImgFileId = oData.FileID;
  67. }
  68. });
  69. },
  70. /*
  71. * 設定背景
  72. */
  73. fnBgimgfile = function () {
  74. $('#bgimgfile').val('').off('change').on('change', function () {
  75. var sLowerName = this.value.toLowerCase();
  76. if (sLowerName.indexOf('.jpg') > -1 || sLowerName.indexOf('.jpeg') > -1 || sLowerName.indexOf('.png') > -1 || sLowerName.indexOf('.gif') > -1 || sLowerName.indexOf('.bmp') > -1) {
  77. var sFileName = this.value;
  78. DelFile(sBackgroundImgFileId, '', false).done(function () {
  79. $.ajaxFileUpload({
  80. url: '/Controller.ashx?action=upload&source=Members&userid=' + parent.UserID + '&orgid=' + parent.OrgID + '&parentid=' + sBackgroundImg,
  81. secureuri: false,
  82. fileElementId: 'bgimgfile',
  83. success: function (el, status, data) {
  84. var oData = $.parseJSON(data.responseText)[0];
  85. sBackgroundImgFileId = oData.FileID;
  86. $('.profile-cover').css({ 'background': "url('../../" + oData.FilePath.replace(/\\/g, "\/") + "')" });
  87. },
  88. error: function (data, status, e) {
  89. showMsg(i18next.t("message.ProgressError"), 'error'); // ╠message.ProgressError⇒資料處理異常╣
  90. }
  91. });
  92. });
  93. }
  94. else {
  95. showMsg(i18next.t("message.FileTypeError"), 'error'); // ╠message.FileTypeError⇒文件格式錯誤╣
  96. }
  97. }).click();
  98. },
  99. /**
  100. * 目的設置個人資料明細
  101. */
  102. fnSetUserInfo = function () {
  103. $('#user_img').attr('src', '/Controller.ashx?action=getimg&folder=Members&id=' + parent.UserInfo.MemberPic + '&orgid=' + parent.UserInfo.OrgID);
  104. $('.user_name').text(parent.UserInfo.MemberName);
  105. $('.user_jobtitle').text(parent.UserInfo.JobtitleName);
  106. $('.user_address').text(parent.UserInfo.Address);
  107. $('.user_mail').text(parent.UserInfo.Email);
  108. fnGetBackgroundImg();
  109. $('.profile-cover').on('click', function () {
  110. fnBgimgfile();
  111. });
  112. $('#user_img').on('click', function (e) {
  113. e.stopPropagation();
  114. });
  115. },
  116. /**
  117. * 公告實現輪播
  118. */
  119. fnAnnouncementTimer = function () {
  120. if ($('.announcement ul').find('li').length > 1) {
  121. var iH = $('.announcement ul li:first').height();
  122. $('.announcement ul').animate({
  123. marginTop: -iH - 13
  124. }, 1000, function () {
  125. $(this).css({ marginTop: -8 }).find("li:first,hr:first").appendTo(this);
  126. });
  127. }
  128. },
  129. /**
  130. * 目的加載公告
  131. */
  132. fnGetAnnouncement = function () {
  133. if (!parent.UserInfo.MemberID) { return; }
  134. g_api.ConnectLite(Service.com, 'GetAnnlist', {}, function (res) {
  135. if (res.RESULT) {
  136. var saData = res.DATA.rel,
  137. sHtml = '';
  138. if (saData.length > 0) {
  139. $.each(saData, function (idx, item) {
  140. sHtml += '<li><a class="a-url" id="' + item.AnnouncementID + '" style="color:' + (item.FontColor || '#000') + '">' + item.Title + '</a></li><hr>';
  141. });
  142. $('.announcement ul').html(sHtml).find('a').on('click', function () {
  143. var sId = this.id;
  144. //parent.openPageTab('Announcement_Upd', '?Action=Upd&AnnouncementID=' + sId);
  145. parent.fnOpenAnn(sId, false);;
  146. });
  147. $('.announcement-get-more a').on('click', function () {
  148. parent.openPageTab('AnnouncementList_Qry');
  149. });
  150. var h1 = $('.announcement').height();
  151. var h2 = $('.announcement ul').height();
  152. if (h2 > h1 + 5) {
  153. Ann_imer = setInterval(fnAnnouncementTimer, 3000);
  154. $('.announcement ul li').mousemove(function () {
  155. clearInterval(Ann_imer);
  156. }).mouseout(function () {
  157. Ann_imer = setInterval(fnAnnouncementTimer, 3000);
  158. });
  159. }
  160. }
  161. else {
  162. $('.announcement-get-more').hide();
  163. }
  164. }
  165. });
  166. },
  167. /**
  168. * 目的加載請假資訊
  169. */
  170. fnGetLeaves = function () {
  171. g_api.ConnectLite(Service.eip, 'GetLeavelist', {}, function (res) {
  172. if (res.RESULT) {
  173. var saData = res.DATA.rel,
  174. sHtml_Today = '',
  175. sHtml_Tomorrow = '',
  176. rToday = new Date(newDate(null, true)),
  177. rTomorrow = new Date(newDate(null, true)).dateAdd('d', 1),
  178. rAfterTomorrow = new Date(newDate(null, true)).dateAdd('d', 2),
  179. saToday = $.grep(saData, function (cur) {
  180. return new Date(cur.Info.StartDate) <= rTomorrow && new Date(cur.Info.EndDate) >= rToday;
  181. }),
  182. saTomorrow = $.grep(saData, function (cur) {
  183. return new Date(cur.Info.StartDate) <= rAfterTomorrow && new Date(cur.Info.EndDate) >= rTomorrow;
  184. });
  185. sHtml_Today = $('#temp_leave').render(saToday);
  186. sHtml_Tomorrow = $('#temp_leave').render(saTomorrow);
  187. $('.today').html(sHtml_Today);
  188. $('.tomorrow').html(sHtml_Tomorrow);
  189. $('#TodayLeavesCount').html($('<a/>', { html: '(' + saToday.length + ')' }));
  190. $('#TomorrowLeavesCount').html($('<a/>', { html: '(' + saTomorrow.length + ')' }));
  191. if (parent.UserInfo.roles.toLowerCase().indexOf('admin') > -1) {
  192. $('span.a-url').on('click', function () {
  193. var sId = $(this).attr('data-id'),
  194. sUserid = $(this).attr('data-userid'),
  195. sStatus = $(this).attr('data-status');
  196. if ('A,C'.indexOf(sStatus) > -1 && sUserid === parent.UserID) {
  197. parent.openPageTab('Leave_Upd', '?Action=Upd&Guid=' + sId);
  198. }
  199. else {
  200. parent.openPageTab('Leave_View', '?Action=Upd&Guid=' + sId);
  201. }
  202. });
  203. }
  204. }
  205. });
  206. },
  207. /**
  208. * 目的加載待處理事項資料(非EIP)
  209. * @param {Object} args grid參數
  210. * @return {Function} ajax 物件
  211. */
  212. fnGetTasks_BILL = function (args) {
  213. var oQueryPm = {};
  214. $.extend(oQueryPm, args);
  215. oQueryPm.IsEIP = false;
  216. oQueryPm.pageIndex = oQueryPm.pageIndex || 1;
  217. oQueryPm.pageSize = oQueryPm.pageSize || 10;
  218. oQueryPm.sortField = oQueryPm.sortField || 'CreateDate';
  219. oQueryPm.sortOrder = oQueryPm.sortOrder || 'desc';
  220. return g_api.ConnectLite('Task_Qry', ComFn.GetPage, oQueryPm, function (res) {
  221. if (res.RESULT) {
  222. var oRes = res.DATA.rel;
  223. $('#TaskListCount').html($('<a/>', { html: '(' + oRes.Total + ')' }));
  224. }
  225. });
  226. },
  227. /**
  228. * 目的加載待處理事項資料(EIP)
  229. * @param {Object} args grid參數
  230. * @return {Function} ajax 物件
  231. */
  232. fnGetTasks_EIP = function (args) {
  233. var oQueryPm = {};
  234. $.extend(oQueryPm, args);
  235. oQueryPm.IsEIP = true;
  236. oQueryPm.pageIndex = oQueryPm.pageIndex || 1;
  237. oQueryPm.pageSize = oQueryPm.pageSize || 10;
  238. oQueryPm.sortField = oQueryPm.sortField || 'CreateDate';
  239. oQueryPm.sortOrder = oQueryPm.sortOrder || 'desc';
  240. return g_api.ConnectLite('Task_Qry', ComFn.GetPage, oQueryPm, function (res) {
  241. if (res.RESULT) {
  242. var oRes = res.DATA.rel;
  243. $('#EipListCount').html($('<a/>', { html: '(' + oRes.Total + ')' }));
  244. }
  245. });
  246. },
  247. /**
  248. * 目的初始化代辦Grid
  249. */
  250. fnInitGrid = function () {
  251. $("#jsGrid_Bill").jsGrid({
  252. width: "100%",
  253. height: "auto",
  254. autoload: true,
  255. pageLoading: true,
  256. inserting: false,
  257. editing: true,
  258. sorting: true,
  259. paging: true,
  260. pageIndex: 1,
  261. pageSize: 10,
  262. pageButtonCount: parent.SysSet.GridPages || 15,
  263. pagePrevText: "<",
  264. pageNextText: ">",
  265. pageFirstText: "<<",
  266. pageLastText: ">>",
  267. fields: [
  268. { name: "EventNo", title: 'common.EventNo', align: 'center', width: 80 },// ╠common.EventNo⇒事件編號╣
  269. { name: "SourceFromName", title: 'common.SourceFromName', width: 70 },
  270. {
  271. name: "EventName", title: 'common.Purpose', width: 250, itemTemplate: function (value, item) {
  272. var oGoPage = $('<a>', {
  273. class: 'a-url',
  274. html: value,
  275. click: function () {
  276. var sEditPrgId = item.SourceFrom.replace('_Qry', '_Upd');
  277. if (navigator.userAgent.match(/mobile/i)) {
  278. goToEdit(sEditPrgId, item.Params);
  279. }
  280. else {
  281. parent.openPageTab(sEditPrgId, item.Params);
  282. }
  283. }
  284. });
  285. return [oGoPage, item.EIP_Status === 'E' ? '<span style="color:#DF5F09">(' + i18next.t('common.ToHandle') + ')</span>' : ''];//╠common.ToHandle⇒待經辦╣
  286. }
  287. },
  288. { name: "CreateUserName", title: 'common.Publisher', width: 70 },//╠common.Publisher⇒發佈人╣
  289. {
  290. name: "Status", title: 'common.Status', width: 60, itemTemplate: function (value) {
  291. var oStatus = { U: '未審核', G: '審核中', D: '已審核(待確認)', O: '已審核' };
  292. return oStatus[value] || '未審核';
  293. }
  294. },
  295. {//╠common.PublishDate⇒發佈時間╣
  296. name: "CreateDate", title: 'common.PublishDate', align: 'center', width: 110, itemTemplate: function (value) {
  297. return newDate(value);
  298. }
  299. }
  300. ],
  301. controller: {
  302. loadData: function (args) {
  303. return fnGetTasks_BILL(args);
  304. },
  305. },
  306. onDataLoaded: function (args) {
  307. setTimeout(function () {
  308. var oPage = $('#PerPageNum');
  309. oPage.after(oPage.val()).remove();
  310. }, 100);
  311. oGrid1 = args.grid;
  312. }
  313. });
  314. $("#jsGrid_Eip").jsGrid({
  315. width: "100%",
  316. height: "auto",
  317. autoload: true,
  318. pageLoading: true,
  319. inserting: false,
  320. editing: true,
  321. sorting: true,
  322. paging: true,
  323. pageIndex: 1,
  324. pageSize: 10,
  325. pageButtonCount: parent.SysSet.GridPages || 15,
  326. pagePrevText: "<",
  327. pageNextText: ">",
  328. pageFirstText: "<<",
  329. pageLastText: ">>",
  330. fields: [
  331. { name: "EventNo", title: 'common.EventNo', align: 'center', width: 80 },
  332. { name: "SourceFromName", title: 'common.SourceFromName', width: 70 },
  333. {
  334. name: "EventName", title: 'common.Purpose', width: 250, itemTemplate: function (value, item) {// ╠common.Purpose⇒主旨╣
  335. var oGoPage = $('<a>', {
  336. class: 'a-url',
  337. html: value,
  338. click: function () {
  339. var sEditPrgId = item.SourceFrom.replace('_Qry', '_Upd');
  340. if (navigator.userAgent.match(/mobile/i)) {
  341. goToEdit(sEditPrgId, item.Params);
  342. }
  343. else {
  344. parent.openPageTab(sEditPrgId, item.Params);
  345. }
  346. }
  347. });
  348. return [oGoPage, item.EIP_Status === 'E' ? '<span style="color:#DF5F09">(' + i18next.t('common.ToHandle') + ')</span>' : ''];//╠common.ToHandle⇒待經辦╣
  349. }
  350. },
  351. { name: "CreateUserName", title: 'common.Publisher', width: 70 },//╠common.Publisher⇒發文者╣
  352. { name: "ProgressShow", title: 'common.Progress', align: 'center', width: 50 },//╠common.Progress⇒進度╣
  353. {
  354. name: "Status", title: 'common.Status', width: 60, itemTemplate: function (value) {//╠common.Status⇒狀態╣
  355. var oStatus = { U: '未審核', G: '審核中', D: '已審核(待確認)', O: '已審核' };
  356. return oStatus[value] || '未審核';
  357. }
  358. },
  359. {
  360. name: "CreateDate", title: 'common.PublishDate', align: 'center', width: 110, itemTemplate: function (value) {
  361. return newDate(value);
  362. }
  363. }
  364. ],
  365. controller: {
  366. loadData: function (args) {
  367. return fnGetTasks_EIP(args);
  368. },
  369. },
  370. onDataLoaded: function (args) {
  371. setTimeout(function () {
  372. var oPage = $('#PerPageNum');
  373. oPage.after(oPage.val()).remove();
  374. }, 100);
  375. oGrid2 = args.grid;
  376. }
  377. });
  378. },
  379. /**
  380. * 目的頁面初始化
  381. */
  382. init = function () {
  383. var myHelpers = {
  384. setDateRange: function (date1, date2) {
  385. var r1 = newDate(date1, true),
  386. r2 = newDate(date2, true);
  387. return r1 + '~' + r2;
  388. },
  389. setFilePath: function (val, orgid) {
  390. return '/Controller.ashx?action=getimg&folder=Members&id=' + val + '&orgid=' + orgid;
  391. },
  392. setLeaveTitle: function (info) {
  393. return $('<span/>', {
  394. class: 'a-url',
  395. html: info.KeyNote,
  396. 'data-id': info.Guid,
  397. 'data-userid': info.AskTheDummy,
  398. 'data-status': info.Status
  399. })[0].outerHTML;
  400. }
  401. };
  402. $.views.helpers(myHelpers);
  403. fnSetUserInfo(); //設置個人資料明細
  404. fnInitGrid()//初始化代辦Grid
  405. fnSetUserDrop([
  406. {
  407. NotUserIDs: parent.UserID,
  408. Action: 'add',
  409. CallBack: function (data) {
  410. allMembers = data;
  411. fnSetUserOnline();
  412. slimScroll();
  413. }
  414. }
  415. ]);//加載公司成員
  416. fnGetAnnouncement();//加載公告
  417. fnGetLeaves();//加載請假資訊
  418. goTop();//置頂控件
  419. onresize();
  420. $('.panel-reload').on('click', function () {
  421. switch (this.id) {
  422. case 'eip_box':
  423. {
  424. //debugger;
  425. oGrid2.pageIndex = 1;
  426. oGrid2.loadData();
  427. }
  428. break;
  429. case 'bill_box':
  430. {
  431. oGrid1.pageIndex = 1;
  432. oGrid1.loadData();
  433. }
  434. break;
  435. case 'ann_box':
  436. fnGetAnnouncement();//加載公告
  437. break;
  438. case 'leave_box1':
  439. case 'leave_box2':
  440. fnGetLeaves();//加載請假資訊
  441. break;
  442. }
  443. });
  444. };
  445. init();
  446. };
  447. require(['base', 'jsgrid', 'ajaxfile', 'util'], fnPageInit);