|
@@ -26,7 +26,6 @@
|
|
|
class="form-input"
|
|
|
placeholder="输入姓名"
|
|
|
v-model="formData.lastname"
|
|
|
- :disabled="!!bankInfo.status"
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
@@ -37,7 +36,6 @@
|
|
|
class="form-input"
|
|
|
placeholder="输入银行名称"
|
|
|
v-model="formData.banktype"
|
|
|
- :disabled="!!bankInfo.status"
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
@@ -48,7 +46,6 @@
|
|
|
class="form-input"
|
|
|
placeholder="输入银行卡开户行"
|
|
|
v-model="formData.address"
|
|
|
- :disabled="!!bankInfo.status"
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
@@ -58,8 +55,8 @@
|
|
|
type="text"
|
|
|
class="form-input"
|
|
|
placeholder="输入银行卡号"
|
|
|
- v-model="formData.banknum"
|
|
|
- :disabled="!!bankInfo.status"
|
|
|
+ v-model="banknumInput"
|
|
|
+ @input="handleBanknumInput"
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
@@ -67,9 +64,8 @@
|
|
|
<button
|
|
|
class="submit-btn"
|
|
|
@click="handleSubmit"
|
|
|
- :disabled="!!bankInfo.status"
|
|
|
>
|
|
|
- {{ bankInfo.status ? '已绑定' : '立即绑定' }}
|
|
|
+ {{ bankInfo.status ? '修改' : '立即绑定' }}
|
|
|
</button>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -78,7 +74,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getBankInfo } from '@/api/profile';
|
|
|
+import { getBankInfo, setBankInfo } from '@/api/profile';
|
|
|
import Toast from '@/components/Toast.vue';
|
|
|
|
|
|
export default {
|
|
@@ -94,25 +90,34 @@ export default {
|
|
|
address: '',
|
|
|
lastname: '',
|
|
|
banknum: ''
|
|
|
- }
|
|
|
+ },
|
|
|
+ banknumInput: ''
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
this.getBankInfo();
|
|
|
},
|
|
|
methods: {
|
|
|
+ handleBanknumInput(event) {
|
|
|
+ // Remove any non-digit characters
|
|
|
+ const value = event.target.value.replace(/\D/g, '');
|
|
|
+ this.banknumInput = value;
|
|
|
+ this.formData.banknum = Number(value) || '';
|
|
|
+ },
|
|
|
async getBankInfo() {
|
|
|
try {
|
|
|
const res = await getBankInfo();
|
|
|
if (res && res.data) {
|
|
|
this.bankInfo = res.data;
|
|
|
if (this.bankInfo && this.bankInfo.status) {
|
|
|
+ // 填充表单数据,允许修改
|
|
|
this.formData = {
|
|
|
banktype: this.bankInfo.banktype || '',
|
|
|
address: this.bankInfo.address || '',
|
|
|
lastname: this.bankInfo.lastname || '',
|
|
|
banknum: this.bankInfo.banknum || ''
|
|
|
};
|
|
|
+ this.banknumInput = this.bankInfo.banknum ? String(this.bankInfo.banknum) : '';
|
|
|
}
|
|
|
} else {
|
|
|
this.bankInfo = {
|
|
@@ -127,8 +132,6 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
async handleSubmit() {
|
|
|
- if (this.bankInfo.status) return;
|
|
|
-
|
|
|
if (!this.formData.banktype) {
|
|
|
this.$refs.toast.show('请输入开户银行', 'warning');
|
|
|
return;
|
|
@@ -145,9 +148,27 @@ export default {
|
|
|
this.$refs.toast.show('请输入银行账号', 'warning');
|
|
|
return;
|
|
|
}
|
|
|
- // TODO: 实现银行卡绑定逻辑
|
|
|
- this.$refs.toast.show('银行卡绑定成功', 'success');
|
|
|
- await this.getBankInfo();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // Ensure all values are strings when sending to FormData
|
|
|
+ const submitData = {
|
|
|
+ banktype: this.formData.banktype.trim(),
|
|
|
+ address: this.formData.address.trim(),
|
|
|
+ lastname: this.formData.lastname.trim(),
|
|
|
+ banknum: String(this.formData.banknum).trim()
|
|
|
+ };
|
|
|
+
|
|
|
+ const res = await setBankInfo(submitData);
|
|
|
+ if (res.code === 1) {
|
|
|
+ this.$refs.toast.show(this.bankInfo.status ? '修改成功' : '绑定成功', 'success');
|
|
|
+ await this.getBankInfo();
|
|
|
+ } else {
|
|
|
+ this.$refs.toast.show(res.msg || '操作失败,请重试', 'error');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('操作失败:', error);
|
|
|
+ this.$refs.toast.show('操作失败,请重试', 'error');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -228,6 +249,8 @@ export default {
|
|
|
font-weight: bold;
|
|
|
color: #333;
|
|
|
margin-bottom: 8px;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
.form-input {
|
|
@@ -262,6 +285,7 @@ export default {
|
|
|
color: #fff;
|
|
|
font-size: 16px;
|
|
|
font-weight: 500;
|
|
|
+ margin-top: 10px;
|
|
|
cursor: pointer;
|
|
|
}
|
|
|
|