user-info.vue 6.8 KB

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