user.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar />
  6. <view v-if="userInfo" class="container">
  7. <view class="main linear-gradient">
  8. <view class="content" @click="handleToUpdate">
  9. <view class="avatar-box">
  10. <wk-avatar
  11. :name="userInfo.realname"
  12. :avatar="userInfo.img"
  13. :size="18"
  14. :preview="false"
  15. class="avatar" />
  16. </view>
  17. <view class="info">
  18. <view class="realname">
  19. {{ userInfo.realname }}
  20. </view>
  21. <view class="dept">
  22. {{ userDesc }}
  23. </view>
  24. </view>
  25. <image v-if="!id" :src="$static('images/icon/edit_white.png')" class="edit-icon" />
  26. </view>
  27. <view class="company">
  28. <text class="wk wk-customer" />
  29. {{ companyInfo.companyName || appName }}
  30. </view>
  31. </view>
  32. <view class="base-info">
  33. <view class="cell">
  34. <view class="cell-title">
  35. 姓名
  36. </view>
  37. <view class="cell-body">
  38. {{ userInfo.realname || '' }}
  39. </view>
  40. </view>
  41. <view class="cell">
  42. <view class="cell-title">
  43. 性别
  44. </view>
  45. <view class="cell-body">
  46. {{ getSex(userInfo.sex) }}
  47. </view>
  48. </view>
  49. <view class="cell">
  50. <view class="cell-title">
  51. 手机
  52. </view>
  53. <view class="cell-body">
  54. {{ userInfo.mobile || '' }}
  55. </view>
  56. <image
  57. :src="$static('images/icon/call_voice.png')"
  58. class="call-icon"
  59. @click="ringUp(userInfo.mobile)" />
  60. </view>
  61. <view class="cell">
  62. <view class="cell-title">
  63. 邮箱
  64. </view>
  65. <view class="cell-body">
  66. {{ userInfo.email || '' }}
  67. </view>
  68. </view>
  69. <view class="cell">
  70. <view class="cell-title">
  71. 部门
  72. </view>
  73. <view class="cell-body">
  74. {{ userInfo.deptName || '' }}
  75. </view>
  76. </view>
  77. <view class="cell">
  78. <view class="cell-title">
  79. 岗位
  80. </view>
  81. <view class="cell-body">
  82. {{ userInfo.post || '' }}
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import {
  92. AdminQueryLoginUser,
  93. AdminQueryUserInfo,
  94. QueryCompanyConfig
  95. } from 'API/admin.js'
  96. import { appName } from '@/config.js'
  97. import { mapMutations } from 'vuex'
  98. export default {
  99. name: 'UserInfo',
  100. data() {
  101. return {
  102. id: null,
  103. userInfo: null,
  104. companyInfo: {},
  105. refreshPage: false
  106. }
  107. },
  108. computed: {
  109. userDesc() {
  110. if (!this.userInfo) return ''
  111. let str = ''
  112. str = `${this.userInfo.deptName || ''}-${this.userInfo.post || ''}`
  113. if (
  114. str.startsWith('-') ||
  115. str.endsWith('-')
  116. ) {
  117. return str.replace(/-/g, '')
  118. }
  119. return str
  120. },
  121. appName() {
  122. return appName
  123. }
  124. },
  125. onLoad(opt) {
  126. this.id = opt.id || null
  127. this.getUserInfo()
  128. this.getCompanyConfig()
  129. },
  130. onShow() {
  131. if (this.refreshPage) {
  132. this.$nextTick(() => {
  133. this.refreshPage = false
  134. this.getUserInfo()
  135. })
  136. }
  137. },
  138. methods: {
  139. ...mapMutations({
  140. setUserInfo: 'user/SET_USER_INFO'
  141. }),
  142. getUserInfo() {
  143. if (this.id) {
  144. AdminQueryUserInfo({
  145. userId: this.id
  146. }).then(res => {
  147. this.userInfo = res
  148. }).catch(() => {})
  149. } else {
  150. AdminQueryLoginUser().then(res => {
  151. this.userInfo = res
  152. this.setUserInfo(res)
  153. }).catch(() => {})
  154. }
  155. },
  156. getCompanyConfig() {
  157. QueryCompanyConfig().then(res => {
  158. this.companyInfo = res || {}
  159. }).catch()
  160. },
  161. getSex(sex) {
  162. if (isNaN(Number(sex))) return sex
  163. if (Number(sex) === 1) return '男'
  164. else if (Number(sex) === 2) return '女'
  165. return ''
  166. },
  167. ringUp(tel) {
  168. if (!tel) {
  169. this.$toast('暂无电话')
  170. return
  171. }
  172. uni.makePhoneCall({
  173. phoneNumber: tel
  174. })
  175. },
  176. handleToUpdate() {
  177. if (this.id) return
  178. this.$Router.navigateTo('/pages_personal/updateUser')
  179. }
  180. }
  181. }
  182. </script>
  183. <style scoped lang="scss">
  184. .main-container {
  185. .container {
  186. flex: 1;
  187. width: 100%;
  188. display: flex;
  189. flex-direction: column;
  190. .main {
  191. width: 100%;
  192. padding: 0 38rpx;
  193. .content {
  194. padding-top: 50rpx;
  195. @include left;
  196. .avatar-box {
  197. width: 136rpx;
  198. height: 136rpx;
  199. border: 5rpx solid white;
  200. border-radius: 50%;
  201. margin-right: 32rpx;
  202. .avatar {
  203. width: 100%;
  204. height: 100%;
  205. }
  206. }
  207. .info {
  208. flex: 1;
  209. color: white;
  210. .realname {
  211. font-size: 46rpx;
  212. margin-bottom: 15rpx;
  213. }
  214. .dept {
  215. font-size: $wk-font-base;
  216. }
  217. }
  218. .edit-icon {
  219. width: 45rpx;
  220. height: 45rpx;
  221. }
  222. }
  223. .company {
  224. width: 100%;
  225. font-size: $wk-font-base;
  226. color: white;
  227. padding: 45rpx 0 24rpx;
  228. @include left;
  229. .wk-customer {
  230. margin-right: 24rpx;
  231. }
  232. }
  233. }
  234. .base-info {
  235. flex: 1;
  236. overflow: auto;
  237. background-color: white;
  238. padding: 0 32rpx;
  239. .cell {
  240. position: relative;
  241. padding: 15rpx 0;
  242. border-bottom: 1rpx solid $border-color;
  243. .cell-title {
  244. color: $light;
  245. font-size: $wk-font-sm;
  246. }
  247. .cell-body {
  248. min-height: 45rpx;
  249. color: $dark;
  250. font-size: $wk-font-medium;
  251. margin-top: 10rpx;
  252. }
  253. .call-icon {
  254. position: absolute;
  255. top: 50%;
  256. right: 20rpx;
  257. transform: translateY(-50%);
  258. width: 56rpx;
  259. height: 56rpx;
  260. }
  261. }
  262. }
  263. }
  264. }
  265. </style>