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.

537 lines
29 KiB

3 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sEditPrgId = getEditPrgId(),
  4. sViewPrgId = sProgramId.replace('_Qry', '_View'),
  5. oGrid = null,
  6. fnPageInit = function () {
  7. var oForm = $('#form_main'),
  8. oBaseQueryPm = {
  9. pageIndex: 1,
  10. pageSize: parent.SysSet.GridRecords || 10,
  11. sortField: 'ModifyDate',
  12. sortOrder: 'desc'
  13. },
  14. /**
  15. * 獲取資料
  16. */
  17. fnGet = function (args) {
  18. var oQueryPm = getFormSerialize(oForm);
  19. $.extend(oQueryPm, oBaseQueryPm, args);
  20. oBaseQueryPm.pageIndex = oQueryPm.pageIndex;
  21. oQueryPm.Roles = parent.UserInfo.roles;
  22. return g_api.ConnectLite(sProgramId, 'QueryPage', oQueryPm, function (res) {
  23. if (res.RESULT) {
  24. var oRes = res.DATA.rel;
  25. if (args.Excel) {//匯出
  26. DownLoadFile(oRes);
  27. }
  28. }
  29. });
  30. },
  31. fnAdd = function (data) {
  32. data = packParams(data);
  33. g_api.ConnectLite('BusinessOpportunity_Qry', 'Insert', data,
  34. function (res) {
  35. if (res.RESULT == '1') {
  36. showMsg(i18next.t("message.Save_Success"), 'success');
  37. } else {
  38. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  39. }
  40. },
  41. function (res) {
  42. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  43. }
  44. )
  45. },
  46. /**
  47. * ToolBar 按鈕事件 function
  48. * @param {Object}inst 按鈕物件對象
  49. * @param {Object} e 事件對象
  50. */
  51. fnModifyBusinessOpportunity = function (data) {
  52. var formData = {};
  53. layer.open({
  54. type: 2, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  55. title: "編輯潛在商機",//i18next.t('common.CustomerTransferToFormal'),// ╠common.CustomerTransferToFormal⇒匯入廠商轉正╣
  56. area: ['70%', '90%'],//寬度
  57. shade: 0.75,//遮罩
  58. //maxmin: true, //开启最大化最小化按钮
  59. id: 'layer_CombineContactor', //设定一个id,防止重复弹出
  60. offset: '10px',//右下角弹出
  61. anim: 0,//彈出動畫
  62. btn: ['作廢','儲存', i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  63. btnAlign: ['c'],//按鈕位置
  64. content: '../CRM/BusinessOpportunity_Upd.html',
  65. success: function (layero, index) {
  66. $('.layui-layer-btn0').css('border', '1px solid #dedede');
  67. $('.layui-layer-btn0').css('background-color', '#FFF');
  68. $('.layui-layer-btn0').css('color', '#333');
  69. $('.layui-layer-btn1').css('background-color', '#1E9FFF');
  70. $('.layui-layer-btn1').css('color', '#FFF');
  71. g_api.ConnectLite('BusinessOpportunity_Qry', 'QueryOne',
  72. {
  73. SN: data.SN
  74. }, function (res) {
  75. if (res.RESULT) {
  76. var oRes = res.DATA.rel;
  77. var iframe = layero.find('iframe').contents();
  78. var DateStart = oRes['DateStart'];
  79. var DateEnd = oRes['DateEnd'];
  80. var sDateStart = '';
  81. var sDateEnd = '';
  82. var DateStr = '';
  83. try {
  84. sDateStart = DateStart.split('T')[0].replaceAll('-', '/');
  85. sDateEnd = DateEnd.split('T')[0].replaceAll('-', '/');
  86. DateStr = sDateStart + '' + " ~ " + sDateEnd;
  87. } catch (e) {
  88. DateStr = null;
  89. }
  90. iframe.find("#State").html($("#State").html());
  91. iframe.find("#Industry").html($("#Industry").html());
  92. if (oRes['ExhibitionNO'] != "") {
  93. iframe.find("#BtnExhibitionCode").attr({ disabled: 'disabled' });
  94. iframe.find('#CreateExhibition').attr({ disabled: 'disabled' });
  95. iframe.find("#ExhibitionShotName").attr({ disabled: 'disabled' });
  96. iframe.find("#ExhibitionName").attr({ disabled: 'disabled' });
  97. iframe.find("#ExhibitionName_EN").attr({ disabled: 'disabled' });
  98. iframe.find("#State").attr({ disabled: 'disabled' });
  99. iframe.find("#Industry").attr({ disabled: 'disabled' });
  100. iframe.find("#Year").attr({ disabled: 'disabled' });
  101. iframe.find("#Date").attr({ disabled: 'disabled' });
  102. }
  103. if (oRes['Effective'] === '1') {
  104. iframe.find('[name = Effective][value = "1"]').click();
  105. $('.layui-layer-btn0').hide();
  106. }else if (oRes['Effective'] === '2')
  107. {
  108. iframe.find('[name = Effective][value = "2"]').click();
  109. iframe.find("#BtnExhibitionCode").attr({ disabled: false });
  110. iframe.find('#CreateExhibition').attr({ disabled: false });
  111. iframe.find("#ExhibitionShotName").attr({ disabled: false });
  112. iframe.find("#ExhibitionName").attr({ disabled: false });
  113. iframe.find("#ExhibitionName_EN").attr({ disabled: false });
  114. iframe.find("#State").attr({ disabled: false });
  115. iframe.find("#Industry").attr({ disabled: false });
  116. iframe.find("#Year").attr({ disabled: false });
  117. iframe.find("#Date").attr({ disabled: false });
  118. $('.layui-layer-btn0').css('position', 'absolute');
  119. $('.layui-layer-btn0').css('left', '5%');
  120. } else {
  121. var EffectiveStatusHtml =
  122. '<input id="Effective_1" type="radio" name="Effective" value="1" />\
  123. <label for="Effective_1" data-i18n="已處理">已處理</label>\
  124. <input id="Effective_2" type="radio" name="Effective" value="2" />\
  125. <label for="Effective_2" data-i18n="未處理">未處理</label>\
  126. <input id="Effective_0" type="radio" name="Effective" value="0" />\
  127. <label for="Effective_0" data-i18n="已作廢">已作廢</label>';
  128. iframe.find('#EffectiveStatusDiv').html(EffectiveStatusHtml);
  129. iframe.find('[name = Effective][value = "0"]').click();
  130. iframe.find('[name = Effective][value = "1"]').attr({ disabled: 'disabled' });
  131. iframe.find('[name = Effective]').click(function () {
  132. if($(this).val() == "2" || $(this).val() == "0"){
  133. iframe.find('#BtnExhibitionCode').attr('disabled', false);
  134. iframe.find('#CreateExhibition').attr('disabled', false);
  135. iframe.find("#ExhibitionShotName").attr('disabled', false);
  136. iframe.find("#ExhibitionName").attr('disabled', false);
  137. iframe.find("#ExhibitionName_EN").attr('disabled', false);
  138. iframe.find("#State").attr('disabled', false);
  139. iframe.find("#Industry").attr('disabled', false);
  140. iframe.find("#Year").attr('disabled', false);
  141. iframe.find("#Date").attr('disabled', false);
  142. iframe.find('#ExhibitionCode').val('');
  143. iframe.find('[name=Effective][value="1"]').attr('disabled', true);
  144. }
  145. })
  146. $('.layui-layer-btn0').hide();
  147. iframe.find("#BtnExhibitionCode").attr({ disabled: false });
  148. iframe.find('#CreateExhibition').attr({ disabled: false });
  149. iframe.find("#ExhibitionShotName").attr({ disabled: false });
  150. iframe.find("#ExhibitionName").attr({ disabled: false });
  151. iframe.find("#ExhibitionName_EN").attr({ disabled: false });
  152. iframe.find("#State").attr({ disabled: false });
  153. iframe.find("#Industry").attr({ disabled: false });
  154. iframe.find("#Year").attr({ disabled: false });
  155. iframe.find("#Date").attr({ disabled: false });
  156. iframe.find('#BtnExhibitionCode').val("");
  157. }
  158. iframe.find("#BtnExhibitionCode").val(oRes['ExhibitionNO'])
  159. iframe.find("#Year").val(oRes['Year']);
  160. iframe.find("#Date").val(DateStr);
  161. iframe.find("#ExhibitionShotName").val(oRes['ExhibitionShotName']);
  162. iframe.find("#ExhibitionName").val(oRes['ExhibitionName']);
  163. iframe.find("#ExhibitionName_EN").val(oRes['ExhibitionName_EN']);
  164. iframe.find("#State").val(oRes['State']);
  165. iframe.find("#Industry").val(oRes['Industry']);
  166. iframe.find("#CustomerName").val(oRes['CustomerName']);
  167. iframe.find("#Contactor").val(oRes['Contactor']);
  168. iframe.find("#Department").val(oRes['Department']);
  169. iframe.find("#JobTitle").val(oRes['JobTitle']);
  170. iframe.find("#Email1").val(oRes['Email1']);
  171. iframe.find("#Email2").val(oRes['Email2']);
  172. iframe.find("#Telephone1").val(oRes['Telephone1']);
  173. iframe.find("#Telephone2").val(oRes['Telephone2']);
  174. iframe.find("#labelCreateUser").html("CreateName");
  175. iframe.find("#labelCreateUser").html(oRes['CreateUser']);
  176. iframe.find("#labelModifyUser").html(oRes['ModifyUser']);
  177. iframe.find("#labelCreateDate").html(oRes['CreateDate']);
  178. iframe.find("#labelModifyDate").html(oRes['ModifyDate']);
  179. }
  180. }
  181. );
  182. },
  183. yes: function (index, layero) {
  184. layer.confirm("確定要作廢?", { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  185. var iframe = layero.find('iframe').contents();
  186. formData = getFormSerialize($(iframe.find('#form_main')));
  187. formData.ExhibitionCode = iframe.find('#BtnExhibitionCode').val();
  188. var voidFlag = iframe.find('input[name=Effective]:checked').val();
  189. if (voidFlag === "0") {
  190. showMsg("作廢失敗,此單已作廢", 'error');
  191. layer.close(index);
  192. return;
  193. }
  194. g_api.ConnectLite('BusinessOpportunity_Qry', 'UpdateByGuid', {
  195. SN: data.SN,
  196. }, function (res) {
  197. showMsg("作廢成功", 'success');
  198. }, function (res) {
  199. showMsg("作廢失敗", 'error');
  200. });
  201. layer.close(index);
  202. layer.close(index-1);
  203. });
  204. },
  205. btn2: function (index, layero) {
  206. var iframe = layero.find('iframe').contents();
  207. var formData = getFormSerialize($(iframe.find('#form_main')));
  208. try {
  209. formData.DateStart = $.trim(formData.Date.split('~')[0]);
  210. formData.DateEnd = $.trim(formData.Date.split('~')[1]);
  211. } catch (e) {
  212. formData.DateStart = null;
  213. formData.DateEnd = null;
  214. }
  215. formData.ExhibitionNO = iframe.find('#BtnExhibitionCode').val();
  216. formData.SN = data.SN;
  217. layer.confirm("確定要儲存?", { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  218. if (formData.CustomerName == "" || formData.CustomerName == null) {
  219. showMsg("請輸入公司名稱", 'info');
  220. layer.close(index);
  221. return;
  222. }
  223. if (formData.Contactor == "" || formData.Contactor == null) {
  224. showMsg("請輸入聯絡人", 'info');
  225. layer.close(index);
  226. return;
  227. }
  228. g_api.ConnectLite('BusinessOpportunity_Qry', 'Update', formData,
  229. function (res) {
  230. if (res.RESULT == '1') {
  231. showMsg(i18next.t("儲存成功"), 'success');
  232. //showMsgAndGo(i18next.t("儲存成功"), sProgramId, '?Action=Upd&SN=0'); // ╠message.Save_Success⇒新增成功╣
  233. } else {
  234. showMsg(i18next.t(""), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  235. }
  236. },
  237. function (res) {
  238. showMsg(i18next.t("儲存失敗"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  239. }
  240. )
  241. layer.close(index);
  242. layer.close(index - 1);
  243. });
  244. return false;
  245. },
  246. end: function () {
  247. oGrid.loadData();
  248. }
  249. });
  250. },
  251. setStateDrop = function () {
  252. return g_api.ConnectLite(Service.com, ComFn.GetArguments, {
  253. OrgID: 'TE',
  254. ArgClassID: 'Area',
  255. LevelOfArgument: 1
  256. }, function (res) {
  257. if (res.RESULT) {
  258. let saState = res.DATA.rel;
  259. if (saState.length > 0) {
  260. $('#State').append(createOptions(saState, 'id', 'text', true)).select2();
  261. }
  262. }
  263. });
  264. },
  265. fnAddBusinessOpportunity = function (_guid1,_guid2, title) {
  266. layer.open({
  267. type: 2, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
  268. title: "建立潛在商機",//i18next.t('common.CustomerTransferToFormal'),// ╠common.CustomerTransferToFormal⇒匯入廠商轉正╣
  269. area: ['70%', '90%'],//寬度
  270. shade: 0.75,//遮罩
  271. //maxmin: true, //开启最大化最小化按钮
  272. id: 'layer_CombineContactor', //设定一个id,防止重复弹出
  273. offset: '10px',//右下角弹出
  274. anim: 0,//彈出動畫
  275. btn: ['儲存', i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  276. btnAlign: 'c',//按鈕位置
  277. content: '../CRM/BusinessOpportunity_Upd.html',
  278. success: function (layero, index) {
  279. var iframe = layero.find('iframe').contents();
  280. iframe.find('[name = Effective][value = "2"]').click();
  281. iframe.find("#State").html($("#State").html());
  282. iframe.find("#Industry").html($("#Industry").html());
  283. },
  284. yes: function (index, layero) {
  285. layer.confirm("確定要儲存?", { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  286. var iframe = layero.find('iframe').contents();
  287. var formData = getFormSerialize($(iframe.find('#form_main')));
  288. if (formData.CustomerName == "" || formData.CustomerName == null) {
  289. showMsg("請輸入公司名稱",'info');
  290. layer.close(index);
  291. return;
  292. }
  293. if (formData.Contactor == "" || formData.Contactor == null) {
  294. showMsg("請輸入聯絡人", 'info');
  295. layer.close(index);
  296. return;
  297. }
  298. try {
  299. formData.DateStart = $.trim(formData.Date.split('~')[0]);
  300. formData.DateEnd = $.trim(formData.Date.split('~')[1]);
  301. } catch (e) {
  302. formData.DateStart = null;
  303. formData.DateEnd = null;
  304. }
  305. formData.ExhibitionCode = iframe.find('#BtnExhibitionCode').val();
  306. fnAdd(formData);
  307. layer.close(index);
  308. layer.close(index - 1);
  309. });
  310. },
  311. end: function () {
  312. oGrid.loadData();
  313. }
  314. });
  315. },
  316. fnButtonHandler = function (inst, e) {
  317. var sId = inst.id;
  318. switch (sId) {
  319. case "Toolbar_Qry":
  320. var iNum = $('#PerPageNum').val();
  321. oGrid.pageSize = iNum === '' ? parent.SysSet.GridRecords || 10 : iNum;
  322. cacheQueryCondition();
  323. oGrid.openPage(window.bToFirstPage ? 1 : oBaseQueryPm.pageIndex);
  324. break;
  325. case "Toolbar_Save":
  326. break;
  327. case "Toolbar_ReAdd":
  328. break;
  329. case "Toolbar_Clear":
  330. clearPageVal();
  331. break;
  332. case "Toolbar_Leave":
  333. break;
  334. case "Toolbar_Add":
  335. fnAddBusinessOpportunity();
  336. break;
  337. case "Toolbar_Upd":
  338. break;
  339. case "Toolbar_Copy":
  340. break;
  341. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  342. break;
  343. case "Toolbar_Exp":
  344. if (oGrid.data.length === 0) {
  345. showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
  346. return false;
  347. }
  348. fnGet({ Excel: true });
  349. break;
  350. default:
  351. alert("No handle '" + sId + "'");
  352. break;
  353. }
  354. },
  355. /**
  356. * 頁面初始化
  357. */
  358. init = function () {
  359. commonInit({
  360. PrgId: sProgramId,
  361. ButtonHandler: fnButtonHandler,
  362. SearchBar: true
  363. });
  364. let saIndustry;
  365. $.whenArray([
  366. setStateDrop(),
  367. fnSetArgDrop([
  368. {
  369. OrgID: 'TE',
  370. ArgClassID: 'ExhibClass',
  371. Select: $('#Industry'),
  372. Select2: true,
  373. ShowId: true
  374. }
  375. ]),
  376. fnSetUserDrop([
  377. {
  378. Select: $('#CreateUser'),
  379. ShowId: true,
  380. Select2: true
  381. }
  382. ]),
  383. g_api.ConnectLite(Service.com, ComFn.GetArguments,
  384. {
  385. ArgClassID: "ExhibClass",
  386. OrgID: 'TE'
  387. },
  388. function (res) {
  389. if (res.RESULT) {
  390. var saRes = res.DATA.rel;
  391. saIndustry = saRes;
  392. }
  393. })
  394. ]).done(function () {
  395. parent.open
  396. reSetQueryPm(sProgramId);
  397. var iHeight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
  398. $("#jsGrid").jsGrid({
  399. width: "100%",
  400. height: iHeight + "px",
  401. autoload: true,
  402. pageLoading: true,
  403. inserting: false,
  404. editing: true,
  405. sorting: true,
  406. paging: true,
  407. pageIndex: window.bToFirstPage ? 1 : window.QueryPageidx || 1,
  408. pageSize: parent.SysSet.GridRecords || 10,
  409. pageButtonCount: parent.SysSet.GridPages || 15,
  410. pagePrevText: "<",
  411. pageNextText: ">",
  412. pageFirstText: "<<",
  413. pageLastText: ">>",
  414. rowClass: function (item) {
  415. if (item.Effective === '0') {
  416. return 'data-void';
  417. }
  418. },
  419. onPageChanged: function (args) {
  420. cacheQueryCondition(args.pageIndex);
  421. },
  422. rowClick: function (args) {
  423. if (navigator.userAgent.match(/mobile/i)) {
  424. if ('A,C'.indexOf(args.item.Status) > -1 && args.item.AskTheDummy === parent.UserID) {
  425. goToEdit(sEditPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  426. }
  427. else {
  428. goToEdit(sViewPrgId, '?Action=Upd&Guid=' + args.item.Guid);
  429. }
  430. }
  431. },
  432. rowDoubleClick: function (args) {
  433. if ('A,C'.indexOf(args.item.Status) > -1 && args.item.Applicant === parent.UserID) {
  434. fnModifyBusinessOpportunity(args.item);
  435. }
  436. else {
  437. fnModifyBusinessOpportunity(args.item);
  438. }
  439. },
  440. fields: [
  441. { name: "RowIndex", title: 'common.RowNumber', align: 'center', width: 40, sorting: false },
  442. { name: "Year", title: '展覽年分', align: 'center', width: 60 },
  443. {
  444. name: "Date", title: '展覽月分', width: 60, align: 'center', itemTemplate: function (val, item) {
  445. var DateStart = new Date(item['DateStart']);
  446. var DateEnd = new Date(item['DateEnd']);
  447. var DateStartVal = parseInt(DateStart.getMonth()) + 1;
  448. var DateStr = ''
  449. if (DateStart.getMonth() != DateEnd.getMonth()) {
  450. DateStr = DateStartVal;
  451. } else {
  452. DateStr = DateStartVal;
  453. }
  454. if (item['DateStart'] == null || item['DateEnd'] == null) {
  455. DateStr = '';
  456. }
  457. return DateStr;
  458. }
  459. },
  460. { name: "ExhibitionName", title: '展覽名稱', width: 150, align: 'center' },
  461. { name: "ExhibitionName_EN", title: '展覽英文名稱', width: 150, align: 'center' },
  462. { name: "State", title: '國家', width: 60, align: 'center' },
  463. {
  464. name: "Industry", title: '產業別', width: 60, align: 'center', itemTemplate: function (val, item) {
  465. for (let idx in saIndustry) {
  466. var sId = saIndustry[idx]['id'] || '';
  467. var sVal = val || '';
  468. if (sId.trim() == sVal) {
  469. return saIndustry[idx]['text'];
  470. }
  471. }
  472. return "";
  473. }
  474. },
  475. { name: "CustomerName", title: '公司名稱', width: 60, align: 'center' },
  476. { name: "Contactor", title: '聯絡人', width: 60, align: 'center' },
  477. { name: "CreateUser", title: 'common.CreateUser', width: 70, align: 'center' },
  478. {
  479. name: "CreateDate", title: 'common.CreateDate', width: 90, align: 'center', itemTemplate: function (val, item) {
  480. return newDate(val);
  481. }
  482. },
  483. {
  484. name: "ModifyDate", title: 'common.ModifyDate', width: 90, align: 'center', itemTemplate: function (val, item) {
  485. return newDate(val);
  486. }
  487. },
  488. {
  489. name: "Effective", title: '狀態', width: 70, align: 'center', itemTemplate: function (val, item) {
  490. if (val == "1") {
  491. return "已處理";
  492. } else if (val == '2') {
  493. return "未處裡";
  494. } else {
  495. return "已作廢";
  496. }
  497. }
  498. },
  499. ],
  500. controller: {
  501. loadData: function (args) {
  502. return fnGet(args);
  503. },
  504. },
  505. onInit: function (args) {
  506. oGrid = args.grid;
  507. }
  508. });
  509. })
  510. };
  511. init();
  512. };
  513. require(['base', 'select2', 'jsgrid', 'util'], fnPageInit);