changeInfo.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <!-- 修改昵称 -->
  2. <template>
  3. <view class='edit_nick_name'>
  4. <view class='input_wrap flex_row_between_center'>
  5. <input type='text' v-model='memberNickName' maxlength='15' placeholder='这么好的你,应该拥有更好的昵称~' placeholder-style='font-size:26rpx;color:#949494'
  6. @input='inputCon' confirm-type='done' @confirm='saveCon'></input>
  7. <text @click="clearCon" v-show="memberNickName" class='clear_con iconfont iconguanbi' />
  8. </view>
  9. <view v-show="memberNickName" class='count'>
  10. <text class='cur_count'>{{memberNickName.length}}</text><text class="totla_count">/15</text>
  11. </view>
  12. <view class="member_nickname_btn" @click="saveCon">{{$L('保存')}}</view>
  13. </view>
  14. </template>
  15. <script>
  16. import {
  17. mapState
  18. } from 'vuex';
  19. export default {
  20. data() {
  21. return {
  22. memberNickName: '',
  23. limitNum: 15,
  24. };
  25. },
  26. onLoad(option) {
  27. this.memberNickName = decodeURIComponent(option.nickName);
  28. },
  29. computed: {
  30. ...mapState(['userInfo'])
  31. },
  32. methods: {
  33. //input输入事件
  34. inputCon(e) {
  35. let {
  36. limitNum
  37. } = this;
  38. let con = e.detail.value;
  39. if (con.length <= limitNum) {
  40. this.memberNickName = con;
  41. }
  42. },
  43. //保存数据
  44. saveCon() {
  45. let {
  46. memberNickName
  47. } = this;
  48. if (memberNickName.trim().length == 0) {
  49. this.$api.msg('请输入昵称');
  50. }else if(memberNickName.trim().length>10){
  51. this.$api.msg('请输入15个字以内的昵称');
  52. } else {
  53. this.saveMemInfo('memberNickName', memberNickName);
  54. }
  55. },
  56. //清空输入值
  57. clearCon() {
  58. this.memberNickName = '';
  59. },
  60. navTo(url) {
  61. uni.navigateTo({
  62. url: url
  63. })
  64. },
  65. //保存会员信息
  66. saveMemInfo(index, val) {
  67. let param = {};
  68. param.url = 'v3/member/front/member/updateInfo';
  69. param.data = {};
  70. param.method = 'POST';
  71. param.data[index] = val;
  72. this.$request(param).then(res => {
  73. this.$api.msg(res.msg);
  74. if (res.state == 200) {
  75. uni.showToast({
  76. title:'修改成功!',
  77. icon:'none',
  78. duration:500
  79. })
  80. setTimeout(()=>{
  81. this[index] = val;
  82. //更新上个页面的会员昵称
  83. var pages = getCurrentPages(); //当前页面栈
  84. if (pages.length > 1) {
  85. var beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
  86. beforePage.$vm.updateMemInfo(val); //触发上个面中的方法updateMemInfo()
  87. }
  88. uni.navigateBack();
  89. },700)
  90. }
  91. }).catch((e) => {
  92. //异常处理
  93. })
  94. },
  95. }
  96. }
  97. </script>
  98. <style lang='scss'>
  99. page {
  100. background: $bg-color-split;
  101. width: 750rpx;
  102. margin: 0 auto;
  103. }
  104. .edit_nick_name {
  105. margin-top: 20rpx;
  106. width: 100%;
  107. display: flex;
  108. flex-direction: column;
  109. justify-content: flex-start;
  110. .member_nickname_btn{
  111. width: 680rpx;
  112. height: 80rpx;
  113. background: linear-gradient(-90deg, #FB1D1B 0%, #FF7A18 100%);
  114. border-radius: 37rpx;
  115. margin: 40rpx auto 0;
  116. font-size: 34rpx;
  117. font-family: PingFang SC;
  118. font-weight: 500;
  119. color: #FFFFFF;
  120. line-height: 80rpx;
  121. text-align: center;
  122. }
  123. }
  124. .edit_nick_name .input_wrap {
  125. height: 100rpx;
  126. padding: 0 20rpx;
  127. width: 100%;
  128. background-color: #fff;
  129. }
  130. .edit_nick_name .input_wrap input {
  131. width: 450rpx;
  132. color: #2D2D2D;
  133. font-size: 28rpx;
  134. }
  135. .edit_nick_name .input_wrap .clear_con {
  136. font-size: 35rpx;
  137. color: #DCDCDC;
  138. }
  139. .edit_nick_name .count {
  140. width: 100%;
  141. display: flex;
  142. justify-content: flex-end;
  143. padding-right: 20rpx;
  144. margin-top: 20rpx;
  145. }
  146. .edit_nick_name .count text {
  147. font-size: 28rpx;
  148. color: #2D2D2D;
  149. }
  150. .edit_nick_name .count .cur_count {
  151. color: #FC1C1C;
  152. }
  153. </style>