huhaoguanli.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. huHaoList: [],
  8. showUnbindModal: false,
  9. currentHuHao: null
  10. },
  11. onLoad: function (options) {
  12. this.getAccountList();
  13. },
  14. // 过滤户号列表,只显示deleted=0的数据
  15. getAccountList: function () {
  16. const _this = this;
  17. wx.showLoading({
  18. title: '获取中...',
  19. mask: true,
  20. });
  21. wx.request({
  22. url: app.globalData.interfaceUrls.accountList,
  23. method: 'GET',
  24. header: {
  25. 'content-type': 'application/json', // 默认值
  26. 'token': app.globalData.userWxInfo.token,
  27. 'source': "wc",
  28. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  29. },
  30. success(res) {
  31. wx.hideLoading();
  32. let apiReturnData = res.data;
  33. debugger;
  34. _this.setData({
  35. huHaoList: apiReturnData.data.map(data => {
  36. return {
  37. id: data.id,
  38. name: data.username,
  39. tag: data.groupName,
  40. phone: data.usernumber,
  41. address: data.address,
  42. deleted: 0
  43. };
  44. }),
  45. })
  46. },
  47. fail(error) {
  48. wx.hideLoading()
  49. utils.simleInfo('登录失败,请稍后再试')
  50. }
  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. })