bankCard.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view>
  3. <view class="bg-img" style="background-image: url('https://upload-file-data.obs.cn-south-1.myhuaweicloud.com/5f263a5a6e7c4f2493e0325f28ab659a-bgimg.png');height: 310upx;"></view>
  4. <view class="container">
  5. <view class="text-bold" style="font-size: 40upx;padding: 30upx 0upx 10upx 40upx;">绑定银行卡</view>
  6. <view class="padding-left-lg" style="font-size: 28upx;">请如实填写一下资料</view>
  7. <u-picker mode="selector" v-model="bankShow" :default-selector="[0]" :range="selector" range-key="dictValue" @confirm="bankConfirm"></u-picker>
  8. <u-picker mode="selector" v-model="accountShow" :default-selector="[0]" :range="accountType" range-key="dictValue" @confirm="accountConfirm"></u-picker>
  9. <view class="flex align-center" style="padding: 30upx 60upx 20upx 60upx;">
  10. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>选择银行</view>
  11. <view class="flex justify-between align-center" style="width: 260upx;height: 60upx;border: #b0b0b0 1upx solid;border-radius: 16upx;" @click="bankShow = true">
  12. <view class="padding-left-sm" :class="cardInfo.bankType.startsWith('请') ? 'text-gray': ''">{{cardInfo.bankType}}</view>
  13. <view class="padding-right-xs cuIcon-unfold"></view>
  14. </view>
  15. </view>
  16. <view style="padding: 0 60upx;">
  17. <u-line color="#d4d4d4"></u-line>
  18. </view>
  19. <view class="flex align-center" style="padding: 20upx 60upx;">
  20. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>账号类型</view>
  21. <view class="flex justify-between align-center" style="width: 260upx;height: 60upx;border: #b0b0b0 1upx solid;border-radius: 16upx;" @click="accountShow = true">
  22. <view class="padding-left-sm" :class="cardInfo.bankAccountType.startsWith('请') ? 'text-gray': ''">{{cardInfo.bankAccountType}}</view>
  23. <view class="padding-right-xs cuIcon-unfold"></view>
  24. </view>
  25. </view>
  26. <view style="padding: 0 60upx;">
  27. <u-line color="#d4d4d4"></u-line>
  28. </view>
  29. <view class="flex align-center" style="padding: 20upx 60upx;">
  30. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>银行卡号</view>
  31. <u-input v-model="cardInfo.cardNo" placeholder="请输入银行卡号" :clearable="false" />
  32. </view>
  33. <view style="padding: 0 60upx;">
  34. <u-line color="#d4d4d4"></u-line>
  35. </view>
  36. <view class="flex align-center" style="padding: 20upx 60upx;">
  37. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>真实姓名</view>
  38. <u-input v-model="cardInfo.realName" placeholder="请输入真实姓名" :clearable="false" />
  39. </view>
  40. <view style="padding: 0 60upx;">
  41. <u-line color="#d4d4d4"></u-line>
  42. </view>
  43. <view class="flex align-center" style="padding: 20upx 60upx;">
  44. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-red">*</text>手机号码</view>
  45. <u-input v-model="cardInfo.phone" placeholder="请输入手机号码" :clearable="false" />
  46. </view>
  47. <view style="padding: 0 60upx;">
  48. <u-line color="#d4d4d4"></u-line>
  49. </view>
  50. <view class="flex align-center" style="padding: 20upx 60upx;">
  51. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;"><text class="text-white">*</text>验证码</view>
  52. <u-input v-model="code" placeholder="请输入验证码" :clearable="false" />
  53. <button class="cu-btn round" style="width: 150upx;background-color: #5d41ed;color: #ffffff;" @click="checking" v-if="!state">验证码</button>
  54. <button class="cu-btn round" style="width: 150upx;background-color: #5d41ed;color: #ffffff;" v-else>{{currentTime}}s</button>
  55. </view>
  56. </view>
  57. <view class="padding">
  58. <u-button class="custom-style" shape="circle" @click="bind">确定绑定</u-button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. export default {
  64. data() {
  65. return {
  66. bankShow: false,
  67. cardInfo: {
  68. userId: '',
  69. bankType: '请选择银行',
  70. cardNo: '',
  71. bankAccountType: '请选择类型',
  72. realName: '',
  73. phone: '',
  74. },
  75. accountType: [],
  76. accountShow: false,
  77. code: '',
  78. state: false, //是否开启倒计时
  79. totalTime: 120, //总时间,单位秒
  80. recordingTime: 0, //记录时间变量
  81. currentTime: 0, //显示时间变量
  82. selector: [],
  83. }
  84. },
  85. onLoad(options) {
  86. if (!this.$u.test.isEmpty(options.cardId)) {
  87. this.getCardInfo();
  88. }
  89. this.getBankType('bank_type');
  90. this.getAccountType('bank_account_type');
  91. },
  92. methods: {
  93. getBankType(param) {
  94. this.$u.api.dict.code({code: param}).then(res => {
  95. this.selector = res;
  96. })
  97. },
  98. getAccountType(param) {
  99. this.$u.api.dict.code({code: param}).then(res => {
  100. this.accountType = res;
  101. })
  102. },
  103. getCardInfo() {
  104. let userId = uni.getStorageSync("userId");
  105. this.$u.api.bankCard.cardDetail({userId: userId}).then(res => {
  106. console.log(res);
  107. this.cardInfo = res.records[0];
  108. })
  109. },
  110. bankConfirm(index) {
  111. this.cardInfo.bankType = this.selector[index].dictValue;
  112. },
  113. accountConfirm(index) {
  114. this.cardInfo.bankAccountType = this.accountType[index].dictValue;
  115. },
  116. checking() {
  117. if(!this.$u.test.mobile(this.cardInfo.phone)) {
  118. uni.showToast({
  119. icon: "none",
  120. title: "请输入正确的手机号码"
  121. })
  122. return;
  123. } else {
  124. let url = 'huawei/sms/sendSms?phone=' + this.cardInfo.phone
  125. this.$u.post(url).then(res => {
  126. if (res == 'success') {
  127. //把显示时间设为总时间
  128. this.currentTime = this.totalTime;
  129. //开始倒计时
  130. this.state = true;
  131. //执行倒计时
  132. this.checkingTime();
  133. } else {
  134. uni.showToast({
  135. icon: "none",
  136. title: res
  137. })
  138. }
  139. })
  140. }
  141. },
  142. checkingTime() {
  143. let that = this;
  144. //判断是否开启
  145. if (this.state) {
  146. //判断显示时间是否已到0,判断记录时间是否已到总时间
  147. if (this.currentTime > 0 && this.recordingTime <= this.totalTime) {
  148. //记录时间增加 1
  149. this.recordingTime = this.recordingTime + 1;
  150. //显示时间,用总时间 - 记录时间
  151. this.currentTime = this.totalTime - this.recordingTime;
  152. //1秒钟后,再次执行本方法
  153. setTimeout(() => {
  154. //定时器内,this指向外部,找不到vue的方法,所以,需要用that变量。
  155. that.checkingTime();
  156. }, 1000)
  157. } else {
  158. //时间已完成,还原相关变量
  159. this.state = false; //关闭倒计时
  160. this.recordingTime = 0; //记录时间为0
  161. this.currentTime = this.totalTime; //显示时间为总时间
  162. }
  163. } else {
  164. //倒计时未开启,初始化默认变量
  165. this.state = false;
  166. this.recordingTime = 0;
  167. this.currentTime = this.totalTime;
  168. }
  169. },
  170. bind() {
  171. if (this.$u.test.isEmpty(this.cardInfo.bankType)) {
  172. uni.showToast({
  173. icon: "none",
  174. title: '请选择银行',
  175. })
  176. return;
  177. }
  178. if (this.$u.test.isEmpty(this.cardInfo.bankAccountType)) {
  179. uni.showToast({
  180. icon: "none",
  181. title: '请选择账号类型',
  182. })
  183. return;
  184. }
  185. if (this.$u.test.isEmpty(this.cardInfo.cardNo)) {
  186. uni.showToast({
  187. icon: "none",
  188. title: '请输入银行卡号',
  189. })
  190. return;
  191. }
  192. if (this.$u.test.isEmpty(this.cardInfo.realName)) {
  193. uni.showToast({
  194. icon: "none",
  195. title: '请输入真实姓名',
  196. })
  197. return;
  198. }
  199. if (this.$u.test.isEmpty(this.cardInfo.phone) || !this.$u.test.mobile(this.cardInfo.phone)) {
  200. uni.showToast({
  201. icon: "none",
  202. title: '请填写正确的手机号',
  203. })
  204. return;
  205. }
  206. if (this.$u.test.isEmpty(this.code)) {
  207. uni.showToast({
  208. icon: "none",
  209. title: '请输入验证码',
  210. })
  211. return;
  212. }
  213. let url = 'huawei/sms/validCode?phone=' + this.cardInfo.phone + '&code=' + this.code;
  214. this.$u.post(url).then(res => {
  215. if (res == 'success') {
  216. uni.showLoading({
  217. title: '绑定银行卡号...',
  218. mask: true
  219. })
  220. setTimeout(() => {
  221. this.saveCardInfo();
  222. },700)
  223. } else {
  224. uni.showToast({
  225. icon: "none",
  226. title: res,
  227. })
  228. }
  229. })
  230. },
  231. saveCardInfo() {
  232. this.cardInfo.userId = uni.getStorageSync("userId");
  233. this.$u.api.bankCard.bindCard(this.cardInfo).then(res => {
  234. console.log("插入成功",res);
  235. uni.hideLoading();
  236. uni.showToast({
  237. icon: "none",
  238. title: res,
  239. duration: 3000,
  240. success: () => {
  241. uni.navigateBack({
  242. delta: 1,
  243. })
  244. }
  245. })
  246. })
  247. }
  248. }
  249. }
  250. </script>
  251. <style>
  252. .container {
  253. border-radius: 36upx;
  254. background-color: #ffffff;
  255. padding-bottom: 30upx;
  256. margin: -120upx 30upx 30upx 30upx;
  257. }
  258. .custom-style {
  259. background-color: #5b3ee7;
  260. color: #ffffff;
  261. }
  262. </style>