phone.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <view class="container register">
  3. <view class="register-main first clearfix">
  4. <view class="register-row none clearfix">
  5. <view class="register-from">
  6. <view class="label">当前手机号:</view> <view class="row-input">{{ params.mobile }}</view>
  7. </view>
  8. </view>
  9. <view class="register-row clearfix">
  10. <view class="register-from">
  11. <input
  12. class="row-input"
  13. type="number"
  14. v-model="params.newMobile"
  15. placeholder="请输入新手机号"
  16. @input="handleInput"
  17. placeholder-class="place-holder"
  18. maxlength="11"
  19. />
  20. </view>
  21. </view>
  22. <view class="register-row clearfix">
  23. <view class="register-from code">
  24. <input
  25. class="row-input"
  26. type="number"
  27. v-model="params.newSmsCode"
  28. placeholder="请输入验证码"
  29. placeholder-class="place-holder"
  30. maxlength="6"
  31. />
  32. </view>
  33. <view class="register-from btn" :class="{ 'disabled' : disabled1 , 'disabled' : isNewMobileDisabled}">
  34. <button
  35. class="row-input"
  36. type="button"
  37. @click.stop="getNewMobileCodeFn"
  38. :disabled="isNewMobileDisabled"
  39. >
  40. {{ newMobileCodeText }}
  41. </button>
  42. </view>
  43. </view>
  44. <view class="register-row clearfix" style="border: 0;">
  45. <button class="register-btn" :disabled="disabled" :class="disabled ? 'disabled' : ''" @click="btnConfirm">
  46. 确定
  47. </button>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { mapMutations } from 'vuex'
  54. var self
  55. export default {
  56. data() {
  57. return {
  58. newCount: '', //倒计时
  59. codeTimeNew: null,
  60. newMobileCodeText: '获取验证码',
  61. isNewMobileDisabled: true, //手机验证码按钮控制
  62. params: {
  63. newMobile: '', //新联系人手机号
  64. newSmsCode: '', //新手机号手机验证码
  65. userId: 0
  66. }
  67. }
  68. },
  69. computed: {
  70. disabled1(){
  71. return !this.params.newMobile.length === 11
  72. },
  73. disabled() {
  74. return !(this.params.newMobile != '' && this.params.newSmsCode != '')
  75. }
  76. },
  77. onLoad(option) {
  78. this.params.mobile = option.phone
  79. },
  80. methods: {
  81. // 监听输入手机号
  82. handleInput(e){
  83. this.params.newMobile = e.detail.value
  84. if(this.params.newMobile.length === 11){
  85. this.isNewMobileDisabled = false
  86. }
  87. },
  88. // 确认更换
  89. btnConfirm() {
  90. if (this.params.newMobile == '') {
  91. this.$util.msg('请输入新的手机号码', 2000)
  92. return
  93. }
  94. if (!this.$reg.isMobile(this.params.newMobile)) {
  95. this.$util.msg('请输入正确的手机号码', 2000)
  96. return
  97. }
  98. if (this.params.smsCode == '') {
  99. this.$util.msg('请输入旧手机验证码', 2000)
  100. return
  101. }
  102. if (!this.$reg.isMobileCode(this.params.smsCode)) {
  103. this.$util.msg('旧手机验证码格式不正确', 2000)
  104. return
  105. }
  106. if (this.params.newSmsCode == '') {
  107. this.$util.msg('请输入新手机验证码', 2000)
  108. return
  109. }
  110. if (!this.$reg.isMobileCode(this.params.newSmsCode)) {
  111. this.$util.msg('新手机验证码格式不正确', 2000)
  112. return
  113. }
  114. this.UserService.UserUpdateMobile(this.params)
  115. .then(response => {
  116. this.$util.msg('修改成功', 1500, true, 'success')
  117. setTimeout(() => {
  118. uni.navigateBack({ delta: 1 })
  119. }, 2000)
  120. })
  121. .catch(error => {
  122. this.$util.msg(error.msg, 2000)
  123. })
  124. },
  125. getNewMobileCodeFn() {
  126. if (this.params.newMobile == '') {
  127. this.$util.msg('请输入手机号', 2000)
  128. return
  129. }
  130. if (!this.$reg.isMobile(this.params.newMobile)) {
  131. this.$util.msg('请输入正确的手机号', 2000)
  132. return
  133. }
  134. let params = {
  135. mobile: this.params.newMobile,
  136. isCheckCaptcha: 1,
  137. activateCodeType: 5,
  138. platformType: 0
  139. }
  140. this.getMobileCode(params)
  141. },
  142. //获取短信
  143. async getMobileCode(params) {
  144. this.isNewMobileDisabled = true
  145. try {
  146. const res = this.PublicService.GetRegisterMobileCode(params)
  147. this.$util.msg('验证短信已发送', 2000)
  148. const TIME_COUNT = 60
  149. if (!this.codeTimeNew) {
  150. this.newCount = TIME_COUNT
  151. this.isNewMobileDisabled = true
  152. this.codeTimeNew = setInterval(() => {
  153. if (this.newCount > 1 && this.newCount <= TIME_COUNT) {
  154. this.newCount--
  155. this.newMobileCodeText = this.newCount + 's重新发送'
  156. } else {
  157. this.isNewMobileDisabled = false
  158. clearInterval(this.codeTimeNew)
  159. this.codeTimeNew = null
  160. this.newMobileCodeText = '获取验证码'
  161. }
  162. }, 1000)
  163. }
  164. } catch (e) {
  165. //TODO handle the exception
  166. this.$util.msg(error.msg, 2000)
  167. this.isNewMobileDisabled = false
  168. }
  169. }
  170. },
  171. onShow() {
  172. this.$api.getStorage().then(resolve => {
  173. this.params.userId = resolve.userId ? resolve.userId : 0
  174. })
  175. }
  176. }
  177. </script>
  178. <style lang="scss">
  179. .register {
  180. width: 100%;
  181. height: auto;
  182. border-top: 1px solid #f7f7f7;
  183. .model-warp.none {
  184. display: none;
  185. }
  186. .model-warp.show {
  187. display: block;
  188. }
  189. .register-main {
  190. width: 100%;
  191. height: auto;
  192. &.detailed {
  193. padding-bottom: 300rpx;
  194. }
  195. &.first {
  196. padding-top: 40rpx;
  197. }
  198. .register-tips {
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. line-height: 44rpx;
  203. font-size: $font-size-24;
  204. color: #ff0000;
  205. margin-bottom: 40rpx;
  206. .iconfont {
  207. font-size: $font-size-24;
  208. }
  209. }
  210. .register-row {
  211. width: 702rpx;
  212. height: auto;
  213. margin: auto;
  214. // margin-bottom: 20rpx;
  215. border-bottom: 2rpx solid #e1e1e1;
  216. &.none{
  217. border-bottom: none;
  218. }
  219. .register-title {
  220. line-height: 60rpx;
  221. font-size: $font-size-32;
  222. color: $text-color;
  223. text-align: left;
  224. padding-left: 20rpx;
  225. .txt {
  226. font-size: $font-size-26;
  227. font-weight: normal;
  228. }
  229. }
  230. .row-btn {
  231. position: absolute;
  232. right: 24rpx;
  233. top: 0;
  234. line-height: 88rpx;
  235. text-align: center;
  236. font-size: $font-size-28;
  237. color: $color-system;
  238. }
  239. .register-from {
  240. width: 702rpx;
  241. height: 64rpx;
  242. padding: 24rpx 0;
  243. position: relative;
  244. .label {
  245. text-align: left;
  246. font-size: $font-size-28;
  247. color: #666666;
  248. line-height: 64rpx;
  249. float: left;
  250. }
  251. .row-input {
  252. width: 440rpx;
  253. padding-left: 10rpx;
  254. font-size: $font-size-28;
  255. color: $text-color;
  256. line-height: 64rpx;
  257. float: left;
  258. height: 64rpx;
  259. &.none {
  260. color: #999999;
  261. }
  262. }
  263. &.code {
  264. width: 410rpx;
  265. float: left;
  266. margin-right: 20rpx;
  267. .row-input {
  268. width: 390rpx;
  269. }
  270. }
  271. &.btn {
  272. width: 180rpx;
  273. height: 64rpx;
  274. float: right;
  275. padding: 0;
  276. border-radius: 32rpx;
  277. background: $btn-confirm;
  278. .row-input {
  279. width: 180rpx;
  280. height: 64rpx;
  281. line-height: 64rpx;
  282. padding: 0;
  283. background: $btn-confirm;
  284. color: #ffffff;
  285. text-align: center;
  286. border-radius: 45rpx;
  287. font-size: $font-size-24;
  288. &.none {
  289. background: #f7f7f7;
  290. }
  291. }
  292. &.disabled {
  293. background: #f7f7f7;
  294. .row-input {
  295. background: #f7f7f7;
  296. color: #999999;
  297. }
  298. }
  299. }
  300. &.btn {
  301. margin-top: 20rpx;
  302. }
  303. }
  304. }
  305. .register-btn {
  306. width: 600rpx;
  307. height: 88rpx;
  308. border-radius: 44rpx;
  309. font-size: $font-size-28;
  310. line-height: 88rpx;
  311. color: #ffffff;
  312. margin: 0 auto;
  313. text-align: center;
  314. background: $btn-confirm;
  315. margin-top: 100rpx;
  316. &.disabled {
  317. background: #e2e2e2;
  318. }
  319. }
  320. }
  321. }
  322. .register-text {
  323. width: 506rpx;
  324. color: #fea785;
  325. font-size: 22rpx;
  326. line-height: 32rpx;
  327. margin: 30rpx auto;
  328. text-align: center;
  329. }
  330. .place-holder {
  331. color: #b2b2b2;
  332. }
  333. </style>