猎豆优选小程序

bindAlipay.vue 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <!-- 绑定支付宝 -->
  3. <view class="page-con">
  4. <u-navbar class="navbar-wrap" :is-back="true" title="绑定支付宝" :background="background" title-color="#ffffff" back-icon-color="#ffffff" />
  5. <view class="info">
  6. <text class="info-title">真实姓名</text>
  7. <input class="info-input" type="text" v-model="modifyAlipayAccount.real_name" placeholder="请填写姓名" />
  8. </view>
  9. <view class="info">
  10. <text class="info-title">支付宝账号</text>
  11. <input class="info-input" type="text" v-model="modifyAlipayAccount.alipay_account" placeholder="请填写支付宝账号" />
  12. </view>
  13. <view class="info">
  14. <text class="info-title">手机号码</text>
  15. <input class="info-input" type="text" v-model="modifyAlipayAccount.phone" placeholder="请填写手机号码" />
  16. </view>
  17. <view class="info">
  18. <text class="info-title">验证码</text>
  19. <input class="info-input" type="number" v-model="code" placeholder="请填写验证码" />
  20. <view :class="['yzm', codeTips != '获取验证码' ? 'yzm_active' : '']" @click="getCode()">{{codeTips != '获取验证码' ? codeTips + 's' : codeTips}}</view>
  21. </view>
  22. <view class="hint"><u-icon name="volume-up-fill"></u-icon> 若需要佣金提现服务,可录入支付宝账号信息,已录入的账号信息仅用于支付宝打款。</view>
  23. <button type="default" class="button" @click="modifyNow">{{isBind?'立即修改':'立即绑定'}}</button>
  24. </view>
  25. </template>
  26. <script>
  27. const md5 = require('../../../utils/md5')
  28. const app = getApp()
  29. export default {
  30. data() {
  31. return {
  32. background: app.globalData.navbarBackground,
  33. modifyAlipayAccount:{
  34. real_name:'',
  35. phone:'',
  36. alipay_account:''
  37. },
  38. codeTips: '获取验证码',
  39. code:'',
  40. isBind:true,//默认已经绑定
  41. }
  42. },
  43. onLoad() {
  44. this.getModifyAlipayAccount({toast:true})
  45. },
  46. methods: {
  47. // 点击立即修改
  48. async modifyNow () {
  49. if(!this.modifyAlipayAccount.real_name || this.modifyAlipayAccount.real_name == '') {
  50. uni.showToast({ title: '请输入真实姓名', icon: 'none' })
  51. return;
  52. }
  53. if(!this.modifyAlipayAccount.alipay_account || this.modifyAlipayAccount.alipay_account == '') {
  54. uni.showToast({ title: '请输入支付宝账号', icon: 'none' })
  55. return;
  56. }
  57. const regex = /^1[3456789]\d{9}$/;
  58. if (!regex.test(this.modifyAlipayAccount.phone)){
  59. uni.showToast({ title: '请输入正确手机号', icon: 'none' })
  60. return;
  61. }
  62. if(!this.code || this.code == '') {
  63. uni.showToast({ title: '请输入验证码', icon: 'none' })
  64. return;
  65. }
  66. try {
  67. let url = this.$api.users_modifyAlipayAccountCode;
  68. if(!this.isBind){// 从未绑定过支付宝,更换接口
  69. url = this.$api.users_bindAlipayCheckCode;
  70. }
  71. const params = {
  72. phone: this.modifyAlipayAccount.phone,
  73. code: this.code,
  74. alipay_account: this.modifyAlipayAccount.alipay_account,
  75. real_name: this.modifyAlipayAccount.real_name
  76. }
  77. uni.showLoading({ title: '加载中...', mask: true })
  78. const { data: res } = await this.$postJSON(url, params)
  79. uni.hideLoading()
  80. if (res && res.errno == 0) {
  81. uni.showToast({ title: res.rst.msg, icon: 'none' })
  82. if( res.rst.flag == 1){
  83. this.getModifyAlipayAccount({toast:false})
  84. this.code = '';
  85. this.codeTips = '获取验证码';
  86. setTimeout(function(){
  87. uni.navigateBack()
  88. },2000)
  89. }
  90. } else {
  91. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  92. }
  93. } catch (error) {
  94. uni.showToast({ title: '服务器错误', icon: 'none' })
  95. }
  96. },
  97. // 点击获取验证码
  98. getCode(){
  99. if(this.codeTips != '获取验证码') return;// 倒计时不可点击
  100. this.getSendCode()
  101. },
  102. // 获取验证码
  103. async getSendCode(){
  104. try {
  105. const ttl = parseInt((new Date().getTime()) / 1000)
  106. const secret_key = 'cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL'
  107. const sign = md5.hex_md5(`phone=${this.modifyAlipayAccount.phone}&ttl=${ttl}${secret_key}`)
  108. const url = this.$api.users_bindAlipaySendCode
  109. const params = {
  110. phone: this.modifyAlipayAccount.phone,
  111. ttl,
  112. sign
  113. }
  114. uni.showLoading({ title: '加载中...', mask: true })
  115. const { data: res } = await this.$postJSON(url, params)
  116. if (res && res.errno == 0) {
  117. this.codeTips = res.rst.wait_time;
  118. this.dTimeout()
  119. } else {
  120. uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  121. }
  122. } catch (error) {
  123. uni.showToast({ title: '服务器错误', icon: 'none' })
  124. } finally {
  125. uni.hideLoading()
  126. }
  127. },
  128. // 倒计时
  129. dTimeout () {
  130. let djs = setTimeout(()=>{
  131. if (this.codeTips > 0) {
  132. this.codeTips = this.codeTips - 1;
  133. this.dTimeout()
  134. }else{
  135. this.codeTips = '获取验证码'
  136. clearTimeout(djs)
  137. }
  138. },1000)
  139. },
  140. // 获取绑定支付宝
  141. async getModifyAlipayAccount({toast}){
  142. try {
  143. const url = this.$api.users_modifyAlipayAccountPage
  144. const params = {}
  145. toast && uni.showLoading({ title: '加载中...', mask: true })
  146. const { data: res } = await this.$postJSON(url, params)
  147. if (res && res.errno == 0) {
  148. this.modifyAlipayAccount = res.rst.data
  149. if(!res.rst.data.alipay_account || res.rst.data.alipay_account == ''){ //判断是否绑定过支付宝
  150. this.isBind = false
  151. }
  152. } else {
  153. toast && uni.showToast({ title: res.err || '操作失败', icon: 'none' })
  154. }
  155. } catch (error) {
  156. toast && uni.showToast({ title: '服务器错误', icon: 'none' })
  157. } finally {
  158. toast && uni.hideLoading()
  159. }
  160. },
  161. },
  162. }
  163. </script>
  164. <style scoped lang="scss">
  165. .page-con{
  166. background-color: #FFFFFF;
  167. height: 100vh;
  168. }
  169. .info{
  170. padding: 20rpx 40rpx;
  171. border-bottom: 2rpx solid #f4f4f4;
  172. display: flex;
  173. align-items: center;
  174. .info-title{
  175. font-size: 32rpx;
  176. line-height: 60rpx;
  177. color: #999999;
  178. display: block;
  179. width: 200rpx;
  180. }
  181. .info-input{
  182. flex: 1;
  183. font-size: 32rpx;
  184. }
  185. .yzm{
  186. font-size: 24rpx;
  187. line-height: 40rpx;
  188. border: 2rpx solid #F51400;
  189. color: #F51400;
  190. padding: 4rpx 0rpx;
  191. border-radius: 40rpx;
  192. width: 160rpx;
  193. text-align: center;
  194. }
  195. .yzm_active{
  196. background: #dddddd;
  197. color: #FFFFFF;
  198. border-color: #dddddd;
  199. }
  200. }
  201. .button{
  202. width: 600rpx;
  203. font-size: 32rpx;
  204. background: #F51400;
  205. color: #FFFFFF;
  206. margin-top: 200rpx;
  207. &::after{
  208. border: none;
  209. }
  210. }
  211. .hint{
  212. font-size: 22rpx;
  213. line-height: 30rpx;
  214. padding: 40rpx;
  215. color: #999;
  216. }
  217. </style>