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.

439 lines
17 KiB

3 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sEditPrgId = getEditPrgId(),
  4. oGrid = null,
  5. objCombineData,
  6. fnPageInit = function () {
  7. var saContactorList = [],
  8. saCustomerShotCNameList = [],
  9. oForm = $('#form_main'),
  10. oBaseQueryPm = {
  11. pageIndex: 1,
  12. pageSize: parent.SysSet.GridRecords || 10,
  13. sortField: 'CustomerShotCName',
  14. sortOrder: 'desc'
  15. },
  16. /**
  17. * 獲取資料
  18. * @param {Object} args 查詢參數
  19. * @return {Object} Ajax 物件
  20. */
  21. fnGet = function (args) {
  22. var oQueryPm = getFormSerialize(oForm);
  23. $.extend(oQueryPm, oBaseQueryPm, args);
  24. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  25. return g_api.ConnectLite(sProgramId, ComFn.GetPage, oQueryPm, function (res) {
  26. if (res.RESULT) {
  27. var oRes = res.DATA.rel;
  28. if (args.Excel) {//匯出
  29. DownLoadFile(oRes);
  30. layer.close(args.Index);
  31. }
  32. }
  33. });
  34. },
  35. /**
  36. * 打開要匯出的pop選擇匯出類別
  37. */
  38. fnOpenPopToExcel = function () {
  39. layer.confirm("確定要匯出嗎?", { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  40. fnGet({
  41. Excel: true,
  42. Index: index
  43. });
  44. })
  45. },
  46. /**
  47. * ToolBar 按鈕事件 function
  48. * @param {Object}inst 按鈕物件對象
  49. * @param {Object} e 事件對象
  50. */
  51. fnButtonHandler = function (inst, e) {
  52. var sId = inst.id;
  53. switch (sId) {
  54. case "Toolbar_Qry":
  55. var iNum = $('#PerPageNum').val();
  56. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  57. cacheQueryCondition();
  58. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  59. break;
  60. case "Toolbar_Save":
  61. fnSave('add');
  62. break;
  63. case "Toolbar_ReAdd":
  64. break;
  65. case "Toolbar_Clear":
  66. clearPageVal();
  67. break;
  68. case "Toolbar_Leave":
  69. break;
  70. case "Toolbar_Add":
  71. parent.openPageTab(sEditPrgId, '?Action=Add');
  72. break;
  73. case "Toolbar_Upd":
  74. break;
  75. case "Toolbar_Copy":
  76. break;
  77. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  78. break;
  79. case "Toolbar_Exp":
  80. if (oGrid.data.length === 0) {
  81. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  82. return false;
  83. }
  84. fnOpenPopToExcel();
  85. break;
  86. default:
  87. alert("No handle '" + sId + "'");
  88. break;
  89. }
  90. },
  91. /**
  92. * 目的 合併聯絡人
  93. * @param
  94. */
  95. fnCombineContactor = function (_guid1,_guid2) {
  96. return g_api.ConnectLite("Contactors_Upd", "GetImmediateSupervisor", {
  97. Guid1: _guid1,
  98. Guid2: _guid2
  99. }, function (res) {
  100. if (res.RESULT) {
  101. let saImmediateSupervisor = res.DATA.rel;
  102. var strCustomerId = "";
  103. if (saImmediateSupervisor.length > 0) {
  104. var obj;
  105. layer.open({
  106. type: 2, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  107. title: "合併聯絡人",//i18next.t('common.CustomerTransferToFormal'),// ╠common.CustomerTransferToFormal⇒匯入廠商轉正╣
  108. area: ['70%', '90%'],//寬度
  109. shade: 0.75,//遮罩
  110. //maxmin: true, //开启最大化最小化按钮
  111. id: 'layer_CombineContactor', //设定一个id,防止重复弹出
  112. offset: '10px',//右下角弹出
  113. anim: 0,//彈出動畫
  114. btn: ['合併', i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  115. btnAlign: 'c',//按鈕位置
  116. content: '../POP/Contactor_Combine.html',
  117. success: function (layero, index) {
  118. objCombineData = layero;
  119. g_api.ConnectLite('Contactors_Qry', 'QueryTwo', {
  120. guid1: _guid1,
  121. guid2 : _guid2
  122. }, function (res) {
  123. if (res.RESULT) {
  124. var oRes = res.DATA.rel;
  125. var iframe = layero.find('iframe').contents();
  126. let objImmediateSupervisor1 = iframe.find('#ImmediateSupervisor1');
  127. let objImmediateSupervisor2 = iframe.find('#ImmediateSupervisor2');
  128. $(objImmediateSupervisor1).html(createOptions(saImmediateSupervisor, 'id', 'text', false)).select();
  129. $(objImmediateSupervisor2).html(createOptions(saImmediateSupervisor, 'id', 'text', false)).select();
  130. let strCustomerName1 = '';
  131. let strCustomerName2 = '';
  132. if(oRes[0].CustomerShotCName == '' || oRes[0].CustomerShotCName == null){
  133. if(oRes[0].CustomerCName == '' || oRes[0].CustomerCName == null){
  134. strCustomerName1 = oRes[0].CustomerEName;
  135. } else {
  136. strCustomerName1 = oRes[0].CustomerCName;
  137. }
  138. } else {
  139. if(oRes[0].CustomerCName == '' || oRes[0].CustomerCName == null){
  140. strCustomerName1 = '(' + oRes[0].CustomerShotCName + ')' + oRes[0].CustomerEName;
  141. } else {
  142. strCustomerName1 = '(' + oRes[0].CustomerShotCName + ')' + oRes[0].CustomerCName;
  143. }
  144. }
  145. if(oRes[1].CustomerShotCName == '' || oRes[1].CustomerShotCName == null){
  146. if(oRes[1].CustomerCName == '' || oRes[1].CustomerCName == null){
  147. strCustomerName2 = oRes[1].CustomerEName;
  148. } else {
  149. strCustomerName2 = oRes[1].CustomerCName;
  150. }
  151. } else {
  152. if(oRes[1].CustomerCName == '' || oRes[1].CustomerCName == null){
  153. strCustomerName2 = '(' + oRes[1].CustomerShotCName + ')' + oRes[1].CustomerEName;
  154. } else {
  155. strCustomerName2 = '(' + oRes[1].CustomerShotCName + ')' + oRes[1].CustomerCName;
  156. }
  157. }
  158. iframe.find('#Call1').val(oRes[0].Call);
  159. iframe.find('#Call2').val(oRes[1].Call);
  160. iframe.find('#ContactorName1').val(oRes[0].ContactorName);
  161. iframe.find('#ContactorName2').val(oRes[1].ContactorName);
  162. iframe.find('#NickName1').val(oRes[0].NickName);
  163. iframe.find('#NickName2').val(oRes[1].NickName);
  164. iframe.find('#Birthday1').val(oRes[0].Birthday);
  165. iframe.find('#Birthday2').val(oRes[1].Birthday);
  166. iframe.find('#MaritalStatus1').val(oRes[0].MaritalStatus);
  167. iframe.find('#MaritalStatus2').val(oRes[1].MaritalStatus);
  168. iframe.find('#PersonalMobilePhone1').val(oRes[0].PersonalMobilePhone);
  169. iframe.find('#PersonalMobilePhone2').val(oRes[1].PersonalMobilePhone);
  170. iframe.find('#PersonalEmail1').val(oRes[0].PersonalEmail);
  171. iframe.find('#PersonalEmail2').val(oRes[1].PersonalEmail);
  172. iframe.find('#LINE1').val(oRes[0].LINE);
  173. iframe.find('#LINE2').val(oRes[1].LINE);
  174. iframe.find('#WECHAT1').val(oRes[0].WECHAT);
  175. iframe.find('#WECHAT2').val(oRes[1].WECHAT);
  176. iframe.find('#Personality1').val(oRes[0].Personality);
  177. iframe.find('#Personality2').val(oRes[1].Personality);
  178. iframe.find('#Preferences1').val(oRes[0].Preferences);
  179. iframe.find('#Preferences2').val(oRes[1].Preferences);
  180. iframe.find('#PersonalAddress1').val(oRes[0].PersonalAddress);
  181. iframe.find('#PersonalAddress2').val(oRes[1].PersonalAddress);
  182. iframe.find('#Memo1').val(oRes[0].Memo);
  183. iframe.find('#Memo2').val(oRes[1].Memo);
  184. iframe.find('#CustomerCName1').val(strCustomerName1);
  185. iframe.find('#CustomerCName2').val(strCustomerName2);
  186. strCustomerId = oRes[0].CustomerId;
  187. iframe.find('#JobTitle1').val(oRes[0].JobTitle);
  188. iframe.find('#JobTitle2').val(oRes[1].JobTitle);
  189. iframe.find('#Department1').val(oRes[0].Department);
  190. iframe.find('#Department2').val(oRes[1].Department);
  191. iframe.find('#ImmediateSupervisor1').val(oRes[0].ImmediateSupervisor);
  192. iframe.find('#ImmediateSupervisor2').val(oRes[1].ImmediateSupervisor);
  193. iframe.find('#Telephone11').val(oRes[0].Telephone1);
  194. iframe.find('#Telephone12').val(oRes[1].Telephone1);
  195. iframe.find('#Telephone21').val(oRes[0].Telephone2);
  196. iframe.find('#Telephone22').val(oRes[1].Telephone2);
  197. iframe.find('#Email11').val(oRes[0].Email1);
  198. iframe.find('#Email12').val(oRes[1].Email1);
  199. iframe.find('#Email21').val(oRes[0].Email2);
  200. iframe.find('#Email22').val(oRes[1].Email2);
  201. iframe.find('#ChoseReason1').val(oRes[0].ChoseReason);
  202. iframe.find('#ChoseReason2').val(oRes[1].ChoseReason);
  203. iframe.find('#Ext11').val(oRes[0].Ext1);
  204. iframe.find('#Ext12').val(oRes[1].Ext1);
  205. iframe.find('#Ext21').val(oRes[0].Ext2);
  206. iframe.find('#Ext22').val(oRes[1].Ext2);
  207. } else {
  208. showMsg(i18next.t('message.NotFindData') + '<br>' + res.MSG, 'error'); // ╠message.NotFindData⇒查不到對應的資料╣
  209. }
  210. }, function () {
  211. showMsg(i18next.t('message.NotFindData'), 'error');
  212. });
  213. },
  214. yes: function (index, layero) {
  215. layer.confirm("確定要合併?", { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  216. var iframe = layero.find('iframe').contents();
  217. var combinedata = getFormSerialize($(iframe.find('#form_main')));
  218. combinedata.guid1=_guid1;
  219. combinedata.guid2=_guid2;
  220. combinedata.CustomerId = strCustomerId;
  221. g_api.ConnectLite('Contactors_Upd', 'CombineContactor', combinedata
  222. , function (res) {
  223. if (res.DATA.rel) {
  224. saContactorList = [];
  225. saCustomerShotCNameList=[];
  226. oGrid.loadData();
  227. showMsg("合併成功", 'success');
  228. layer.close(index);
  229. }
  230. else {
  231. showMsg("合併失敗", 'error');
  232. }
  233. }
  234. , function () {
  235. showMsg("合併失敗", 'error');
  236. });
  237. layer.close(index-1);
  238. });
  239. },
  240. end: function () {
  241. saContactorList = [];
  242. saCustomerShotCNameList=[];
  243. oGrid.loadData();
  244. }
  245. });
  246. }
  247. }
  248. });
  249. },
  250. /**
  251. * 初始化 function
  252. */
  253. init = function () {
  254. commonInit({
  255. PrgId: sProgramId,
  256. ButtonHandler: fnButtonHandler,
  257. SearchBar: true
  258. });
  259. $.whenArray([
  260. fnSetUserDrop([
  261. {
  262. Select: $('#CreateUser'),
  263. Select2: true,
  264. ShowId: true
  265. }
  266. ])
  267. ])
  268. .done(function () {
  269. reSetQueryPm(sProgramId);
  270. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  271. $("#jsGrid").jsGrid({
  272. width: "100%",
  273. height: iHeight + "px",
  274. autoload: true,
  275. pageLoading: true,
  276. sorting: true,
  277. paging: true,
  278. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  279. pageSize: parent.SysSet.GridRecords || 10,
  280. pageButtonCount: parent.SysSet.GridPages || 15,
  281. pagePrevText: "<",
  282. pageNextText: ">",
  283. pageFirstText: "<<",
  284. pageLastText: ">>",
  285. onPageChanged: function (args) {
  286. cacheQueryCondition(args.pageIndex);
  287. },
  288. rowClick: function (args) {
  289. /* if (navigator.userAgent.match(/mobile/i)) {
  290. goToEdit(sEditPrgId, '?Action=Upd&guid=' + args.item.guid);
  291. } */
  292. },
  293. rowDoubleClick: function (args) {
  294. parent.openPageTab(sEditPrgId, '?Action=Upd&guid=' + args.item.guid);
  295. },
  296. fields: [
  297. {
  298. name: "CheckCombine", title: '', width: 30, align: "center",
  299. itemTemplate: function (value, item) {
  300. return $("<input>", {
  301. type: 'checkbox', click: function (e) {
  302. e.stopPropagation();
  303. if (this.checked) {
  304. saContactorList.push(item);
  305. saCustomerShotCNameList.push($(this).parent().parent().find("td:eq(5)").text());
  306. } else {
  307. var saNewList = [];
  308. var intIndex=0;
  309. $.each(saContactorList, function (idx, data) {
  310. if (item.guid != data.guid) {
  311. saNewList.push(data);
  312. } else {
  313. intIndex = idx;
  314. }
  315. });
  316. var saNewCustomerShotCNameList = [];
  317. $.each(saCustomerShotCNameList, function (idx, data) {
  318. if (intIndex != idx) {
  319. saNewCustomerShotCNameList.push(data);
  320. }
  321. });
  322. saContactorList = saNewList;
  323. saCustomerShotCNameList = saNewCustomerShotCNameList;
  324. }
  325. }
  326. });
  327. }
  328. },
  329. {
  330. name: "RowIndex", title: 'common.RowNumber', type: "text", width: 30, align: "center", sorting: false
  331. },
  332. {
  333. name: "Call", title: '稱呼', type: "text", width: 40, itemTemplate: function (val, item) {
  334. if(item.Call == "1"){
  335. return "Mr.";
  336. } else if(item.Call == "2"){
  337. return "Miss.";
  338. }
  339. }
  340. },
  341. {
  342. name: "ContactorName", title: '聯絡人姓名', type: "text", width: 100
  343. },
  344. {
  345. name: "JobTitle", title: '職稱', type: "text", width: 100
  346. },
  347. {
  348. name: "CustomerShotCName", title: '客戶簡稱', type: "text", width: 120
  349. },
  350. {
  351. name: "UniCode", title: '統一編號', type: "text", width: 100
  352. },
  353. {
  354. name: "Telephone1", title: '電話', type: "text", width: 120
  355. },
  356. {
  357. name: "Ext1", title: '分機', type: "text", width: 80
  358. },
  359. {
  360. name: "Email1", title: 'Email', type: "text", width: 150
  361. },
  362. {
  363. name: "Birthday", title: '生日', type: "text", width: 60
  364. },
  365. {
  366. name: "ModifyDate", title: 'common.ModifyDate', type: "text", align: "center", width: 100,itemTemplate: function (val, item) {
  367. if(val != null){
  368. return newDate(val);
  369. }
  370. }
  371. }
  372. ],
  373. controller: {
  374. loadData: function (args) {
  375. return fnGet(args);
  376. }
  377. },
  378. onInit: function (args) {
  379. oGrid = args.grid;
  380. }
  381. });
  382. $("#Toolbar").append(
  383. '<button type="button" key="Combine" id="Toolbar_Combine" name="Toolbar_Combine" data-i18n="" class="btn-custom orange">合併</button>');
  384. $('#Toolbar_Combine').click(function () {
  385. if (saContactorList.length != 2) {
  386. showMsg("請勾選兩筆資料進行合併");
  387. return false;
  388. }
  389. if(saCustomerShotCNameList[0] != saCustomerShotCNameList[1]){
  390. showMsg("合併聯絡人只能選擇相同的客戶合併");
  391. return false;
  392. }
  393. fnCombineContactor(saContactorList[0].guid,saContactorList[1].guid);
  394. return false;
  395. });
  396. });
  397. };
  398. init();
  399. };
  400. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);