123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- huHaoList: [],
- showUnbindModal: false,
- unbindId: null
- },
- onLoad: function (options) {
- this.getAccountList();
- },
- // 过滤户号列表,只显示deleted=0的数据
- getAccountList: function () {
- const _this = this;
- wx.showLoading({
- title: '获取中...',
- mask: true,
- });
- wx.request({
- url: app.globalData.interfaceUrls.accountList,
- method: 'GET',
- header: {
- 'content-type': 'application/json', // 默认值
- 'token': app.globalData.userWxInfo.token,
- 'source': "wc",
- '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
- },
- success(res) {
- wx.hideLoading();
- let apiReturnData = res.data;
- debugger;
- _this.setData({
- huHaoList: apiReturnData.data,
- })
- },
- fail(error) {
- wx.hideLoading()
- utils.simleInfo('获取数据失败,请稍后再试')
- }
- });
- },
- // 点击解除绑定按钮
- unbindHuHao: function (e) {
- const id = e.currentTarget.dataset.id;
- this.setData({
- showUnbindModal: true,
- unbindId: id
- });
- },
- // 取消解绑
- cancelUnbind: function () {
- this.setData({
- showUnbindModal: false,
- unbindId: null
- });
- },
- // 确认解绑
- confirmUnbind: function () {
- const id = this.data.unbindId;
- this.accountUnbind(id);
- },
- // 解绑方法
- accountUnbind:function (id) {
- debugger;
- const unbindInfo = this.data.huHaoList.filter(item => {
- return item.id === id;
- })[0];
- const otherInfo=this.data.huHaoList.filter(item => {
- return item.id!= id;
- });
- const _this = this;
- wx.showLoading({
- title: '获取中...',
- mask: true,
- });
- wx.request({
- url: app.globalData.interfaceUrls.accountUnbind,
- method: 'POST',
- data: {
- account: unbindInfo.usernumber,
- deKey: unbindInfo.dsKey,
- refresh: false,
- //为true 时otherDsKeys最好必填节约后端请求时间
- otherDsKeys: []
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'token': app.globalData.userWxInfo.token,
- // '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
- },
- success(res) {
- wx.hideLoading();
- let apiReturnData = res.data;
- if(apiReturnData.code=='200'){
- wx.showToast({
- title: '解绑成功',
- icon: 'success',
- duration: 2000
- });
- _this.setData({
- huHaoList: otherInfo,
- showUnbindModal: false,
- currentHuHao: null
- });
- if(otherInfo.length==0){
- app.globalData.currentAccountInfo=[];
- app.globalData.userWxInfo.currentDsKey="";
- wx.redirectTo({
- url: '/pages/FirstBangDing/FirstBangDing',
- })
- }else{
- app.globalData.currentAccountInfo=otherInfo[0];
- app.globalData.userWxInfo.currentDsKey=otherInfo[0].deKey;
- }
- }else{
- wx.showToast({
- title: apiReturnData.msg,
- icon: 'error',
- duration: 2000
- })
- wx.hideLoading();
- }
- },
- fail(error) {
- wx.hideLoading();
- utils.simleInfo('户号解绑失败,请稍后再试');
- }
- });
- },
- // 跳转到绑定新户号页面
- goToBindNewHuHao: function () {
- wx.navigateTo({
- url: '/pages/huhaobangding/huhaobangding'
- });
- },
- /**
- * 返回上一页
- */
- goBack: function () {
- wx.navigateBack();
- },
- })
|