nc.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view>
  3. <view class="uni-form-item uni-column">
  4. <view class="with-fun" style="padding: 20upx;">
  5. <input class="uni-input" type="text" confirm-type="done" focus :placeholder="name" placeholder-style="color:#666" @input="onKeyInput" :value="inputValue" />
  6. </view>
  7. </view>
  8. <button class="onname" :style="{'background':dbled?'#999':'#E17503'}" :disabled="dbled" type="primary" @tap="onOKname()">确 认</button>
  9. </view>
  10. </template>
  11. <script>
  12. import { mapMutations} from 'vuex';
  13. export default {
  14. data() {
  15. return {
  16. inputValue: '',
  17. dbled:true,
  18. name:'',
  19. ty:''
  20. }
  21. },
  22. onLoad(options){
  23. //接收传值,id里面放的是标题,因为测试数据并没写id
  24. let ty = options.ty;
  25. let name = options.name;
  26. let v = options.v;
  27. this.ty=ty;
  28. this.name='请修改'+name;
  29. uni.setNavigationBarTitle({
  30. title: '修改'+name
  31. });
  32. if(v=='null'){
  33. this.inputValue='';
  34. }else{
  35. this.inputValue=v;
  36. }
  37. },
  38. methods: {
  39. ...mapMutations(['login']),
  40. onKeyInput(event){
  41. this.inputValue = event.target.value
  42. let lens = event.target.value
  43. if(lens.length){
  44. this.dbled=false
  45. }else{
  46. this.dbled=true
  47. }
  48. },
  49. async onOKname(){
  50. let _this=this;
  51. var data={[this.ty]:this.inputValue};
  52. let [err,res] = await this.$httpas.post('/api/user/edituser',data,{token:true});
  53. if (!this.$httpas.errorCheck(err,res)) return;
  54. if(res.data.code === 1){
  55. var pages = getCurrentPages();
  56. var currPage = pages[pages.length - 1]; //当前页面
  57. var prevPage = pages[pages.length - 2]; //上一个页面
  58. //将前一页的address和address_id修改为当前选中的
  59. if(this.ty=='nickname'){
  60. var userInfo =uni.getStorageSync("userInfo");
  61. if(userInfo){
  62. userInfo.nickname=this.inputValue;
  63. this.login(userInfo);
  64. }
  65. }
  66. uni.showModal({
  67. content: '修改成功',
  68. success: (e)=>{
  69. if(e.confirm){
  70. setTimeout(()=>{
  71. uni.navigateBack();
  72. }, 200)
  73. }
  74. }
  75. });
  76. }else{
  77. uni.showToast({ title: res.data.msg,icon:"none" });
  78. this.logining = false;
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped>
  85. .title {
  86. padding: 10upx 25upx;
  87. }
  88. .with-fun{
  89. background: #f8f8f8;
  90. position: relative;
  91. }
  92. .with-fun:after{
  93. position: absolute;
  94. content: $name;
  95. height: 50px;
  96. line-height: 50px;
  97. top: 0px;
  98. left: 20px;
  99. font-size: 32upx;
  100. }
  101. .uni-input{
  102. height: 50px;
  103. line-height: 50px;
  104. font-size: 32upx;
  105. background: #f8f8f8;
  106. color: #666;
  107. }
  108. .uni-icon-clear,
  109. .uni-icon-eye {
  110. color: #999;
  111. }
  112. .onname{
  113. width: 94%;
  114. margin: 20upx auto;
  115. background: -webkit-linear-gradient(left top, #E49315 , #E17503); /* Safari 5.1 - 6.0 */
  116. background: -o-linear-gradient(bottom right, #E49315, #E17503); /* Opera 11.1 - 12.0 */
  117. background: -moz-linear-gradient(bottom right, #E49315,#E17503); /* Firefox 3.6 - 15 */
  118. background: linear-gradient(to bottom right, #E49315 , #E17503); /* 标准的语法(必须放在最后) */
  119. }
  120. .onnames{
  121. width: 94%;
  122. margin: 20upx auto;
  123. background: -webkit-linear-gradient(left top, #f1f1f1 , #f9f9f9); /* Safari 5.1 - 6.0 */
  124. background: -o-linear-gradient(bottom right, #f1f1f1, #f9f9f9); /* Opera 11.1 - 12.0 */
  125. background: -moz-linear-gradient(bottom right, #f1f1f1,#f9f9f9); /* Firefox 3.6 - 15 */
  126. background: linear-gradient(to bottom right, #f1f1f1 , #f9f9f9); /* 标准的语法(必须放在最后) */
  127. }
  128. </style>