bind.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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">&#xeb6d;</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. Api_setBindEmail,
  62. Api_setBindMobile
  63. } from "@/api/index.js";
  64. export default {
  65. name: 'bind-phone',
  66. data() {
  67. return {
  68. title: '',
  69. Api_: '',
  70. type: null,
  71. codeText: '获取验证码',
  72. errIndex: '',
  73. next: false,
  74. account: {
  75. user_string: '17777777777',
  76. area_code: '',
  77. code: '893720'
  78. },
  79. errText: [
  80. '',
  81. '请选择国家地区',
  82. '请输入正确的手机号',
  83. '请输入正确的邮箱号',
  84. ]
  85. };
  86. },
  87. onLoad(opt) {
  88. this.type = opt?.type || 1;
  89. if (this.type == 1) {
  90. // 手机号
  91. this.Api_ = Api_getSmsSend
  92. this.title = '绑定手机'
  93. }
  94. if (this.type == 2) {
  95. // 邮箱
  96. this.Api_ = Api_getEmailCode;
  97. this.title = '绑定邮箱'
  98. }
  99. },
  100. mounted() {
  101. },
  102. watch: {
  103. account: {
  104. handler(newContent) {
  105. if (newContent.user_string && newContent.code && (this.type == 1 ? newContent.area_code : true)) {
  106. this.next = true
  107. } else {
  108. this.next = false
  109. }
  110. },
  111. immediate: true,
  112. deep: true
  113. },
  114. 'account.area_code': {
  115. handler(newCode) {
  116. if (newCode && this.errIndex === 1) {
  117. this.errIndex = 0
  118. }
  119. },
  120. immediate: true
  121. },
  122. 'account.user_string': {
  123. handler(newCode) {
  124. if (newCode && [2, 3].includes(this.errIndex)) {
  125. this.errIndex = 0
  126. }
  127. },
  128. immediate: true
  129. }
  130. },
  131. methods: {
  132. selectAreaCode() {
  133. uni.navigateTo({
  134. url: '/pages/login/area-code'
  135. })
  136. },
  137. setAreaCode(e) {
  138. if (e) {
  139. this.account.area_code = e.area_code;
  140. }
  141. },
  142. // 校验
  143. jiaoyan() {
  144. if ([1, '1'].includes(this.type)) {
  145. if (!this.account.area_code) {
  146. this.errIndex = 1
  147. return false
  148. };
  149. if (!this.account.user_string) {
  150. this.errIndex = 2
  151. return false
  152. };
  153. } else if ([2, '2'].includes(this.type)) {
  154. if (!this.account.user_string) {
  155. this.errIndex = 3
  156. return false
  157. };
  158. } else {
  159. return false
  160. }
  161. return true
  162. },
  163. getCode() {
  164. if (this.codeText !== '获取验证码') {
  165. return false
  166. }
  167. const errStatus = this.jiaoyan()
  168. if (!errStatus) {
  169. return false
  170. }
  171. let obj = {
  172. user_string: this.account.user_string
  173. };
  174. if (this.type == 1) {
  175. obj.area_code = this.account.area_code
  176. };
  177. if (this.Api_) {
  178. this.Api_(obj).then(res => {
  179. uni.showToast({
  180. title: '验证码发送成功',
  181. icon: 'none'
  182. })
  183. }).catch(err => {
  184. })
  185. let num = 60
  186. this.timeInterval = setInterval(() => {
  187. num--;
  188. if (num <= 0) {
  189. clearInterval(this.timeInterval);
  190. this.codeText = '获取验证码';
  191. return false
  192. };
  193. this.codeText = `${num}秒后重新发送`;
  194. }, 1000)
  195. }
  196. },
  197. submitBindAccount() {
  198. //
  199. let Api_ = '',
  200. obj = {},
  201. title = ''
  202. if (this.type == 1) {
  203. // 手机号
  204. title = '手机号'
  205. Api_ = Api_setBindMobile;
  206. obj = {
  207. mobile: this.account.user_string,
  208. code: this.account.code
  209. }
  210. }
  211. if (this.type == 2) {
  212. // 邮箱
  213. title = '邮箱'
  214. Api_ = Api_setBindEmail;
  215. obj = {
  216. email: this.account.user_string,
  217. code: this.account.code
  218. }
  219. }
  220. if (Api_) {
  221. uni.showLoading({
  222. title: '',
  223. mask: true
  224. })
  225. Api_(obj).then(res => {
  226. setTimeout(() => {
  227. uni.showToast({
  228. title: `绑定${title}成功`,
  229. icon: "none"
  230. })
  231. setTimeout(() => {
  232. uni.navigateBack()
  233. }, 1000)
  234. }, 300)
  235. }).catch(err => {
  236. }).failly(() => {
  237. setTimeout(() => {
  238. uni.hideLoading()
  239. }, 200)
  240. })
  241. }
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. .bangding-box {
  248. width: 100%;
  249. padding: 0 $pages-padding;
  250. .bangding-item {
  251. display: flex;
  252. justify-content: space-between;
  253. align-items: center;
  254. height: 100rpx;
  255. border-bottom: 1rpx solid $border-color2;
  256. font-size: 28rpx;
  257. padding-top: 20rpx;
  258. .item-lable {
  259. flex-shrink: 0;
  260. width: 120rpx;
  261. }
  262. .item-area {
  263. flex-shrink: 0;
  264. width: 196rpx;
  265. color: $SizeColor1;
  266. font-weight: bold;
  267. display: flex;
  268. align-items: center;
  269. .iconfont {
  270. margin-left: 3px;
  271. color: #5b5b5b;
  272. font-size: 20rpx;
  273. }
  274. // border-right: 1rpx solid $border-color6;
  275. }
  276. .item-link {
  277. display: inline-block;
  278. margin-right: 30rpx;
  279. width: 3rpx;
  280. height: 24rpx;
  281. background-color: $border-color4;
  282. }
  283. .item-input {
  284. flex: 1;
  285. font-size: 28rpx;
  286. }
  287. .placeholder-class {
  288. font-size: 28rpx;
  289. color: $SizeColor1;
  290. font-weight: bold;
  291. }
  292. .item-code {
  293. color: $Theme-Color;
  294. }
  295. }
  296. .code-item {
  297. padding-top: 0;
  298. height: 80rpx;
  299. }
  300. .err-hint {
  301. width: 100%;
  302. height: 70rpx;
  303. font-size: 28rpx;
  304. padding-top: 20rpx;
  305. color: red;
  306. }
  307. }
  308. .bangding-btn {
  309. width: 100%;
  310. margin-top: 80rpx;
  311. height: 90rpx;
  312. border-radius: 10rpx;
  313. font-size: 30rpx;
  314. text-align: center;
  315. line-height: 90rpx;
  316. color: #fff;
  317. background-color: $btnBgColor;
  318. }
  319. .active-btn {
  320. background-color: $Theme-Color;
  321. }
  322. </style>