user-info.vue 5.6 KB

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