user-info.vue 6.7 KB

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