bindPhone.vue 7.7 KB

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