bankCard.vue 11 KB

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