ZBLOG

$.ajax({ method: "POST", url: "../d/detail/keyInfo", data: { custId: custId }, success: function(result) { var jsonRes = JSON.parse(result); for (const item of jsonRes) { if (item.code === 'customerInfo...

为了在现有的 JavaScript 代码中为合同模块添加四个按钮(”全部”、”已结清”、”停催” 和 “诉讼”),并实现点击切换功能,你可以通过以下步骤来完成:

  1. 定义按钮:我们需要创建按钮并将它们添加到 DOM 中。
  2. 状态管理:我们需要一个变量来管理当前显示的贷款状态。
  3. 筛选逻辑:根据选中的按钮,筛选显示的合同信息。

以下是修改后的代码示例。请注意,我假设你将在合同模块的数据展示部分执行这些更改。

  1. $.ajax({
  2. method: "POST",
  3. url: "../d/detail/keyInfo",
  4. data: { custId: custId },
  5. success: function(result) {
  6. var jsonRes = JSON.parse(result);
  7. // 定义按钮状态
  8. const loanStatusButtons = ['all', 'settled', 'stopCollection', 'litigation'];
  9. let currentLoanStatus = 'all'; // 默认状态为全
  10. // 创建按钮并附加事件
  11. function createLoanStatusButtons() {
  12. const buttonContainer = document.createElement('div');
  13. buttonContainer.classList.add('loan-status-buttons');
  14. loanStatusButtons.forEach(status => {
  15. const button = document.createElement('button');
  16. button.innerText = status === 'settled' ? '已结清' :
  17. status === 'stopCollection' ? '停催' :
  18. status === 'litigation' ? '诉讼' :
  19. '全部';
  20. button.onclick = () => {
  21. currentLoanStatus = status;
  22. renderLoans(); // 更新显示的贷款数据
  23. };
  24. buttonContainer.appendChild(button);
  25. });
  26. document.body.appendChild(buttonContainer); // 假设你要将其添加到 body
  27. }
  28. createLoanStatusButtons(); // 初始化按钮
  29. function renderLoans() {
  30. for (const item of jsonRes) {
  31. if (item.code === 'loan') {
  32. const filteredLoans = item.child.filter(loan => {
  33. switch (currentLoanStatus) {
  34. case 'settled':
  35. return loan.status === "settled"; // 假设存在status属性标识是否已结清
  36. case 'stopCollection':
  37. return loan.status === "stopCollection"; // 同上
  38. case 'litigation':
  39. return loan.status === "litigation"; // 同上
  40. case 'all':
  41. default:
  42. return true; // 全部返回true
  43. }
  44. });
  45. item.child = filteredLoans; // 更新贷款信息为过滤后的结果
  46. for (const loan of filteredLoans) { // 渲染过滤后的贷款信息
  47. const Index = loan.path.split('.')[1];
  48. let contractCode;
  49. me.overDueInfoIndex[loan.path] = Index;
  50. const child_OverduePeriod = loan.child.find(val => val.code === "overduePeriod");
  51. const child_LoanCharacter = loan.child.find(val => val.code === "loanCharacter");
  52. if (child_LoanCharacter && child_LoanCharacter.value === "Y") {
  53. Object.assign(authMapLoan, { totalPaymentAmount: '' });
  54. }
  55. const child_ProductLine = loan.child.find(val => val.code === "productLine");
  56. if (child_ProductLine && !child_ProductLine.ifVirtual) {
  57. Object.assign(authMapLoan, { installmentLoanAmount: '' });
  58. const productLine = child_ProductLine.line;
  59. loan.child.forEach(child => {
  60. if (child.code == 'overduePeriod') {
  61. if (child.title.includes("(") && child.title.includes(")")) {
  62. child.title = child.title.replace('(', '(').replace(')', ')');
  63. }
  64. }
  65. if (child.code == 'loanStatus' && child_OverduePeriod && child_OverduePeriod.value == '0') {
  66. child.valueMap[child.value] += `(${lang('NO_DEBT')})`;
  67. }
  68. if (child.code === 'contractCode') {
  69. contractCode = child.value;
  70. me.loanPathContractCodes[loan.path] = child.value;
  71. }
  72. if (!(child.code in authMapLoan)) arr.push(child);
  73. });
  74. }
  75. }
  76. }
  77. }
  78. me.keyInfo = JSON.parse(result)
  79. me.form.initForm(jsonRes)
  80. }
  81. renderLoans(); // 初始渲染所有贷款
  82. }
  83. });

说明:

  • 创建按钮createLoanStatusButtons 函数动态创建了四个按钮,并给每个按钮绑定了点击事件。
  • 状态管理:使用 currentLoanStatus 来跟踪当前选择的状态。
  • 筛选逻辑:在 renderLoans 函数中,根据所选的状态对贷款进行筛选,并更新展示的信息。

请确保替换适合你的 HTML 结构和样式。如果还需其他帮助,请告诉我!


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=22062

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?