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.

533 lines
24 KiB

2 years ago
  1. 'use strict';
  2. var
  3. /**
  4. * 獲取文件list
  5. * @param {Object} handle jquery dom 對象
  6. * @param {String} parentid 文件來源id
  7. * @param {String} oldid 退件文件來源id
  8. * @param {String} oldtext 退件文件來源id
  9. * @param {String} goprg 退件文件來源id
  10. * @return {Object} Ajax 物件 ExFeild1
  11. */
  12. fnGetFiles = function (handle, parentid, oldid, oldtext, goprg) {
  13. var callback = function (files) {
  14. var saFiles = files,
  15. sHtml = '';
  16. $.each(saFiles, function (idx, file) {
  17. if (file.fileid) {
  18. var icon = 'default';
  19. file.subname = file.subname.toLowerCase();
  20. if ("doc|xls|txt|exe|mp3|mv|pdf|ppt|psd|".indexOf(file.subname) > -1) {
  21. icon = file.subname;
  22. }
  23. else if ("png|jpg|jpeg|gif|bmp".indexOf(file.subname) > -1) {
  24. icon = 'jpg';
  25. }
  26. else if ("7z|zip|rar".indexOf(file.subname) > -1) {
  27. icon = 'rar';
  28. }
  29. else if ("docx|doc".indexOf(file.subname) > -1) {
  30. icon = 'doc';
  31. }
  32. else if ("xls|xlsx".indexOf(file.subname) > -1) {
  33. icon = 'xls';
  34. }
  35. else if ("pptx".indexOf(file.subname) > -1) {
  36. icon = 'ppt';
  37. }
  38. sHtml += '<p style="line-height: 15px;"><img src="https://www.eurotran.com:9001/Ueditor/dialogs/attachment/fileTypeImages/icon_' + icon + '.gif"><a style="text-decoration: underline !important;" href="javascript:void(0);" title="' + file.name + '" path="' + file.path + '" subname="' + icon + '"><span style="font-size: 12px;">' + file.name + '</span></a></p>';
  39. }
  40. });
  41. if (oldid) {
  42. sHtml += '<p style="line-height: 15px;"><img src="https://www.eurotran.com:9001/Ueditor/dialogs/attachment/fileTypeImages/icon_txt.gif"><a style="text-decoration: underline !important;" href="javascript:void(0);" title="' + oldtext + '"oldid="' + oldid + '"goprg="' + goprg + '"><span style="font-size: 12px;">' + oldtext + '</span></a></p>';
  43. }
  44. handle.append(sHtml).find('a').on('click', function () {
  45. var sPath = $(this).attr('path'),
  46. sFileName = $(this).text().split('.')[0],
  47. sSubName = $(this).attr('subname'),
  48. sPrg = $(this).attr('goprg'),
  49. sOldid = $(this).attr('oldid');
  50. if (sPrg) {
  51. parent.layer.open({
  52. type: 2, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  53. title: i18next.t('common.Info'), //不显示标题栏
  54. area: ['900px', '600px'],
  55. shade: false,//遮罩
  56. closeBtn: 1,
  57. shadeClose: true,
  58. maxmin: true, //开启最大化最小化按钮
  59. offset: '100px',//右下角弹出
  60. anim: 0,//彈出動畫
  61. content: "/Page/Eip/" + sPrg + ".html?Action=Upd&Guid=" + sOldid,
  62. success: function (layero) {
  63. layero.find('iframe').contents().find('#Toolbar').hide();
  64. }
  65. });
  66. }
  67. else {
  68. if ("pdf|jpg".indexOf(sSubName) > -1) {
  69. var sUrl = gServerUrl + '/' + sPath;
  70. window.open(sUrl);
  71. }
  72. else {
  73. DownLoadFile(sPath, sFileName);
  74. }
  75. }
  76. });
  77. };
  78. return fnGetUploadFiles(parentid, callback);
  79. },
  80. /**
  81. * 打印
  82. * @param {Object} handle jquery dom 對象
  83. */
  84. fnPrePrint = function (handle) {
  85. $(':input,select').not('[type="button"],[type="radio"]').each(function () {
  86. var parentDom = $(this).parent();
  87. if (!parentDom.attr('printele')) {
  88. var sOldrHTML = '',
  89. sPrintrHTML = '';
  90. parentDom.find(':input,select').each(function () {
  91. $(this).attr('value', this.value);
  92. var thisHtml = this.outerHTML,
  93. printHtml = $('<div>', { class: 'show-text' });
  94. switch (this.type) {
  95. case 'text':
  96. case 'number':
  97. case 'textarea':
  98. printHtml.html(this.value);
  99. break;
  100. case 'select':
  101. case 'select-one':
  102. printHtml.html($(this).find('option:selected').text());
  103. break;
  104. }
  105. sOldrHTML += thisHtml;
  106. sPrintrHTML += printHtml[0].outerHTML;
  107. });
  108. }
  109. parentDom.attr('printele', sOldrHTML).html(sPrintrHTML);
  110. });
  111. handle.jqprint({ operaSupport: false });
  112. $('[printele]').each(function () {
  113. var oldHtml = $(this).attr('printele');
  114. $(this).html(oldHtml).removeAttr('printele').find(':input,select').each(function () {
  115. this.value = $(this).attr('value');
  116. });
  117. });
  118. },
  119. /**
  120. * 處理簽核流程
  121. * @param {Object} data 當前資料
  122. * @param {Boolean} flag 當前資料
  123. * @param {Boolean} isstrfy 當前資料
  124. * @param {Array} users 當前資料
  125. * @return {Object} 返回流程字串或json對象
  126. */
  127. fnCheckFlows = function (data, flag, isstrfy, users) {
  128. var Applicant = data.Applicant ? data.Applicant : data.AskTheDummy;
  129. var saCheckFlows = [],
  130. iOrder = 0;
  131. if (flag && data.Agent_Person) {
  132. iOrder++;
  133. var oCurUser = $.grep(users, function (cur) { return cur.MemberID === data.Agent_Person; })[0],
  134. oFlow = {};
  135. oFlow.ParentId = '0';
  136. oFlow.FlowId = guid();
  137. oFlow.Order = iOrder;
  138. oFlow.SignedWay = 'flow1';
  139. oFlow.SignedId = data.Agent_Person;
  140. oFlow.SignedMember = oCurUser.MemberName;
  141. oFlow.Department = oCurUser.DepartmentName;
  142. oFlow.Jobtitle = oCurUser.JobtitleName;
  143. oFlow.SignedDecision = '';
  144. oFlow.SignedOpinion = '';
  145. oFlow.SignedDate = '';
  146. saCheckFlows.push(oFlow);
  147. }
  148. var ShiftOrder = 0;
  149. $.each(data.CheckOrder, function (idx, order) {
  150. if (flag && idx === 0) {
  151. var saExsit = Jsonget(order.SignedMember, 'id', data.Agent_Person);
  152. if (saExsit.length > 0) {
  153. iOrder--;
  154. saCheckFlows = [];
  155. }
  156. }
  157. $.each(order.SignedMember, function (i, _user) {
  158. if (_user.id !== Applicant) {
  159. let intOrder = parseInt(order.Order);
  160. var oFlow = {};
  161. oFlow.ParentId = order.id;
  162. oFlow.FlowId = guid();
  163. oFlow.Order = intOrder + iOrder + ShiftOrder;
  164. oFlow.SignedWay = order.SignedWay;
  165. oFlow.SignedId = _user.id;
  166. oFlow.SignedMember = _user.name;
  167. oFlow.Department = _user.deptname;
  168. oFlow.Jobtitle = _user.jobname;
  169. oFlow.SignedDecision = '';
  170. oFlow.SignedOpinion = '';
  171. oFlow.SignedDate = '';
  172. if (order.SignedMember.length > 1 && i !== order.SignedMember.length - 1) {
  173. oFlow.Line = true;
  174. }
  175. if (i === 0) {
  176. oFlow.Icon = true;
  177. }
  178. saCheckFlows.push(oFlow);
  179. }
  180. else if (order.SignedWay == "flow1") {
  181. --ShiftOrder;
  182. }
  183. });
  184. });
  185. return isstrfy ? JSON.stringify(saCheckFlows) : saCheckFlows;
  186. },
  187. /**
  188. *處理簽辦流程
  189. *@method fnHandleFlows
  190. *@param {Object} data 當前資料
  191. *@param {Array} users 當前資料
  192. *@return {Object} 返回流程字串或json對象
  193. */
  194. fnHandleFlows = function (data, users) {
  195. var saHandleFlows = [],
  196. iOrder = 1;
  197. if (data.Handle_Person) {
  198. var oCurUser = $.grep(users, function (cur) { return cur.MemberID === data.Handle_Person; })[0],
  199. oFlow = {};
  200. oFlow.FlowId = guid();
  201. oFlow.Order = iOrder;
  202. oFlow.SignedWay = 'flow1';
  203. oFlow.SignedId = data.Handle_Person;
  204. oFlow.SignedMember = oCurUser.MemberName;
  205. oFlow.Department = oCurUser.DepartmentName;
  206. oFlow.Jobtitle = oCurUser.JobtitleName;
  207. oFlow.SignedDecision = 'N';
  208. oFlow.SignedOpinion = '';
  209. oFlow.SignedDate = '';
  210. saHandleFlows.push(oFlow);
  211. }
  212. return JSON.stringify(saHandleFlows);
  213. },
  214. /**
  215. * 合併通知
  216. * @param {Array} list Grid list
  217. * @return {Array} list New Grid list
  218. */
  219. releaseGridList = function (list) {
  220. var saIndex = [],
  221. saList_New = [];
  222. list = Enumerable.From(list).OrderBy("$.Order").ToArray();
  223. $.each(list, function (idx, _data) {
  224. if (saIndex.indexOf(idx) === -1) {
  225. var nextdata_1 = list[idx + 1],
  226. nextdata_2 = list[idx + 2],
  227. bTwo = false;
  228. if (nextdata_1 && nextdata_1.SignedWay === _data.SignedWay && _data.SignedWay === 'flow4') {
  229. _data.SignedMember = _data.SignedMember.concat(nextdata_1.SignedMember);
  230. saIndex.push(idx + 1);
  231. bTwo = true;
  232. }
  233. if (bTwo && nextdata_2 && nextdata_2.SignedWay === _data.SignedWay && _data.SignedWay === 'flow4') {
  234. _data.SignedMember = _data.SignedMember.concat(nextdata_2.SignedMember);
  235. saIndex.push(idx + 2);
  236. }
  237. saList_New.push(_data);
  238. }
  239. });
  240. $.each(saList_New, function (idx, _data) {
  241. _data.Order = idx + 1;
  242. });
  243. return saList_New;
  244. },
  245. /**
  246. * 開啟複選選單Pop
  247. * @param {Object} option 配置
  248. */
  249. oPenUserListPop = function (option) {
  250. option = option || {};
  251. var oGrid = null,
  252. saUserList = [],// ╠common.Filter⇒過濾╣
  253. sContent = '<style>.btn-xs {padding: 1px 5px; }</style>\
  254. <div class="row popsrow">\
  255. <label class="col-sm-3 control-label wright" for="input-Default"><span data-i18n="common.Department">部門</span></label>\
  256. <div class="col-sm-6">\
  257. <select class="form-control" id="Department"></select>\
  258. </div>\
  259. </div>\
  260. <div class="row popsrow">\
  261. <label class="col-sm-3 control-label wright" for="input-Default"><span data-i18n="common.Filter">過濾</span></label>\
  262. <div class="col-sm-6">\
  263. <input type="text" class="form-control w100p" id="Filter" maxlength="50">\
  264. </div>\
  265. </div>\
  266. <div class="row popsrow">\
  267. <div class="col-sm-2"></div>\
  268. <div class="col-sm-8">\
  269. <table style="width: 100%">\
  270. <tr>\
  271. <td class="w50p">\
  272. <select size="10" name="lstLeft" id="lstLeft" class="form-control w100p" multiple></select>\
  273. </td>\
  274. <td>\
  275. <p>\
  276. <button type="button" id="btnToRight" class="btn-custom btn-xs"><i class="fa fa-chevron-right"></i></button>\
  277. </p>\
  278. <p>\
  279. <button type="button" id="btnToLeft" class="btn-custom btn-xs"><i class="fa fa-chevron-left"></i></button>\
  280. </p>\
  281. </td>\
  282. <td class="w50p">\
  283. <select size="10" name="lstRight" id="lstRight" class="form-control w100p" multiple></select>\
  284. </td>\
  285. <td>\
  286. <p>\
  287. <button type="button" id="btnToUp" class="btn-custom btn-xs"><i class="fa fa-chevron-up"></i></button>\
  288. </p>\
  289. <p>\
  290. <button type="button" id="btnToDown" class="btn-custom btn-xs"><i class="fa fa-chevron-down"></i></button>\
  291. </p>\
  292. </td>\
  293. </tr>\
  294. </table>\
  295. </div>\
  296. <div class="col-sm-2"></div>\
  297. </div>\
  298. <div class="row popsrow">\
  299. <div class="col-sm-2"></div>\
  300. <div id="flowtype">\
  301. </div>\
  302. </div>';
  303. layer.open({
  304. type: 1,
  305. title: i18next.t('common.SelectUsers'),//╠common.SelectUsers⇒選取人員╣
  306. shadeClose: false,
  307. shade: 0.1,
  308. maxmin: true, //开启最大化最小化按钮
  309. area: ['500px', '460px'],
  310. content: sContent,
  311. success: function (layero, index) {
  312. var saFlowTypes = [
  313. { id: 'flow1', text: i18next.t('common.flow1') },//╠common.flow1⇒串簽╣
  314. { id: 'flow2', text: i18next.t('common.flow2') },//╠common.flow2⇒會辦╣
  315. { id: 'flow3', text: i18next.t('common.flow3') },//╠common.flow3⇒擇辦╣
  316. { id: 'flow4', text: i18next.t('common.flow4') }];//╠common.flow4⇒通知╣
  317. layero.find('#flowtype').html(createRadios(saFlowTypes, 'id', 'text', 'flowtype')).find('label:first').click();
  318. if (option.SignedWay) {
  319. layero.find('#flowtype [value=' + option.SignedWay + ']').click();
  320. }
  321. if (option.Flowtype) {
  322. layero.find('#flowtype').hide();
  323. layero.find('#lstLeft,#lstRight').attr('size', 12);
  324. }
  325. fnSetDeptDrop(layero.find('#Department'));
  326. fnSetUserDrop([{
  327. Select: layero.find('#lstLeft'),
  328. Action: 'add',
  329. ShowId: true,
  330. CallBack: function (data) {
  331. saUserList = data;
  332. layero.find('#lstLeft')[0].remove(0);
  333. optionListSearch(layero.find('#lstLeft'), layero.find('#lstRight'), layero.find('#Filter'));
  334. if (option.SignedMember) {
  335. option.SignedMember = Enumerable.From(option.SignedMember).Distinct("$=>$.id").ToArray();
  336. layero.find('#lstRight').html(createOptions(option.SignedMember, 'id', 'name'));
  337. layero.find('#lstRight')[0].remove(0);
  338. $.each(option.SignedMember, function (idx, _user) {
  339. layero.find('#lstLeft').find('option[value="' + _user.id + '"]').remove();
  340. });
  341. }
  342. }
  343. }]);
  344. layero.find('#Department').on('change', function () {
  345. var sDeptId = this.value;
  346. fnSetUserDrop([{
  347. Select: layero.find('#lstLeft'),
  348. Action: 'add',
  349. DepartmentID: sDeptId,
  350. CallBack: function (data) {
  351. layero.find('#lstLeft')[0].remove(0);
  352. optionListSearch(layero.find('#lstLeft'), layero.find('#lstRight'), layero.find('#Filter'));
  353. }
  354. }]);
  355. });
  356. layero.find('#btnToRight').on('click', function () {
  357. optionListMove(layero.find('#lstLeft'), layero.find('#lstRight'));
  358. });
  359. layero.find('#btnToLeft').on('click', function () {
  360. optionListMove(layero.find('#lstRight'), layero.find('#lstLeft'));
  361. });
  362. layero.find('#btnToUp').on('click', function () {
  363. optionListOrder(layero.find('#lstRight'), true);
  364. });
  365. layero.find('#btnToDown').on('click', function () {
  366. optionListOrder(layero.find('#lstRight'), false);
  367. });
  368. },
  369. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  370. yes: function (index, layero) {
  371. var oRetn = {},
  372. saUsers = [],
  373. sFlowtype = layero.find('#flowtype [name=flowtype]:checked').val();
  374. layero.find('#lstRight option').each(function () {
  375. var userid = $(this).val(),
  376. oCurUser = Enumerable.From(saUserList).Where(function (e) { return e.MemberID === userid; }).First();
  377. let Name = $(this).text().split("-")[1];
  378. saUsers.push({
  379. id: $(this).val(),
  380. name: Name,
  381. deptname: oCurUser.DepartmentName,
  382. jobname: oCurUser.JobtitleName
  383. });
  384. });
  385. oRetn.Users = saUsers;
  386. oRetn.FlowType = sFlowtype || '';
  387. if (typeof option.Callback === 'function') option.Callback(oRetn);
  388. layer.close(index);
  389. },
  390. cancel: function () {
  391. if (typeof option.CancelCallback === 'function') option.CancelCallback();
  392. }
  393. });
  394. },
  395. /**
  396. * 設定簽核流程下拉選單
  397. * @param {Object} drop 當前控件
  398. * @return {Object} Ajax 物件
  399. */
  400. fnSetFlowDrop = function (drop) {
  401. return g_api.ConnectLite(Service.eip, 'GetFlows',
  402. {
  403. Flow_Type: drop.Flow_Type || '',
  404. ShareTo: drop.ShareTo || ''
  405. },
  406. function (res) {
  407. if (res.RESULT) {
  408. var saRes = res.DATA.rel;
  409. if (drop.Select) {
  410. drop.Select.html(createOptions(saRes, 'Guid', 'Flow_Name', drop.ShowId || false));
  411. if (drop.DefultVal) {
  412. drop.Select.val(drop.DefultVal);
  413. }
  414. if (drop.Select2) {
  415. drop.Select.each(function () {
  416. $(this).select2();
  417. $(this).next().after($(this));
  418. });
  419. }
  420. }
  421. if (drop.CallBack && typeof drop.CallBack === 'function') {
  422. drop.CallBack(saRes);
  423. }
  424. }
  425. });
  426. },
  427. /**
  428. * 獲取賬單資料
  429. * @param {Object} o 參數
  430. * @return {Object} Ajax 物件
  431. */
  432. fnGetBills = function (o) {
  433. return g_api.ConnectLite(Service.opm, 'GetBills',
  434. {
  435. BillNO: o.BillNO || ''
  436. },
  437. function (res) {
  438. if (res.RESULT) {
  439. var saRes = res.DATA.rel;
  440. if (o.CallBack && typeof o.CallBack === 'function') {
  441. o.CallBack(saRes);
  442. }
  443. }
  444. });
  445. },
  446. /**
  447. * 根據帳單狀態移除抽單按鈕(扣除已經辦只能admin抽單)
  448. * @param {Object} status 帳單狀態
  449. * @param {Object} applicant 申請者
  450. */
  451. fnCheckReEdit = function (status, applicant) {
  452. let RemoveReEdit = false;
  453. let AdminUser = parent.UserInfo.roles.indexOf('Admin') > -1;
  454. switch (status) {
  455. case "A":
  456. case "B":
  457. case "E":
  458. if (applicant !== parent.UserID) {
  459. RemoveReEdit = true;
  460. }
  461. break;
  462. case "C-O":
  463. case "D-O":
  464. case "X":
  465. //不能抽單狀況:已抽單、已退件、已作廢、已經辦。
  466. RemoveReEdit = true;
  467. break;
  468. case "H-O":
  469. //"已經辦"(H-O),僅超級管理員可
  470. if (AdminUser) {
  471. RemoveReEdit = false;
  472. }
  473. else {
  474. RemoveReEdit = true;
  475. }
  476. break;
  477. default:
  478. RemoveReEdit = true;
  479. break;
  480. }
  481. //調整抽單鈕
  482. if (RemoveReEdit)
  483. $('#Toolbar_ReEdit').remove();
  484. },
  485. /**
  486. * 重新取得新的流程再執行複製
  487. *@param {Object} oCurData 目前的資料
  488. *@param {Object} CopyFn 流程更新後執行的Function
  489. */
  490. fnRefreshFlowsThenCopy = function (oCurData, CopyFn) {
  491. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  492. Type: '',
  493. Params: {
  494. checkflow: {
  495. Guid: oCurData.FlowId
  496. }
  497. }
  498. }, function (res) {
  499. if (res.d) {
  500. //取得新的flow資料 start
  501. var oRes = $.parseJSON(res.d);
  502. // ╠message.RefreshFlowsThenCopy_Failed_FlowsNotFound⇒複製失敗,找不到原始對應流程單據╣
  503. if (oRes.ShareTo === null)
  504. showMsg(i18next.t("message.RefreshFlowsThenCopy_Failed_FlowsNotFound"), 'error');
  505. else if (oRes.ShareTo.indexOf(parent.UserID) === -1)
  506. // ╠message.RefreshFlowsThenCopy_Failed_FlowsNotFound⇒複製失敗,沒有使用該流程權限。╣
  507. showMsg(i18next.t("message.RefreshFlowsThenCopy_Failed_FlowsAccessDenied"), 'error');
  508. else {
  509. oRes.Flows = $.parseJSON(oRes.Flows);
  510. oCurData.CheckOrder = oRes.Flows;
  511. oCurData.Flows_Lock = oRes.Flows_Lock;
  512. oCurData.Handle_Lock = oRes.Handle_Lock;
  513. oCurData.Handle_Person = oRes.Handle_Person;
  514. oCurData.Handle_DeptID = oRes.Handle_DeptID;
  515. CopyFn();
  516. }
  517. //取得新的flow資料 end
  518. }
  519. // ╠message.RefreshFlowsThenCopy_Failed_SearchingFlowsError⇒複製失敗,搜尋時發生錯誤。╣
  520. else {
  521. showMsg(i18next.t("message.RefreshFlowsThenCopy_Failed_SearchingFlowsError"), 'error');
  522. }
  523. });
  524. };