user-info.vue 5.8 KB

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