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.

845 lines
42 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sViewPrgId = sProgramId.replace('_Upd', '_View'),
  5. sAction = getUrlParam('Action') || 'Add',
  6. sDataId = getUrlParam('Guid'),
  7. sCheckId = sDataId,
  8. fnPageInit = function () {
  9. var oCurData = { CheckOrder: [] },
  10. oForm = $('#form_main'),
  11. oValidator = null,
  12. oGrid = null,
  13. sHolidays = '',
  14. iOneDayHours = 8,
  15. saUsers = [],
  16. /**
  17. * 獲取資料
  18. */
  19. fnGet = function () {
  20. if (sDataId) {
  21. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  22. {
  23. Guid: sDataId
  24. },
  25. function (res) {
  26. if (res.RESULT) {
  27. var oRes = res.DATA.rel;
  28. oCurData = oRes;
  29. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  30. setFormVal(oForm, oRes);
  31. $('#StartDate').val(newDate(oCurData.StartDate));
  32. $('#EndDate').val(newDate(oCurData.EndDate));
  33. $('.AskTheDummy').text(oCurData.AskTheDummyName + '(' + oCurData.AskTheDummy + ') ' + oCurData.DeptName);
  34. fnGetUploadFiles(oCurData.Guid, fnUpload);
  35. if (oCurData.Handle_DeptID) {
  36. fnSetUserDrop([
  37. {
  38. Select: $('#Handle_Person'),
  39. DepartmentID: oCurData.Handle_DeptID,
  40. ShowId: true,
  41. Select2: true,
  42. Action: sAction,
  43. DefultVal: oCurData.Handle_Person
  44. }
  45. ]);
  46. }
  47. if (oCurData.Agent_DeptID) {
  48. fnSetUserDrop([
  49. {
  50. Select: $('#Agent_Person'),
  51. DepartmentID: oCurData.Agent_DeptID,
  52. ShowId: true,
  53. Select2: true,
  54. Action: sAction,
  55. DefultVal: oCurData.Agent_Person
  56. }
  57. ]);
  58. }
  59. if (oRes.Flows_Lock === 'Y') {
  60. $(".checkordertoolbox").hide();
  61. }
  62. else {
  63. $(".checkordertoolbox").show();
  64. }
  65. if (oRes.Handle_Lock === 'Y') {
  66. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  67. }
  68. else {
  69. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  70. }
  71. $("#jsGrid").jsGrid("loadData");
  72. setNameById().done(function () {
  73. getPageVal();//緩存頁面值,用於清除
  74. });
  75. }
  76. });
  77. }
  78. else {
  79. $('.AskTheDummy').text(parent.UserInfo.MemberName + '(' + parent.UserInfo.MemberID + ') ' + parent.UserInfo.DepartmentName);
  80. $('#AskTheDummy').val(parent.UserInfo.MemberID);
  81. oCurData.CheckOrder = [];
  82. oCurData.Guid = guid();
  83. fnUpload();
  84. return $.Deferred().resolve().promise();
  85. }
  86. },
  87. /**
  88. * 新增資料
  89. * @param {String} flag 新增或儲存後新增
  90. */
  91. fnAdd = function (flag) {
  92. var data = getFormSerialize(oForm);
  93. data = packParams(data);
  94. data.OrgID = parent.OrgID;
  95. data.Guid = oCurData.Guid;
  96. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|BT|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  97. data.CheckFlows = fnCheckFlows(oCurData, true, true, saUsers);
  98. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  99. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  100. data.Status = 'A';
  101. data.IsHandled = 'N';
  102. data.Inspectors = '';
  103. data.Reminders = '';
  104. data.Flows_Lock = oCurData.Flows_Lock;
  105. data.Handle_Lock = oCurData.Handle_Lock;
  106. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  107. Params: {
  108. businesstravel: data
  109. }
  110. }, function (res) {
  111. if (res.d > 0) {
  112. bRequestStorage = false;
  113. if (flag == 'add') {
  114. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Save_Success⇒新增成功╣
  115. }
  116. else {
  117. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  118. }
  119. }
  120. else {
  121. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  122. }
  123. }, function () {
  124. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  125. });
  126. },
  127. /**
  128. * 修改資料
  129. * @param {Boolean} balert 是否提示
  130. */
  131. fnUpd = function (balert) {
  132. var data = getFormSerialize(oForm);
  133. data = packParams(data, 'upd');
  134. data.CheckFlows = fnCheckFlows(oCurData, true, true, saUsers);
  135. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  136. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  137. data.Flows_Lock = oCurData.Flows_Lock;
  138. data.Handle_Lock = oCurData.Handle_Lock;
  139. return CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  140. Params: {
  141. businesstravel: {
  142. values: data,
  143. keys: { Guid: sDataId }
  144. }
  145. }
  146. }, function (res) {
  147. if (res.d > 0) {
  148. if (!balert) {
  149. bRequestStorage = false;
  150. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  151. if (window.bLeavePage) {
  152. setTimeout(function () {
  153. pageLeave();
  154. }, 1000);
  155. }
  156. }
  157. }
  158. else {
  159. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  160. }
  161. }, function () {
  162. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  163. });
  164. },
  165. /**
  166. * 資料刪除
  167. */
  168. fnDel = function () {
  169. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  170. Params: {
  171. businesstravel: {
  172. Guid: sDataId
  173. }
  174. }
  175. }, function (res) {
  176. if (res.d > 0) {
  177. DelTask(sDataId);
  178. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  179. }
  180. else {
  181. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  182. }
  183. }, function () {
  184. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  185. });
  186. },
  187. /**
  188. * 上傳附件
  189. * @param {Array} files 上傳的文件
  190. */
  191. fnUpload = function (files) {
  192. var option = {};
  193. option.input = $('#fileInput');
  194. option.theme = 'dragdropbox';
  195. option.folder = 'BusinessTravel';
  196. option.type = 'list';
  197. option.parentid = oCurData.Guid;
  198. if (files) {
  199. option.files = files;
  200. }
  201. fnUploadRegister(option);
  202. },
  203. /**
  204. * 計算時差
  205. */
  206. fnGetDateDiff = function () {
  207. try {
  208. var sStartDate = $('#StartDate').val(),
  209. sEndDate = $('#EndDate').val();
  210. if (sStartDate === '' || sEndDate === '') {
  211. return false;
  212. }
  213. var date_s = sStartDate.split(" ")[0].replaceAll('/', '-'),//開始的日期部分
  214. date_e = sEndDate.split(" ")[0].replaceAll('/', '-'),//結束的日期部分
  215. time_s = sStartDate.split(" ")[1],//開始的時間部分
  216. time_e = sEndDate.split(" ")[1],//結束的日期部分
  217. newdate_s = new Date(date_s + ' 00:00').getTime();
  218. newdate_s = new Date(newdate_s + 24 * 60 * 60 * 1000);
  219. var newdate_e = new Date(date_e + ' 23:59').getTime();
  220. newdate_e = new Date(newdate_e - 24 * 60 * 60 * 1000);
  221. var intDays = 0;
  222. var intHours = 0;
  223. var intDaysHours = "";
  224. while (newdate_s <= newdate_e) {
  225. intDaysHours = fnDaysAndHours(newdate_s);
  226. intDays += parseInt(intDaysHours.split('|')[0]);
  227. intHours += parseInt(intDaysHours.split('|')[1]);
  228. newdate_s = new Date(newdate_s.getTime() + 24 * 60 * 60 * 1000);
  229. }
  230. //計算第一天和最後一天
  231. if (date_s === date_e) {//若都是當天
  232. intDaysHours = fnDateSE(date_s, time_s, time_e);
  233. intDays += parseInt(intDaysHours.split('|')[0]);
  234. intHours += (intDaysHours.split('|')[1] * 1);
  235. }
  236. else {
  237. //第一天
  238. intDaysHours = fnDateSE(date_s, time_s, "23:59");
  239. intDays += parseInt(intDaysHours.split('|')[0]);
  240. intHours += (intDaysHours.split('|')[1] * 1);
  241. //最後一天
  242. intDaysHours = fnDateSE(date_e, "00:00", time_e);
  243. intDays += parseInt(intDaysHours.split('|')[0]);
  244. intHours += (intDaysHours.split('|')[1] * 1);
  245. }
  246. var days = Math.floor(intHours / iOneDayHours);
  247. intDays = intDays + days;
  248. //intHours = intHours % iOneDayHours;
  249. $('#TotalTime').val(intDays * iOneDayHours + intHours);
  250. } catch (e) { }
  251. },
  252. /**
  253. * 返回週幾信息
  254. * @param {Date} times 開始時間
  255. * @param {Date} timee 結束時間
  256. */
  257. fnDiffTimeSE = function (times, timee) {
  258. var minute = 1000 * 60 * 60,
  259. DateS1 = new Date(times).getTime(),
  260. DateE1 = new Date(timee).getTime(),
  261. diffValue = DateE1 - DateS1,
  262. minC = diffValue / minute;
  263. return minC;
  264. },
  265. /**
  266. * 日期和時間
  267. * @param {Date} dates 當前日期
  268. * @param {Date} times 開始時間
  269. * @param {Date} timee 結束時間
  270. */
  271. fnDateSE = function (dates, times, timee) {
  272. try {
  273. var intDays = 0,
  274. inthour = 0,
  275. intAllhour = 0,
  276. aryTimeSE = [parent.SysSet.WorkTimePM, parent.SysSet.WorkTimeAM];
  277. if (sHolidays.indexOf(dates) > -1) {
  278. //是節假日
  279. intDays = 0;
  280. inthour = 0;
  281. }
  282. else {//非節假日
  283. var IsCheckAllDay = "";
  284. for (var i = 0; i < aryTimeSE.length; i++) {
  285. if (aryTimeSE[i] != "" && aryTimeSE[i] !== undefined) {
  286. var aryTimeS = dates + " " + aryTimeSE[i].split('~')[0];//設小
  287. var aryTimeE = dates + " " + aryTimeSE[i].split('~')[1];//設大
  288. if (fnDiffTimeSE((dates + " " + times), aryTimeS) >= 0 && fnDiffTimeSE(aryTimeE, (dates + " " + timee)) >= 0) {
  289. IsCheckAllDay += "Y";
  290. intAllhour += fnDiffTimeSE(aryTimeS, aryTimeE);
  291. }
  292. else {
  293. IsCheckAllDay += "N";
  294. //傳小>設小 AND 傳大>=設大
  295. if ((fnDiffTimeSE(aryTimeS, (dates + " " + times)) >= 0 && fnDiffTimeSE((dates + " " + timee), aryTimeE) > 0) || (fnDiffTimeSE(aryTimeS, (dates + " " + times)) > 0 && fnDiffTimeSE((dates + " " + timee), aryTimeE) >= 0)) {
  296. intAllhour += fnDiffTimeSE((dates + " " + times), (dates + " " + timee));
  297. }
  298. else if (fnDiffTimeSE(aryTimeS, (dates + " " + times)) > 0 && fnDiffTimeSE(aryTimeE, (dates + " " + timee)) > 0 && fnDiffTimeSE((dates + " " + times), aryTimeE) > 0) {
  299. intAllhour += fnDiffTimeSE((dates + " " + times), aryTimeE);
  300. }
  301. else if (fnDiffTimeSE((dates + " " + times), aryTimeS) > 0 && fnDiffTimeSE(aryTimeS, (dates + " " + timee)) > 0 && fnDiffTimeSE((dates + " " + timee), aryTimeE) > 0) {
  302. intAllhour += fnDiffTimeSE(aryTimeS, (dates + " " + timee));
  303. }
  304. }
  305. }
  306. }
  307. if (IsCheckAllDay.indexOf("N") > -1) {//非全天
  308. intDays = 0;
  309. inthour = intAllhour;
  310. var days = Math.floor(inthour / iOneDayHours);
  311. if (days > 0) {
  312. //全天
  313. intDays = 1;
  314. inthour = 0;
  315. }
  316. }
  317. else {
  318. intDays = 1;
  319. inthour = 0;
  320. }
  321. }
  322. return intDays + "|" + inthour;
  323. } catch (e) { }
  324. },
  325. /**
  326. * 日期和小時
  327. * @param {Date} curdate 當前日期
  328. */
  329. fnDaysAndHours = function (curdate) {
  330. try {
  331. var intDays = 0,
  332. inthour = 0;
  333. if (sHolidays.indexOf(curdate.formate("yyyy-MM-dd")) > -1) { //是節假日
  334. intDays = 0;
  335. inthour = 0;
  336. }
  337. else {//非節假日
  338. intDays = 1;
  339. inthour = 0;
  340. }
  341. return intDays + "|" + inthour;
  342. } catch (e) { }
  343. },
  344. /**
  345. * 獲取假日信息
  346. */
  347. fnGetHolidays = function () {
  348. var sYear = new Date().getFullYear() + ',' + new Date().dateAdd('y', 1).getFullYear();
  349. CallAjax(ComFn.W_Com, ComFn.GetList, {
  350. Type: '',
  351. Params: {
  352. holidays: {
  353. _CHARINDEX_Year: sYear,
  354. OrgID: parent.OrgID
  355. }
  356. }
  357. }, function (res) {
  358. if (res.d) {
  359. var saRes = $.parseJSON(res.d);
  360. $.each(saRes, function (idx, _data) {
  361. sHolidays += _data.Holidays;
  362. });
  363. }
  364. });
  365. },
  366. /**
  367. * 提交簽呈
  368. */
  369. fnSubmitPetition = function () {
  370. g_api.ConnectLite(sProgramId, 'BusinessTravelToAudit', {
  371. guid: oCurData.Guid
  372. }, function (res) {
  373. if (res.RESULT) {
  374. showMsgAndGo(i18next.t("message.ToAudit_Success"), sViewPrgId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.ToAudit_Success⇒提交審核成功╣
  375. parent.msgs.server.pushTip(parent.OrgID, res.DATA.rel);
  376. }
  377. else {
  378. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  379. }
  380. }, function () {
  381. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  382. });
  383. },
  384. /**
  385. * ToolBar 按鈕事件 function
  386. * @param {Object}inst 按鈕物件對象
  387. * @param {Object} e 事件對象
  388. */
  389. fnButtonHandler = function (inst, e) {
  390. var sId = inst.id;
  391. switch (sId) {
  392. case "Toolbar_Qry":
  393. break;
  394. case "Toolbar_Save":
  395. if (!$("#form_main").valid()) {
  396. oValidator.focusInvalid();
  397. return false;
  398. }
  399. if (sAction === 'Add') {
  400. fnAdd('add');
  401. }
  402. else {
  403. fnUpd();
  404. }
  405. break;
  406. case "Toolbar_ReAdd":
  407. if (!$("#form_main").valid()) {
  408. oValidator.focusInvalid();
  409. return false;
  410. }
  411. fnAdd('readd');
  412. break;
  413. case "Toolbar_Clear":
  414. clearPageVal();
  415. break;
  416. case "Toolbar_Leave":
  417. pageLeave();
  418. break;
  419. case "Toolbar_Add":
  420. break;
  421. case "Toolbar_Upd":
  422. break;
  423. case "Toolbar_Copy":
  424. break;
  425. case "Toolbar_Petition":
  426. if (!$("#form_main").valid()) {
  427. oValidator.focusInvalid();
  428. return false;
  429. }
  430. fnUpd(true).done(function () {
  431. fnSubmitPetition();
  432. });
  433. break;
  434. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  435. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  436. fnDel();
  437. layer.close(index);
  438. });
  439. break;
  440. default:
  441. alert("No handle '" + sId + "'");
  442. break;
  443. }
  444. },
  445. /**
  446. * 初始化 function
  447. */
  448. init = function () {
  449. var saCusBtns = null;
  450. if (sAction === 'Upd') {
  451. saCusBtns = [{
  452. id: 'Toolbar_Petition',
  453. value: 'common.SubmitPetition'// ╠common.SubmitPetition⇒提交簽呈╣
  454. }];
  455. }
  456. commonInit({
  457. PrgId: sProgramId,
  458. ButtonHandler: fnButtonHandler,
  459. Buttons: saCusBtns,
  460. GoTop: true,
  461. onSelect: function (d, el) {
  462. fnGetDateDiff();
  463. }
  464. });
  465. oValidator = $("#form_main").validate();
  466. $.whenArray([
  467. fnSetDeptDrop($('#Handle_DeptID,#Agent_DeptID')),
  468. fnSetFlowDrop({
  469. Flow_Type: parent.SysSet.Eip_002,
  470. ShareTo: parent.UserID,
  471. CallBack: function (data) {
  472. $.each(data, function (idx, item) {
  473. var saFlows = $.parseJSON(item.Flows),
  474. saFlowsText = [],
  475. sFlowsText = '';
  476. $.each(saFlows, function (idx, flow) {
  477. var sFlowType = i18next.t('common.' + flow.SignedWay);
  478. if (flow.SignedWay !== 'flow1') {
  479. saFlowsText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  480. }
  481. else {
  482. saFlowsText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  483. }
  484. });
  485. sFlowsText = saFlowsText.join(' → ');
  486. item.text = item.Flow_Name + ' - ' + (sFlowsText.length > 60 ? sFlowsText.substr(0, 60) + '...' : sFlowsText);
  487. });
  488. $('#FlowId').html(createOptions(data, 'Guid', 'text')).on('change', function () {
  489. var sFlowId = this.value;
  490. if (sFlowId) {
  491. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  492. Type: '',
  493. Params: {
  494. checkflow: {
  495. Guid: sFlowId
  496. }
  497. }
  498. }, function (res) {
  499. if (res.d) {
  500. var oRes = $.parseJSON(res.d);
  501. oRes.Flows = $.parseJSON(oRes.Flows);
  502. oCurData.CheckOrder = oRes.Flows;
  503. oCurData.Flows_Lock = oRes.Flows_Lock;
  504. oCurData.Handle_Lock = oRes.Handle_Lock;
  505. $("#Handle_DeptID").val(oRes.Handle_DeptID);
  506. $("#Handle_Person").val(oRes.Handle_Person).trigger('change');
  507. if (oRes.Flows_Lock === 'Y') {
  508. $(".checkordertoolbox").hide();
  509. }
  510. else {
  511. $(".checkordertoolbox").show();
  512. }
  513. if (oRes.Handle_Lock === 'Y') {
  514. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  515. }
  516. else {
  517. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  518. }
  519. $("#jsGrid").jsGrid("loadData");
  520. }
  521. });
  522. }
  523. else {
  524. oCurData.CheckOrder = [];
  525. $(".checkordertoolbox").hide();
  526. $("#jsGrid").jsGrid("loadData");
  527. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  528. }
  529. });
  530. }
  531. }),
  532. fnSetUserDrop([
  533. {
  534. Select: $('#Handle_Person,#Agent_Person'),
  535. Select2: true,
  536. Action: sAction,
  537. CallBack: function (data) {
  538. saUsers = data;
  539. }
  540. }
  541. ]),
  542. fnGetHolidays(),
  543. fnSetArgDrop([
  544. {
  545. ArgClassID: 'BTrlType',
  546. Select: $('#HolidayCategory'),
  547. ShowId: true
  548. }
  549. ])])
  550. .done(function () {
  551. fnGet();
  552. });
  553. $('#Handle_DeptID').on('change', function () {
  554. fnSetUserDrop([
  555. {
  556. Select: $('#Handle_Person'),
  557. DepartmentID: this.value,
  558. ShowId: true,
  559. Select2: true,
  560. Action: sAction
  561. }
  562. ]);
  563. });
  564. $('#Agent_DeptID').on('change', function () {
  565. fnSetUserDrop([
  566. {
  567. Select: $('#Agent_Person'),
  568. DepartmentID: this.value,
  569. ShowId: true,
  570. Select2: true,
  571. Action: sAction
  572. }
  573. ]);
  574. });
  575. $('#Agent_Person').on('change', function () {
  576. oCurData.Agent_Person = this.value;
  577. });
  578. $('.flowlink').on('click', function () {
  579. var oOption = {};
  580. oOption.SignedWay = this.id;
  581. oOption.Callback = function (data) {
  582. if (data.Users.length > 0) {
  583. var oFlow = {};
  584. if (data.FlowType === 'flow1') {
  585. $.each(data.Users, function (idx, user) {
  586. oFlow = {};
  587. oFlow.id = guid();
  588. oFlow.Order = oCurData.CheckOrder.length + 1;
  589. oFlow.SignedWay = data.FlowType;
  590. oFlow.SignedMember = [{
  591. id: user.id,
  592. name: user.name,
  593. deptname: user.deptname,
  594. jobname: user.jobname
  595. }];
  596. oCurData.CheckOrder.push(oFlow);
  597. });
  598. }
  599. else {
  600. var saUsers = [];
  601. $.each(data.Users, function (idx, user) {
  602. saUsers.push({
  603. id: user.id,
  604. name: user.name,
  605. deptname: user.deptname,
  606. jobname: user.jobname
  607. });
  608. });
  609. oFlow.id = guid();
  610. oFlow.Order = oCurData.CheckOrder.length + 1;
  611. oFlow.SignedWay = data.FlowType;
  612. oFlow.SignedMember = saUsers;
  613. oCurData.CheckOrder.push(oFlow);
  614. }
  615. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  616. $("#jsGrid").jsGrid("loadData");
  617. }
  618. };
  619. oPenUserListPop(oOption);
  620. });
  621. $("#jsGrid").jsGrid({
  622. width: "100%",
  623. height: "auto",
  624. autoload: true,
  625. filtering: false,
  626. pageLoading: true,
  627. pageIndex: 1,
  628. pageSize: 10000,
  629. fields: [
  630. {
  631. name: "Order", title: 'common.Order', width: 50, align: "center",
  632. itemTemplate: function (val, item) {
  633. return val < 10 ? '0' + val : val;
  634. }
  635. },
  636. {
  637. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  638. itemTemplate: function (val, item) {
  639. return i18next.t('common.' + val);
  640. }
  641. },
  642. {
  643. type: "Icon", width: 50, align: "center",
  644. itemTemplate: function (val, item) {
  645. var oIcon = {
  646. flow1: '<img src="../../images/flow_check.gif">',
  647. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  648. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  649. flow4: '<img src="../../images/flow4.gif">'
  650. },
  651. sIcon = oIcon[item.SignedWay];
  652. if (item.Order !== oCurData.CheckOrder.length) {
  653. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  654. }
  655. return sIcon;
  656. }
  657. },
  658. {
  659. name: "SignedMember", title: 'common.SignedMember', width: 500,
  660. itemTemplate: function (val, item) {
  661. return Enumerable.From(val).ToString(",", "$.name");
  662. }
  663. },
  664. {
  665. type: "control", title: 'common.Action', width: 200,
  666. itemTemplate: function (val, item) {
  667. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  668. class: 'glyphicon glyphicon-pencil' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  669. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  670. click: function () {
  671. if ($(this).hasClass('disabled')) { return false; }
  672. var oOption = {};
  673. oOption.SignedWay = item.SignedWay;
  674. oOption.SignedMember = item.SignedMember;
  675. oOption.Callback = function (data) {
  676. if (data.Users.length > 0) {
  677. var oFlow = {};
  678. if (data.FlowType === 'flow1') {
  679. $.each(data.Users, function (idx, user) {
  680. var oFlow = {};
  681. oFlow.id = guid();
  682. oFlow.Order = item.Order + idx;
  683. oFlow.SignedWay = data.FlowType;
  684. oFlow.SignedMember = [{
  685. id: user.id,
  686. name: user.name,
  687. deptname: user.deptname,
  688. jobname: user.jobname
  689. }];
  690. oCurData.CheckOrder.insert(item.Order + idx, oFlow);
  691. });
  692. }
  693. else {
  694. var saUsers = [];
  695. $.each(data.Users, function (idx, user) {
  696. saUsers.push({
  697. id: user.id,
  698. name: user.name,
  699. deptname: user.deptname,
  700. jobname: user.jobname
  701. });
  702. });
  703. oFlow.id = guid();
  704. oFlow.Order = item.Order;
  705. oFlow.SignedWay = data.FlowType;
  706. oFlow.SignedMember = saUsers;
  707. oCurData.CheckOrder.insert(item.Order, oFlow);
  708. }
  709. var iOrder = 1;
  710. $.each(oCurData.CheckOrder, function (idx, _data) {
  711. if (item.id !== _data.id) {
  712. _data.Order = iOrder;
  713. iOrder++;
  714. }
  715. });
  716. oCurData.CheckOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  717. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  718. $("#jsGrid").jsGrid("loadData");
  719. }
  720. };
  721. oPenUserListPop(oOption);
  722. }
  723. })),
  724. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  725. class: 'glyphicon glyphicon-trash' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  726. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  727. click: function () {
  728. if ($(this).hasClass('disabled')) { return false; }
  729. var saNewList = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  730. oCurData.CheckOrder = saNewList;
  731. $.each(oCurData.CheckOrder, function (idx, _data) {
  732. _data.Order = idx + 1;
  733. });
  734. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  735. $("#jsGrid").jsGrid("loadData");
  736. }
  737. }))];
  738. if (oCurData.CheckOrder.length !== item.Order) {
  739. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  740. class: 'glyphicon glyphicon-arrow-down' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  741. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  742. click: function () {
  743. if ($(this).hasClass('disabled')) { return false; }
  744. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  745. iOrder = sOrder * 1;
  746. $.each(oCurData.CheckOrder, function (idx, _data) {
  747. if (iOrder === _data.Order) {
  748. _data.Order++;
  749. }
  750. else if ((iOrder + 1) === _data.Order) {
  751. _data.Order--;
  752. }
  753. });
  754. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  755. $("#jsGrid").jsGrid("loadData");
  756. }
  757. })));
  758. }
  759. else {
  760. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  761. }
  762. if (1 !== item.Order) {
  763. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  764. class: 'glyphicon glyphicon-arrow-up' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  765. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  766. click: function () {
  767. if ($(this).hasClass('disabled')) { return false; }
  768. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  769. iOrder = sOrder * 1;
  770. $.each(oCurData.CheckOrder, function (idx, _data) {
  771. if (iOrder === _data.Order) {
  772. _data.Order--;
  773. }
  774. else if ((iOrder - 1) === _data.Order) {
  775. _data.Order++;
  776. }
  777. });
  778. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  779. $("#jsGrid").jsGrid("loadData");
  780. }
  781. })));
  782. }
  783. return oBtns;
  784. }
  785. }
  786. ],
  787. controller: {
  788. loadData: function (args) {
  789. return {
  790. data: oCurData.CheckOrder,
  791. itemsCount: oCurData.CheckOrder.length //data.length
  792. };
  793. },
  794. insertItem: function (args) {
  795. },
  796. updateItem: function (args) {
  797. },
  798. deleteItem: function (args) {
  799. }
  800. },
  801. onInit: function (args) {
  802. oGrid = args.grid;
  803. }
  804. });
  805. };
  806. init();
  807. };
  808. require(['base', 'select2', 'jsgrid', 'filer', 'timepicker', 'common_eip', 'util'], fnPageInit, 'timepicker');