bankCard.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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="bank.startsWith('请') ? 'text-gray': ''">{{bank}}</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="account.startsWith('请') ? 'text-gray': ''">{{account}}</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="cardNum" 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="name" 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="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. bank: '请选择银行',
  68. cardNum: '',
  69. account: '请选择类型',
  70. accountType: [],
  71. accountShow: false,
  72. name: '',
  73. phone: '',
  74. code: '',
  75. state: false, //是否开启倒计时
  76. totalTime: 120, //总时间,单位秒
  77. recordingTime: 0, //记录时间变量
  78. currentTime: 0, //显示时间变量
  79. selector: [],
  80. }
  81. },
  82. onLoad() {
  83. this.getBankType('bank_type');
  84. this.getAccountType('bank_account_type');
  85. },
  86. methods: {
  87. getBankType(param) {
  88. this.$u.api.dict.code({code: param}).then(res => {
  89. this.selector = res;
  90. })
  91. },
  92. getAccountType(param) {
  93. this.$u.api.dict.code({code: param}).then(res => {
  94. this.accountType = res;
  95. })
  96. },
  97. bankConfirm(index) {
  98. this.bank = this.selector[index].dictValue;
  99. },
  100. accountConfirm(index) {
  101. this.account = this.accountType[index].dictValue;
  102. },
  103. checking() {
  104. if(!this.$u.test.mobile(this.phone)) {
  105. uni.showToast({
  106. icon: "none",
  107. title: "请输入正确的手机号码"
  108. })
  109. return;
  110. } else {
  111. let url = 'huawei/sms/sendSms?phone=' + this.phone
  112. this.$u.post(url).then(res => {
  113. if (res == 'success') {
  114. //把显示时间设为总时间
  115. this.currentTime = this.totalTime;
  116. //开始倒计时
  117. this.state = true;
  118. //执行倒计时
  119. this.checkingTime();
  120. } else {
  121. uni.showToast({
  122. icon: "none",
  123. title: res
  124. })
  125. }
  126. })
  127. }
  128. },
  129. checkingTime() {
  130. let that = this;
  131. //判断是否开启
  132. if (this.state) {
  133. //判断显示时间是否已到0,判断记录时间是否已到总时间
  134. if (this.currentTime > 0 && this.recordingTime <= this.totalTime) {
  135. //记录时间增加 1
  136. this.recordingTime = this.recordingTime + 1;
  137. //显示时间,用总时间 - 记录时间
  138. this.currentTime = this.totalTime - this.recordingTime;
  139. //1秒钟后,再次执行本方法
  140. setTimeout(() => {
  141. //定时器内,this指向外部,找不到vue的方法,所以,需要用that变量。
  142. that.checkingTime();
  143. }, 1000)
  144. } else {
  145. //时间已完成,还原相关变量
  146. this.state = false; //关闭倒计时
  147. this.recordingTime = 0; //记录时间为0
  148. this.currentTime = this.totalTime; //显示时间为总时间
  149. }
  150. } else {
  151. //倒计时未开启,初始化默认变量
  152. this.state = false;
  153. this.recordingTime = 0;
  154. this.currentTime = this.totalTime;
  155. }
  156. },
  157. bind() {
  158. if (this.$u.test.isEmpty(this.bank)) {
  159. uni.showToast({
  160. icon: "none",
  161. title: '请选择银行',
  162. })
  163. return;
  164. }
  165. if (this.$u.test.isEmpty(this.account)) {
  166. uni.showToast({
  167. icon: "none",
  168. title: '请选择账号类型',
  169. })
  170. return;
  171. }
  172. if (this.$u.test.isEmpty(this.cardNum)) {
  173. uni.showToast({
  174. icon: "none",
  175. title: '请输入银行卡号',
  176. })
  177. return;
  178. }
  179. if (this.$u.test.isEmpty(this.name)) {
  180. uni.showToast({
  181. icon: "none",
  182. title: '请输入真实姓名',
  183. })
  184. return;
  185. }
  186. if (this.$u.test.isEmpty(this.phone) || !this.$u.test.mobile(this.phone)) {
  187. uni.showToast({
  188. icon: "none",
  189. title: '请填写正确的手机号',
  190. })
  191. return;
  192. }
  193. if (this.$u.test.isEmpty(this.code)) {
  194. uni.showToast({
  195. icon: "none",
  196. title: '请输入验证码',
  197. })
  198. return;
  199. }
  200. let url = 'huawei/sms/validCode?phone=' + this.phone + '&code=' + this.code;
  201. this.$u.post(url).then(res => {
  202. if (res == 'success') {
  203. uni.showLoading({
  204. title: '绑定银行卡号...',
  205. mask: true
  206. })
  207. this.$u.api.bankCard.bindCard({
  208. userId: uni.getStorageSync("userId"),
  209. cardNo: this.cardNum,
  210. realName: this.name,
  211. phone: this.phone,
  212. bankType: this.bank,
  213. bankAccountType: this.account,
  214. }).then(res => {
  215. console.log("绑定成功", res)
  216. uni.hideLoading();
  217. uni.showToast({
  218. icon: "none",
  219. title: res,
  220. duration: 3000,
  221. success() {
  222. uni.navigateBack({
  223. delta: 1,
  224. })
  225. }
  226. })
  227. })
  228. } else {
  229. uni.showToast({
  230. icon: "none",
  231. title: res,
  232. })
  233. }
  234. })
  235. }
  236. }
  237. }
  238. </script>
  239. <style>
  240. .container {
  241. border-radius: 36upx;
  242. background-color: #ffffff;
  243. padding-bottom: 30upx;
  244. margin: -120upx 30upx 30upx 30upx;
  245. }
  246. .custom-style {
  247. background-color: #5b3ee7;
  248. color: #ffffff;
  249. }
  250. </style>