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.

592 lines
28 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sAction = getUrlParam('Action') || 'Add',
  5. sDataId = getUrlParam('Guid'),
  6. sCheckId = sDataId,
  7. fnPageInit = function () {
  8. var oCurData = {},
  9. oForm = $('#form_main'),
  10. oValidator = null,
  11. oGrid = null,
  12. saGridData = [],
  13. /**
  14. * 獲取分享權限
  15. */
  16. fnGetRightOption = function () {
  17. var saRight = [];
  18. $('#lstRight option').each(function () {
  19. saRight.push(this.value);
  20. });
  21. return saRight.join(',');
  22. },
  23. /**
  24. * 獲取資料
  25. */
  26. fnGet = function () {
  27. if (sDataId) {
  28. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  29. {
  30. Guid: sDataId
  31. },
  32. function (res) {
  33. if (res.RESULT) {
  34. var oRes = res.DATA.rel;
  35. oCurData = oRes;
  36. saGridData = $.parseJSON(oCurData.Flows);
  37. setFormVal(oForm, oRes);
  38. fnSetHandle_PersonDrop(oCurData.Handle_DeptID, 1);
  39. fnSetHandle_PersonDrop('', 2, false);
  40. $("#jsGrid").jsGrid("loadData");
  41. setNameById().done(function () {
  42. getPageVal();//緩存頁面值,用於清除
  43. });
  44. }
  45. });
  46. }
  47. else {
  48. return $.Deferred().resolve().promise();
  49. }
  50. },
  51. /**
  52. * 新增資料
  53. * @param {String} sFlag 新增或儲存後新增
  54. */
  55. fnAdd = function (sFlag) {
  56. var data = getFormSerialize(oForm),
  57. oAddPm = {};
  58. data = packParams(data);
  59. data.OrgID = parent.OrgID;
  60. data.ShareTo = fnGetRightOption();
  61. data.Flows = JSON.stringify(saGridData);
  62. data.Flows_Lock = data.Flows_Lock || 'N';
  63. data.Handle_Lock = data.Handle_Lock || 'N';
  64. delete data.lstLeft;
  65. delete data.lstRight;
  66. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  67. Params: {
  68. checkflow: data
  69. }
  70. }, function (res) {
  71. if (res.d > 0) {
  72. bRequestStorage = false;
  73. if (sFlag == 'add') {
  74. showMsgAndGo(i18next.t("message.Save_Success"), sQueryPrgId); // ╠message.Save_Success⇒新增成功╣
  75. }
  76. else {
  77. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  78. }
  79. parent.msgs.server.broadcast(data);
  80. }
  81. else {
  82. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  83. }
  84. }, function () {
  85. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  86. });
  87. },
  88. /**
  89. * 修改資料
  90. */
  91. fnUpd = function () {
  92. var data = getFormSerialize(oForm);
  93. data = packParams(data, 'upd');
  94. data.ShareTo = fnGetRightOption();
  95. data.Flows = JSON.stringify(saGridData);
  96. data.Flows_Lock = data.Flows_Lock || 'N';
  97. data.Handle_Lock = data.Handle_Lock || 'N';
  98. delete data.lstLeft;
  99. delete data.lstRight;
  100. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  101. Params: {
  102. checkflow: {
  103. values: data,
  104. keys: { Guid: sDataId }
  105. }
  106. }
  107. }, function (res) {
  108. if (res.d > 0) {
  109. bRequestStorage = false;
  110. showMsgAndGo(i18next.t("message.Modify_Success"), sQueryPrgId); //╠message.Modify_Success⇒修改成功╣
  111. }
  112. else {
  113. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  114. }
  115. }, function () {
  116. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  117. });
  118. },
  119. /**
  120. * 資料刪除
  121. */
  122. fnDel = function () {
  123. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  124. Params: {
  125. checkflow: {
  126. Guid: sDataId
  127. }
  128. }
  129. }, function (res) {
  130. if (res.d > 0) {
  131. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  132. }
  133. else {
  134. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  135. }
  136. }, function () {
  137. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  138. });
  139. },
  140. /**
  141. * 設置公告類別下拉單
  142. * @param {String} deptid 部門ID
  143. * @param {String} flag 經辦單位或者共享對象
  144. */
  145. fnSetHandle_PersonDrop = function (deptid, flag, bchange) {
  146. var sDepartmentID = deptid || '';
  147. fnSetUserDrop([
  148. {
  149. ShowId: true,
  150. Action: sAction,
  151. DepartmentID: sDepartmentID,
  152. CallBack: function (data) {
  153. var saList = data;
  154. if (flag === 1) {
  155. $('#Handle_Person').html(createOptions(saList, 'MemberID', 'MemberName', true));
  156. if (oCurData.Handle_Person) {
  157. $('#Handle_Person').val(oCurData.Handle_Person);
  158. }
  159. }
  160. else {
  161. var saLeft = [],
  162. saRight = [];
  163. if (oCurData.ShareTo) {
  164. $.each(saList, function (idx, data) {
  165. if (oCurData.ShareTo.indexOf(data.MemberID) > -1) {
  166. saRight.push(data);
  167. }
  168. else {
  169. saLeft.push(data);
  170. }
  171. });
  172. }
  173. else {
  174. saLeft = saList;
  175. }
  176. $('#lstLeft').html(createOptions(saLeft, 'MemberID', 'MemberName', true)).find('option:first').remove();
  177. if (!bchange) {
  178. $('#lstRight').html(createOptions(saRight, 'MemberID', 'MemberName', true)).find('option:first').remove();
  179. }
  180. }
  181. }
  182. }
  183. ]);
  184. },
  185. /**
  186. * 獲取匯入的資料
  187. */
  188. fnGetPopData_ImportData = function (args) {
  189. args = args || {};
  190. args.Flow_Type = $('#Pop_Flow_Type').val();
  191. args.Flow_Name = $('#Pop_Flow_Name').val();
  192. return g_api.ConnectLite(sQueryPrgId, ComFn.GetPage, args);
  193. },
  194. /**
  195. * 匯入資料
  196. */
  197. fnImport = function () {
  198. var oConfig = {
  199. Get: fnGetPopData_ImportData,
  200. SearchFields: [
  201. { id: "Pop_Flow_Type", type: 'select', i18nkey: 'CheckFlow_Upd.Flow_Type', html: $('#Flow_Type').html() },
  202. { id: "Pop_Flow_Name", type: 'text', i18nkey: 'CheckFlow_Upd.Flow_Name' }
  203. ],
  204. Fields: [
  205. { name: "RowIndex", title: 'common.RowNumber', sorting: false, align: 'center', width: 40 },
  206. { name: "Flow_TypeName", title: 'CheckFlow_Upd.Flow_Type', width: 120 },
  207. { name: "Flow_Name", title: 'CheckFlow_Upd.Flow_Name', width: 150 }
  208. ],
  209. Callback: function (item) {
  210. oCurData = item;
  211. saGridData = $.parseJSON(oCurData.Flows);
  212. setFormVal(oForm, oCurData);
  213. fnSetHandle_PersonDrop(oCurData.Handle_DeptID, 1);
  214. fnSetHandle_PersonDrop('', 2, false);
  215. $("#jsGrid").jsGrid("loadData");
  216. }
  217. };
  218. oPenPops(oConfig);
  219. },
  220. /**
  221. * ToolBar 按鈕事件 function
  222. * @param {Object}inst 按鈕物件對象
  223. * @param {Object} e 事件對象
  224. */
  225. fnButtonHandler = function (inst, e) {
  226. var sId = inst.id;
  227. switch (sId) {
  228. case "Toolbar_Qry":
  229. break;
  230. case "Toolbar_Save":
  231. if (!$("#form_main").valid()) {
  232. oValidator.focusInvalid();
  233. return false;
  234. }
  235. if (sAction == 'Add') {
  236. fnAdd('add');
  237. }
  238. else {
  239. fnUpd();
  240. }
  241. break;
  242. case "Toolbar_ReAdd":
  243. if (!$("#form_main").valid()) {
  244. oValidator.focusInvalid();
  245. return false;
  246. }
  247. fnAdd('readd');
  248. break;
  249. case "Toolbar_Clear":
  250. clearPageVal();
  251. break;
  252. case "Toolbar_Leave":
  253. pageLeave();
  254. break;
  255. case "Toolbar_Add":
  256. break;
  257. case "Toolbar_Upd":
  258. break;
  259. case "Toolbar_Copy":
  260. break;
  261. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  262. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  263. fnDel();
  264. layer.close(index);
  265. });
  266. break;
  267. case "Toolbar_Imp":
  268. fnImport();
  269. break;
  270. default:
  271. alert("No handle '" + sId + "'");
  272. break;
  273. }
  274. },
  275. /**
  276. * 初始化 function
  277. */
  278. init = function () {
  279. var saCusBtns = [];
  280. if (sAction === 'Add') {
  281. saCusBtns = [{
  282. id: 'Toolbar_Imp',
  283. value: 'common.Toolbar_Imp'// ╠common.Toolbar_Imp⇒匯入╣
  284. }];
  285. }
  286. commonInit({
  287. PrgId: sProgramId,
  288. ButtonHandler: fnButtonHandler,
  289. Buttons: saCusBtns,
  290. GoTop: true
  291. });
  292. oValidator = $("#form_main").validate();
  293. $.whenArray([
  294. fnSetDeptDrop($('#Handle_DeptID,#ShareType')),
  295. fnSetUserDrop([
  296. {
  297. ShowId: true,
  298. Select: $('#Handle_Person'),
  299. Select2: true,
  300. Action: sAction,
  301. CallBack: function (data) {
  302. $('#lstLeft').html(createOptions(data, 'MemberID', 'MemberName', true))[0].remove(0);
  303. }
  304. }
  305. ]),
  306. fnSetArgDrop([
  307. {
  308. ArgClassID: 'Flow_Type',
  309. Select: $('#Flow_Type'),
  310. ShowId: true
  311. }
  312. ])])
  313. .done(function () {
  314. fnGet();
  315. });
  316. $('#Handle_DeptID').on('change', function () {
  317. fnSetHandle_PersonDrop(this.value, 1);
  318. });
  319. $('#Agent_Person').on('change', function () {
  320. oCurData.Agent_Person = this.value;
  321. });
  322. $('#ShareType').on('change', function () {
  323. fnSetHandle_PersonDrop(this.value, 2, true);
  324. });
  325. $('#btnToRight').click(function () {
  326. optionListMove($('#lstLeft'), $('#lstRight'));
  327. oCurData.ShareTo = fnGetRightOption();
  328. });
  329. $('#btnToLeft').click(function () {
  330. optionListMove($('#lstRight'), $('#lstLeft'));
  331. oCurData.ShareTo = fnGetRightOption();
  332. });
  333. $('.flowlink').on('click', function () {
  334. var oOption = {};
  335. oOption.SignedWay = this.id;
  336. oOption.Callback = function (data) {
  337. if (data.Users.length > 0) {
  338. var oFlow = {};
  339. if (data.FlowType === 'flow1') {
  340. $.each(data.Users, function (idx, user) {
  341. oFlow = {};
  342. oFlow.id = guid();
  343. oFlow.Order = saGridData.length + 1;
  344. oFlow.SignedWay = data.FlowType;
  345. oFlow.SignedMember = [{
  346. id: user.id,
  347. name: user.name,
  348. deptname: user.deptname,
  349. jobname: user.jobname
  350. }];
  351. saGridData.push(oFlow);
  352. });
  353. }
  354. else {
  355. var saUsers = [];
  356. $.each(data.Users, function (idx, user) {
  357. saUsers.push({
  358. id: user.id,
  359. name: user.name,
  360. deptname: user.deptname,
  361. jobname: user.jobname
  362. });
  363. });
  364. oFlow.id = guid();
  365. oFlow.Order = saGridData.length + 1;
  366. oFlow.SignedWay = data.FlowType;
  367. oFlow.SignedMember = saUsers;
  368. saGridData.push(oFlow);
  369. }
  370. saGridData = releaseGridList(saGridData);
  371. $("#jsGrid").jsGrid("loadData");
  372. }
  373. };
  374. oPenUserListPop(oOption);
  375. });
  376. $("#jsGrid").jsGrid({
  377. width: "100%",
  378. height: "auto",
  379. autoload: true,
  380. filtering: false,
  381. pageLoading: true,
  382. pageIndex: 1,
  383. pageSize: 10000,
  384. fields: [
  385. {
  386. name: "Order", title: 'common.Order', width: 50, align: "center",
  387. itemTemplate: function (val, item) {
  388. return val < 10 ? '0' + val : val;
  389. }
  390. },
  391. {
  392. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  393. itemTemplate: function (val, item) {
  394. return i18next.t('common.' + val);
  395. }
  396. },
  397. {
  398. type: "Icon", width: 50, align: "center",
  399. itemTemplate: function (val, item) {
  400. var oIcon = {
  401. flow1: '<img src="../../images/flow_check.gif">',
  402. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  403. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  404. flow4: '<img src="../../images/flow4.gif">'
  405. },
  406. sIcon = oIcon[item.SignedWay];
  407. if (item.Order !== saGridData.length) {
  408. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  409. }
  410. return sIcon;
  411. }
  412. },
  413. {
  414. name: "SignedMember", title: 'common.SignedMember', width: 500,
  415. itemTemplate: function (val, item) {
  416. return Enumerable.From(val).ToString(",", "$.name");
  417. }
  418. },
  419. {
  420. type: "control", title: 'common.Action', width: 200,
  421. itemTemplate: function (val, item) {
  422. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  423. class: 'glyphicon glyphicon-pencil',
  424. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  425. click: function () {
  426. var oOption = {};
  427. oOption.SignedWay = item.SignedWay;
  428. oOption.SignedMember = item.SignedMember;
  429. oOption.Callback = function (data) {
  430. if (data.Users.length > 0) {
  431. var oFlow = {};
  432. if (data.FlowType === 'flow1') {
  433. $.each(data.Users, function (idx, user) {
  434. oFlow = {};
  435. oFlow.id = guid();
  436. oFlow.Order = item.Order + idx;
  437. oFlow.SignedWay = data.FlowType;
  438. oFlow.SignedMember = [{
  439. id: user.id,
  440. name: user.name,
  441. deptname: user.deptname,
  442. jobname: user.jobname
  443. }];
  444. saGridData.insert(item.Order + idx, oFlow);
  445. });
  446. }
  447. else {
  448. var saUsers = [];
  449. $.each(data.Users, function (idx, user) {
  450. saUsers.push({
  451. id: user.id,
  452. name: user.name,
  453. deptname: user.deptname,
  454. jobname: user.jobname
  455. });
  456. });
  457. oFlow.id = guid();
  458. oFlow.Order = item.Order;
  459. oFlow.SignedWay = data.FlowType;
  460. oFlow.SignedMember = saUsers;
  461. saGridData.insert(item.Order, oFlow);
  462. }
  463. var iOrder = 1;
  464. $.each(saGridData, function (idx, _data) {
  465. if (item.id !== _data.id) {
  466. _data.Order = iOrder;
  467. iOrder++;
  468. }
  469. });
  470. saGridData = Enumerable.From(saGridData).Where(function (e) { return e.id !== item.id; }).ToArray();
  471. saGridData = releaseGridList(saGridData);
  472. $("#jsGrid").jsGrid("loadData");
  473. }
  474. };
  475. oPenUserListPop(oOption);
  476. }
  477. })),
  478. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  479. class: 'glyphicon glyphicon-trash',
  480. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  481. click: function () {
  482. var saNewList = Enumerable.From(saGridData).Where(function (e) { return e.id !== item.id; }).ToArray();
  483. saGridData = saNewList;
  484. $.each(saGridData, function (idx, _data) {
  485. _data.Order = idx + 1;
  486. });
  487. saGridData = releaseGridList(saGridData);
  488. $("#jsGrid").jsGrid("loadData");
  489. }
  490. }))];
  491. if (saGridData.length !== item.Order) {
  492. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  493. class: 'glyphicon glyphicon-arrow-down',
  494. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  495. click: function () {
  496. var sOrder = Enumerable.From(saGridData).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  497. iOrder = sOrder * 1;
  498. $.each(saGridData, function (idx, _data) {
  499. if (iOrder === _data.Order) {
  500. _data.Order++;
  501. }
  502. else if ((iOrder + 1) === _data.Order) {
  503. _data.Order--;
  504. }
  505. });
  506. saGridData = releaseGridList(saGridData);
  507. $("#jsGrid").jsGrid("loadData");
  508. }
  509. })));
  510. }
  511. else {
  512. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  513. }
  514. if (1 !== item.Order) {
  515. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  516. class: 'glyphicon glyphicon-arrow-up',
  517. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  518. click: function () {
  519. var sOrder = Enumerable.From(saGridData).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  520. iOrder = sOrder * 1;
  521. $.each(saGridData, function (idx, _data) {
  522. if (iOrder === _data.Order) {
  523. _data.Order--;
  524. }
  525. else if ((iOrder - 1) === _data.Order) {
  526. _data.Order++;
  527. }
  528. });
  529. saGridData = releaseGridList(saGridData);
  530. $("#jsGrid").jsGrid("loadData");
  531. }
  532. })));
  533. }
  534. return oBtns;
  535. }
  536. }
  537. ],
  538. controller: {
  539. loadData: function (args) {
  540. return {
  541. data: saGridData,
  542. itemsCount: saGridData.length //data.length
  543. };
  544. },
  545. insertItem: function (args) {
  546. },
  547. updateItem: function (args) {
  548. },
  549. deleteItem: function (args) {
  550. }
  551. },
  552. onInit: function (args) {
  553. oGrid = args.grid;
  554. }
  555. });
  556. };
  557. init();
  558. };
  559. require(['base', 'select2', 'jsgrid', 'common_eip', 'util'], fnPageInit);