123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <template>
- <view class="bindingCard">
- <capsule :showBorder="true" bgColor="#FFFFFF">
- <template v-slot:top>
- <view class="detail-top">
- <view class="back-icon" @click="backClick">
- <tui-icon name="arrowleft" :size="32" color="#000"></tui-icon>
- </view>
- <view class="shop-name">{{ title }}</view>
- </view>
- </template>
- </capsule>
- <view class="seize"></view>
- <view class="binding-box">
- <view class="binding-title">绑定账户</view>
- <view class="binding-container">
- <view class="change-box">
- <view class="change-title">银行卡卡号</view>
- <view class="change-ipt">
- <tui-input
- placeholder="请输入"
- padding="0 16rpx 0 0 "
- :size="28"
- :inputBorder="false"
- :borderBottom="false"
- v-model="bankInfo.cardNumber"
- >
- </tui-input>
- </view>
- </view>
- <view class="change-box">
- <view class="change-title">持卡人姓名</view>
- <view class="change-ipt">
- <tui-input
- placeholder="请输入"
- padding="0 16rpx 0 0 "
- :size="28"
- :inputBorder="false"
- :borderBottom="false"
- v-model="bankInfo.cardName"
- @blur="changeCardName"
- >
- </tui-input>
- </view>
- </view>
- <view class="change-box">
- <view class="change-title">银行</view>
- <view class="change-ipt">
- <tui-input
- placeholder="请输入"
- padding="0 16rpx 0 0 "
- :size="28"
- :inputBorder="false"
- :borderBottom="false"
- :disabled="true"
- :value="dictName"
- >
- <template #right>
- <view class="right-text" @click="showChange">选择</view>
- </template>
- </tui-input>
- </view>
- </view>
- <view class="change-box">
- <view class="change-title">注册手机号</view>
- <view class="change-ipt">
- <tui-input
- placeholder="请输入手机号码"
- padding="0 16rpx 0 0 "
- :size="28"
- :inputBorder="false"
- :borderBottom="false"
- v-model="bankInfo.phone"
- >
- <template #left>
- <view class="ipt-left">+86</view>
- </template>
- </tui-input>
- </view>
- </view>
- <view class="change-box">
- <view class="change-title">短信验证码</view>
- <view class="change-ipt">
- <tui-input
- placeholder="请输入"
- padding="0 16rpx 0 0 "
- :size="28"
- :inputBorder="false"
- :borderBottom="false"
- v-model="code"
- >
- <template #right>
- <tui-countdown-verify
- text="获取验证码"
- sendText="发送中..."
- borderColor="#E7E7E7"
- color="rgba(0, 0, 0, 0.6)"
- :size="28"
- :seconds="60"
- :successVal="successVal"
- :resetVal="resetVal"
- @send="getVerify"
- ></tui-countdown-verify>
- <!-- <view class="ipt-right">获取验证码</view> -->
- </template>
- </tui-input>
- </view>
- </view>
- </view>
- </view>
- <view class="btn-list">
- <view class="btn" @click="backClick">取消</view>
- <view class="btn" @click="btnClick">{{ btnTitle }}</view>
- </view>
- <tui-picker
- :show="showPicker"
- :layer="1"
- :pickerData="bankList"
- textField="dictName"
- valueField="dictId"
- cancelColor="rgba(0, 0, 0, 0.6)"
- confirmColor="#EA5C1E"
- :value="value"
- @change="nameChange"
- @hide="showChange"
- ></tui-picker>
- </view>
- </template>
- <script>
- import {
- getSelect,
- getCode,
- updateReceiving,
- saveReceiving,
- } from "@/config/index.js";
- // {
- // "id": "",
- // "cardName": "徐枝浪",
- // "cardNumber": "1234567893333",
- // "bank": 2001,
- // "phone": "13539102414",
- // "code": "1",
- // "bankType": 2,
- // "province": "",
- // "city": "",
- // "bankName": "",
- // "unionBank": "",
- // "bankCode": ""
- // }
- export default {
- created() {
- // 获取所有银行列表
- this.getBankAll();
- },
- onLoad(option) {
- // type == 1 表示已经有银行卡了
- if (option.type == 1) {
- this.title = "修改银行卡";
- this.btnTitle = "修改";
- // 本地获取数据
- this.bankInfo = uni.getStorageSync("bankInfo");
- this.dictName = this.bankInfo.dictName;
- // 给 value 赋值
- this.value = [this.bankInfo.dictName];
- }
- },
- data() {
- return {
- title: "绑定银行卡",
- btnTitle: "确认",
- // 银行卡名称
- dictName: "",
- bankInfo: {
- // cardNumber: "",
- // cardName: "",
- // bank: "",
- // phone: "",
- // code: "",
- id: "",
- cardName: "",
- cardNumber: "",
- bank: "",
- phone: "",
- bankType: "",
- province: "",
- city: "",
- bankName: "",
- unionBank: "",
- bankCode: "",
- },
- // 控制 选择银行显示
- showPicker: false,
- bankList: [],
- value: [],
- // 控制获取验证码成功
- successVal: 0,
- // 控制获取验证码失败
- resetVal: 0,
- // 二维码
- code: "",
- };
- },
- methods: {
- // 姓名特殊字符判断
- changeCardName() {
- let rule = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘’,。、' ']/g;
- if (rule.test(this.bankInfo.cardName)) {
- this.$showToast("姓名不能包含特殊字符!");
- this.bankInfo.cardName = this.bankInfo.cardName.replace(rule, "");
- }
- },
- // 获取所有银行
- async getBankAll() {
- let { data } = await getSelect({ dictName: "所属银行" });
- this.bankList = data;
- },
- // 获取验证码
- async getVerify() {
- const phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
- if (!phoneCodeVerification.test(this.bankInfo.phone)) {
- this.$showToast("请输入正确的手机号!");
- this.resetVal++;
- return;
- }
- let res = await getCode({ phone: this.bankInfo.phone });
- if (res.message == "") {
- this.successVal++;
- } else {
- this.$showToast(res.message);
- this.resetVal++;
- }
- },
- // 保存 / 修改点击事件
- btnClick() {
- // 进去先对数据进行正则判断
- const phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
- const cardRule = /^([1-9]{1})(\d{15}|\d{18})$/;
- if (!phoneCodeVerification.test(this.bankInfo.phone)) {
- this.$showToast("请输入正确的手机号!");
- return;
- }
- if (!cardRule.test(this.bankInfo.cardNumber)) {
- this.$showToast("卡号需为16~19位的数字");
- return;
- }
- if (this.code == "") {
- this.$showToast("验证码不能为空");
- return;
- }
- this.bankInfo.code = this.code;
- if (this.btnTitle == "修改") {
- this.updateAccount();
- } else {
- this.saveAccount();
- }
- },
- // 修改账户信息
- async updateAccount() {
- // 对数据进行处理
- let obj = { ...this.bankInfo };
- // 删除自己添加的数据
- delete obj.dictName;
- let res = await updateReceiving(obj);
- if (res.code == "") {
- this.$showToast("修改成功");
- // 跳转回我的账户页面
- setTimeout(() => {
- this.backClick();
- }, 1500);
- }
- },
- // 保存账户信息
- async saveAccount() {
- let res = await saveReceiving(this.bankInfo);
- if (res.code == "") {
- this.$showToast("保存成功");
- // 跳转回我的账户页面
- setTimeout(() => {
- this.backClick();
- }, 1500);
- }
- },
- // 控制选择显示
- showChange() {
- this.showPicker = !this.showPicker;
- },
- // 选择银行确认
- nameChange(key) {
- this.bankInfo.bank = key.dictId;
- this.dictName = key.dictName;
- },
- backClick() {
- uni.navigateBack({
- fail: () => {
- uni.redirectTo({
- url: "/pages_module/receiving/index",
- });
- },
- });
- },
- },
- // 页面卸载清除缓存
- onUnload() {
- uni.removeStorageSync("bankInfo");
- },
- };
- </script>
- <style lang="scss" scoped>
- @import "./index.scss";
- </style>
|