phone.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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.newSmsCode == '') {
  99. this.$util.msg('请输入新手机验证码', 2000)
  100. return
  101. }
  102. if (!this.$reg.isMobileCode(this.params.newSmsCode)) {
  103. this.$util.msg('新手机验证码格式不正确', 2000)
  104. return
  105. }
  106. this.UserService.UserUpdateMobile(this.params)
  107. .then(response => {
  108. this.$util.msg('修改成功', 1500, true, 'success')
  109. setTimeout(() => {
  110. uni.navigateBack({ delta: 1 })
  111. }, 2000)
  112. })
  113. .catch(error => {
  114. this.$util.msg(error.msg, 2000)
  115. })
  116. },
  117. getNewMobileCodeFn() {
  118. if (this.params.newMobile == '') {
  119. this.$util.msg('请输入手机号', 2000)
  120. return
  121. }
  122. if (!this.$reg.isMobile(this.params.newMobile)) {
  123. this.$util.msg('请输入正确的手机号', 2000)
  124. return
  125. }
  126. let params = {
  127. mobile: this.params.newMobile,
  128. isCheckCaptcha: 1,
  129. activateCodeType: 11,
  130. platformType: 0
  131. }
  132. this.getMobileCode(params)
  133. },
  134. //获取短信
  135. async getMobileCode(params) {
  136. this.isNewMobileDisabled = true
  137. try {
  138. const res = this.PublicService.GetRegisterMobileCode(params)
  139. this.$util.msg('验证短信已发送', 2000)
  140. const TIME_COUNT = 60
  141. if (!this.codeTimeNew) {
  142. this.newCount = TIME_COUNT
  143. this.isNewMobileDisabled = true
  144. this.codeTimeNew = setInterval(() => {
  145. if (this.newCount > 1 && this.newCount <= TIME_COUNT) {
  146. this.newCount--
  147. this.newMobileCodeText = this.newCount + 's重新发送'
  148. } else {
  149. this.isNewMobileDisabled = false
  150. clearInterval(this.codeTimeNew)
  151. this.codeTimeNew = null
  152. this.newMobileCodeText = '获取验证码'
  153. }
  154. }, 1000)
  155. }
  156. } catch (e) {
  157. //TODO handle the exception
  158. this.$util.msg(error.msg, 2000)
  159. this.isNewMobileDisabled = false
  160. }
  161. }
  162. },
  163. onShow() {
  164. this.$api.getStorage().then(resolve => {
  165. this.params.userId = resolve.userId ? resolve.userId : 0
  166. })
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. .register {
  172. width: 100%;
  173. height: auto;
  174. border-top: 1px solid #f7f7f7;
  175. .model-warp.none {
  176. display: none;
  177. }
  178. .model-warp.show {
  179. display: block;
  180. }
  181. .register-main {
  182. width: 100%;
  183. height: auto;
  184. &.detailed {
  185. padding-bottom: 300rpx;
  186. }
  187. &.first {
  188. padding-top: 40rpx;
  189. }
  190. .register-tips {
  191. display: flex;
  192. flex-direction: column;
  193. align-items: center;
  194. line-height: 44rpx;
  195. font-size: $font-size-24;
  196. color: #ff0000;
  197. margin-bottom: 40rpx;
  198. .iconfont {
  199. font-size: $font-size-24;
  200. }
  201. }
  202. .register-row {
  203. width: 702rpx;
  204. height: auto;
  205. margin: auto;
  206. // margin-bottom: 20rpx;
  207. border-bottom: 2rpx solid #e1e1e1;
  208. &.none{
  209. border-bottom: none;
  210. }
  211. .register-title {
  212. line-height: 60rpx;
  213. font-size: $font-size-32;
  214. color: $text-color;
  215. text-align: left;
  216. padding-left: 20rpx;
  217. .txt {
  218. font-size: $font-size-26;
  219. font-weight: normal;
  220. }
  221. }
  222. .row-btn {
  223. position: absolute;
  224. right: 24rpx;
  225. top: 0;
  226. line-height: 88rpx;
  227. text-align: center;
  228. font-size: $font-size-28;
  229. color: $color-system;
  230. }
  231. .register-from {
  232. width: 702rpx;
  233. height: 64rpx;
  234. padding: 24rpx 0;
  235. position: relative;
  236. .label {
  237. text-align: left;
  238. font-size: $font-size-28;
  239. color: #666666;
  240. line-height: 64rpx;
  241. float: left;
  242. }
  243. .row-input {
  244. width: 440rpx;
  245. padding-left: 10rpx;
  246. font-size: $font-size-28;
  247. color: $text-color;
  248. line-height: 64rpx;
  249. float: left;
  250. height: 64rpx;
  251. &.none {
  252. color: #999999;
  253. }
  254. }
  255. &.code {
  256. width: 410rpx;
  257. float: left;
  258. margin-right: 20rpx;
  259. .row-input {
  260. width: 390rpx;
  261. }
  262. }
  263. &.btn {
  264. width: 180rpx;
  265. height: 64rpx;
  266. float: right;
  267. padding: 0;
  268. border-radius: 32rpx;
  269. background: $btn-confirm;
  270. .row-input {
  271. width: 180rpx;
  272. height: 64rpx;
  273. line-height: 64rpx;
  274. padding: 0;
  275. background: $btn-confirm;
  276. color: #ffffff;
  277. text-align: center;
  278. border-radius: 45rpx;
  279. font-size: $font-size-24;
  280. &.none {
  281. background: #f7f7f7;
  282. }
  283. }
  284. &.disabled {
  285. background: #f7f7f7;
  286. .row-input {
  287. background: #f7f7f7;
  288. color: #999999;
  289. }
  290. }
  291. }
  292. &.btn {
  293. margin-top: 20rpx;
  294. }
  295. }
  296. }
  297. .register-btn {
  298. width: 600rpx;
  299. height: 88rpx;
  300. border-radius: 44rpx;
  301. font-size: $font-size-28;
  302. line-height: 88rpx;
  303. color: #ffffff;
  304. margin: 0 auto;
  305. text-align: center;
  306. background: $btn-confirm;
  307. margin-top: 100rpx;
  308. &.disabled {
  309. background: #e2e2e2;
  310. }
  311. }
  312. }
  313. }
  314. .register-text {
  315. width: 506rpx;
  316. color: #fea785;
  317. font-size: 22rpx;
  318. line-height: 32rpx;
  319. margin: 30rpx auto;
  320. text-align: center;
  321. }
  322. .place-holder {
  323. color: #b2b2b2;
  324. }
  325. </style>