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.

489 lines
28 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sEditPrgId = getEditPrgId(),
  4. oGrid = null,
  5. fnPageInit = function () {
  6. var oForm = $('#form_main'),
  7. oBaseQueryPm = {
  8. pageIndex: 1,
  9. pageSize: parent.SysSet.GridRecords || 10,
  10. sortField: 'CreateDate',
  11. sortOrder: 'desc'
  12. },
  13. /**
  14. * 獲取資料
  15. * @param {Object} args 查詢條件參數
  16. * @return {Object} Ajax 物件
  17. */
  18. fnGet = function (args) {
  19. var oQueryPm = getFormSerialize(oForm);
  20. $.extend(oQueryPm, oBaseQueryPm, args);
  21. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  22. return g_api.ConnectLite(sProgramId, ComFn.GetPage, oQueryPm);
  23. },
  24. /**
  25. * 匯出資料
  26. * @param {Object} args 查詢參數
  27. * @return {Object} Ajax 物件
  28. */
  29. fnExcel = function (args) {
  30. var oQueryPm = getFormSerialize(oForm);
  31. $.extend(oQueryPm, oBaseQueryPm, args);
  32. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  33. oQueryPm.Excel = true;
  34. g_api.ConnectLite(sProgramId, ComFn.GetPage, oQueryPm, function (res) {
  35. if (res.RESULT) {
  36. DownLoadFile(res.DATA.rel);
  37. }
  38. });
  39. },
  40. /**
  41. * 目的 對應匯入廠商
  42. * @param {String}item 預約單資料
  43. */
  44. fnCorrespondImpCus = function (item) {
  45. layer.open({
  46. type: 1, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  47. title: i18next.t("PackingOrder_Upd.CorrespondImpCus"), // ╠PackingOrder_Upd.CorrespondImpCus⇒對應匯入廠商╣
  48. area: '640px;',//寬度
  49. shade: 0.75,//遮罩
  50. closeBtn: 1,
  51. //maxmin: true, //开启最大化最小化按钮
  52. id: 'layer_PackingInfo', //设定一个id,防止重复弹出
  53. offset: '100px',//右下角弹出
  54. anim: 0,//彈出動畫
  55. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  56. btnAlign: 'c',//按鈕位置
  57. content: '<style>.select2-container{z-index: 39891015;}</style><div class="form-group">\
  58. <div class="col-sm-12">\
  59. <select class= "form-control w95p" id="CustomerId" name="CustomerId"></select>\
  60. </div>\
  61. </div >',
  62. success: function (layero, index) {
  63. g_api.ConnectLite(sEditPrgId, 'SetImpCusDrop', {
  64. Id: item.ExhibitionNO
  65. }, function (res) {
  66. if (res.RESULT) {
  67. var saList = res.DATA.rel;
  68. var sOptions = createOptions(saList, 'guid', 'CustomerCName');
  69. $('#CustomerId').html(sOptions).select2();
  70. }
  71. });
  72. transLang(layero);
  73. },
  74. yes: function (index, layero) {
  75. var sCustomerId = $('#CustomerId').val();
  76. if (!sCustomerId) {
  77. showMsg(i18next.t('message.SelectImpCus'));//╠message.SelectImpCus⇒請選擇對應的廠商╣
  78. return false;
  79. }
  80. g_api.ConnectLite(sEditPrgId, 'CorrespondImpCus', {
  81. Id: item.AppointNO,
  82. CustomerId: sCustomerId
  83. }, function (res) {
  84. if (res.DATA.rel) {
  85. oGrid.loadData();
  86. showMsg(i18next.t("message.Correspond_Success"), 'success'); //╠message.Correspond_Success⇒對應成功╣
  87. layer.close(index);
  88. }
  89. else {
  90. showMsg(i18next.t("message.Correspond_Failed"), 'error');//╠message.Correspond_Failed⇒對應失敗╣
  91. }
  92. });
  93. }
  94. });
  95. },
  96. /**
  97. * 匯入到其他入口
  98. * @param {String}item 預約單資料
  99. */
  100. fnImportOthers = function (item) {
  101. layer.open({
  102. type: 1,
  103. title: i18next.t('PackingOrder_Upd.SelectImportPrg'),// ╠PackingOrder_Upd.SelectImportPrg⇒選擇匯入入口╣
  104. area: ['300px', '160px'],//寬度
  105. shade: 0.75,//遮罩
  106. shadeClose: true,
  107. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  108. content: '<div class="pop-box">\
  109. <button type="button" data-i18n="PackingOrder_Upd.OtherPrg" id="OtherPrg" class="btn-custom green">其他</button>\
  110. <button type="button" data-i18n="PackingOrder_Upd.OtherPrgTG" id="OtherPrgTG" class="btn-custom green">其他駒驛</button>\
  111. </div>',//PackingOrder_Upd.OtherPrg其他PackingOrder_Upd.OtherPrgTG其他駒驛
  112. success: function (layero, index) {
  113. $('.pop-box :button').click(function () {
  114. if (this.id === 'OtherPrg') {
  115. parent.openPageTab('OtherBusiness_Upd', '?Action=Add&AppointNO=' + item.AppointNO);
  116. }
  117. else {
  118. parent.openPageTab('OtherExhibitionTG_Upd', '?Action=Add&AppointNO=' + item.AppointNO);
  119. }
  120. layer.close(index);
  121. });
  122. transLang(layero);
  123. }
  124. });
  125. },
  126. /**
  127. * ToolBar 按鈕事件 function
  128. * @param {Object}inst 按鈕物件對象
  129. * @param {Object} e 事件對象
  130. */
  131. fnButtonHandler = function (inst, e) {
  132. var sId = inst.id;
  133. switch (sId) {
  134. case "Toolbar_Qry":
  135. var iNum = $('#PerPageNum').val();
  136. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  137. cacheQueryCondition();
  138. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  139. break;
  140. case "Toolbar_Save":
  141. break;
  142. case "Toolbar_ReAdd":
  143. break;
  144. case "Toolbar_Clear":
  145. clearPageVal();
  146. break;
  147. case "Toolbar_Leave":
  148. break;
  149. case "Toolbar_Add":
  150. break;
  151. case "Toolbar_Upd":
  152. break;
  153. case "Toolbar_Copy":
  154. break;
  155. case "Toolbar_EntryOrder":
  156. parent.openPageTab(sEditPrgId, '?Action=Add');
  157. break;
  158. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  159. break;
  160. case "Toolbar_Exp":
  161. if (oGrid.data.length === 0) {
  162. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  163. return false;
  164. }
  165. fnExcel();
  166. break;
  167. default:
  168. alert("No handle '" + sId + "'");
  169. break;
  170. }
  171. },
  172. /**
  173. * 頁面初始化
  174. */
  175. init = function () {
  176. var saCusBtns = [{
  177. id: 'Toolbar_EntryOrder',
  178. value: 'common.Toolbar_EntryOrder'// ╠common.Toolbar_EntryOrder⇒錄入預約單╣
  179. }];
  180. commonInit({
  181. PrgId: sProgramId,
  182. ButtonHandler: fnButtonHandler,
  183. Buttons: saCusBtns,
  184. SearchBar: true
  185. }).done(function () {
  186. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  187. $("#jsGrid").jsGrid({
  188. width: "100%",
  189. height: iHeight + "px",
  190. autoload: true,
  191. pageLoading: true,
  192. inserting: false,
  193. editing: false,
  194. sorting: true,
  195. paging: true,
  196. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  197. pageSize: parent.SysSet.GridRecords || 10,
  198. pageButtonCount: parent.SysSet.GridPages || 15,
  199. pagePrevText: "<",
  200. pageNextText: ">",
  201. pageFirstText: "<<",
  202. pageLastText: ">>",
  203. onPageChanged: function (args) {
  204. cacheQueryCondition(args.pageIndex);
  205. },
  206. rowClass: function (item) {
  207. var sClass = '';
  208. if (item.IsKeyMode) {
  209. sClass = 'key-in';
  210. }
  211. return sClass;
  212. },
  213. rowClick: function (args) {
  214. if (navigator.userAgent.match(/mobile/i)) {
  215. goToEdit(sEditPrgId, '?Action=Upd&AppointNO=' + args.item.AppointNO);
  216. }
  217. },
  218. rowDoubleClick: function (args) {
  219. if (args.item.IsKeyMode) {
  220. parent.openPageTab(sEditPrgId, '?Action=Upd&AppointNO=' + args.item.AppointNO);
  221. }
  222. else {
  223. var saPackingInfo = JSON.parse(args.item.PackingInfo),
  224. sContent = '<div class="row popsrow">\
  225. <div class="col-sm-12">\
  226. <div id="jsGrid_PackingInfo"></div>\
  227. </div>\
  228. </div>\
  229. <div class="row popsrow">\
  230. <div class="col-sm-12 wcenter" style="font-size: 20px;font-weight: bold;">\
  231. 費用總計(新臺幣含稅)NT$<span class="PackingTotal"></span>\
  232. </div>\
  233. </div>';
  234. layer.open({
  235. type: 1,
  236. title: i18next.t('common.BookingDetails'),//╠common.BookingDetails⇒預約明細╣
  237. shadeClose: false,
  238. shade: 0.1,
  239. maxmin: true, //开启最大化最小化按钮
  240. area: ['800px', '500px'],
  241. content: sContent,
  242. success: function (layero, index) {
  243. $("#jsGrid_PackingInfo").jsGrid({
  244. width: "100%",
  245. height: "auto",
  246. autoload: true,
  247. pageLoading: true,
  248. pageIndex: 1,
  249. pageSize: 10000,
  250. fields: [
  251. { name: "Index", title: 'common.RowNumber', width: 50, align: "center" },
  252. {// ╠common.Packaging⇒包裝類型╣
  253. name: "ExpoType", title: 'common.Packaging', width: 100, align: "center",
  254. itemTemplate: function (val, item) {
  255. var oExpoType = {
  256. 'zh-TW': { '01': '裸機', '02': '木箱', '03': '散貨', '04': '打板', '05': '其他' },
  257. 'en': { '01': 'Unwrapped', '02': 'Wooden Crate', '03': 'Bulk Cargo', '04': 'Pallet', '05': 'Other' }
  258. },
  259. bEn = 'Unwrapped,Wooden Crate,Bulk Cargo,Pallet,Other'.indexOf(item.ExpoTypeText) > -1;
  260. return val ? oExpoType[bEn ? 'en' : 'zh-TW'][val] : '';
  261. }
  262. },
  263. {// ╠common.Dimensions⇒尺寸╣
  264. name: "ExpoLen", title: 'common.Dimensions', width: 100,
  265. itemTemplate: function (val, item) {
  266. return item.ExpoLen.toMoney() + '*' + item.ExpoWidth.toMoney() + '*' + item.ExpoHeight.toMoney();
  267. }
  268. },
  269. {// ╠common.WeightKG⇒重量╣
  270. name: "ExpoWeight", title: 'common.WeightKG', width: 100, align: "right",
  271. itemTemplate: function (val, item) {
  272. return val.toMoney();
  273. }
  274. },
  275. {
  276. name: "ExpoNumber", title: 'common.Number', width: 100, align: "center",
  277. itemTemplate: function (val, item) {
  278. return val.toMoney();
  279. }
  280. },// ╠common.Number⇒件數╣
  281. {// ╠common.ServiceProject⇒服務項目╣
  282. name: "ExpoStack", title: 'common.ServiceProject', width: 200,
  283. itemTemplate: function (val, item) {
  284. var oService = {
  285. 'zh-TW': ['堆高機服務', '拆箱(含空箱收送與儲存)', '裝箱', '空箱收送', '空箱儲存', '天'],
  286. 'en': ['Forklift', 'Unpacking (including empty crate transport & storage)', 'Packing', 'Empty Crate Transport', 'Empty Crate Storage', 'Days']
  287. },
  288. saText = [],
  289. bEn = 'Unwrapped,Wooden Crate,Bulk Cargo,Pallet,Other'.indexOf(item.ExpoTypeText) > -1;
  290. oService = oService[bEn ? 'en' : 'zh-TW'];
  291. if (item.ExpoStack) {
  292. saText.push(oService[0]);
  293. }
  294. if (item.ExpoSplit) {
  295. saText.push(oService[1]);
  296. }
  297. if (item.ExpoPack) {
  298. saText.push(oService[2]);
  299. }
  300. if (item.ExpoFeed) {
  301. saText.push(oService[3]);
  302. }
  303. if (item.ExpoStorage) {
  304. saText.push(oService[4] + item.ExpoDays + oService[5]);
  305. }
  306. return saText.join(',');
  307. }
  308. },
  309. {// ╠common.Cost⇒費用╣
  310. name: "SubTotal", title: 'common.Cost', width: 100, align: "right",
  311. itemTemplate: function (val, item) {
  312. return fMoney(val || 0, 0, 'NTD');
  313. }
  314. }
  315. ],
  316. controller: {
  317. loadData: function (args) {
  318. return {
  319. data: saPackingInfo,
  320. itemsCount: saPackingInfo.length //data.length
  321. };
  322. }
  323. }
  324. });
  325. $(".PackingTotal").text(fMoney(args.item.Total || 0, 0, 'NTD'));
  326. },
  327. btn: [i18next.t('common.Close')],//╠common.Close⇒關閉╣
  328. });
  329. }
  330. },
  331. fields: [
  332. { name: "RowIndex", title: 'common.RowNumber', align: "center", type: "text", width: 40, sorting: false },
  333. {// ╠common.AppointNO⇒預約單號╣
  334. name: "AppointNO", title: 'common.AppointNO', type: "text", width: 120
  335. },
  336. {// ╠common.CompanyName⇒公司名稱╣
  337. name: "CompName", title: 'common.CompanyName', type: "text", width: 150
  338. },
  339. {
  340. name: "Exhibitioname_TW", title: 'Exhibition_Upd.Exhibitioname_TW', type: "text", width: 150,
  341. itemTemplate: function (val, item) {
  342. return $('<a />', {
  343. class: 'link',
  344. text: val, click: function () {
  345. parent.openPageTab('Exhibition_Upd', '?Action=Upd&SN=' + item.ExhibitionNO);
  346. }
  347. })
  348. }
  349. },
  350. {// ╠common.MuseumMumber⇒預約攤號╣
  351. name: "MuseumMumber", title: 'common.MuseumMumber', type: "text", width: 70
  352. },
  353. {// ╠common.AppointUser⇒預約人員╣
  354. name: "AppointUser", title: 'common.AppointUser', type: "text", width: 80
  355. },
  356. {// ╠common.AppointTel⇒預約電話╣
  357. name: "AppointTel", title: 'common.AppointTel', type: "text", width: 80
  358. },
  359. {// ╠common.AppointEmail⇒預約Email╣
  360. name: "AppointEmail", title: 'common.AppointEmail', type: "text", width: 140
  361. },
  362. {// ╠ExhibitionImport_Upd.SitiContactor⇒現場聯絡人╣
  363. name: "Contactor", title: 'ExhibitionImport_Upd.SitiContactor', type: "text", width: 80
  364. },
  365. {// ╠ExhibitionImport_Upd.SitiTelephone⇒現場聯絡電話╣
  366. name: "ContactTel", title: 'ExhibitionImport_Upd.SitiTelephone', type: "text", width: 80
  367. },
  368. {// ╠ExhibitionImport_Upd.ApproachTime⇒進場時間╣
  369. name: "ApproachTime", title: 'ExhibitionImport_Upd.ApproachTime', type: "text", align: "center", width: 100,
  370. itemTemplate: function (val, item) {
  371. return newDate(val);
  372. }
  373. },
  374. {// ╠ExhibitionImport_Upd.ExitTime⇒退場時間╣
  375. name: "ExitTime", title: 'ExhibitionImport_Upd.ExitTime', type: "text", align: "center", width: 100,
  376. itemTemplate: function (val, item) {
  377. return newDate(val);
  378. }
  379. },
  380. {// ╠common.AppointDateTime⇒預約時間╣
  381. name: "AppointDateTime", title: 'common.AppointDateTime', type: "text", align: "center", width: 100,
  382. itemTemplate: function (val, item) {
  383. return newDate(val);
  384. }
  385. },
  386. {// ╠PackingOrder_Upd.CorrespondStatus⇒對應狀態╣
  387. name: "CustomerId", title: 'PackingOrder_Upd.CorrespondStatus', type: "text", align: "center", width: 100,
  388. itemTemplate: function (val, item) {
  389. var templ = [];
  390. if (val) {// ╠PackingOrder_Upd.HasCorrespond⇒已對應╣
  391. templ.push($('<span />', { text: i18next.t('PackingOrder_Upd.HasCorrespond') }).css('color', 'green'));
  392. if (item.IsFormal) {
  393. // ╠common.HasFormal⇒已轉正╣
  394. templ.push('(', $('<span />', { text: i18next.t('common.HasFormal') }).css('color', 'green'), ')');
  395. }
  396. else {
  397. // ╠common.NotFormal⇒未轉正╣
  398. templ.push('(', $('<a />', {
  399. class: 'link',
  400. text: i18next.t('common.NotFormal'), click: function () {
  401. parent.openPageTab('Customers_Upd', '?Action=Add&FromId=' + item.AppointNO + '&From=Appoint&Flag=Appoint');
  402. }
  403. }).css('color', 'red'), ')');
  404. }
  405. }
  406. else {
  407. templ.push($('<a/>', {
  408. html: i18next.t('PackingOrder_Upd.CorrespondImpCus'),// ╠PackingOrder_Upd.CorrespondImpCus⇒對應到匯入廠商╣
  409. class: 'link',
  410. click: function () {
  411. fnCorrespondImpCus(item);
  412. }
  413. }));
  414. }
  415. return templ;
  416. }
  417. },
  418. {// ╠PackingOrder_Upd.ImpOtherPrgStatus⇒匯入狀態╣
  419. name: "OtherId", title: 'PackingOrder_Upd.ImpOtherPrgStatus', type: "text", align: "center", width: 100,
  420. itemTemplate: function (val, item) {
  421. var templ = $('<a />', {
  422. class: 'link',
  423. text: i18next.t('PackingOrder_Upd.HasImpOtherPrg'), click: function () {
  424. var bTG = item.OtherIdFrom === 'OtherBusiness_Upd';
  425. parent.openPageTab(item.OtherIdFrom, '?Action=Upd&' + (bTG ? 'ImportBillNO' : 'Guid') + '=' + item.OtherId + '&GoTab=' + (bTG ? 2 : 3));
  426. }
  427. }).css('color', 'green');// ╠PackingOrder_Upd.HasImpOtherPrg⇒已產生賬單資料╣
  428. if (!val) {
  429. templ = $('<a/>', {
  430. html: i18next.t('PackingOrder_Upd.ImpOtherPrg'),// ╠PackingOrder_Upd.ImpOtherPrg⇒匯入到「其他」入口╣
  431. class: 'link',
  432. click: function () {
  433. var sError = '';
  434. if (!item.CustomerId) {
  435. sError = i18next.t('message.CorrespondImpCusFirst');//╠message.CorrespondImpCusFirst⇒請先對應到匯入廠商╣
  436. }
  437. if (!item.IsFormal) {
  438. sError = i18next.t('message.TransferToFormalFirst');//╠message.TransferToFormalFirst⇒請先轉正該廠商╣
  439. }
  440. if (sError) {
  441. showMsg(sError);
  442. return false;
  443. }
  444. fnImportOthers(item);
  445. }
  446. });
  447. }
  448. return templ;
  449. }
  450. }
  451. ],
  452. controller: {
  453. loadData: function (args) {
  454. return fnGet(args);
  455. }
  456. },
  457. onInit: function (args) {
  458. oGrid = args.grid;
  459. }
  460. });
  461. });
  462. };
  463. init();
  464. };
  465. require(['base', 'jsgrid', 'select2', 'util'], fnPageInit);