huhaoguanli.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. huHaoList: [
  7. {
  8. id: 1,
  9. name: '王源',
  10. tag: '家',
  11. phone: '32018545245104',
  12. address: '徐州市丰县***楼102室',
  13. deleted: 0
  14. },
  15. {
  16. id: 2,
  17. name: '王长江',
  18. tag: '父母家',
  19. phone: '32018545245104',
  20. address: '徐州市泗县***楼502室',
  21. deleted: 0
  22. },
  23. {
  24. id: 3,
  25. name: '李明',
  26. tag: '公司',
  27. phone: '32018545245105',
  28. address: '徐州市云龙区***路88号',
  29. deleted: 0
  30. },
  31. {
  32. id: 4,
  33. name: '张伟',
  34. tag: '',
  35. phone: '32018545245106',
  36. address: '徐州市鼓楼区***街道45号',
  37. deleted: 0
  38. }
  39. ],
  40. showUnbindModal: false,
  41. currentHuHao: null
  42. },
  43. onLoad: function(options) {
  44. this.filterHuHaoList();
  45. },
  46. // 过滤户号列表,只显示deleted=0的数据
  47. filterHuHaoList: function() {
  48. const filteredList = this.data.huHaoList.filter(item => item.deleted === 0);
  49. this.setData({
  50. huHaoList: filteredList
  51. });
  52. },
  53. // 点击解除绑定按钮
  54. unbindHuHao: function(e) {
  55. const id = e.currentTarget.dataset.id;
  56. const huHao = this.data.huHaoList.find(item => item.id === id);
  57. this.setData({
  58. showUnbindModal: true,
  59. currentHuHao: huHao
  60. });
  61. },
  62. // 取消解绑
  63. cancelUnbind: function() {
  64. this.setData({
  65. showUnbindModal: false,
  66. currentHuHao: null
  67. });
  68. },
  69. // 确认解绑
  70. confirmUnbind: function() {
  71. const id = this.data.currentHuHao.id;
  72. // 这里应该调用后端接口,将deleted设为1
  73. // 模拟接口调用成功后的处理
  74. const updatedList = this.data.huHaoList.map(item => {
  75. if (item.id === id) {
  76. return {...item, deleted: 1};
  77. }
  78. return item;
  79. });
  80. this.setData({
  81. huHaoList: updatedList,
  82. showUnbindModal: false,
  83. currentHuHao: null
  84. });
  85. // 刷新页面数据
  86. this.filterHuHaoList();
  87. wx.showToast({
  88. title: '解绑成功',
  89. icon: 'success',
  90. duration: 2000
  91. });
  92. },
  93. // 跳转到绑定新户号页面
  94. goToBindNewHuHao: function() {
  95. wx.navigateTo({
  96. url: '/pages/huhaobangding/huhaobangding'
  97. });
  98. },
  99. /**
  100. * 返回上一页
  101. */
  102. goBack: function() {
  103. wx.navigateBack();
  104. },
  105. })