352 lines
19 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. oGrid = null,
  4. fnPageInit = function () {
  5. var oForm = $('#form_main'),
  6. oBaseQueryPm = {
  7. pageIndex: 1,
  8. pageSize: parent.SysSet.GridRecords || 10,
  9. sortField: 'BillCreateDate',
  10. sortOrder: 'desc'
  11. },
  12. /**
  13. * 獲取資料
  14. * @param {Object} args 查詢條件參數
  15. * @return {Object} Ajax 物件
  16. */
  17. fnGetPro = function (args) {
  18. var oQueryPm = getFormSerialize(oForm);
  19. oQueryPm.BillStatus = !oQueryPm.BillStatus ? Enumerable.From($(':checkbox')).Select("x=>x.value").ToArray().join(',') : oQueryPm.BillStatus.join(',');
  20. $.extend(oQueryPm, oBaseQueryPm, args);
  21. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  22. return g_api.ConnectLite(sProgramId, 'QueryPage', oQueryPm, function (res) {
  23. var oRes = res.DATA.rel;
  24. if (args.Excel) {//匯出
  25. if (res.STATUSCODE != 200) {
  26. showMsg(res.MSG, 'error');
  27. }
  28. else {
  29. var oRes = res.DATA.rel;
  30. DownLoadFile(oRes);
  31. layer.close(args.Index);
  32. }
  33. }
  34. });
  35. },
  36. /**
  37. * 打開要匯出的pop選擇匯出類別
  38. */
  39. fnOpenPopToExcel = function () {
  40. layer.open({
  41. type: 1,
  42. title: i18next.t('common.DownLoadDocuments'),// ╠common.DownLoadDocuments⇒下載文檔╣
  43. area: ['300px', '160px'],//寬度
  44. shade: 0.75,//遮罩
  45. shadeClose: true,
  46. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  47. content: '<div class="pop-box">\
  48. <button type="button" data-i18n="ExhibitionImport_Upd.Quotation" id="BillList" class="btn-custom green">帳單資料</button>\
  49. <button type="button" data-i18n="common.BillAndPrice" id="BillAndPrice" class="btn-custom green">帳單成本金額</button>\
  50. </div>',//common.Quotation帳單資料common.BillAndPrice帳單成本金額
  51. success: function (layero, idx) {
  52. $('.pop-box :button').click(function () {
  53. var sToExcelType = this.id;
  54. fnGetPro({
  55. Excel: true,
  56. ExcelType: sToExcelType,
  57. Index: idx
  58. });
  59. });
  60. transLang(layero);
  61. }
  62. });
  63. },
  64. /**
  65. * ToolBar 按鈕事件 function
  66. * @param {Object}inst 按鈕物件對象
  67. * @param {Object} e 事件對象
  68. */
  69. fnButtonHandler = function (inst, e) {
  70. var sId = inst.id;
  71. switch (sId) {
  72. case "Toolbar_Qry":
  73. var iNum = $('#PerPageNum').val();
  74. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  75. cacheQueryCondition();
  76. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  77. break;
  78. case "Toolbar_Save":
  79. fnSave('add');
  80. break;
  81. case "Toolbar_ReAdd":
  82. break;
  83. case "Toolbar_Clear":
  84. clearPageVal();
  85. break;
  86. case "Toolbar_Leave":
  87. break;
  88. case "Toolbar_Add":
  89. break;
  90. case "Toolbar_Upd":
  91. break;
  92. case "Toolbar_Copy":
  93. break;
  94. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  95. break;
  96. case "Toolbar_Exp":
  97. if (oGrid.data.length === 0) {
  98. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  99. return false;
  100. }
  101. fnOpenPopToExcel();
  102. break;
  103. default:
  104. alert("No handle '" + sId + "'");
  105. break;
  106. }
  107. },
  108. /**
  109. * 頁面初始化
  110. */
  111. init = function () {
  112. commonInit({
  113. PrgId: sProgramId,
  114. ButtonHandler: fnButtonHandler,
  115. SearchBar: true
  116. });
  117. $('#SearchBetween').change(function () {
  118. var sValue = this.value;
  119. $(':checkbox[name="BillStatus[]"]').prop('checked', false).prop('disabled', true);
  120. if (sValue === '1') {
  121. //帳單時間
  122. //已審核,已銷帳,已過帳
  123. $(':checkbox[name="BillStatus[]"][value="2"],:checkbox[name="BillStatus[]"][value="4"],:checkbox[name="BillStatus[]"][value="5"]').prop('checked', true);
  124. }
  125. else if (sValue === '2') {
  126. //銷帳時間
  127. //已過帳
  128. $(':checkbox[name="BillStatus[]"][value="4"]').prop('checked', true);
  129. }
  130. else if (sValue === '3') {
  131. //帳單創建時間
  132. $(':checkbox[name="BillStatus[]"]').prop('checked', false).prop('disabled', false);
  133. }
  134. }).change();
  135. fnSetUserDrop([
  136. {
  137. Select: $('#ResponsiblePerson'),
  138. Select2: true,
  139. ShowId: true,
  140. CallBack: function (data) {
  141. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  142. $("#jsGrid").jsGrid({
  143. width: "100%",
  144. height: iHeight + "px",
  145. autoload: true,
  146. pageLoading: true,
  147. inserting: false,
  148. editing: false,
  149. sorting: true,
  150. paging: true,
  151. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  152. pageSize: parent.SysSet.GridRecords || 10,
  153. pageButtonCount: parent.SysSet.GridPages || 15,
  154. invalidMessage: '输入的数据无效!',
  155. confirmDeleting: true,
  156. deleteConfirm: "確定要刪除嗎?",
  157. pagePrevText: "<",
  158. pageNextText: ">",
  159. pageFirstText: "<<",
  160. pageLastText: ">>",
  161. rowClass: function (item) {
  162. var sClass = '';
  163. if (item.AuditVal === '6') {
  164. sClass = 'data-void';
  165. }
  166. return sClass;
  167. },
  168. onPageChanged: function (args) {
  169. cacheQueryCondition(args.pageIndex);
  170. },
  171. rowClick: function (args) {
  172. if (navigator.userAgent.match(/mobile/i)) {
  173. var sPrgId = args.item.BillType,
  174. sId = args.item.ParentId,
  175. sBillNO = args.item.BillNO,
  176. sIdName = 'ImportBillNO',
  177. sGoTab = '2';
  178. if (sPrgId === 'ExhibitionImport_Upd') {
  179. sGoTab = args.item.IsRetn === 'N' ? '3' : '9';
  180. }
  181. else if (sPrgId === 'ExhibitionExport_Upd') {
  182. sIdName = 'ExportBillNO';
  183. sGoTab = args.item.IsRetn === 'N' ? '3' : '5';
  184. }
  185. else if (sPrgId === 'OtherExhibitionTG_Upd') {
  186. sIdName = 'Guid';
  187. sGoTab = '3';
  188. }
  189. goToEdit(sPrgId, '?Action=Upd&GoTab=' + sGoTab + '&' + sIdName + '=' + sId + '&BillNO=' + sBillNO);
  190. }
  191. },
  192. rowDoubleClick: function (args) {
  193. var sPrgId = args.item.BillType,
  194. sId = args.item.ParentId,
  195. sBillNO = args.item.BillNO,
  196. sIdName = 'ImportBillNO',
  197. sGoTab = '2';
  198. if (sPrgId === 'ExhibitionImport_Upd') {
  199. sGoTab = args.item.IsRetn === 'N' ? '3' : '9';
  200. }
  201. else if (sPrgId === 'ExhibitionExport_Upd') {
  202. sIdName = 'ExportBillNO';
  203. sGoTab = args.item.IsRetn === 'N' ? '3' : '5';
  204. }
  205. else if (sPrgId === 'OtherExhibitionTG_Upd') {
  206. sIdName = 'Guid';
  207. sGoTab = '3';
  208. }
  209. parent.openPageTab(sPrgId, '?Action=Upd&GoTab=' + sGoTab + '&' + sIdName + '=' + sId + '&BillNO=' + sBillNO);
  210. },
  211. fields: [
  212. { name: "RowIndex", title: 'common.RowNumber', align: "center", type: "text", width: 50, sorting: false },
  213. {
  214. name: "BillNO", title: 'common.BillNO', align: "left", type: "text", width: 80
  215. },
  216. {
  217. name: "ExhibitioName", title: 'common.ExhibitionName', align: "left", type: "text", width: 150
  218. },
  219. {
  220. name: "PayerName", title: 'ExhibitionImport_Upd.Payer', align: "left", type: "text", width: 150
  221. },
  222. {
  223. name: "ResponsiblePersonName", title: 'common.ResponsiblePerson', align: "left", type: "text", width: 60
  224. },
  225. {
  226. name: "Currency", title: 'common.Financial_Currency', align: "left", type: "text", width: 50
  227. },
  228. {
  229. name: "ExchangeRate", title: 'common.ExchangeRate', align: "left", type: "text", width: 50
  230. },
  231. {
  232. name: "Advance", title: 'common.Financial_Advance', align: "right", type: "text", width: 60,
  233. itemTemplate: function (val, item) {
  234. return !val ? '' : fMoney(parseFloat(val.replaceAll(',', '')), 2, item.ForeignCurrencyCode);
  235. }
  236. },
  237. {// ╠common.NOTaxAmount⇒未稅金額╣
  238. name: "AmountSum", title: 'common.NOTaxAmount', align: "right", type: "text", width: 70,
  239. itemTemplate: function (val, item) {
  240. return !val ? '' : fMoney(parseFloat(val.replaceAll(',', '')), 2, item.ForeignCurrencyCode);
  241. }
  242. },
  243. {// ╠common.TaxAmount⇒稅金╣
  244. name: "TaxSum", title: 'common.TaxAmount', align: "right", type: "text", width: 70,
  245. itemTemplate: function (val, item) {
  246. return !val ? '' : fMoney(parseFloat(val.replaceAll(',', '')), 2, item.ForeignCurrencyCode);
  247. }
  248. },
  249. {// ╠common.Financial_Sum⇒合計╣
  250. name: "AmountTaxSum", title: 'common.Financial_Sum', align: "right", type: "text", width: 70,
  251. itemTemplate: function (val, item) {
  252. return !val ? '' : fMoney(parseFloat(val.replaceAll(',', '')), 2, item.ForeignCurrencyCode);
  253. }
  254. },
  255. {// ╠common.TotalReceivable⇒總應收╣
  256. name: "TotalReceivable", title: 'common.TotalReceivable', align: "right", type: "text", width: 70,
  257. itemTemplate: function (val, item) {
  258. return !val ? '' : fMoney(parseFloat(val.replaceAll(',', '')), 2, item.ForeignCurrencyCode);
  259. }
  260. },
  261. {
  262. name: "CreateUserName", title: 'common.CreateUser', align: "left", type: "text", width: 70
  263. },
  264. {
  265. name: "BillCreateDate", title: 'common.CreateDate', type: "text", align: "center", width: 100,
  266. itemTemplate: function (val, item) {
  267. var rDate = !val ? item.CreateDate : val;
  268. return newDate(rDate);
  269. }
  270. },
  271. {
  272. name: "AuditVal", title: 'common.Bill_Status', type: "text", align: "center", width: 100,// ╠common.Bill_Status⇒帳單狀態╣
  273. itemTemplate: function (val, item) {
  274. var sStatusName = '';
  275. switch (val) {
  276. case '0':// ╠common.NotAudit⇒未提交審核╣
  277. sStatusName = i18next.t("common.NotAudit");
  278. break;
  279. case '1':// ╠common.InAudit⇒提交審核中╣
  280. sStatusName = i18next.t("common.InAudit");
  281. break;
  282. case '2':// ╠common.Audited⇒已審核╣
  283. sStatusName = i18next.t("common.Audited");
  284. break;
  285. case '3':// ╠common.NotPass⇒不通過╣
  286. sStatusName = i18next.t("common.NotPass");
  287. break;
  288. case '4':// ╠common.HasBeenRealized⇒已銷帳╣
  289. sStatusName = i18next.t("common.HasBeenRealized");
  290. break;
  291. case '5':// ╠common.HasBeenPost⇒已過帳╣
  292. sStatusName = i18next.t("common.HasBeenPost");
  293. break;
  294. case '6':// ╠common.HasVoid⇒已作廢╣
  295. sStatusName = i18next.t("common.HasVoid");
  296. break;
  297. case '7':// ╠common.HasReEdit⇒抽單中╣
  298. sStatusName = i18next.t("common.HasReEdit");
  299. break;
  300. }
  301. return sStatusName;
  302. }
  303. }
  304. ],
  305. controller: {
  306. loadData: function (args) {
  307. return fnGetPro(args);
  308. }
  309. },
  310. onInit: function (args) {
  311. oGrid = args.grid;
  312. }
  313. });
  314. }
  315. }
  316. ]);
  317. fnSetEpoDrop({
  318. Select: $('#ExhibitionSN'),
  319. Select2: true
  320. });
  321. fnSetCustomerWithGuid({
  322. Select: $('#PayerGuid'),
  323. Select2: true
  324. });
  325. };
  326. init();
  327. };
  328. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);