phone.vue 9.1 KB

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