index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="content">
  3. <uni-forms ref="form" :model="form" :rules="rules" label-width="auto">
  4. <uni-forms-item name="account">
  5. <uni-easyinput v-model="form.account" placeholder="请输入登录账号" disabled />
  6. </uni-forms-item>
  7. <uni-forms-item name="phone">
  8. <uni-easyinput v-model="form.phone" placeholder="请输入联系电话" />
  9. </uni-forms-item>
  10. <uni-forms-item name="nick_name">
  11. <uni-easyinput v-model="form.nick_name" placeholder="请输入账号昵称" />
  12. </uni-forms-item>
  13. <uni-forms-item name="gender">
  14. <uni-data-checkbox v-model="form.gender" :localdata="genderList" :map="{text:'label',value:'value'}" />
  15. </uni-forms-item>
  16. <uni-forms-item name="logo_url">
  17. <upload :list="form.logo_url" name="logo_url" :count="1" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  18. </uni-forms-item>
  19. </uni-forms>
  20. <view class="btn">
  21. <button size="mini" @tap="toSubmit('form')">提交保存</button>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import upload from "@/components/upload/index.vue";
  27. export default {
  28. components: {
  29. upload,
  30. },
  31. data() {
  32. return {
  33. form: {
  34. logo_url: [],
  35. },
  36. // 规则
  37. rules: {
  38. account: {
  39. rules: [{
  40. required: true,
  41. errorMessage: '请输入登录账号'
  42. }]
  43. },
  44. phone: {
  45. rules: [{
  46. required: true,
  47. errorMessage: '请输入联系电话'
  48. }]
  49. },
  50. },
  51. // 性别
  52. genderList: []
  53. };
  54. },
  55. onLoad() {
  56. const that = this;
  57. that.search();
  58. that.searchOther();
  59. },
  60. onShow() {},
  61. methods: {
  62. search() {
  63. const that = this;
  64. uni.getStorage({
  65. key: 'token',
  66. success: async (res) => {
  67. let arr = that.$jwt(res.data);
  68. if (arr) {
  69. let user = await that.$api(`user/${arr._id}`, 'GET', {})
  70. if (user && user.errcode == '0') {
  71. that.$set(that, `form`, user.data)
  72. }
  73. }
  74. }
  75. })
  76. },
  77. // 图片保存
  78. uplSuc(e) {
  79. const that = this;
  80. that.$set(that.form, `${e.name}`, [...that.form[e.name], e.data]);
  81. },
  82. // 图片删除
  83. uplDel(e) {
  84. const that = this;
  85. let data = that.form[e.name];
  86. let arr = data.filter((i, index) => index != e.data.index);
  87. that.$set(that.form, `${e.name}`, arr);
  88. },
  89. // 提交保存
  90. toSubmit(ref) {
  91. const that = this;
  92. let agree = that.agree;
  93. that.$refs[ref].validate().then(async parmas => {
  94. let res = await that.$api(`user/${that.form._id}`, 'POST', parmas)
  95. if (res.errcode == '0') {
  96. uni.showToast({
  97. title: '维护信息成功',
  98. icon: 'none'
  99. })
  100. uni.navigateBack()
  101. } else {
  102. uni.showToast({
  103. title: res.errmsg,
  104. icon: 'none'
  105. })
  106. }
  107. }).catch(err => {
  108. console.log('err', err);
  109. })
  110. },
  111. // 查询其他信息
  112. async searchOther() {
  113. const that = this;
  114. let res;
  115. res = await that.$api('dictdata', 'GET', {
  116. type: 'gender'
  117. })
  118. if (res.errcode == '0') {
  119. that.$set(that, `genderList`, res.data)
  120. }
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss">
  126. .content {
  127. background-color: var(--rgb000);
  128. padding: 0 2vw;
  129. overflow-y: auto;
  130. .btn {
  131. padding: 2vw 0 0 0;
  132. text-align: center;
  133. button {
  134. width: 80%;
  135. background-color: var(--rgbfa4);
  136. color: var(--rgbfff);
  137. padding: 1vw 0;
  138. }
  139. }
  140. }
  141. </style>