huhaoguanli.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. huHaoList: [],
  8. showUnbindModal: false,
  9. unbindId: 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,
  36. })
  37. },
  38. fail(error) {
  39. wx.hideLoading()
  40. utils.simleInfo('获取数据失败,请稍后再试')
  41. }
  42. });
  43. },
  44. // 点击解除绑定按钮
  45. unbindHuHao: function (e) {
  46. const id = e.currentTarget.dataset.id;
  47. this.setData({
  48. showUnbindModal: true,
  49. unbindId: id
  50. });
  51. },
  52. // 取消解绑
  53. cancelUnbind: function () {
  54. this.setData({
  55. showUnbindModal: false,
  56. unbindId: null
  57. });
  58. },
  59. // 确认解绑
  60. confirmUnbind: function () {
  61. const id = this.data.unbindId;
  62. this.accountUnbind(id);
  63. },
  64. // 解绑方法
  65. accountUnbind:function (id) {
  66. debugger;
  67. const unbindInfo = this.data.huHaoList.filter(item => {
  68. return item.id === id;
  69. })[0];
  70. const otherInfo=this.data.huHaoList.filter(item => {
  71. return item.id!= id;
  72. });
  73. const _this = this;
  74. wx.showLoading({
  75. title: '获取中...',
  76. mask: true,
  77. });
  78. wx.request({
  79. url: app.globalData.interfaceUrls.accountUnbind,
  80. method: 'POST',
  81. data: {
  82. account: unbindInfo.usernumber,
  83. deKey: unbindInfo.dsKey,
  84. refresh: false,
  85. //为true 时otherDsKeys最好必填节约后端请求时间
  86. otherDsKeys: []
  87. },
  88. header: {
  89. 'content-type': 'application/json', // 默认值
  90. 'token': app.globalData.userWxInfo.token,
  91. // '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  92. },
  93. success(res) {
  94. wx.hideLoading();
  95. let apiReturnData = res.data;
  96. if(apiReturnData.code=='200'){
  97. wx.showToast({
  98. title: '解绑成功',
  99. icon: 'success',
  100. duration: 2000
  101. });
  102. _this.setData({
  103. huHaoList: otherInfo,
  104. showUnbindModal: false,
  105. currentHuHao: null
  106. });
  107. if(otherInfo.length==0){
  108. app.globalData.currentAccountInfo=[];
  109. app.globalData.userWxInfo.currentDsKey="";
  110. wx.redirectTo({
  111. url: '/pages/FirstBangDing/FirstBangDing',
  112. })
  113. }else{
  114. app.globalData.currentAccountInfo=otherInfo[0];
  115. app.globalData.userWxInfo.currentDsKey=otherInfo[0].deKey;
  116. }
  117. }else{
  118. wx.showToast({
  119. title: apiReturnData.msg,
  120. icon: 'error',
  121. duration: 2000
  122. })
  123. wx.hideLoading();
  124. }
  125. },
  126. fail(error) {
  127. wx.hideLoading();
  128. utils.simleInfo('户号解绑失败,请稍后再试');
  129. }
  130. });
  131. },
  132. // 跳转到绑定新户号页面
  133. goToBindNewHuHao: function () {
  134. wx.navigateTo({
  135. url: '/pages/huhaobangding/huhaobangding'
  136. });
  137. },
  138. /**
  139. * 返回上一页
  140. */
  141. goBack: function () {
  142. wx.navigateBack();
  143. },
  144. })