changeEmail.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <!-- 修改电子邮箱页面 -->
  2. <template>
  3. <view class="container flex_column_start_start">
  4. <template v-if="step==1">
  5. <view class="bind_mobile flex_row_start_center">
  6. {{$L('使用已绑定邮箱')}}{{userCenterData.memberEmail}}{{$L('进行身份验证')}}
  7. </view>
  8. <view class="main_content">
  9. <view class="input-item pwd_wrap flex_row_between_center">
  10. <input type="number" class="sms_code" :value="smsCodeOri" maxlength="4" :placeholder="$L('请输入邮箱验证码')" placeholder-class='smsCodePlaceholder'
  11. data-key="smsCodeOri" @input="inputChange" @confirm="toLogin" />
  12. <view class="pwd-right flex_row_end_center">
  13. <text class="clear-pwd iconfont iconziyuan51" v-show="smsCodeOri" @click="clearContent('smsCodeOri')"></text>
  14. <view :style="{opacity: countDownM?0.3:1}" class="sms-code-view" @click="getSmsCode">
  15. <text class="sms-code">{{countDownM?`${countDownM}s后重新获取`:'获取验证码'}}</text>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <template v-if="step==2">
  22. <view class="second_main_content">
  23. <view class="flex_row_between_center input-item pwd_wrap ">
  24. <input type="text" class="sms_code" :value="email" maxlength="50" :placeholder="$L('请输入新邮箱')" placeholder-class='smsCodePlaceholder'
  25. data-key="email" @input="inputChange" />
  26. <view class="pwd-right flex_row_end_center">
  27. <text class="clear-pwd iconfont iconziyuan51" v-show="email" @click="clearContent('email')"></text>
  28. </view>
  29. </view>
  30. <view class="flex_row_between_center input-item pwd_wrap " style="margin-top: 20rpx">
  31. <input type="number" class="sms_code" :value="smsCode" maxlength="4" :placeholder="$L('请输入邮箱验证码')" placeholder-class='smsCodePlaceholder'
  32. data-key="smsCode" @input="inputChange" @confirm="toLogin" />
  33. <view class="pwd-right flex_row_end_center">
  34. <text class="clear-pwd iconfont iconziyuan51" v-show="smsCode" @click="clearContent('smsCode')"></text>
  35. <view :style="{opacity: countDownM?0.3:1}" class="sms-code-view" @click="getSmsCode">
  36. <text class="sms-code">{{countDownM?`${countDownM}s后重新获取`:'获取验证码'}}</text>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <view class="confirm_btn flex_row_center_center" @click="confirm">
  43. 确定
  44. </view>
  45. <uni-popup ref="popup" type="dialog">
  46. <uni-popup-dialog type="input" :title="$L('温馨提示')" :content="bindTip" :duration="2000" before-close="true" @close="closeDialog" @confirm="confirmBind"></uni-popup-dialog>
  47. </uni-popup>
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. mapState,mapMutations
  53. } from 'vuex';
  54. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  55. import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
  56. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
  57. export default {
  58. components: {
  59. uniPopup,
  60. uniPopupMessage,
  61. uniPopupDialog
  62. },
  63. data() {
  64. return {
  65. email:'',//新邮箱
  66. smsCodeOri: '', //邮箱验证码(原先的)
  67. smsCode: '', //新邮箱验证码
  68. step: 1, //步骤
  69. countDownM: 0,//邮箱验证码倒计时
  70. timeOutId:'',//定时器的返回值
  71. bind:'',//是否进行绑定,1-解绑,0-不解绑
  72. bindTip:'',//弹框内容提示
  73. };
  74. },
  75. computed: {
  76. ...mapState(['userInfo', 'userCenterData'])
  77. },
  78. onLoad() {
  79. },
  80. methods: {
  81. ...mapMutations(['setUserCenterData']),
  82. inputChange(e) {
  83. const key = e.currentTarget.dataset.key;
  84. this[key] = e.detail.value;
  85. },
  86. //清空输入的内容
  87. clearContent(type) {
  88. this[type] = '';
  89. },
  90. //获取邮箱验证码
  91. getSmsCode() {
  92. if(this.countDownM){
  93. return;
  94. }
  95. //验证邮箱
  96. if (this.step==2&&!this.$checkEmail(this.email)) {
  97. return;
  98. }
  99. let param = {};
  100. param.url = 'v3/msg/front/commons/sendVerifyCode';
  101. param.data = {};
  102. param.method = 'GET';
  103. param.data.verifyType = 1;
  104. param.data.changeType = this.step==1?'old':'new';
  105. param.data.verifyAddr = this.step==1?this.userCenterData.memberEmail:this.email;
  106. this.$request(param).then(res => {
  107. this.$api.msg(res.msg);
  108. if(res.state == 200){
  109. this.countDownM = 60;
  110. this.countDown();
  111. }else if(res.state == 267){
  112. if(this.step == 2){
  113. this.step = 1;
  114. //设置页面标题
  115. uni.setNavigationBarTitle({
  116. title: '身份验证'
  117. });
  118. }
  119. }
  120. })
  121. },
  122. //倒计时
  123. countDown() {
  124. this.countDownM--;
  125. if (this.countDownM == 0) {
  126. clearTimeout(this.timeOutId);
  127. } else {
  128. this.timeOutId = setTimeout(this.countDown,1000);
  129. }
  130. },
  131. //确认事件
  132. confirm(){
  133. let param = {};
  134. param.data = {};
  135. param.method = 'POST';
  136. param.data.key = this.userInfo.access_token;
  137. if(this.step == 1){
  138. param.url = 'v3/member/front/memberPassword/verifyOldEmail';
  139. param.data.emailCode = this.smsCodeOri;
  140. param.data.memberEmail = this.userCenterData.memberEmail;
  141. }else{
  142. //验证邮箱是否正确
  143. if (!this.$checkEmail(this.email)) {
  144. return false
  145. }
  146. param.url = 'v3/member/front/memberPassword/editEmail';
  147. param.data.memberEmail = this.email;
  148. param.data.emailCode = this.smsCode;
  149. if(this.bind != ''){
  150. param.data.isUnbound = this.bind;
  151. }
  152. }
  153. this.$request(param).then(res => {
  154. if(res.state == 200){
  155. this.$api.msg(res.msg);
  156. if(this.step == 1){
  157. this.step = 2;
  158. //重置验证码倒计时
  159. this.countDownM = 1;
  160. this.countDown();
  161. //设置页面标题
  162. uni.setNavigationBarTitle({
  163. title: '修改电子邮箱'
  164. });
  165. }else{
  166. //更新个人信息数据
  167. this.userCenterData.memberEmail = this.email;
  168. this.setUserCenterData(this.userCenterData);
  169. //返回上级页面
  170. setTimeout(() => {
  171. uni.navigateTo({
  172. url:'/pages/account/account'
  173. })
  174. }, 2000)
  175. }
  176. }else if(res.state == 267){
  177. //提示是否进行绑定
  178. this.bindTip = res.msg;
  179. this.$refs.popup.open();
  180. }else{
  181. this.$api.msg(res.msg);
  182. }
  183. })
  184. },
  185. //关闭弹框
  186. closeDialog(){
  187. this.bind = 0;
  188. this.$refs.popup.close();
  189. //返回上级页面
  190. setTimeout(() => {
  191. uni.navigateBack();
  192. }, 200)
  193. },
  194. //确认绑定
  195. confirmBind(){
  196. this.bind = 1;
  197. this.$refs.popup.close();
  198. this.confirm();
  199. },
  200. }
  201. }
  202. </script>
  203. <style lang='scss'>
  204. page {
  205. background: $bg-color-split;
  206. display: flex;
  207. flex: 1;
  208. height: 100%;
  209. width: 750rpx;
  210. margin: 0 auto;
  211. }
  212. .container {
  213. display: flex;
  214. flex: 1;
  215. .bind_mobile {
  216. height: 80rpx;
  217. width: 100%;
  218. width: 100%;
  219. background: #F8F8F8;
  220. padding-left: 40rpx;
  221. color: $main-font-color;
  222. font-size: 26rpx;
  223. }
  224. .second_main_content{
  225. display: flex;
  226. flex-direction: column;
  227. flex: 1;
  228. width: 100%;
  229. background-color: #fff;
  230. margin-top: 20rpx;
  231. padding: 20rpx 40rpx 0;
  232. }
  233. .main_content {
  234. display: flex;
  235. flex: 1;
  236. width: 100%;
  237. background-color: #fff;
  238. padding: 20rpx 40rpx 0;
  239. }
  240. .input-item {
  241. height: 100rpx;
  242. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  243. position: relative;
  244. width: 100%;
  245. .sms_code_laceholder {
  246. color: #949494;
  247. font-size: 26rpx;
  248. }
  249. .sms_code {
  250. font-size: 28rpx;
  251. color: $main-font-color;
  252. }
  253. .clear-account {
  254. position: absolute;
  255. right: 6rpx;
  256. top: 28rpx;
  257. font-size: 24rpx;
  258. color: #999;
  259. }
  260. .pwd-right {
  261. flex-shrink: 0;
  262. .clear-pwd {
  263. font-size: 24rpx;
  264. color: #999;
  265. }
  266. .sms-code-view {
  267. border: 1px solid $main-color;
  268. padding: 14rpx;
  269. border-radius: 6rpx;
  270. line-height: 0;
  271. margin-left: 20rpx;
  272. .sms-code {
  273. color: $main-color;
  274. font-size: 24rpx;
  275. line-height: 24rpx;
  276. }
  277. }
  278. }
  279. .tit {
  280. height: 50upx;
  281. line-height: 56upx;
  282. font-size: $font-sm+2upx;
  283. color: $font-color-base;
  284. }
  285. input {
  286. height: 60upx;
  287. font-size: $font-base + 2upx;
  288. color: $font-color-dark;
  289. width: 100%;
  290. }
  291. }
  292. .confirm_btn {
  293. position: fixed;
  294. width: 668rpx;
  295. margin: 0 41rpx;
  296. height: 88rpx;
  297. background: linear-gradient(-90deg, rgba(252, 29, 28, 1) 0%, rgba(255, 122, 24, 1) 100%);
  298. border-radius: 44rpx;
  299. left: 50%;
  300. transform: translateX(-375rpx);
  301. bottom: 40rpx;
  302. color: #fff;
  303. font-size: 36rpx;
  304. }
  305. }
  306. </style>