alipay-account.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!-- 绑定支付宝帐号 alipayAccount -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60">
  6. <view class="head-title ss-m-b-20">
  7. {{ userInfo.alipayName && userInfo.alipayAccount ? t('account.change_alipay_account') : t('account.bind_alipay_account') }}
  8. </view>
  9. <view class="head-subtitle">{{ t('account.bind_realname_alipay') }}</view>
  10. </view>
  11. <!-- 表单项 -->
  12. <uni-forms ref="alipayAccountRef" v-model="state.model" :rules="state.rules" validateTrigger="bind"
  13. labelWidth="140" labelAlign="center" class="loginUniForm">
  14. <uni-forms-item :label="t('account.name')" class="loginUniFormItem">
  15. <uni-easyinput :placeholder="t('account.enter_name')" v-model="state.model.alipayName" :inputBorder="false">
  16. </uni-easyinput>
  17. </uni-forms-item>
  18. <uni-forms-item name="alipayAccount" :label="t('account.account')" class="loginUniFormItem">
  19. <uni-easyinput :placeholder="t('account.enter_account')" v-model="state.model.alipayAccount" :inputBorder="false">
  20. </uni-easyinput>
  21. </uni-forms-item>
  22. </uni-forms>
  23. <view style="display: flex;justify-content: space-between;margin-top: 20rpx;">
  24. <!-- <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  25. 忘记密码
  26. </button> -->
  27. <button class="ss-reset-button login-btn-start" @tap="submit">{{ t('common.confirm') }}</button>
  28. </view>
  29. </view>
  30. </template>
  31. <script setup>
  32. import {
  33. ref,
  34. reactive,
  35. unref,
  36. computed
  37. } from 'vue';
  38. import sheep from '@/sheep';
  39. import {
  40. alipayAccount
  41. } from '@/sheep/validate/form';
  42. import {
  43. showAuthModal,
  44. closeAuthModal
  45. } from '@/sheep/hooks/useModal';
  46. import AuthUtil from '@/sheep/api/member/auth';
  47. import UserApi from '@/sheep/api/member/user';
  48. import {
  49. onLoad
  50. } from '@dcloudio/uni-app';
  51. import { t } from '@/locale'
  52. const userInfo = computed(() => sheep.$store('user').userInfo);
  53. const alipayAccountRef = ref(null);
  54. const emits = defineEmits(['onConfirm']);
  55. const props = defineProps({
  56. agreeStatus: {
  57. type: Boolean,
  58. default: false,
  59. },
  60. });
  61. // 数据
  62. const state = reactive({
  63. model: {
  64. alipayName: '', // 名称
  65. alipayAccount: '', // 账号
  66. },
  67. rules:{
  68. alipayAccount
  69. }
  70. });
  71. // 账号登录
  72. async function submit() {
  73. // 表单验证
  74. // console.log(state.model.alipayName ,state.model.alipayAccount)
  75. if(!state.model.alipayName || !state.model.alipayAccount){
  76. return false;
  77. }
  78. const validate = await unref(alipayAccountRef)
  79. .validate()
  80. .catch((error) => {
  81. console.log('error: ', error);
  82. });
  83. if (!validate) return;
  84. // 同意协议
  85. // if (!props.agreeStatus) {
  86. // emits('onConfirm', true)
  87. // sheep.$helper.toast('请勾选同意');
  88. // return;
  89. // }
  90. // 提交数据
  91. const {
  92. code
  93. } = await UserApi.updateUserAlipayAccount({
  94. alipayName: state.model.alipayName,
  95. alipayAccount: state.model.alipayAccount,
  96. });
  97. // const {
  98. // code,
  99. // data
  100. // } = await AuthUtil.login(state.model);
  101. if (code === 0) {
  102. uni.showToast({
  103. icon: 'success',
  104. title: t('account.change_password'),
  105. });
  106. closeAuthModal();
  107. uni.$emit('alipayAccountChangeComplete');
  108. }
  109. }
  110. onLoad(async (options) => {
  111. state.model.alipayName = userInfo.value.alipayName;
  112. state.model.alipayAccount = userInfo.value.alipayAccount;
  113. });
  114. </script>
  115. <style lang="scss" scoped>
  116. @import '../index.scss';
  117. .login-btn-start {
  118. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  119. width: 100%;
  120. height: 80rpx;
  121. font-size: 32rpx;
  122. }
  123. .loginUniForm {
  124. border: 1rpx solid #d6d6d6;
  125. padding: 10rpx 15rpx;
  126. border-radius: 10rpx;
  127. }
  128. .loginUniFormItem:first-child {
  129. border-bottom: 1rpx solid #d6d6d6;
  130. padding-bottom: 10rpx;
  131. }
  132. .loginUniFormItem:last-child {
  133. // border-bottom: 1rpx solid #d6d6d6;
  134. padding-top: 10rpx;
  135. }
  136. ::v-deep .loginUniFormItem .uni-forms-item__inner {
  137. padding-bottom: 0;
  138. }
  139. ::v-deep .loginUniFormItem .uni-error-message {
  140. bottom: -20rpx;
  141. }
  142. </style>