user-info.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="user-info">
  3. <view class="info-item">
  4. <text class="tit">头像</text>
  5. <view class="avater" @click="gainimg">
  6. <image :src="userinfos.image" mode="aspectFill"></image>
  7. </view>
  8. </view>
  9. <view class="info-item">
  10. <text class="tit">用户名</text>
  11. <input type="text" v-model="userinfos.username" :class="compileTF?'valinput valinput2':'valinput'" :disabled="!compileTF"
  12. maxlength='8' />
  13. </view>
  14. <view class="info-item">
  15. <text class="tit">用户身份</text>
  16. <text class="val">管理员</text>
  17. </view>
  18. <view class="info-item">
  19. <text class="tit">用户电话</text>
  20. <input type="text" v-model="userinfos.mobile" :class="compileTF?'valinput valinput2':'valinput'" :disabled="!compileTF"
  21. @blur="verifyphone" />
  22. <p class="hint" v-if="phonehint">手机号格式不正确</p>
  23. </view>
  24. <view class="info-item">
  25. <text class="tit">E-mail</text>
  26. <input type="text" v-model="userinfos.email" :class="compileTF?'valinput valinput2':'valinput'" :disabled="!compileTF"
  27. @blur="verifyemail" />
  28. <p class="hint" v-if="emailhint">邮箱格式不正确</p>
  29. </view>
  30. <view class="info-item">
  31. <text class="tit">我的地址</text>
  32. <input type="text" v-model="location" :class="compileTF?'valinput valinput2':'valinput'"
  33. :disabled="!compileTF" />
  34. </view>
  35. <view class="compile">
  36. <p @click="compile" v-if="!compileTF">编辑</p>
  37. <p @click="submit" v-else>提交</p>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. userinfos: {},
  46. location:'',
  47. imageList: '',
  48. compileTF: false,
  49. phonehint: false,
  50. emailhint: false
  51. }
  52. },
  53. methods: {
  54. gainimg() { //添加图片
  55. if (this.compileTF) {
  56. uni.chooseImage({
  57. count: 1, //默认9
  58. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  59. sourceType: ['album', 'camera'], //从相册选择
  60. success: (res) => {
  61. uni.uploadFile({
  62. url: 'http://182.92.193.64:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
  63. filePath: res.tempFilePaths[0],
  64. name: 'img_file',
  65. formData: {
  66. 'user': 'test'
  67. },
  68. success: (uploadFileRes) => {
  69. this.userinfos.image = JSON.parse(uploadFileRes.data).data.src
  70. this.$forceUpdate() //强制刷新视图
  71. }
  72. });
  73. }
  74. })
  75. }
  76. }, //
  77. async postusers() {
  78. const res = await this.$myRequest({
  79. url: '/api/api_gateway?method=home.homes.personal_center',
  80. data: {
  81. ret: 'change',
  82. username: this.userinfos.username,
  83. mobile: this.userinfos.mobile,
  84. province: this.userinfos.province,
  85. city: this.userinfos.city,
  86. district: this.userinfos.district,
  87. image: this.userinfos.image,
  88. email: this.userinfos.email
  89. }
  90. })
  91. },
  92. compile() { //编辑按钮
  93. this.compileTF = true
  94. },
  95. submit() {//提交按钮
  96. if(this.phonehint == false &&this.emailhint == false){
  97. this.userinfos.province = this.location.slice(0,this.location.indexOf("省")+1)
  98. this.userinfos.city = this.location.slice(this.location.indexOf("省")+1,this.location.indexOf("市")+1)
  99. this.userinfos.district = this.location.slice(this.location.indexOf("市")+1)
  100. this.postusers()
  101. this.compileTF = false
  102. uni.redirectTo({
  103. url:"../index/index"
  104. })
  105. }
  106. },
  107. verifyphone() { //手机号验证
  108. var reg = /^1[356789]\d{9}$/;
  109. if (!reg.test(this.userinfos.mobile)) {
  110. this.phonehint = true
  111. } else {
  112. this.phonehint = false
  113. }
  114. },
  115. verifyemail() { //邮箱验证
  116. var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  117. if (!reg.test(this.userinfos.email)) {
  118. this.emailhint = true
  119. } else {
  120. this.emailhint = false
  121. }
  122. }
  123. },
  124. onLoad(option) {
  125. this.userinfos = JSON.parse(option.data)
  126. this.location = this.userinfos.province+this.userinfos.city+this.userinfos.district
  127. console.log(this.userinfos)
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. page {
  133. background: $uni-bg-color-grey;
  134. .user-info {
  135. background: #fff;
  136. padding: 0 40rpx;
  137. .info-item {
  138. display: flex;
  139. justify-content: space-between;
  140. line-height: 100rpx;
  141. position: relative;
  142. .avater {
  143. width: 100rpx;
  144. height: 100rpx;
  145. border-radius: 50%;
  146. overflow: hidden;
  147. image {
  148. width: 100%;
  149. height: 100%;
  150. }
  151. }
  152. .tit {
  153. font-size: 14px
  154. }
  155. .val {
  156. font-size: 12px;
  157. color: #666;
  158. }
  159. .valinput {
  160. margin-top: 24rpx;
  161. text-align: right;
  162. font-size: 12px;
  163. color: #666;
  164. padding: 10rpx 0;
  165. width: 360rpx;
  166. }
  167. .valinput2 {
  168. background-color: #e1e5ee;
  169. }
  170. .hint {
  171. position: absolute;
  172. top: 40rpx;
  173. right: 220rpx;
  174. font-size: 24rpx;
  175. color: #ff0000;
  176. }
  177. }
  178. .compile {
  179. width: 100%;
  180. margin-top: 40rpx;
  181. height: 60rpx;
  182. line-height: 60rpx;
  183. text-align: center;
  184. background-color: #58C77A;
  185. border-radius: 30rpx;
  186. color: #FFFFFF;
  187. }
  188. }
  189. }
  190. </style>