Commit 86b06ea6 by zhangxw

登录修改

1 parent 7c14f61a
// pages/Login/components/EnableWallet/EnableWallet.js // pages/Login/components/EnableWallet/EnableWallet.js
import commonApi from '~/api/module/common.js'
Component({ Component({
/** /**
...@@ -10,7 +11,12 @@ Component({ ...@@ -10,7 +11,12 @@ Component({
}, },
walletObj: { walletObj: {
type: Object, type: Object,
value: {} value: {},
observer: function(n) {
this.setData({
copyWalletObj: JSON.parse(JSON.stringify(n))
})
}
} }
}, },
...@@ -40,7 +46,26 @@ Component({ ...@@ -40,7 +46,26 @@ Component({
methods: { methods: {
// 关闭弹窗 // 关闭弹窗
closeWallet() { closeWallet() {
this.triggerEvent('close') let { copyWalletObj } = this.data
this.setData({show: false})
// 仅替换积分数据返回的内容,使用copyWalletObj 防止修改弹窗内容也做了替换
this.replaceNickName(copyWalletObj)
},
// 替换积分钱包名称
replaceNickName(data) {
let userInfo = wx.p.cache.userInfo.getUserInfo()
commonApi.replaceWalletName({
nickName: data?.name,
phone: data?.phone,
scoreSource: data?.scoreSource
}).then(res => {
let { code, message } = res
if (code == 0) {
wx.p.storage.set('userInfo', {...userInfo, nickName: data?.name}) // 更新storage中的nickName
} else {
wx.p.wxApi.showToast(message)
}
})
}, },
input(e) { input(e) {
let { target } = e.currentTarget.dataset let { target } = e.currentTarget.dataset
...@@ -50,12 +75,28 @@ Component({ ...@@ -50,12 +75,28 @@ Component({
[`walletObj.${target}`]: value [`walletObj.${target}`]: value
}) })
}, },
// 一键开通积分钱包
enableWalletConfirm() {
let { walletObj } = this.data
commonApi.openPointsWallet(walletObj).then(res => {
let { code, message } = res
if (code == 0) {
this.setData({
showEnableSuccess: true,
show: false
})
this.replaceNickName(walletObj)
} else {
wx.p.wxApi.showToast(message)
}
})
},
// 开通 // 开通
confirm() { confirm() {
let { walletObj } = this.data let { walletObj } = this.data
if (!walletObj?.name) return wx.p.wxApi.showToast('姓名不能为空') if (!walletObj?.name) return wx.p.wxApi.showToast('姓名不能为空')
if (!walletObj?.phone || !/^[1]([3-9])[0-9]{9}$/.test(walletObj?.phone)) return wx.p.wxApi.showToast('请输入正确手机号') if (!walletObj?.phone || !/^[1]([3-9])[0-9]{9}$/.test(walletObj?.phone)) return wx.p.wxApi.showToast('请输入正确手机号')
this.triggerEvent('confirm', {walletObj}) this.enableWalletConfirm()
} }
} }
}) })
\ No newline at end of file \ No newline at end of file
{ {
"component": true, "component": true,
"usingComponents": {} "usingComponents": {
"enable-success": "/components/EnableSuccess/EnableSuccess"
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -33,4 +33,6 @@ ...@@ -33,4 +33,6 @@
<view class="wallet-btn" bindtap="confirm">一键开通</view> <view class="wallet-btn" bindtap="confirm">一键开通</view>
</view> </view>
</view> </view>
</view>
\ No newline at end of file \ No newline at end of file
</view>
<!-- 钱包开通成功 -->
<enable-success show="{{showEnableSuccess}}" bindconfirm="successConfirm"></enable-success>
\ No newline at end of file \ No newline at end of file
...@@ -134,11 +134,12 @@ Page({ ...@@ -134,11 +134,12 @@ Page({
const userInfo = wx.p.cache.userInfo.getUserInfo() const userInfo = wx.p.cache.userInfo.getUserInfo()
this.setData({userInfo}) this.setData({userInfo})
wx.p.router.getRouterParams(options).then(params => { wx.p.router.getRouterParams(options).then(params => {
this.setData({loginPageFlag: params?.loginPageFlag}) this.setData({loginPageFlag: params?.loginPageFlag}, () => {
this.getPointsWallet()
})
}).catch(err => { }).catch(err => {
console.error('参数获取失败:', err) console.error('参数获取失败:', err)
}) })
this.getPointsWallet()
}, },
// 获取积分钱包数据 // 获取积分钱包数据
...@@ -179,45 +180,6 @@ Page({ ...@@ -179,45 +180,6 @@ Page({
}) })
}, },
closeWallet() {
let { copyWalletObj } = this.data
this.setData({showEnableWallet: false})
// 仅替换积分数据返回的内容,使用copyWalletObj 防止修改弹窗内容也做了替换
this.replaceNickName(copyWalletObj)
},
// 替换积分钱包名称
replaceNickName(data) {
let userInfo = wx.p.cache.userInfo.getUserInfo()
commonApi.replaceWalletName({
nickName: data?.name,
phone: data?.phone,
scoreSource: data?.scoreSource
}).then(res => {
let { code, message } = res
if (code == 0) {
wx.p.storage.set('userInfo', {...userInfo, nickName: data?.name}) // 更新storage中的nickName
} else {
wx.p.wxApi.showToast(message)
}
})
},
// 一键开通积分钱包
enableWalletConfirm(e) {
let { walletObj } = e.detail
commonApi.openPointsWallet(walletObj).then(res => {
let { code, message } = res
if (code == 0) {
this.setData({
showEnableSuccess: true,
showEnableWallet: false
})
this.replaceNickName(walletObj)
} else {
wx.p.wxApi.showToast(message)
}
})
},
// 跳转积分中心 // 跳转积分中心
handleToPointCenter() { handleToPointCenter() {
wx.p.router.go('/packageIndex/pages/integral/index/index') wx.p.router.go('/packageIndex/pages/integral/index/index')
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
"good-tab": "./components/good-tab/good-tab", "good-tab": "./components/good-tab/good-tab",
"goods": "/components/goods/goods", "goods": "/components/goods/goods",
"search-box": "./components/SearchBox/SearchBox", "search-box": "./components/SearchBox/SearchBox",
"enable-wallet": "/components/EnableWallet/EnableWallet", "enable-wallet": "/components/EnableWallet/EnableWallet"
"enable-success": "/components/EnableSuccess/EnableSuccess"
}, },
"navigationStyle": "custom", "navigationStyle": "custom",
"backgroundColor": "#F9F7F7" "backgroundColor": "#F9F7F7"
......
...@@ -56,7 +56,5 @@ ...@@ -56,7 +56,5 @@
</view> </view>
</block> </block>
<!-- 开通钱包 --> <!-- 开通钱包 -->
<enable-wallet show="{{showEnableWallet}}" walletObj="{{walletObj}}" bindclose="closeWallet" bindconfirm="enableWalletConfirm"></enable-wallet> <enable-wallet show="{{showEnableWallet}}" walletObj="{{walletObj}}"></enable-wallet>
<!-- 钱包开通成功 -->
<enable-success show="{{showEnableSuccess}}" bindconfirm="successConfirm"></enable-success>
<glsx-privacy appletName="积分商城"></glsx-privacy> <glsx-privacy appletName="积分商城"></glsx-privacy>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!