bindPhone.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="container">
  3. <uni-nav-bar id="nav-bar" status-bar="true" @clickLeft="onBack" :title="pageTitle" color="#000000" fixed="true"
  4. :border="false">
  5. <view slot="left">
  6. <view class=" flex align-center margin-left">
  7. <image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
  8. </view>
  9. </view>
  10. </uni-nav-bar>
  11. <view style="height:6px ;width: 100%; background-color: #f2eff2;"></view>
  12. <!-- 手机端登录,获取验证码 -->
  13. <view class="input-container" style="margin: 32px 102rpx 0 68rpx;">
  14. <view class="make-text-bPurple text-bold margin-bottom" style="font-size: 20px;">绑定手机</view>
  15. <view class="input-row padding" style="width: 318px;">
  16. <m-input type="number" maxlength="11" clearable v-model="account" placeholder="请填写11位手机号码"></m-input>
  17. </view>
  18. </view>
  19. <view class="flex justify-between" style="margin: 32px 96rpx 0 68rpx; ">
  20. <view class="text-22px make-text-bPurple">输入验证码</view>
  21. <view v-if="bCodeDisabled" class="btn-code" style="background-color: rgb(0,0,0);opacity: 0.5;">重新获取({{count}})</view>
  22. <view v-else class="btn-code" @tap="onGetCode">获取验证码</view>
  23. </view>
  24. <!-- 手机端登录 -->
  25. <view class="text-16px text-gray" style="margin: 20px 0 0 96rpx;">已发送4位验证码...</view>
  26. <view class="code-input-main">
  27. <view class="inputLine">
  28. <view class="input-item">{{inputCode[0]}}</view>
  29. <view class="input-item">{{inputCode[1]}}</view>
  30. <view class="input-item">{{inputCode[2]}}</view>
  31. <view class="input-item">{{inputCode[3]}}</view>
  32. </view>
  33. <input class="code-input-input" v-model="inputCode" maxlength="4" type="number" />
  34. </view>
  35. <view class="btn-row">
  36. <view class="btn-confirm" :disabled="inputCode.length<4" @tap="onConfirm">确认绑定</view>
  37. </view>
  38. <input class='ipt' type="number" :maxlength="Length" :focus="bFocus"></input>
  39. </view>
  40. </template>
  41. <script>
  42. import mInput from '@/components/m-input.vue'
  43. import config from '@/common/config.js';
  44. import reqUtil from "@/util/util-js/requstUtil.js";
  45. import verify from '@/util/util-js/verify.js'
  46. import {
  47. mapState,
  48. mapMutations
  49. } from 'vuex'
  50. export default {
  51. components: {
  52. mInput
  53. },
  54. data() {
  55. return {
  56. //获取验证码页面
  57. bGetCode: true,
  58. bMobileLogin: true,
  59. providerList: [],
  60. hasProvider: true,
  61. account: '',
  62. password: '',
  63. positionTop: 0,
  64. //输入框参数
  65. Length: 4, //输入框个数
  66. bFocus: false, //聚焦
  67. Value: "", //输入的内容
  68. inputCode: '',
  69. pageTitle: "绑定手机",
  70. bConfirm: false,
  71. }
  72. },
  73. computed: mapState(['bNewUser', 'forcedLogin', 'phoneNumber', 'bCodeDisabled', 'count']),
  74. methods: {
  75. ...mapMutations(['countDown','resetCountDown']),
  76. onBack() {
  77. uni.navigateBack({
  78. delta: 1
  79. })
  80. },
  81. onGetCode() {
  82. if (!verify.checkPhone(this.account)) {
  83. uni.showToast({
  84. icon: 'none',
  85. title: '输入手机号错误'
  86. });
  87. return;
  88. }
  89. // this.$store.state.phoneNumber = this.account;
  90. //置灰状态
  91. if (this.bCodeDisabled) return;
  92. //调用store 倒计时
  93. this.countDown(this.account);
  94. },
  95. inputEvent(res) {
  96. console.log("input 1 input inputCode components : ", res.detail.value);
  97. },
  98. //验证码操作
  99. //注册
  100. onConfirm() {
  101. var _self = this;
  102. if (!verify.checkPhone(_self.account)) {
  103. uni.showToast({
  104. icon: 'none',
  105. title: '输入手机号错误'
  106. });
  107. return;
  108. }
  109. if (_self.bConfirm) return;
  110. uni.showToast({
  111. title:"",
  112. icon:"loading",
  113. mask:true,
  114. duration:10000
  115. })
  116. _self.bConfirm = true;
  117. reqUtil.requestData(config.URL.BINDPHONE, {
  118. "phoneNumber": _self.account,
  119. "code": _self.inputCode
  120. }).then(res => {
  121. console.log('requestData BINDPHONE =====', res);
  122. uni.hideToast();
  123. _self.bConfirm = false;
  124. if (res.code == 0) {
  125. uni.showToast({
  126. title: "绑定手机号成功",
  127. mask: true,
  128. duration: 1000
  129. })
  130. _self.$store.state.phoneNumber = _self.account;
  131. _self.resetCountDown();
  132. // 绑定电话成功后,回退页面
  133. uni.navigateBack({
  134. delta: 1
  135. })
  136. } else if (res.code == 213) {
  137. uni.showToast({
  138. title: "手机号已使用过,请换个号码",
  139. mask: true,
  140. icon: 'none',
  141. duration: 3000
  142. })
  143. } else {
  144. uni.showToast({
  145. title: "绑定失败",
  146. mask: true,
  147. icon: 'none',
  148. duration: 1000
  149. })
  150. }
  151. },
  152. e => {
  153. console.log(e);
  154. uni.hideToast();
  155. _self.bConfirm = false;
  156. });
  157. }
  158. }
  159. }
  160. </script>
  161. <style>
  162. .input-row {
  163. display: flex;
  164. flex-direction: row;
  165. position: relative;
  166. }
  167. .btn-row {
  168. display: flex;
  169. justify-content: center;
  170. align-items: center;
  171. }
  172. .container {
  173. position: absolute;
  174. top: 0;
  175. bottom: 0;
  176. left: 0;
  177. right: 0;
  178. background-color: #FFFFFF;
  179. }
  180. .input-container {
  181. border-bottom: 1rpx solid #e7e9eb;
  182. }
  183. .btn-code {
  184. width: 235rpx;
  185. height: 63rpx;
  186. background-color: rgba(151, 151, 255, 1);
  187. border-radius: 10px;
  188. display: flex;
  189. justify-content: center;
  190. align-items: center;
  191. font-size: 15px;
  192. color: #FFFFFF;
  193. }
  194. .btn-confirm {
  195. width: 636rpx;
  196. height: 102rpx;
  197. background-color: rgba(151, 151, 255, 1);
  198. border-radius: 10px;
  199. display: flex;
  200. justify-content: center;
  201. align-items: center;
  202. font-size: 17px;
  203. color: #FFFFFF;
  204. }
  205. .code-input-main {
  206. display: flex;
  207. flex-direction: column;
  208. width: 100%;
  209. /* border: 1rpx solid #000000; */
  210. height: 150px;
  211. position: relative;
  212. }
  213. .input-item {
  214. width: 106rpx;
  215. height: 118rpx;
  216. font-size: 20px;
  217. line-height: 118rpx;
  218. background-color: rgba(244, 241, 244, 255);
  219. /* border: 1rpx solid #ddd; */
  220. text-align: center;
  221. border-radius: 8px;
  222. margin-left: 44rpx;
  223. /* margin-right: 40upx; */
  224. color: rgba(86, 86, 86, 1);
  225. font-weight: bold;
  226. }
  227. .inputLine {
  228. display: flex;
  229. justify-content: flex-start;
  230. width: 100%;
  231. top: 80rpx;
  232. left: 52rpx;
  233. position: absolute;
  234. z-index: 1;
  235. }
  236. .code-input-input {
  237. height: 150px;
  238. position: absolute;
  239. width: 100%;
  240. outline: none;
  241. color: transparent;
  242. text-shadow: 0 0 0 transparent;
  243. width: 300%;
  244. left: -100%;
  245. top: 0;
  246. /* background: #000000; */
  247. /* border: 1rpx solid #007AFF; */
  248. z-index: 10;
  249. }
  250. .ipt {
  251. width: 0;
  252. height: 0;
  253. }
  254. </style>