bind.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view>
  3. <headContent borderBottom>
  4. <template #left>
  5. <reverse-back />
  6. </template>
  7. <template #content>
  8. <view class="haed-title">
  9. {{ title }}
  10. </view>
  11. </template>
  12. </headContent>
  13. <view class="bangding-box">
  14. <view class="bangding-item" v-show="type == 1">
  15. <view class="item-lable">
  16. 手机
  17. </view>
  18. <view class="item-area" @click.stop="selectAreaCode">
  19. <template v-if="account.area_code">
  20. <text style="color: #000;">+{{ account.area_code }}</text>
  21. </template>
  22. <template v-else>
  23. <text>国家和地区</text>
  24. <text class="iconfont">&#xe60e;</text>
  25. </template>
  26. </view>
  27. <text class="item-link"></text>
  28. <input class="item-input" v-model="account.user_string" type="text"
  29. placeholder-class="placeholder-class" placeholder="手机号">
  30. </view>
  31. <view class="bangding-item" v-show="type == 2">
  32. <view class="item-lable">
  33. 邮箱
  34. </view>
  35. <input class="item-input" v-model="account.user_string" type="text"
  36. placeholder-class="placeholder-class" placeholder="邮箱号">
  37. </view>
  38. <view class="err-hint">
  39. {{ errText[errIndex || 0] }}
  40. </view>
  41. <view class="bangding-item code-item">
  42. <view class="item-lable">
  43. 验证码
  44. </view>
  45. <input class="item-input" type="text" v-model="account.code" placeholder-class="placeholder-class"
  46. placeholder="请输入手机验证码">
  47. <view class="item-code" @click.stop="getCode()">
  48. {{ codeText }}
  49. </view>
  50. </view>
  51. <view :class="['bangding-btn' , next ? 'active-btn': '' ] " @click.stop="next ? submitBindAccount() : ''">
  52. 绑定
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. Api_getEmailCode,
  60. Api_getSmsSend
  61. } from "@/api/index.js";
  62. export default {
  63. name: 'bind-phone',
  64. data() {
  65. return {
  66. title: '',
  67. Api_: '',
  68. type: null,
  69. codeText: '获取验证码',
  70. errIndex: '',
  71. next: false,
  72. account: {
  73. user_string: '',
  74. area_code: '',
  75. code: ''
  76. },
  77. errText: [
  78. '',
  79. '请选择国家地区',
  80. '请输入正确的手机号',
  81. '请输入正确的邮箱号',
  82. ]
  83. };
  84. },
  85. onLoad(opt) {
  86. this.type = opt?.type || 1;
  87. if (this.type == 1) {
  88. // 手机号
  89. this.Api_ = Api_getSmsSend
  90. this.title = '绑定手机'
  91. }
  92. if (this.type == 2) {
  93. // 邮箱
  94. this.Api_ = Api_getEmailCode;
  95. this.title = '绑定邮箱'
  96. }
  97. },
  98. mounted() {
  99. },
  100. watch: {
  101. account: {
  102. handler(newContent) {
  103. if (newContent.user_string && newContent.code && (this.type == 1 ? newContent.area_code : true)) {
  104. this.next = true
  105. } else {
  106. this.next = false
  107. }
  108. },
  109. immediate: true,
  110. deep: true
  111. },
  112. 'account.area_code': {
  113. handler(newCode) {
  114. if (newCode && this.errIndex === 1) {
  115. this.errIndex = 0
  116. }
  117. },
  118. immediate: true
  119. },
  120. 'account.user_string': {
  121. handler(newCode) {
  122. if (newCode && [2, 3].includes(this.errIndex)) {
  123. this.errIndex = 0
  124. }
  125. },
  126. immediate: true
  127. }
  128. },
  129. methods: {
  130. selectAreaCode() {
  131. uni.navigateTo({
  132. url: '/pages/login/area-code'
  133. })
  134. },
  135. setAreaCode(e) {
  136. if (e) {
  137. this.account.area_code = e.area_code;
  138. }
  139. },
  140. // 校验
  141. jiaoyan() {
  142. if ([1, '1'].includes(this.type)) {
  143. if (!this.account.area_code) {
  144. this.errIndex = 1
  145. return false
  146. };
  147. if (!this.account.user_string) {
  148. this.errIndex = 2
  149. return false
  150. };
  151. } else if ([2, '2'].includes(this.type)) {
  152. if (!this.account.user_string) {
  153. this.errIndex = 3
  154. return false
  155. };
  156. } else {
  157. return false
  158. }
  159. return true
  160. },
  161. getCode() {
  162. if (this.codeText !== '获取验证码') {
  163. return false
  164. }
  165. const errStatus = this.jiaoyan()
  166. if (!errStatus) {
  167. return false
  168. }
  169. let obj = {
  170. user_string: this.account.user_string
  171. };
  172. if (this.account.area_code) {
  173. obj.area_code = this.account.area_code
  174. }
  175. if (this.Api_) {
  176. this.Api_(obj).then(res => {
  177. }).catch(err => {
  178. })
  179. let num = 60
  180. this.timeInterval = setInterval(() => {
  181. num--;
  182. if (num <= 0) {
  183. clearInterval(this.timeInterval);
  184. this.codeText = '获取验证码';
  185. return false
  186. };
  187. this.codeText = `${num}秒后重新发送`;
  188. }, 1000)
  189. }
  190. },
  191. submitBindAccount(){
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss" scoped>
  197. .bangding-box {
  198. width: 100%;
  199. padding: 0 $pages-padding;
  200. .bangding-item {
  201. display: flex;
  202. justify-content: space-between;
  203. align-items: center;
  204. height: 100rpx;
  205. border-bottom: 1rpx solid $border-color2;
  206. font-size: 28rpx;
  207. padding-top: 20rpx;
  208. .item-lable {
  209. flex-shrink: 0;
  210. width: 120rpx;
  211. }
  212. .item-area {
  213. flex-shrink: 0;
  214. width: 196rpx;
  215. color: $SizeColor1;
  216. font-weight: bold;
  217. display: flex;
  218. align-items: center;
  219. .iconfont {
  220. margin-left: 3px;
  221. color: #5b5b5b;
  222. font-size: 20rpx;
  223. }
  224. // border-right: 1rpx solid $border-color6;
  225. }
  226. .item-link {
  227. display: inline-block;
  228. margin-right: 30rpx;
  229. width: 3rpx;
  230. height: 24rpx;
  231. background-color: $border-color4;
  232. }
  233. .item-input {
  234. flex: 1;
  235. font-size: 28rpx;
  236. }
  237. .placeholder-class {
  238. font-size: 28rpx;
  239. color: $SizeColor1;
  240. font-weight: bold;
  241. }
  242. .item-code {
  243. color: $Theme-Color;
  244. }
  245. }
  246. .code-item {
  247. padding-top: 0;
  248. height: 80rpx;
  249. }
  250. .err-hint {
  251. width: 100%;
  252. height: 70rpx;
  253. font-size: 28rpx;
  254. padding-top: 20rpx;
  255. color: red;
  256. }
  257. }
  258. .bangding-btn {
  259. width: 100%;
  260. margin-top: 80rpx;
  261. height: 90rpx;
  262. border-radius: 10rpx;
  263. font-size: 30rpx;
  264. text-align: center;
  265. line-height: 90rpx;
  266. color: #fff;
  267. background-color: $btnBgColor;
  268. }
  269. .active-btn {
  270. background-color: $Theme-Color;
  271. }
  272. </style>