lyqu 4 лет назад
Родитель
Сommit
77974cf092

+ 1 - 1
common/http/http.api.js

@@ -90,7 +90,7 @@ let yeePayUrl = {
 
 let bankCardUrl = {
 	bindCardUrl: 'cyzh-userBank/userbank//submit',
-	cardDetailUrl: 'cyzh-userBank/userbank/submit/detail',
+	cardDetailUrl: 'cyzh-userBank/userbank/list',
 }
 
 // 此处第二个参数vm,就是我们在页面使用的this,你可以通过vm获取vuex等操作,更多内容详见uView对拦截器的介绍部分:

+ 12 - 8
pages/activityList/activity/awards.vue

@@ -30,8 +30,10 @@
 					<text class="title padding-left-xs">元</text>
 				</view>
 				<view class="flex text-sm align-center">
-					<view class="padding-right-xs" v-if="!$u.test.isEmpty(carNumber)">已绑定卡号{{carNumber}}</view>
-					<button class="cu-btn sm round margin-right-sm" style="background-color: #f75757;color: #ffffff;" v-if="!$u.test.isEmpty(cardNumber)" @click="changeNum">点击更换</button>
+					<block v-if="!$u.test.isEmpty(cardNumber)">
+						<view class="padding-right-xs">已绑定卡号{{cardNumber}}</view>
+						<button class="cu-btn sm round margin-right-sm" style="background-color: #f75757;color: #ffffff;" @click="changeNum">点击更换</button>
+					</block>
 					<button class="cu-btn sm round margin-right-sm" style="background-color: #f75757;color: #ffffff;" v-else @click="changeNum">点击绑定</button>
 				</view>
 			</view>
@@ -79,7 +81,8 @@
 				list:[],
 				cardNumber: '',
 				status: 'loadmore',
-				current:1
+				current:1,
+				cardInfo: {},
 			}
 		},
 		onLoad() {
@@ -107,11 +110,12 @@
 		},
 		methods: {
 			getCardInfo() {
-				console.log("刷新后")
 				let userId = uni.getStorageSync("userId");
 				this.$u.api.bankCard.cardDetail({userId: userId}).then(res => {
-					console.log("获取银行卡号",res)
-					this.cardNumber = "**** " + res.cardNo.substring(res.cardNo.length - 4, res.cardNo.length);
+					console.log(res);
+					this.cardInfo = res.records[0];
+					let cardNo = res.records[0].cardNo;
+					this.cardNumber = "**** " + cardNo.substring(cardNo.length - 4, cardNo.length);
 				})
 			},
 			init(){
@@ -145,9 +149,9 @@
 					url:"doAwards?userId="+this.userId
 				})
 			},
-			changeNum() {
+			changeNum(id) {
 				uni.navigateTo({
-					url: "/pages/activityList/activity/bankCard"
+					url: "/pages/activityList/activity/bankCard?cardId=" + this.cardInfo.id
 				})
 			}
 		}

+ 54 - 42
pages/activityList/activity/bankCard.vue

@@ -9,7 +9,7 @@
 			<view class="flex align-center" style="padding: 30upx 60upx 20upx 60upx;">
 				<view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>选择银行</view>
 				<view class="flex justify-between align-center" style="width: 260upx;height: 60upx;border: #b0b0b0 1upx solid;border-radius: 16upx;" @click="bankShow = true">
-					<view class="padding-left-sm" :class="bank.startsWith('请') ? 'text-gray': ''">{{bank}}</view>
+					<view class="padding-left-sm" :class="cardInfo.bankType.startsWith('请') ? 'text-gray': ''">{{cardInfo.bankType}}</view>
 					<view class="padding-right-xs cuIcon-unfold"></view>
 				</view>
 			</view>
@@ -19,7 +19,7 @@
 			<view class="flex align-center" style="padding: 20upx 60upx;">
 				<view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>账号类型</view>
 				<view class="flex justify-between align-center" style="width: 260upx;height: 60upx;border: #b0b0b0 1upx solid;border-radius: 16upx;" @click="accountShow = true">
-					<view class="padding-left-sm" :class="account.startsWith('请') ? 'text-gray': ''">{{account}}</view>
+					<view class="padding-left-sm" :class="cardInfo.bankAccountType.startsWith('请') ? 'text-gray': ''">{{cardInfo.bankAccountType}}</view>
 					<view class="padding-right-xs cuIcon-unfold"></view>
 				</view>
 			</view>
@@ -28,21 +28,21 @@
 			</view>
 			<view class="flex align-center" style="padding: 20upx 60upx;">
 				<view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>银行卡号</view>
-				<u-input v-model="cardNum" placeholder="请输入银行卡号" :clearable="false" />
+				<u-input v-model="cardInfo.cardNo" placeholder="请输入银行卡号" :clearable="false" />
 			</view>
 			<view style="padding: 0 60upx;">
 				<u-line color="#d4d4d4"></u-line>
 			</view>
 			<view class="flex align-center" style="padding: 20upx 60upx;">
 				<view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>真实姓名</view>
-				<u-input v-model="name" placeholder="请输入真实姓名" :clearable="false" />
+				<u-input v-model="cardInfo.realName" placeholder="请输入真实姓名" :clearable="false" />
 			</view>
 			<view style="padding: 0 60upx;">
 				<u-line color="#d4d4d4"></u-line>
 			</view>
 			<view class="flex align-center" style="padding: 20upx 60upx;">
 				<view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>手机号码</view>
-				<u-input v-model="phone" placeholder="请输入手机号码" :clearable="false" />
+				<u-input v-model="cardInfo.phone" placeholder="请输入手机号码" :clearable="false" />
 			</view>
 			<view style="padding: 0 60upx;">
 				<u-line color="#d4d4d4"></u-line>
@@ -65,13 +65,16 @@
 		data() {
 			return {
 				bankShow: false,
-				bank: '请选择银行',
-				cardNum: '',
-				account: '请选择类型',
+				cardInfo: {
+					userId: '',
+					bankType: '请选择银行',
+					cardNo: '',
+					bankAccountType: '请选择类型',
+					realName: '',
+					phone: '',
+				},
 				accountType: [],
 				accountShow: false,
-				name: '',
-				phone: '',
 				code: '',
 				state: false,		//是否开启倒计时
 				totalTime: 120,		//总时间,单位秒
@@ -80,7 +83,10 @@
 				selector: [],
 			}
 		},
-		onLoad() {
+		onLoad(options) {
+			if (!this.$u.test.isEmpty(options.cardId)) {
+				this.getCardInfo();
+			}
 			this.getBankType('bank_type');
 			this.getAccountType('bank_account_type');
 		},
@@ -95,21 +101,28 @@
 					this.accountType = res;
 				})
 			},
+			getCardInfo() {
+				let userId = uni.getStorageSync("userId");
+				this.$u.api.bankCard.cardDetail({userId: userId}).then(res => {
+					console.log(res);
+					this.cardInfo = res.records[0];
+				})
+			},
 			bankConfirm(index) {
-				this.bank = this.selector[index].dictValue;
+				this.cardInfo.bankType = this.selector[index].dictValue;
 			},
 			accountConfirm(index) {
-				this.account = this.accountType[index].dictValue;
+				this.cardInfo.bankAccountType = this.accountType[index].dictValue;
 			},
 			checking() {
-				if(!this.$u.test.mobile(this.phone)) {
+				if(!this.$u.test.mobile(this.cardInfo.phone)) {
 					uni.showToast({
 						icon: "none",
 						title: "请输入正确的手机号码"
 					})
 					return;
 				} else {
-					let url = 'huawei/sms/sendSms?phone=' + this.phone
+					let url = 'huawei/sms/sendSms?phone=' + this.cardInfo.phone
 					this.$u.post(url).then(res => {
 						if (res == 'success') {
 							//把显示时间设为总时间
@@ -156,35 +169,35 @@
 				}
 			},
 			bind() {
-				if (this.$u.test.isEmpty(this.bank)) {
+				if (this.$u.test.isEmpty(this.cardInfo.bankType)) {
 					uni.showToast({
 						icon: "none",
 						title: '请选择银行',
 					})
 					return;
 				}
-				if (this.$u.test.isEmpty(this.account)) {
+				if (this.$u.test.isEmpty(this.cardInfo.bankAccountType)) {
 					uni.showToast({
 						icon: "none",
 						title: '请选择账号类型',
 					})
 					return;
 				}
-				if (this.$u.test.isEmpty(this.cardNum)) {
+				if (this.$u.test.isEmpty(this.cardInfo.cardNo)) {
 					uni.showToast({
 						icon: "none",
 						title: '请输入银行卡号',
 					})
 					return;
 				}
-				if (this.$u.test.isEmpty(this.name)) {
+				if (this.$u.test.isEmpty(this.cardInfo.realName)) {
 					uni.showToast({
 						icon: "none",
 						title: '请输入真实姓名',
 					})
 					return;
 				}
-				if (this.$u.test.isEmpty(this.phone) || !this.$u.test.mobile(this.phone)) {
+				if (this.$u.test.isEmpty(this.cardInfo.phone) || !this.$u.test.mobile(this.cardInfo.phone)) {
 					uni.showToast({
 						icon: "none",
 						title: '请填写正确的手机号',
@@ -198,34 +211,16 @@
 					})
 					return;
 				}
-				let url = 'huawei/sms/validCode?phone=' + this.phone + '&code=' + this.code;
+				let url = 'huawei/sms/validCode?phone=' + this.cardInfo.phone + '&code=' + this.code;
 				this.$u.post(url).then(res => {
 					if (res == 'success') {
 						uni.showLoading({
 						    title: '绑定银行卡号...',
 							mask: true
 						})
-						this.$u.api.bankCard.bindCard({
-							userId: uni.getStorageSync("userId"),
-							cardNo: this.cardNum,
-							realName: this.name,
-							phone: this.phone,
-							bankType: this.bank,
-							bankAccountType: this.account,
-						}).then(res => {
-							console.log("绑定成功", res)
-							uni.hideLoading();
-							uni.showToast({
-								icon: "none",
-								title: res,
-								duration: 3000,
-								success() {
-									uni.navigateBack({
-										delta: 1,
-									})
-								}
-							})
-						})
+						setTimeout(() => {
+							this.saveCardInfo();
+						},700)
 					} else {
 						uni.showToast({
 							icon: "none",
@@ -233,6 +228,23 @@
 						})
 					}
 				})
+			},
+			saveCardInfo() {
+				this.cardInfo.userId = uni.getStorageSync("userId");
+				this.$u.api.bankCard.bindCard(this.cardInfo).then(res => {
+					console.log("插入成功",res);
+					uni.hideLoading();
+					uni.showToast({
+						icon: "none",
+						title: res,
+						duration: 3000,
+						success: () => {
+							uni.navigateBack({
+								delta: 1,
+							})
+						}
+					})
+				})
 			}
 		}
 	}