user-info.vue 6.8 KB

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