bankCard.vue 9.4 KB

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