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.

1096 lines
58 KiB

3 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: [], PayeeInfo: [] },
  10. oForm = $('#form_main'),
  11. oGrid = null,
  12. oValidator = null,
  13. sOptionHtml_PrjCode = '',
  14. sOptionHtml_Currency = '',
  15. sOptionHtml_Bills = '',
  16. sOptionHtml_ComplaintNumber = '',
  17. oAddItem = {},
  18. saUsers = [],
  19. /**
  20. * 獲取資料
  21. */
  22. fnGet = function () {
  23. if (sDataId) {
  24. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  25. {
  26. Guid: sDataId
  27. },
  28. function (res) {
  29. if (res.RESULT) {
  30. var oRes = res.DATA.rel;
  31. oCurData = oRes;
  32. oCurData.PayeeInfo = $.parseJSON(oCurData.PayeeInfo);
  33. oCurData.RemittanceInformation = $.parseJSON(oCurData.RemittanceInformation);
  34. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  35. setFormVal(oForm, oRes);
  36. $('.Applicant').text(oCurData.ApplicantName + '(' + oCurData.Applicant + ') ' + oCurData.DeptName);
  37. $('#PayeeCode').text(oCurData.CustomerNO);
  38. fnGetUploadFiles(oCurData.Guid, fnUpload);
  39. if (oCurData.Handle_DeptID) {
  40. fnSetUserDrop([
  41. {
  42. Select: $('#Handle_Person'),
  43. DepartmentID: oCurData.Handle_DeptID,
  44. ShowId: true,
  45. Select2: true,
  46. Action: sAction,
  47. DefultVal: oCurData.Handle_Person
  48. }
  49. ]);
  50. }
  51. if (oCurData.Flows_Lock === 'Y') {
  52. $(".checkordertoolbox").hide();
  53. }
  54. else {
  55. $(".checkordertoolbox").show();
  56. }
  57. if (oCurData.Handle_Lock === 'Y') {
  58. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  59. }
  60. else {
  61. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  62. }
  63. $("#jsGrid").jsGrid("loadData");
  64. $("#jsGrid1").jsGrid("loadData");
  65. setNameById().done(function () {
  66. getPageVal();//緩存頁面值,用於清除
  67. });
  68. }
  69. });
  70. }
  71. else {
  72. $('.Applicant').text(parent.UserInfo.MemberName + '(' + parent.UserInfo.MemberID + ') ' + parent.UserInfo.DepartmentName);
  73. $('#Applicant').val(parent.UserInfo.MemberID);
  74. oCurData.PayeeInfo = [];
  75. oCurData.CheckOrder = [];
  76. oCurData.Guid = guid();
  77. fnUpload();
  78. return $.Deferred().resolve().promise();
  79. }
  80. },
  81. /**
  82. * 新增資料
  83. * @param {String} sFlag 新增或儲存後新增
  84. */
  85. fnAdd = function (flag) {
  86. var data = getFormSerialize(oForm);
  87. data = packParams(data);
  88. data.OrgID = parent.OrgID;
  89. data.Guid = oCurData.Guid;
  90. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|IAC|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  91. data.CheckFlows = fnCheckFlows(oCurData, false, true, saUsers);
  92. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  93. data.PayeeInfo = JSON.stringify(oCurData.PayeeInfo);
  94. data.RemittanceInformation = JSON.stringify(data.RemittanceInformation);
  95. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  96. data.Status = 'A';
  97. data.IsHandled = 'N';
  98. data.PayeeType = 'C';
  99. data.Inspectors = '';
  100. data.Reminders = '';
  101. data.Flows_Lock = oCurData.Flows_Lock;
  102. data.Handle_Lock = oCurData.Handle_Lock;
  103. data.PayeeName = $('#Payee option:selected').text();
  104. if (data.PaymentType === 'A') {
  105. delete data.PaymentTime;
  106. }
  107. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  108. Params: {
  109. invoiceapplyinfo: data
  110. }
  111. }, function (res) {
  112. if (res.d > 0) {
  113. bRequestStorage = false;
  114. if (flag == 'add') {
  115. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Save_Success⇒新增成功╣
  116. }
  117. else {
  118. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  119. }
  120. }
  121. else {
  122. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  123. }
  124. }, function () {
  125. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  126. });
  127. },
  128. /**
  129. * 修改資料
  130. * @param {Boolean} balert 是否提示
  131. */
  132. fnUpd = function (balert) {
  133. var data = getFormSerialize(oForm);
  134. data = packParams(data, 'upd');
  135. data.CheckFlows = fnCheckFlows(oCurData, false, true, saUsers);
  136. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  137. data.PayeeInfo = JSON.stringify(oCurData.PayeeInfo);
  138. data.RemittanceInformation = JSON.stringify(data.RemittanceInformation);
  139. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  140. data.Flows_Lock = oCurData.Flows_Lock;
  141. data.Handle_Lock = oCurData.Handle_Lock;
  142. data.PayeeName = $('#Payee option:selected').text();
  143. if (data.PaymentType === 'A') {
  144. delete data.PaymentTime;
  145. }
  146. return CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  147. Params: {
  148. invoiceapplyinfo: {
  149. values: data,
  150. keys: { Guid: sDataId }
  151. }
  152. }
  153. }, function (res) {
  154. if (res.d > 0) {
  155. if (!balert) {
  156. bRequestStorage = false;
  157. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  158. if (window.bLeavePage) {
  159. setTimeout(function () {
  160. pageLeave();
  161. }, 1000);
  162. }
  163. }
  164. }
  165. else {
  166. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  167. }
  168. }, function () {
  169. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  170. });
  171. },
  172. /**
  173. * 資料刪除
  174. */
  175. fnDel = function () {
  176. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  177. Params: {
  178. invoiceapplyinfo: {
  179. Guid: sDataId
  180. }
  181. }
  182. }, function (res) {
  183. if (res.d > 0) {
  184. DelTask(sDataId);
  185. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  186. }
  187. else {
  188. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  189. }
  190. }, function () {
  191. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  192. });
  193. },
  194. /**
  195. * 設定受款人下拉選單
  196. */
  197. setPayeeDrop = function () {
  198. return g_api.ConnectLite(Service.sys, 'GetCustomerlist', {}, function (res) {
  199. if (res.RESULT) {
  200. var saPayee = res.DATA.rel;
  201. if (saPayee.length > 0) {
  202. $('#Payee').html(createOptions(saPayee, 'id', 'text')).change(function () {
  203. var sId = this.value,
  204. oPayee = $.grep(saPayee, function (item) { return item.id === sId; })[0];
  205. $('#PayeeCode').text(oPayee.CusNO);
  206. });
  207. select2Init($('#Payee').parent());
  208. }
  209. }
  210. });
  211. },
  212. /**
  213. * 上傳附件
  214. * @param {Array} files 上傳的文件
  215. */
  216. fnUpload = function (files) {
  217. var option = {};
  218. option.input = $('#fileInput');
  219. option.theme = 'dragdropbox';
  220. option.folder = 'InvoiceApplyForCustomer';
  221. option.type = 'list';
  222. option.parentid = oCurData.Guid;
  223. if (files) {
  224. option.files = files;
  225. }
  226. fnUploadRegister(option);
  227. },
  228. /**
  229. * 提交簽呈
  230. */
  231. fnSubmitPetition = function () {
  232. g_api.ConnectLite(sProgramId, 'InvoiceApplyForCustomerToAudit', {
  233. guid: oCurData.Guid
  234. }, function (res) {
  235. if (res.RESULT) {
  236. showMsgAndGo(i18next.t("message.ToAudit_Success"), sViewPrgId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.ToAudit_Success⇒提交審核成功╣
  237. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  238. }
  239. else {
  240. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  241. }
  242. }, function () {
  243. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  244. });
  245. },
  246. /**
  247. * 提交費用項目
  248. * TETG以TWD為主其他幣別為輔
  249. * SG以RMB為主其他幣別為輔
  250. */
  251. fnSumPayeeInfo = function () {
  252. //TE、TG以TWD為主,其他幣別為輔。
  253. //SG以RMB為主,其他幣別為輔。
  254. var iTotal_MainCurrency = 0;
  255. var iTotal_SecondCurrency = 0;
  256. var MainRoundingPoint = 0;
  257. var MainCurrency = 'NTD';
  258. var SecondCurrency = 'NTD';
  259. var SecondRoundingPoint = 2;
  260. if (parent.OrgID === 'SG') {
  261. MainCurrency = 'RMB';
  262. SecondCurrency = 'RMB';
  263. MainRoundingPoint = 2;
  264. }
  265. $.each(oCurData.PayeeInfo, function (idx, info) {
  266. let PayeeAmount = parseFloat((info.Amount || '0').toString().replaceAll(',', ''));
  267. if (info.Currency === MainCurrency) {
  268. iTotal_MainCurrency += PayeeAmount;
  269. }
  270. else {
  271. iTotal_SecondCurrency += PayeeAmount;
  272. SecondCurrency = info.Currency;
  273. if (info.Currency === 'NTD') {
  274. SecondRoundingPoint = 0;
  275. }
  276. }
  277. });
  278. $('#RemittanceInformation_TotalCurrencyTW').val(MainCurrency);
  279. $('#RemittanceInformation_InvoiceApplyTotalTW').val(fMoney(iTotal_MainCurrency, MainRoundingPoint, MainCurrency));
  280. $('#RemittanceInformation_TotalCurrency').val(SecondCurrency);
  281. $('#RemittanceInformation_InvoiceApplyTotal').val(fMoney(iTotal_SecondCurrency, SecondRoundingPoint, ''));
  282. },
  283. /**
  284. * 通過帳單號碼抓去專案代號
  285. * @param {HTMLElement} dom select控件
  286. */
  287. fnGetPrjCodeByBillNO = function (dom) {
  288. var sBillNO = dom.value;
  289. g_api.ConnectLite(Service.eip, 'GetPrjCodeByBillNO', {
  290. BillNO: sBillNO
  291. }, function (res) {
  292. if (res.RESULT) {
  293. var oRes = res.DATA.rel;
  294. $(dom).parent().next().next().find('select').val(oRes.PrjCode).trigger("change");
  295. }
  296. });
  297. },
  298. /**
  299. * 抓取客訴編號
  300. * @param {string} Guid
  301. */
  302. fnGetComplaintNumber = function (o) {
  303. g_api.ConnectLite('CrmCom', 'GetComplaintNumber', {
  304. Guid: o.Guid || ''
  305. }, function (res) {
  306. if (res.RESULT) {
  307. var oRes = res.DATA.rel;
  308. if (o.CallBack && typeof o.CallBack === 'function') {
  309. o.CallBack(oRes);
  310. }
  311. }
  312. });
  313. },
  314. /**
  315. * ToolBar 按鈕事件 function
  316. * @param {Object}inst 按鈕物件對象
  317. * @param {Object} e 事件對象
  318. */
  319. fnButtonHandler = function (inst, e) {
  320. var sId = inst.id;
  321. switch (sId) {
  322. case "Toolbar_Qry":
  323. break;
  324. case "Toolbar_Save":
  325. if (!$("#form_main").valid()) {
  326. oValidator.focusInvalid();
  327. return false;
  328. }
  329. if (sAction === 'Add') {
  330. fnAdd('add');
  331. }
  332. else {
  333. fnUpd();
  334. }
  335. break;
  336. case "Toolbar_ReAdd":
  337. if (!$("#form_main").valid()) {
  338. oValidator.focusInvalid();
  339. return false;
  340. }
  341. fnAdd('readd');
  342. break;
  343. case "Toolbar_Clear":
  344. clearPageVal();
  345. break;
  346. case "Toolbar_Leave":
  347. pageLeave();
  348. break;
  349. case "Toolbar_Add":
  350. break;
  351. case "Toolbar_Upd":
  352. break;
  353. case "Toolbar_Copy":
  354. break;
  355. case "Toolbar_Petition":
  356. if (!$("#form_main").valid()) {
  357. oValidator.focusInvalid();
  358. return false;
  359. }
  360. fnUpd(true).done(function () {
  361. fnSubmitPetition();
  362. });
  363. break;
  364. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  365. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  366. fnDel();
  367. layer.close(index);
  368. });
  369. break;
  370. default:
  371. alert("No handle '" + sId + "'");
  372. break;
  373. }
  374. },
  375. /**
  376. * 初始化 function
  377. */
  378. init = function () {
  379. var saCusBtns = null;
  380. if (sAction === 'Upd') {
  381. saCusBtns = [{
  382. id: 'Toolbar_Petition',
  383. value: 'common.SubmitPetition'// ╠common.SubmitPetition⇒提交簽呈╣
  384. }];
  385. }
  386. commonInit({
  387. PrgId: sProgramId,
  388. ButtonHandler: fnButtonHandler,
  389. Buttons: saCusBtns,
  390. GoTop: true
  391. });
  392. oValidator = $("#form_main").validate();
  393. $.whenArray([
  394. fnSetDeptDrop($('#Handle_DeptID')),
  395. fnGetBills({
  396. CallBack: function (data) {
  397. sOptionHtml_Bills = createOptions(data, 'BillNO', 'BillNO');
  398. }
  399. }),
  400. fnGetComplaintNumber({
  401. CallBack: function (data) {
  402. sOptionHtml_ComplaintNumber = createOptions(data, 'ComplaintNumber', 'ComplaintNumber');
  403. }
  404. }),
  405. setPayeeDrop(),
  406. fnSetFlowDrop({
  407. Flow_Type: parent.SysSet.Eip_006,
  408. ShareTo: parent.UserID,
  409. CallBack: function (data) {
  410. $.each(data, function (idx, item) {
  411. var saFlows = $.parseJSON(item.Flows),
  412. saFlowsText = [],
  413. sFlowsText = '';
  414. $.each(saFlows, function (idx, flow) {
  415. var sFlowType = i18next.t('common.' + flow.SignedWay);
  416. if (flow.SignedWay !== 'flow1') {
  417. saFlowsText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  418. }
  419. else {
  420. saFlowsText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  421. }
  422. });
  423. sFlowsText = saFlowsText.join(' → ');
  424. item.text = item.Flow_Name + ' - ' + (sFlowsText.length > 60 ? sFlowsText.substr(0, 60) + '...' : sFlowsText);
  425. });
  426. $('#FlowId').html(createOptions(data, 'Guid', 'text')).on('change', function () {
  427. var sFlowId = this.value;
  428. if (sFlowId) {
  429. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  430. Type: '',
  431. Params: {
  432. checkflow: {
  433. Guid: sFlowId
  434. }
  435. }
  436. }, function (res) {
  437. if (res.d) {
  438. var oRes = $.parseJSON(res.d);
  439. oRes.Flows = $.parseJSON(oRes.Flows);
  440. oCurData.CheckOrder = oRes.Flows;
  441. oCurData.Flows_Lock = oRes.Flows_Lock;
  442. oCurData.Handle_Lock = oRes.Handle_Lock;
  443. //選擇新流程,變更現有經辦人(Handle_Person)與經辦部門(Handle_DeptID)。
  444. //因為新增或者修改是fnHandleFlows(oCurData,saUsers); //Mark 20190617
  445. oCurData.Handle_Person = oRes.Handle_Person;
  446. oCurData.Handle_DeptID = oRes.Handle_DeptID;
  447. oCurData.Handle_PersonName = oRes.Handle_PersonName;
  448. //設置經辦部門
  449. $("#Handle_DeptID").val(oRes.Handle_DeptID);
  450. //設置經辦人員
  451. fnSetUserDrop([
  452. {
  453. Select: $('#Handle_Person'),
  454. DepartmentID: oRes.Handle_DeptID,
  455. ShowId: true,
  456. Select2: true,
  457. Action: sAction,
  458. DefultVal: oRes.Handle_Person
  459. }
  460. ]);
  461. //$("#Handle_Person").val(oRes.Handle_Person).trigger('change');
  462. if (oRes.Flows_Lock === 'Y') {
  463. $(".checkordertoolbox").hide();
  464. }
  465. else {
  466. $(".checkordertoolbox").show();
  467. }
  468. if (oRes.Handle_Lock === 'Y') {
  469. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  470. }
  471. else {
  472. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  473. }
  474. $("#jsGrid").jsGrid("loadData");
  475. }
  476. });
  477. }
  478. else {
  479. oCurData.CheckOrder = [];
  480. $(".checkordertoolbox").hide();
  481. $("#jsGrid").jsGrid("loadData");
  482. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  483. }
  484. });
  485. }
  486. }),
  487. fnSetEpoDrop({
  488. CallBack: function (data) {
  489. sOptionHtml_PrjCode = createOptions(data, 'ExhibitionCode', 'ExhibitioShotName_TW');
  490. }
  491. }),
  492. fnSetUserDrop([
  493. {
  494. ShowId: true,
  495. Select: $('#Handle_Person'),
  496. Select2: true,
  497. Action: sAction,
  498. CallBack: function (data) {
  499. saUsers = data;
  500. }
  501. }
  502. ]),
  503. fnSetArgDrop([
  504. {
  505. ArgClassID: 'Currency',
  506. CallBack: function (data) {
  507. sOptionHtml_Currency = createOptions(data, 'id', 'id');
  508. if (parent.OrgID === 'SG') {
  509. $('#RemittanceInformation_TotalCurrencyTW,#RemittanceInformation_TotalCurrency').html(sOptionHtml_Currency).val('RMB')[0].remove(0);
  510. }
  511. else {
  512. $('#RemittanceInformation_TotalCurrencyTW,#RemittanceInformation_TotalCurrency').html(sOptionHtml_Currency).val('NTD')[0].remove(0);
  513. }
  514. }
  515. }
  516. ])])
  517. .done(function () {
  518. fnGet();
  519. $("#jsGrid1").jsGrid({
  520. width: "100%",
  521. height: "auto",
  522. autoload: true,
  523. filtering: false,
  524. inserting: true,
  525. editing: true,
  526. pageLoading: true,
  527. confirmDeleting: true,
  528. invalidMessage: i18next.t('common.InvalidData'),// ╠common.InvalidData⇒输入的数据无效!╣
  529. deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
  530. pageIndex: 1,
  531. pageSize: 10000,
  532. fields: [
  533. {// ╠common.FeeItemName⇒費用名稱╣
  534. name: "FeeItemName", title: 'common.FeeItemName', width: 150, type: "text", validate: { validator: 'required', message: i18next.t('common.FeeItemName_required') },
  535. insertTemplate: function (val, item) {
  536. var oControl = $('<input />', {
  537. class: "form-control w100p"
  538. });
  539. return this.insertControl = oControl;
  540. },
  541. insertValue: function () {
  542. return this.insertControl.val();
  543. },
  544. editTemplate: function (val, item) {
  545. var oControl = $('<input />', {
  546. class: "form-control w100p",
  547. value: val
  548. });
  549. return this.editControl = oControl;
  550. },
  551. editValue: function () {
  552. return this.editControl.val();
  553. }
  554. },
  555. {
  556. name: "BillNO", title: 'common.BillNO', width: 140, type: "text",
  557. insertTemplate: function (val, item) {
  558. var oControl = $('<select />', {
  559. class: "form-control w50p",
  560. html: sOptionHtml_Bills,
  561. change: function () {
  562. fnGetPrjCodeByBillNO(this);
  563. }
  564. });
  565. setTimeout(function () {
  566. oControl.select2({ width: '180px' });
  567. }, 100);
  568. return this.insertControl = oControl;
  569. },
  570. insertValue: function () {
  571. return this.insertControl.val();
  572. },
  573. editTemplate: function (val, item) {
  574. var oControl = $('<select />', {
  575. class: "form-control w50p",
  576. html: sOptionHtml_Bills,
  577. change: function () {
  578. fnGetPrjCodeByBillNO(this);
  579. }
  580. });
  581. setTimeout(function () {
  582. oControl.select2({ width: '180px' });
  583. }, 100);
  584. return this.editControl = oControl.val(item.BillNO);
  585. },
  586. editValue: function () {
  587. return this.editControl.val();
  588. }
  589. },
  590. {
  591. name: "ComplaintNumber", title: '客訴編號', width: 140, type: "text",
  592. itemTemplate: function (val, item) {
  593. return val + (!item.ComplaintNumber ? '' : '(' + item.ComplaintNumber + ')');
  594. },
  595. insertTemplate: function (val, item) {
  596. var oControl = $('<select />', {
  597. class: "form-control w80p",
  598. html: sOptionHtml_ComplaintNumber
  599. });
  600. setTimeout(function () {
  601. oControl.select2({ width: '180px' });
  602. }, 1000);
  603. return this.insertControl = oControl;
  604. },
  605. insertValue: function () {
  606. var SelectedOption = this.insertControl.find('option:selected');
  607. if (this.insertControl.val() && SelectedOption.val()) {
  608. oAddItem.ComplaintNumber = SelectedOption.text();
  609. }
  610. else {
  611. oAddItem.ComplaintNumber = '';
  612. }
  613. return this.insertControl.val();
  614. },
  615. editTemplate: function (val, item) {
  616. var oControl = $('<select />', {
  617. class: "form-control w80p",
  618. html: sOptionHtml_ComplaintNumber,
  619. change: function () {
  620. var SelectedOption = $(this).find('option:selected');
  621. if (SelectedOption.val()) {
  622. item.ComplaintNumber = SelectedOption.text();
  623. }
  624. else {
  625. item.ComplaintNumber = '';
  626. }
  627. }
  628. });
  629. setTimeout(function () {
  630. oControl.select2({ width: '180px' });
  631. }, 100);
  632. return this.editControl = oControl.val(item.ComplaintNumber);
  633. },
  634. editValue: function () {
  635. return this.editControl.val();
  636. }
  637. },
  638. {
  639. name: "PrjCode", title: 'common.PrjCode', width: 140, type: "text",
  640. itemTemplate: function (val, item) {
  641. return val + (!item.PrjName ? '' : '(' + item.PrjName + ')');
  642. },
  643. insertTemplate: function (val, item) {
  644. var oControl = $('<select />', {
  645. class: "form-control w80p",
  646. html: sOptionHtml_PrjCode
  647. });
  648. setTimeout(function () {
  649. oControl.select2({ width: '180px' });
  650. }, 1000);
  651. return this.insertControl = oControl;
  652. },
  653. insertValue: function () {
  654. var SelectedOption = this.insertControl.find('option:selected');
  655. if (this.insertControl.val() && SelectedOption.val()) {
  656. oAddItem.PrjName = SelectedOption.text();
  657. }
  658. else {
  659. oAddItem.PrjName = '';
  660. }
  661. return this.insertControl.val();
  662. },
  663. editTemplate: function (val, item) {
  664. var oControl = $('<select />', {
  665. class: "form-control w80p",
  666. html: sOptionHtml_PrjCode,
  667. change: function () {
  668. var SelectedOption = $(this).find('option:selected');
  669. if (SelectedOption.val()) {
  670. item.PrjName = SelectedOption.text();
  671. }
  672. else {
  673. item.PrjName = '';
  674. }
  675. }
  676. });
  677. setTimeout(function () {
  678. oControl.select2({ width: '180px' });
  679. }, 100);
  680. return this.editControl = oControl.val(item.PrjCode);
  681. },
  682. editValue: function () {
  683. return this.editControl.val();
  684. }
  685. },
  686. {
  687. name: "Currency", title: 'common.Financial_Currency', width: 60, type: "text", validate: { validator: 'required', message: i18next.t('common.Currency_required') },// ╠common.Currency_required⇒請選擇幣別╣
  688. insertTemplate: function (val, item) {
  689. var oControl = $('<select />', {
  690. class: "form-control w100p",
  691. html: sOptionHtml_Currency
  692. });
  693. return this.insertControl = oControl;
  694. },
  695. insertValue: function () {
  696. return this.insertControl.val();
  697. },
  698. editTemplate: function (val, item) {
  699. var oControl = $('<select />', {
  700. class: "form-control w100p",
  701. html: sOptionHtml_Currency
  702. });
  703. return this.editControl = oControl.val(item.Currency);
  704. },
  705. editValue: function () {
  706. return this.editControl.val();
  707. }
  708. },
  709. {
  710. name: "Amount", title: 'common.Financial_Amount', width: 70, type: "text", align: "right", validate: { validator: 'required', message: i18next.t('common.Amount_required') },
  711. itemTemplate: function (val, item) {
  712. return val.toString().toMoney();
  713. },
  714. insertTemplate: function (val, item) {
  715. var oControl = $('<input />', {
  716. class: "form-control w100p",
  717. 'data-type': 'int',
  718. 'data-name': 'int',
  719. value: val
  720. });
  721. moneyInput(oControl, 2, true);
  722. return this.insertControl = oControl;
  723. },
  724. insertValue: function () {
  725. if (this._grid.fields[3].insertControl.val() == 'NTD') {
  726. let AmountStr = this.insertControl.val().replaceAll(',', '');
  727. let PositiveInt = parseInt(AmountStr);
  728. this.insertControl.val(PositiveInt);
  729. this.insertControl[0].dataset.value = PositiveInt;
  730. }
  731. return this.insertControl.attr('data-value');
  732. },
  733. editTemplate: function (val, item) {
  734. var oControl = $('<input />', {
  735. class: "form-control w100p",
  736. 'data-type': 'int',
  737. 'data-name': 'int',
  738. value: val
  739. });
  740. moneyInput(oControl, 2, true);
  741. return this.editControl = oControl.val(val);
  742. },
  743. editValue: function () {
  744. if (this._grid.fields[3].editControl.val() == 'NTD') {
  745. let AmountStr = this.editControl.val().replaceAll(',', '');
  746. let PositiveInt = parseInt(AmountStr);
  747. this.editControl.val(PositiveInt);
  748. this.editControl[0].dataset.value = PositiveInt;
  749. }
  750. return this.editControl.attr('data-value');
  751. }
  752. },
  753. {
  754. type: "control", width: 50
  755. }
  756. ],
  757. controller: {
  758. loadData: function (args) {
  759. return {
  760. data: oCurData.PayeeInfo,
  761. itemsCount: oCurData.PayeeInfo.length //data.length
  762. };
  763. },
  764. insertItem: function (args) {
  765. args.guid = guid();
  766. args.Index = oCurData.PayeeInfo.length + 1;
  767. args.PrjName = oAddItem.PrjName;
  768. oCurData.PayeeInfo.push(args);
  769. fnSumPayeeInfo();
  770. },
  771. updateItem: function (args) {
  772. $.each(oCurData.PayeeInfo, function (idx, _data) {
  773. if (_data.guid === args.guid) {
  774. _data.Amount = args.Amount;
  775. _data.BillNO = args.BillNO;
  776. _data.Currency = args.Currency;
  777. _data.FeeItemName = args.FeeItemName;
  778. _data.PrjCode = args.PrjCode;
  779. _data.PrjName = args.PrjName;
  780. }
  781. });
  782. fnSumPayeeInfo();
  783. },
  784. deleteItem: function (args) {
  785. var saPayeeInfo = [];
  786. $.each(oCurData.PayeeInfo, function (idx, _data) {
  787. if (_data.guid !== args.guid) {
  788. saPayeeInfo.push(_data);
  789. }
  790. });
  791. $.each(saPayeeInfo, function (idx, _data) {
  792. _data.Index = idx + 1;
  793. });
  794. oCurData.PayeeInfo = saPayeeInfo;
  795. fnSumPayeeInfo();
  796. }
  797. },
  798. onInit: function (args) {
  799. oGrid = args.grid;
  800. }
  801. });
  802. });
  803. $('#Handle_DeptID').on('change', function () {
  804. fnSetUserDrop([
  805. {
  806. Select: $('#Handle_Person'),
  807. DepartmentID: this.value,
  808. ShowId: true,
  809. Select2: true,
  810. Action: sAction
  811. }
  812. ]);
  813. });
  814. $('#Agent_Person').on('change', function () {
  815. oCurData.Agent_Person = this.value;
  816. });
  817. $('[name="PaymentType"]').on('click', function () {
  818. if (this.value === 'A') {
  819. $('#PaymentTime').removeAttr('required');
  820. }
  821. else {
  822. $('#PaymentTime').attr('required', true);
  823. }
  824. });
  825. $('.flowlink').on('click', function () {
  826. var oOption = {};
  827. oOption.SignedWay = this.id;
  828. oOption.Callback = function (data) {
  829. if (data.Users.length > 0) {
  830. var oFlow = {};
  831. if (data.FlowType === 'flow1') {
  832. $.each(data.Users, function (idx, user) {
  833. oFlow = {};
  834. oFlow.id = guid();
  835. oFlow.Order = oCurData.CheckOrder.length + 1;
  836. oFlow.SignedWay = data.FlowType;
  837. oFlow.SignedMember = [{
  838. id: user.id,
  839. name: user.name,
  840. deptname: user.deptname,
  841. jobname: user.jobname
  842. }];
  843. oCurData.CheckOrder.push(oFlow);
  844. });
  845. }
  846. else {
  847. var saSignedMember = [];
  848. $.each(data.Users, function (idx, user) {
  849. saSignedMember.push({
  850. id: user.id,
  851. name: user.name,
  852. deptname: user.deptname,
  853. jobname: user.jobname
  854. });
  855. });
  856. oFlow.id = guid();
  857. oFlow.Order = oCurData.CheckOrder.length + 1;
  858. oFlow.SignedWay = data.FlowType;
  859. oFlow.SignedMember = saSignedMember;
  860. oCurData.CheckOrder.push(oFlow);
  861. }
  862. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  863. $("#jsGrid").jsGrid("loadData");
  864. }
  865. };
  866. oPenUserListPop(oOption);
  867. });
  868. $("#jsGrid").jsGrid({
  869. width: "100%",
  870. height: "auto",
  871. autoload: true,
  872. filtering: false,
  873. pageLoading: true,
  874. pageIndex: 1,
  875. pageSize: 10000,
  876. fields: [
  877. {
  878. name: "Order", title: 'common.Order', width: 50, align: "center",
  879. itemTemplate: function (val, item) {
  880. return val < 10 ? '0' + val : val;
  881. }
  882. },
  883. {
  884. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  885. itemTemplate: function (val, item) {
  886. return i18next.t('common.' + val);
  887. }
  888. },
  889. {
  890. type: "Icon", width: 50, align: "center",
  891. itemTemplate: function (val, item) {
  892. var oIcon = {
  893. flow1: '<img src="../../images/flow_check.gif">',
  894. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  895. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  896. flow4: '<img src="../../images/flow4.gif">'
  897. },
  898. sIcon = oIcon[item.SignedWay];
  899. if (item.Order !== oCurData.CheckOrder.length) {
  900. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  901. }
  902. return sIcon;
  903. }
  904. },
  905. {
  906. name: "SignedMember", title: 'common.SignedMember', width: 500,
  907. itemTemplate: function (val, item) {
  908. return Enumerable.From(val).ToString(",", "$.name");
  909. }
  910. },
  911. {
  912. type: "control", title: 'common.Action', width: 200,
  913. itemTemplate: function (val, item) {
  914. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  915. class: 'glyphicon glyphicon-pencil' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  916. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  917. click: function () {
  918. if ($(this).hasClass('disabled')) { return false; }
  919. var oOption = {};
  920. oOption.SignedWay = item.SignedWay;
  921. oOption.SignedMember = item.SignedMember;
  922. oOption.Callback = function (data) {
  923. if (data.Users.length > 0) {
  924. var oFlow = {};
  925. if (data.FlowType === 'flow1') {
  926. $.each(data.Users, function (idx, user) {
  927. var oFlow = {};
  928. oFlow.id = guid();
  929. oFlow.Order = item.Order + idx;
  930. oFlow.SignedWay = data.FlowType;
  931. oFlow.SignedMember = [{
  932. id: user.id,
  933. name: user.name,
  934. deptname: user.deptname,
  935. jobname: user.jobname
  936. }];
  937. oCurData.CheckOrder.insert(item.Order + idx, oFlow);
  938. });
  939. }
  940. else {
  941. var saSignedMember = [];
  942. $.each(data.Users, function (idx, user) {
  943. saSignedMember.push({
  944. id: user.id,
  945. name: user.name,
  946. deptname: user.deptname,
  947. jobname: user.jobname
  948. });
  949. });
  950. oFlow.id = guid();
  951. oFlow.Order = item.Order;
  952. oFlow.SignedWay = data.FlowType;
  953. oFlow.SignedMember = saSignedMember;
  954. oCurData.CheckOrder.insert(item.Order, oFlow);
  955. }
  956. var iOrder = 1;
  957. $.each(oCurData.CheckOrder, function (idx, _data) {
  958. if (item.id !== _data.id) {
  959. _data.Order = iOrder;
  960. iOrder++;
  961. }
  962. });
  963. oCurData.CheckOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  964. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  965. $("#jsGrid").jsGrid("loadData");
  966. }
  967. };
  968. oPenUserListPop(oOption);
  969. }
  970. })),
  971. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  972. class: 'glyphicon glyphicon-trash' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  973. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  974. click: function () {
  975. if ($(this).hasClass('disabled')) { return false; }
  976. var saNewList = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  977. oCurData.CheckOrder = saNewList;
  978. $.each(oCurData.CheckOrder, function (idx, _data) {
  979. _data.Order = idx + 1;
  980. });
  981. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  982. $("#jsGrid").jsGrid("loadData");
  983. }
  984. }))];
  985. if (oCurData.CheckOrder.length !== item.Order) {
  986. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  987. class: 'glyphicon glyphicon-arrow-down' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  988. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  989. click: function () {
  990. if ($(this).hasClass('disabled')) { return false; }
  991. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  992. iOrder = sOrder * 1;
  993. $.each(oCurData.CheckOrder, function (idx, _data) {
  994. if (iOrder === _data.Order) {
  995. _data.Order++;
  996. }
  997. else if ((iOrder + 1) === _data.Order) {
  998. _data.Order--;
  999. }
  1000. });
  1001. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  1002. $("#jsGrid").jsGrid("loadData");
  1003. }
  1004. })));
  1005. }
  1006. else {
  1007. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  1008. }
  1009. if (1 !== item.Order) {
  1010. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  1011. class: 'glyphicon glyphicon-arrow-up' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  1012. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  1013. click: function () {
  1014. if ($(this).hasClass('disabled')) { return false; }
  1015. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  1016. iOrder = sOrder * 1;
  1017. $.each(oCurData.CheckOrder, function (idx, _data) {
  1018. if (iOrder === _data.Order) {
  1019. _data.Order--;
  1020. }
  1021. else if ((iOrder - 1) === _data.Order) {
  1022. _data.Order++;
  1023. }
  1024. });
  1025. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  1026. $("#jsGrid").jsGrid("loadData");
  1027. }
  1028. })));
  1029. }
  1030. return oBtns;
  1031. }
  1032. }
  1033. ],
  1034. controller: {
  1035. loadData: function (args) {
  1036. return {
  1037. data: oCurData.CheckOrder,
  1038. itemsCount: oCurData.CheckOrder.length //data.length
  1039. };
  1040. },
  1041. insertItem: function (args) {
  1042. },
  1043. updateItem: function (args) {
  1044. },
  1045. deleteItem: function (args) {
  1046. }
  1047. }
  1048. });
  1049. };
  1050. init();
  1051. };
  1052. require(['base', 'select2', 'jsgrid', 'formatnumber', 'filer', 'common_eip', 'util'], fnPageInit);