upBasic.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <mobile-frame>
  3. <view class="info">
  4. <view class="one">
  5. <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
  6. <uni-forms-item label="头像" name="icon">
  7. <upload :list="icon" name="icon" :count="1" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  8. </uni-forms-item>
  9. <uni-forms-item label="真实姓名" name="name">
  10. <uni-easyinput type="text" v-model="form.name" placeholder="请输入真实姓名" />
  11. </uni-forms-item>
  12. <uni-forms-item label="性别" name="gender">
  13. <picker @change="genderChange" name="gender" :value="form.gender" :range="genderList"
  14. range-key="label">
  15. <view class="uni-input">{{form.zhGender||'请选择性别'}}</view>
  16. </picker>
  17. </uni-forms-item>
  18. <uni-forms-item label="生日" name="date">
  19. <picker mode="date" :value="form.date" name="date" :start="startDate" :end="endDate"
  20. @change="bindDateChange">
  21. <view class="uni-input">{{form.date||'请选择日期'}}</view>
  22. </picker>
  23. </uni-forms-item>
  24. <uni-forms-item label="昵称" name="Nname">
  25. <uni-easyinput type="text" v-model="form.Nname" placeholder="请输入昵称" />
  26. </uni-forms-item>
  27. </uni-forms>
  28. <view class="btn">
  29. <button type="primary" @click="onSubmit('form')" size="small">提交</button>
  30. <view class="name">提示:为了您的账户安全,建议定期修改密码</view>
  31. </view>
  32. </view>
  33. </view>
  34. </mobile-frame>
  35. </template>
  36. <script>
  37. import upload from '@/components/upload/index.vue';
  38. export default {
  39. components: {
  40. upload
  41. },
  42. data() {
  43. return {
  44. frameStyle: {
  45. useBar: false
  46. },
  47. form: {},
  48. rules: {
  49. name: {
  50. rules: [{
  51. required: true,
  52. errorMessage: '请输入真实姓名',
  53. }]
  54. },
  55. num: {
  56. rules: [{
  57. required: true,
  58. errorMessage: '请输入邮箱验证码',
  59. }]
  60. },
  61. },
  62. genderList: [{
  63. label: '保密',
  64. value: '0'
  65. },
  66. {
  67. label: '男',
  68. value: '1'
  69. },
  70. {
  71. label: '女',
  72. value: '2'
  73. },
  74. ],
  75. icon: []
  76. };
  77. },
  78. onLoad: function(e) {
  79. const that = this;
  80. that.watchLogin();
  81. },
  82. onShow: function() {},
  83. methods: {
  84. watchLogin() {
  85. const that = this;
  86. uni.getStorage({
  87. key: 'token',
  88. success: (res) => {
  89. let user = that.$jwt(res.data);
  90. if (user) {
  91. console.log(user);
  92. // that.$set(that, `form`, {
  93. // id: user.id,
  94. // phone: user.phone
  95. // })
  96. }
  97. },
  98. fail: (err) => {}
  99. })
  100. },
  101. toPath(e) {
  102. if (e && e.route) uni.redirectTo({
  103. url: `/${e.route}`
  104. })
  105. },
  106. // 图片上传
  107. uplSuc(e) {
  108. const that = this;
  109. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  110. },
  111. // 图片删除
  112. uplDel(e) {
  113. const that = this;
  114. let data = that[e.name];
  115. let arr = data.filter((i, index) => index != e.data.index);
  116. that.$set(that, `${e.name}`, arr)
  117. },
  118. // 选择性别
  119. genderChange(e) {
  120. const that = this;
  121. let data = that.genderList[e.detail.value];
  122. if (data) {
  123. that.$set(that.form, `gender`, data.value);
  124. that.$set(that.form, `zhGender`, data.label);
  125. }
  126. },
  127. // 选择日期
  128. bindDateChange(e) {
  129. // this.date = e.detail.value
  130. const that = this;
  131. that.$set(that.form, `date`, e.detail.value);
  132. },
  133. // 提交保存
  134. onSubmit() {
  135. const that = this;
  136. let data = that.form;
  137. data.logo = that.logo;
  138. console.log(data);
  139. // this.$refs.form.validate().then(async (res) => {
  140. // let arr;
  141. // if (data._id) {
  142. // arr = await that.$api(``, 'POST', data)
  143. // } else {
  144. // arr = await that.$api(``, 'POST', data)
  145. // }
  146. // if (arr.errcode == '0') {
  147. // uni.showToast({
  148. // title: `维护信息成功`,
  149. // icon: 'success',
  150. // duration: 2000
  151. // });
  152. // that.back()
  153. // } else {
  154. // uni.showToast({
  155. // title: arr.errmsg,
  156. // icon: 'error',
  157. // duration: 2000
  158. // })
  159. // }
  160. // })
  161. },
  162. }
  163. }
  164. </script>
  165. <style lang="scss">
  166. .info {
  167. display: flex;
  168. flex-direction: column;
  169. width: 100vw;
  170. height: 100vh;
  171. .one {
  172. padding: 2vw;
  173. .uni-input {
  174. border: #f1f1ff 1px solid;
  175. padding: 2vw 2vw;
  176. border-radius: 1vw;
  177. }
  178. .btn {
  179. text-align: center;
  180. button {
  181. margin: 0 2vw 2vw 2vw;
  182. background-color: var(--ff0Color);
  183. color: var(--fffColor);
  184. }
  185. .name {
  186. color: var(--f85Color);
  187. font-size: var(--font14Size);
  188. }
  189. }
  190. }
  191. }
  192. .uni-forms-item {
  193. margin-bottom: 6vw !important;
  194. display: flex;
  195. flex-direction: row;
  196. }
  197. </style>