personalData.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view>
  3. <navbar :config="config" backColor="#999999"></navbar>
  4. <view class="box">
  5. <view class="item">
  6. <view class="item_l">头像</view>
  7. <view class="item_r" @click="getHead">
  8. <view class="item_r_text">
  9. <image v-if="user.headPhoto" :src="$getImgPath(user.headPhoto)" mode=""></image>
  10. <image v-else src="/static/default-avatar.png" mode=""></image>
  11. </view>
  12. <text class="iconfont_yige">&#xe65f;</text>
  13. </view>
  14. </view>
  15. <view class="item" @click="openModal('nickname','昵称')">
  16. <view class="item_l">昵称</view>
  17. <view class="item_r">
  18. <view class="item_r_text">{{user.nickname}}</view>
  19. <text class="iconfont_yige">&#xe65f;</text>
  20. </view>
  21. </view>
  22. <view class="item">
  23. <view class="item_l">手机号</view>
  24. <view class="item_r">
  25. <view class="item_r_text">{{$onDesensitization('tel', user.mobile || '')}}</view>
  26. </view>
  27. </view>
  28. <view class="item" @click="openModal('gender','性别')">
  29. <view class="item_l">性别</view>
  30. <view class="item_r">
  31. <view class="item_r_text">{{user.gender==0?'未知':user.gender==1?'男':user.gender==2?'女':''}}</view>
  32. <text class="iconfont_yige">&#xe65f;</text>
  33. </view>
  34. </view>
  35. <view class="item" @click="openModal('email','邮箱')">
  36. <view class="item_l">邮箱</view>
  37. <view class="item_r">
  38. <view class="item_r_text">{{user.email}}</view>
  39. <text class="iconfont_yige">&#xe65f;</text>
  40. </view>
  41. </view>
  42. <view class="item" @click="pickerShow=true">
  43. <view class="item_l">生日</view>
  44. <view class="item_r">
  45. <view class="item_r_text">{{user.birthday}}</view>
  46. <text class="iconfont_yige">&#xe65f;</text>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="btnBox">
  51. <u-button type="primary" hover-class="hoverClass" @click="submit()">提交修改</u-button>
  52. </view>
  53. <u-modal v-model="show" :title="title" show-cancel-button @confirm="modalConfirm" @cancel="modalCancel"
  54. confirm-color="#3EBCD0">
  55. <view class="slot-content">
  56. <u-input v-if="title!='性别'" v-model="value" input-align="center" type="text" focus
  57. :placeholder="'请输入'+title" />
  58. <u-radio-group v-if="title=='性别'" v-model="value">
  59. <u-radio :name="1">男</u-radio>
  60. <u-radio :name="2">女</u-radio>
  61. </u-radio-group>
  62. </view>
  63. </u-modal>
  64. <u-picker v-model="pickerShow" :default-time="user.birthday||''" mode="time" confirm-color="#3EBCD0"
  65. @confirm="pickerConfirm"></u-picker>
  66. </view>
  67. </template>
  68. <script>
  69. import {
  70. getUserInfo
  71. } from "@/api/government.js"
  72. import permision from "@/utils/permission.js"
  73. export default {
  74. data() {
  75. return {
  76. config: {
  77. back: true, //false是tolbar页面 是则不写
  78. title: '个人资料',
  79. color: '#000',
  80. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  81. // backgroundColor: [0, '#2cba28'],
  82. rightSlot: true,
  83. },
  84. user: {},
  85. value: "",
  86. show: false,
  87. title: "昵称",
  88. pickerShow: false,
  89. btnLoading: false
  90. }
  91. },
  92. onLoad() {
  93. this.getUserData()
  94. },
  95. methods: {
  96. openModal(key, title) {
  97. this.key = key;
  98. this.title = title;
  99. this.value = this.user[key];
  100. this.show = true;
  101. },
  102. modalCancel() {
  103. this.show = false;
  104. },
  105. modalConfirm() {
  106. this.user[this.key] = this.value
  107. },
  108. pickerConfirm(e) {
  109. this.user.birthday = e.year + '-' + e.month + '-' + e.day;
  110. this.pickerShow = false;
  111. },
  112. async getHead() {
  113. let that = this;
  114. // #ifdef APP-PLUS
  115. let flag = await permision.showAuthTipModal("android.permission.READ_EXTERNAL_STORAGE")
  116. if (!flag) return
  117. // #endif
  118. uni.chooseImage({
  119. count: 1,
  120. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  121. sourceType: ['album'], //从相册选择
  122. crop: {
  123. quality: 100, // 图片裁剪质量
  124. width: 100, // 裁剪的宽度
  125. height: 100, //裁剪的高度
  126. resize: false //是否将width和height作为裁剪保存图片真实的像素值。默认值为true。注:设置为false时在裁剪编辑界面显示图片的像素值,设置为true时不显示
  127. },
  128. success: (res) => {
  129. uni.showLoading({
  130. title: '上传中',
  131. mask: true
  132. });
  133. let tempFilePaths = res.tempFilePaths[0]
  134. uni.uploadFile({
  135. url: this.$mConfig.baseUrl + '/common/upload',
  136. filePath: tempFilePaths,
  137. name: 'file',
  138. success: (uploadFileRes) => {
  139. let data = JSON.parse(uploadFileRes.data)
  140. this.user.headPhoto = data.data.url
  141. uni.showToast({
  142. title: '上传成功',
  143. icon: 'success',
  144. duration: 1000
  145. })
  146. },
  147. fail(fail){
  148. if ([0, 11, 12].includes(fail.code)) return;
  149. permision.showManualAuth('android.permission.READ_EXTERNAL_STORAGE');
  150. },
  151. complete: () => {
  152. uni.hideLoading();
  153. }
  154. })
  155. },
  156. complete: () => {
  157. uni.hideLoading();
  158. }
  159. })
  160. },
  161. submit() {
  162. if (this.btnLoading) return
  163. this.btnLoading = true;
  164. if (!this.user.nickname) {
  165. uni.showToast({
  166. icon: "none",
  167. title: '请输入昵称!',
  168. duration: 2000,
  169. mask: true
  170. });
  171. this.btnLoading = false;
  172. return
  173. }
  174. uni.showLoading({
  175. title: '提交中',
  176. mask: true
  177. });
  178. this.$yghttp.post('/user/personalData/update', this.user).then(res => {
  179. uni.hideLoading();
  180. this.btnLoading = false;
  181. uni.showToast({
  182. title: '修改成功!',
  183. icon: 'success',
  184. duration: 1000
  185. })
  186. }).catch(() => {
  187. this.btnLoading = false;
  188. uni.hideLoading();
  189. })
  190. },
  191. getUserData() {
  192. getUserInfo().then(res => {
  193. this.user = res.data
  194. })
  195. }
  196. }
  197. }
  198. </script>
  199. <style>
  200. page {
  201. background-color: #F8F8F8;
  202. }
  203. </style>
  204. <style lang="scss">
  205. .box {
  206. padding: 0rpx 30rpx;
  207. background: #fff;
  208. border-radius: 20rpx;
  209. margin: 30rpx;
  210. .item {
  211. display: flex;
  212. justify-content: space-between;
  213. align-items: center;
  214. height: 120rpx;
  215. padding: 0 30rpx;
  216. border-bottom: 1rpx solid rgba(239, 239, 239, .6);
  217. .item_l {
  218. font-size: 30rpx;
  219. font-weight: 700;
  220. }
  221. .item_r {
  222. display: flex;
  223. align-items: center;
  224. .item_r_text {
  225. margin-right: 20rpx;
  226. font-weight: bold;
  227. image {
  228. width: 80rpx;
  229. height: 80rpx;
  230. border-radius: 50%;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. .btnBox {
  237. width: 100%;
  238. // display: flex;
  239. // justify-content: center;
  240. margin-top: 150rpx;
  241. }
  242. .u-btn {
  243. width: 534rpx;
  244. border-radius: 10rpx;
  245. background: rgb(64, 149, 229);
  246. font-size: 30rpx;
  247. font-weight: 700;
  248. margin: auto;
  249. font-family: Microsoft YaHei, Microsoft YaHei-Bold;
  250. background: linear-gradient(6deg, #56d9ee 0%, #3ebcd0 100%) #3c66d9;
  251. }
  252. .hoverClass {
  253. background: linear-gradient(6deg, #56d9ee 0%, #3ebcd0 100%) #3c66d9;
  254. }
  255. .slot-content {
  256. padding: 40rpx;
  257. text-align: center;
  258. }
  259. .iconfont_yige {
  260. color: #333333;
  261. opacity: 0.5;
  262. font-weight: 700;
  263. }
  264. /deep/ .u-drawer-content-visible {
  265. border-radius: 30rpx 30rpx 0 0;
  266. overflow: hidden;
  267. }
  268. </style>