info.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="main">
  3. <view class="head_bg">
  4. <u-avatar size="150" @click="chooseAvatar" :src="form.avatar" mode="circle">
  5. </u-avatar>
  6. </view>
  7. <view style="border-radius: 16rpx;box-shadow: 6rpx 6rpx 10rpx rgba(122, 122, 122, 0.2);"
  8. class="u-margin-left-20 u-margin-right-20 u-margin-top-20 bg-white padding">
  9. <u-form :model="form" ref="uForm">
  10. <u-form-item label="姓名" label-width="125" :border-bottom="true">
  11. <u-input border placeholder="请输入您的真实姓名" v-model="form.name" />
  12. </u-form-item>
  13. <u-form-item label="年龄" label-width="125" :border-bottom="true">
  14. <u-input border type="number" maxlength="18" placeholder="请输入您的年龄" v-model="form.age" />
  15. </u-form-item>
  16. <u-form-item label="手机号" label-width="125" :border-bottom="true">
  17. <u-input border type="number" maxlength="11" placeholder="请输入您的手机号码" v-model="form.phone" />
  18. </u-form-item>
  19. <u-form-item label="所属地区" label-width="125" :border-bottom="true">
  20. <u-input border placeholder="请选择所属地区" border type="select" @click="show = true"
  21. v-model="form.cityName" />
  22. </u-form-item>
  23. </u-form>
  24. <u-picker mode="region" @confirm="selectReg" v-model="show"
  25. :area-code='[form.province, form.city, form.area]'>
  26. </u-picker>
  27. </view>
  28. <u-button shape="circle" hover-class="none" :custom-style="customStyle" @click="editInfo" throttle-time="1000">
  29. 提交</u-button>
  30. </view>
  31. </template>
  32. <script>
  33. import store from '@/store'
  34. export default {
  35. data() {
  36. return {
  37. form: {
  38. avatar: '',
  39. name: '',
  40. city: '1303',
  41. sex: 1,
  42. age: '',
  43. phone: '',
  44. area: '130304',
  45. province: '13',
  46. cityName: ''
  47. },
  48. show: false,
  49. customStyle: {
  50. marginTop: '30rpx',
  51. marginLeft: '20rpx',
  52. marginRight: '20rpx',
  53. // width:'182rpx',
  54. height: '74rpx',
  55. color: '#fff',
  56. background: '#FBC600',
  57. border: 'none'
  58. },
  59. }
  60. },
  61. onLoad() {
  62. if (this.vuex_user.name != null) {
  63. this.form = {
  64. ...store.state.vuex_user
  65. }
  66. if (this.form.province.length != 2) {
  67. this.form.province = (this.form.province / 10000) + ''
  68. }
  69. if (this.form.city.length != 4) {
  70. this.form.city = (this.form.city / 100) + ''
  71. }
  72. console.log(this.form)
  73. }
  74. },
  75. created() {
  76. // 监听从裁剪页发布的事件,获得裁剪结果
  77. uni.$on('uAvatarCropper', path => {
  78. // 可以在此上传到服务端
  79. uni.uploadFile({
  80. url: this.$upload + '/common/uploadImg',
  81. filePath: path,
  82. name: 'file',
  83. complete: (res) => {
  84. this.form.avatar = JSON.parse(res.data).data.file_url
  85. }
  86. });
  87. })
  88. },
  89. methods: {
  90. chooseAvatar() {
  91. // 此为uView的跳转方法,详见"文档-JS"部分,也可以用uni的uni.navigateTo
  92. this.$u.route({
  93. // 关于此路径,请见下方"注意事项"
  94. url: '/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
  95. // 内部已设置以下默认参数值,可不传这些参数
  96. params: {
  97. // 输出图片宽度,高等于宽,单位px
  98. destWidth: 300,
  99. // 裁剪框宽度,高等于宽,单位px
  100. rectWidth: 300,
  101. // 输出的图片类型,如果'png'类型发现裁剪的图片太大,改成"jpg"即可
  102. fileType: 'jpg',
  103. }
  104. })
  105. },
  106. selectReg(e) {
  107. this.form.province = e.province.value
  108. this.form.city = e.city.value
  109. this.form.area = e.area.value
  110. this.form.cityName = e.province.label + '-' + e.city.label + '-' + e.area.label
  111. },
  112. async editInfo() {
  113. let province = this.form.province + "0000"
  114. let city = this.form.city + "00"
  115. let res = await this.$u.post("manager/updateUser", {
  116. ...this.form,
  117. province,
  118. city
  119. })
  120. if (res.code == 200) {
  121. let obj = {
  122. ...this.form,
  123. }
  124. this.$u.vuex('vuex_user', obj)
  125. uni.showToast({
  126. title: "修改成功",
  127. icon: "none",
  128. duration: 1000
  129. })
  130. setTimeout(() => {
  131. uni.switchTab({
  132. url: "./mine"
  133. })
  134. }, 1000)
  135. }else{
  136. uni.showToast({
  137. title:res.message,
  138. icon:"none"
  139. })
  140. return false
  141. }
  142. }
  143. }
  144. }
  145. </script>
  146. <style>
  147. .head_bg {
  148. background-color: #FBC600;
  149. height: 350rpx;
  150. width: 100%;
  151. display: flex;
  152. justify-content: center;
  153. align-items: center;
  154. flex-direction: column;
  155. /* border-radius: 0 0 50rpx 50rpx; */
  156. }
  157. </style>