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.

372 lines
16 KiB

2 years ago
  1. 'use strict';
  2. var fnPageInit = function () {
  3. var saCustomerList = [],
  4. saState = [],
  5. sBlackListReasonHtml = '',
  6. oAuditFlag = {
  7. 'N': 'common.NotAudit',
  8. 'Y': 'common.Audited',
  9. 'P': 'common.InAudit',
  10. 'A': 'common.AuditAgain',
  11. 'Z': 'common.ApplyforUpdateing',
  12. 'Q': 'common.NotPass'
  13. },
  14. setStateDrop = function () {
  15. return g_api.ConnectLite(Service.com, ComFn.GetArguments, {
  16. OrgID: 'TE',
  17. ArgClassID: 'Area',
  18. LevelOfArgument: 1
  19. }, function (res) {
  20. if (res.RESULT) {
  21. saState = res.DATA.rel;
  22. if (saState.length > 0) {
  23. $('#State').append(createOptions(saState, 'id', 'text', true)).select2();
  24. }
  25. }
  26. });
  27. },
  28. canDo = new CanDo({
  29. sortField: 'CreateDate',
  30. sortOrder: 'desc',
  31. /**
  32. * 當前程式所有ID名稱集合
  33. */
  34. idKeys: ['OrgID', 'guid'],
  35. /**
  36. * Grid欄位設置可以是 function
  37. */
  38. gridFields: [
  39. {
  40. name: "CheckCombine", title: '', width: 30, align: "center",
  41. itemTemplate: function (value, item) {
  42. return $("<input>", {
  43. type: 'checkbox', click: function (e) {
  44. e.stopPropagation();
  45. if (this.checked) {
  46. saCustomerList.push(item);
  47. }
  48. else {
  49. var saNewList = [];
  50. $.each(saCustomerList, function (idx, data) {
  51. if (item.guid !== data.guid) {
  52. saNewList.push(data);
  53. }
  54. });
  55. saCustomerList = saNewList;
  56. }
  57. }
  58. });
  59. }
  60. },
  61. {
  62. name: "RowIndex", title: 'common.RowNumber', type: "text", width: 50, align: "center", sorting: false
  63. },
  64. {
  65. name: "CustomerNO", title: 'Customers_Upd.CustomerNO', type: "text", align: "center", width: 80
  66. },
  67. {
  68. name: "CustomerShotCName", title: 'Customers_Upd.CustomerShotCName', type: "text", width: 100
  69. },
  70. {
  71. name: "CustomerCName", title: 'Customers_Upd.CustomerCName', type: "text", width: 200
  72. },
  73. {
  74. name: "CustomerEName", title: 'Customers_Upd.CustomerEName', type: "text", width: 200
  75. },
  76. {
  77. name: "UniCode", title: 'Customers_Upd.UniCode', type: "text", align: "center", width: 80
  78. },
  79. /* {
  80. name: "Contactors", title: 'common.Contactor', type: "text", width: 120, itemTemplate: function (val, item) {
  81. var saContactors = JSON.parse(item.Contactors || '[]'),
  82. sContactors = '';
  83. if (saContactors.length > 0) {
  84. sContactors = Enumerable.From(saContactors).Select("$.FullName").ToArray().join(',');
  85. }
  86. return sContactors;
  87. }
  88. },
  89. {
  90. name: "Address", title: 'common.Address', type: "text", width: 230
  91. }, */
  92. {
  93. name: "CreateUserName", title: 'common.CreateUser', type: "text", width: 70
  94. },
  95. {
  96. name: "CreateDate", title: 'common.CreateDate', type: "text", width: 120, itemTemplate: function (val, item) {
  97. return newDate(val);
  98. }
  99. },
  100. {
  101. name: "ModifyDate", title: 'common.ModifyDate', type: "text", width: 120, itemTemplate: function (val, item) {
  102. return newDate(val);
  103. }
  104. },
  105. {
  106. name: "IsAudit", title: 'common.Audit_Status', type: "text", width: 80, align: "center", itemTemplate: function (val, item) {
  107. return i18next.t(oAuditFlag[val]);
  108. }
  109. },
  110. {
  111. name: "Effective", title: 'common.Status', type: "text", width: 50, align: "center", itemTemplate: function (val, item) {
  112. return val === 'Y' ? i18next.t('common.Effective') : i18next.t('common.Invalid');// ╠common.Effective⇒有效╣ ╠common.Invalid⇒無效╣
  113. }
  114. }
  115. ],
  116. /**
  117. * 打開要匯出的pop選擇匯出類別
  118. */
  119. getExcel: function (pargs) {
  120. layer.open({
  121. type: 1,
  122. title: i18next.t('common.DownLoadDocuments'),// ╠common.DownLoadDocuments⇒下載文檔╣
  123. area: ['200px', '280px'],//寬度
  124. shade: 0.75,//遮罩
  125. shadeClose: true,
  126. btn: [i18next.t('common.Cancel')],// ╠common.Cancel⇒取消╣
  127. content: '\
  128. <div class="pop-box">\
  129. <p><button type="button" data-i18n="common.BasicInformation" id="Cus_BasicInformation" class="btn-custom w100p green">基本資料</button></p>\
  130. <p><button type="button" data-i18n="common.Cus_Email" id="Cus_Email" class="btn-custom w100p green">名稱+Email</button></p>\
  131. <p><button type="button" data-i18n="common.WenzhongCusFile" id="Cus_WenzhongCusFile" class="btn-custom w100p green">文中客供商檔</button></p>\
  132. </div>',//common.BasicInformation基本資料common.Cus_Email名稱+Emailcommon.WenzhongCusFile文中客供商檔
  133. success: function (layero, idx) {
  134. $('.pop-box :button').click(function () {
  135. var sToExcelType = this.id;
  136. canDo.getPage({
  137. Excel: true,
  138. ExcelType: sToExcelType,
  139. Index: idx
  140. });
  141. });
  142. canDo._transLang(layero);
  143. }
  144. });
  145. },
  146. /**
  147. * 頁面初始化
  148. * @param {Object} pargs CanDo 對象
  149. */
  150. pageInit: function (pargs) {
  151. var ss = canDo;
  152. $.whenArray([
  153. setStateDrop(),
  154. fnSetUserDrop([
  155. {
  156. Select: $('#CreateUser'),
  157. ShowId: true,
  158. Select2: true
  159. }
  160. ]),
  161. fnSetArgDrop([
  162. {
  163. OrgID: 'TE',
  164. ArgClassID: 'ExhibClass',
  165. ShowId: true,
  166. CallBack: function (data) {
  167. $('#Industry').html(createOptions(data, 'id', 'text', true));
  168. }
  169. },
  170. {
  171. OrgID: 'TE',
  172. ArgClassID: 'BlackListReason',
  173. CallBack: function (data) {
  174. sBlackListReasonHtml = createOptions(data, 'id', 'text');
  175. }
  176. }
  177. ]),
  178. fnSetArgDrop([
  179. {
  180. ArgClassID: 'TranType',
  181. CallBack: function (data) {
  182. var sOptions = '<label for="TransactionType_7"><input type="radio" id="TransactionType_7" name="TransactionType" value="A,B,C,D,E,F," checked="checked">全部</label>' + createRadios(data, 'id', 'text', 'TransactionType')
  183. $('#transactiontype').html(sOptions).find('[name="TransactionType"]').click(function () {
  184. $('#Toolbar_Qry').trigger('click');
  185. });
  186. pargs._uniformInit($('#transactiontype'));
  187. }
  188. }
  189. ]),
  190. ])
  191. .done(function () {
  192. pargs._reSetQueryPm();
  193. pargs._initGrid();
  194. });
  195. $("#Toolbar").append(
  196. '<button type="button" key="Combine" id="Toolbar_Combine" name="Toolbar_Combine" data-i18n="" class="btn-custom orange">合併</button>');
  197. $('#Toolbar_Combine').click(function () {
  198. if (saCustomerList.length != 2) {
  199. showMsg("請勾選兩筆資料進行合併");
  200. return false;
  201. } else {
  202. g_api.ConnectLite('Customers_Upd', 'CheckCombineCustomer', {
  203. guid1: saCustomerList[0].guid,
  204. guid2 : saCustomerList[1].guid
  205. }, function (res) {
  206. if (res.DATA.rel) {
  207. if(res.DATA.rel == 1){
  208. layer.open({
  209. type: 2, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  210. title: "合併客戶",//i18next.t('common.CustomerTransferToFormal'),// ╠common.CustomerTransferToFormal⇒匯入廠商轉正╣
  211. area: ['70%', '90%'],//寬度
  212. shade: 0.75,//遮罩
  213. //maxmin: true, //开启最大化最小化按钮
  214. id: 'layer_CombineCustomer', //设定一个id,防止重复弹出
  215. offset: '10px',//右下角弹出
  216. anim: 0,//彈出動畫
  217. btn: ["合併", i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  218. btnAlign: 'c',//按鈕位置
  219. content: '../POP/Customer_Combine.html',
  220. success: function (layero, index) {
  221. g_api.ConnectLite('Customers_Upd', 'Querytwo', {
  222. guid1: saCustomerList[0].guid,
  223. guid2 : saCustomerList[1].guid
  224. }, function (res) {
  225. if (res.RESULT) {
  226. var oRes = res.DATA.rel;
  227. var iframe = layero.find('iframe').contents();
  228. if (saState.length > 0) {
  229. iframe.find('#State1').html(createOptions(saState, 'id', 'text', true));
  230. iframe.find('#State2').html(createOptions(saState, 'id', 'text', true));
  231. }
  232. iframe.find('#BlackListReason1').html(sBlackListReasonHtml).val(oRes[0].BlackListReason);
  233. iframe.find('#BlackListReason2').html(sBlackListReasonHtml).val(oRes[1].BlackListReason);
  234. iframe.find('#CustomerNO1').val(oRes[0].CustomerNO);
  235. iframe.find('#UniCode1').val(oRes[0].UniCode);
  236. iframe.find('#CustomerShotCName1').val(oRes[0].CustomerShotCName);
  237. iframe.find('#CustomerCName1').val(oRes[0].CustomerCName);
  238. iframe.find('#CustomerEName1').val(oRes[0].CustomerEName);
  239. iframe.find('#Telephone1').val(oRes[0].Telephone);
  240. iframe.find('#Email1').val(oRes[0].Email);
  241. iframe.find('#FAX1').val(oRes[0].FAX);
  242. iframe.find('#State1').val(oRes[0].State);
  243. iframe.find('#Address1').val(oRes[0].Address);
  244. iframe.find('#InvoiceAddress1').val(oRes[0].InvoiceAddress);
  245. iframe.find('#WebsiteAddress1').val(oRes[0].WebsiteAddress);
  246. iframe.find('#Memo1').val(oRes[0].Memo);
  247. iframe.find('[name=IsBlackList1][value="' + oRes[0].IsBlackList + '"]').attr("checked", true);
  248. iframe.find('[name=IsGroupUnit1][value="' + oRes[0].IsGroupUnit + '"]').attr("checked", true);
  249. if(oRes[0].IsBlackList == "Y"){
  250. iframe.find('#BlackListReason1').attr("disabled", false);
  251. }
  252. iframe.find('#CustomerNO2').val(oRes[1].CustomerNO);
  253. iframe.find('#UniCode2').val(oRes[1].UniCode);
  254. iframe.find('#CustomerShotCName2').val(oRes[1].CustomerShotCName);
  255. iframe.find('#CustomerCName2').val(oRes[1].CustomerCName);
  256. iframe.find('#CustomerEName2').val(oRes[1].CustomerEName);
  257. iframe.find('#Telephone2').val(oRes[1].Telephone);
  258. iframe.find('#Email2').val(oRes[1].Email);
  259. iframe.find('#FAX2').val(oRes[1].FAX);
  260. iframe.find('#State2').val(oRes[1].State);
  261. iframe.find('#Address2').val(oRes[1].Address);
  262. iframe.find('#InvoiceAddress2').val(oRes[1].InvoiceAddress);
  263. iframe.find('#WebsiteAddress2').val(oRes[1].WebsiteAddress);
  264. iframe.find('#Memo2').val(oRes[1].Memo);
  265. iframe.find('[name=IsBlackList2][value="' + oRes[1].IsBlackList + '"]').attr("checked", true);
  266. iframe.find('[name=IsGroupUnit2][value="' + oRes[1].IsGroupUnit + '"]').attr("checked", true);
  267. if(oRes[1].IsBlackList == "Y"){
  268. iframe.find('#BlackListReason2').attr("disabled", false);
  269. }
  270. }
  271. else {
  272. showMsg(i18next.t('message.NotFindData') + '<br>' + res.MSG, 'error'); // ╠message.NotFindData⇒查不到對應的資料╣
  273. }
  274. }, function () {
  275. showMsg(i18next.t('message.NotFindData'), 'error');
  276. });
  277. },
  278. yes: function (index, layero) {
  279. layer.confirm("確定要合併?", { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  280. var iframe = layero.find('iframe').contents();
  281. //var combinedata = getFormSerialize($(iframe.find('#form_main')));
  282. var combinedata = ss._getFormSerialize($(iframe.find('#form_main')));
  283. combinedata.Type = res.DATA.rel;
  284. combinedata.guid1 = saCustomerList[0].guid;
  285. combinedata.guid2 = saCustomerList[1].guid;
  286. g_api.ConnectLite('Customers_Upd', 'CombineCustomer', combinedata
  287. , function (res) {
  288. if (res.DATA.rel) {
  289. //oGrid.loadData();
  290. showMsg("合併成功", 'success');
  291. pargs._initGrid();
  292. layer.close(index);
  293. }
  294. else {
  295. showMsg("合併失敗", 'error');
  296. }
  297. }
  298. , function () {
  299. showMsg("合併失敗", 'error');
  300. });
  301. layer.close(index-1);
  302. });
  303. },
  304. end: function () {
  305. saCustomerList = [];
  306. pargs._initGrid();
  307. }
  308. });
  309. } else if(res.DATA.rel == 2){
  310. layer.confirm("正式客戶合併非正式客戶,確定要合併?", { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  311. var combinedata = {};
  312. combinedata.Type = res.DATA.rel;
  313. combinedata.guid1 = saCustomerList[0].guid;
  314. combinedata.guid2 = saCustomerList[1].guid;
  315. g_api.ConnectLite('Customers_Upd', 'CombineCustomer', combinedata
  316. , function (res) {
  317. if (res.DATA.rel) {
  318. saCustomerList = [];
  319. //oGrid.loadData();
  320. showMsg("合併成功", 'success');
  321. pargs._initGrid();
  322. layer.close(index);
  323. }
  324. else {
  325. showMsg("合併失敗", 'error');
  326. }
  327. }
  328. , function () {
  329. showMsg("合併失敗", 'error');
  330. });
  331. layer.close(index);
  332. });
  333. } else if(res.DATA.rel == 3){
  334. showMsg("所選客戶皆為正式客戶,無法合併", 'error');
  335. } else if(res.DATA.rel == 4){
  336. showMsg("所選客戶中有重新提交審核中之客戶,無法合併", 'error');
  337. } else if(res.DATA.rel == 5){
  338. showMsg("所選客戶中有提交審核中之客戶,無法合併", 'error');
  339. } else if(res.DATA.rel == 6){
  340. showMsg("所選客戶中有申請修改中之客戶,無法合併", 'error');
  341. } else if(res.DATA.rel == 7){
  342. showMsg("所選客戶中有狀態無法確認之客戶,無法合併", 'error');
  343. }
  344. }
  345. else {
  346. showMsg("無法確認客戶資料,無法合併", 'error');
  347. }
  348. }
  349. , function () {
  350. showMsg("無法確認客戶資料,無法合併", 'error');
  351. });
  352. }
  353. return false;
  354. });
  355. }
  356. });
  357. };
  358. require(['base', 'select2', 'jsgrid', 'cando'], fnPageInit);