index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view class="container" :style="{paddingTop: navbarHeight + 'rpx'}">
  3. <!-- 顶部渐变背景 -->
  4. <view class="top-gradient"></view>
  5. <!-- 自定义导航栏 -->
  6. <view class="custom-navbar" :style="{paddingTop: statusBarHeight + 'px'}">
  7. <view class="navbar-content">
  8. <view class="navbar-back" @click="handleBack">
  9. <view class="iconfont icon-right back-icon"></view>
  10. </view>
  11. <text class="navbar-title">账号信息</text>
  12. <view class="navbar-placeholder"></view>
  13. </view>
  14. </view>
  15. <!-- 第一个卡片:基本信息 -->
  16. <view class="info-card">
  17. <view class="info-item" @click="handleAvatar">
  18. <view class="item-label">头像</view>
  19. <view class="item-value">
  20. <image v-if="user.headImg" :src="user.headImg" class="avatar-img" mode="aspectFill"></image>
  21. <view v-else class="avatar-placeholder">
  22. <view class="iconfont icon-people"></view>
  23. </view>
  24. <view class="iconfont icon-right arrow-icon"></view>
  25. </view>
  26. </view>
  27. <view class="info-divider"></view>
  28. <view class="info-item" @click="handleEdit('name')">
  29. <view class="item-label">姓名</view>
  30. <view class="item-value">
  31. <text class="value-text">{{ user.nickName || user.userName || '未设置' }}</text>
  32. <view class="iconfont icon-right arrow-icon"></view>
  33. </view>
  34. </view>
  35. <view class="info-divider"></view>
  36. <view class="info-item" @click="handleEdit('intro')">
  37. <view class="item-label">简介</view>
  38. <view class="item-value">
  39. <text class="value-text placeholder">{{ user.intro || '添加一条简介' }}</text>
  40. <view class="iconfont icon-right arrow-icon"></view>
  41. </view>
  42. </view>
  43. <view class="info-divider"></view>
  44. <view class="info-item" @click="handleEdit('phone')">
  45. <view class="item-label">手机号码</view>
  46. <view class="item-value">
  47. <text class="value-text">{{ user.phonenumber || '未设置' }}</text>
  48. <view class="iconfont icon-right arrow-icon"></view>
  49. </view>
  50. </view>
  51. <view class="info-divider"></view>
  52. <view class="info-item">
  53. <view class="item-label">接单状态</view>
  54. <view class="item-value">
  55. <text class="status-text" :class="{ active: orderStatus }">{{ orderStatus ? '接单中' : '暂停接单' }}</text>
  56. <switch :checked="orderStatus" @change="handleOrderStatusChange" color="#007AFF" />
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 第二个卡片:专业和财务信息 -->
  61. <view class="info-card">
  62. <view class="info-item" @click="handleEdit('practiceTime')">
  63. <view class="item-label">从业时间</view>
  64. <view class="item-value">
  65. <text class="value-text">{{ user.practiceTime || '未设置' }}</text>
  66. <view class="iconfont icon-right arrow-icon"></view>
  67. </view>
  68. </view>
  69. <view class="info-divider"></view>
  70. <view class="info-item" @click="handleEdit('professionalField')">
  71. <view class="item-label">专业领域</view>
  72. <view class="item-value">
  73. <text class="value-text">{{ user.professionalField || '未设置' }}</text>
  74. <view class="iconfont icon-right arrow-icon"></view>
  75. </view>
  76. </view>
  77. <view class="info-divider"></view>
  78. <view class="info-item" @click="handleEdit('legalScenarios')">
  79. <view class="item-label">法律场景</view>
  80. <view class="item-value">
  81. <text class="value-text">{{ user.legalScenarios || '未设置' }}</text>
  82. <view class="iconfont icon-right arrow-icon"></view>
  83. </view>
  84. </view>
  85. <view class="info-divider"></view>
  86. <view class="info-item" @click="handleEdit('lawFirm')">
  87. <view class="item-label">所属律所</view>
  88. <view class="item-value">
  89. <text class="value-text">{{ user.lawFirm || '未设置' }}</text>
  90. <view class="iconfont icon-right arrow-icon"></view>
  91. </view>
  92. </view>
  93. <view class="info-divider"></view>
  94. <view class="info-item" @click="handleEdit('receivingAccount')">
  95. <view class="item-label">收款账户</view>
  96. <view class="item-value">
  97. <text class="value-text">{{ user.receivingAccount || '未设置' }}</text>
  98. <view class="iconfont icon-right arrow-icon"></view>
  99. </view>
  100. </view>
  101. <view class="info-divider"></view>
  102. <view class="info-item" @click="handleEdit('address')">
  103. <view class="item-label">联系地址</view>
  104. <view class="item-value">
  105. <text class="value-text">{{ user.address || '未设置' }}</text>
  106. <view class="iconfont icon-right arrow-icon"></view>
  107. </view>
  108. </view>
  109. </view>
  110. <!-- 第三个卡片:账号管理 -->
  111. <view class="info-card">
  112. <view class="info-item" @click="handleDeregister">
  113. <view class="item-label">注销账号</view>
  114. <view class="item-value">
  115. <view class="iconfont icon-right arrow-icon"></view>
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. </template>
  121. <script>
  122. import { getLawyerInfo, editLawyerUser } from "@/api/api"
  123. import upload from '@/utils/upload'
  124. import config from '@/config'
  125. export default {
  126. data() {
  127. return {
  128. user: {},
  129. orderStatus: true,
  130. statusBarHeight: 0
  131. }
  132. },
  133. onLoad() {
  134. // 获取状态栏高度
  135. const systemInfo = uni.getSystemInfoSync()
  136. this.statusBarHeight = systemInfo.statusBarHeight || 0
  137. },
  138. onShow() {
  139. // 从其他页面返回时刷新数据
  140. this.getLawyerInfoData()
  141. },
  142. computed: {
  143. navbarHeight() {
  144. // 状态栏高度(px转rpx) + 导航栏高度(88rpx) + 间距(20rpx)
  145. return (this.statusBarHeight * 2) + 88 + 20
  146. }
  147. },
  148. methods: {
  149. getLawyerInfoData() {
  150. getLawyerInfo({ lawyerId: 1 }).then(response => {
  151. // 处理返回的律师信息
  152. if (response.data) {
  153. // 合并律师信息到 user 对象
  154. this.user = { ...this.user, ...response.data }
  155. // 如果有接单状态字段,使用它
  156. if (response.data.orderStatus !== undefined) {
  157. this.orderStatus = response.data.orderStatus
  158. }
  159. }
  160. }).catch(error => {
  161. console.error('获取律师信息失败:', error)
  162. })
  163. },
  164. handleAvatar() {
  165. const that = this
  166. uni.chooseImage({
  167. count: 1,
  168. sizeType: ['compressed'],
  169. sourceType: ['album'],
  170. success: function(res) {
  171. const tempFilePath = res.tempFilePaths[0]
  172. // 显示上传中提示
  173. uni.showLoading({
  174. title: '上传中...',
  175. mask: true
  176. })
  177. // 上传图片,使用 baseUrl1
  178. upload({
  179. url: '/file/upload',
  180. filePath: tempFilePath,
  181. name: 'file',
  182. baseUrl: config.baseUrl1
  183. }).then(response => {
  184. console.log('上传响应:', response)
  185. // 上传成功,更新用户头像
  186. // 根据实际返回的数据结构处理
  187. let headImg = null
  188. if (response.data) {
  189. // 如果 response.data 是字符串,直接使用
  190. if (typeof response.data === 'string') {
  191. headImg = response.data
  192. }
  193. // 如果 response.data 是对象,尝试获取 url 或 imgUrl
  194. else if (response.data.url) {
  195. headImg = response.data.url
  196. } else if (response.data.imgUrl) {
  197. headImg = response.data.imgUrl
  198. }
  199. } else if (response.url) {
  200. headImg = response.url
  201. } else if (response.imgUrl) {
  202. headImg = response.imgUrl
  203. }
  204. if (!headImg) {
  205. throw new Error('上传失败,未返回图片地址')
  206. }
  207. // 如果返回的是相对路径,需要拼接 baseUrl1
  208. if (headImg.startsWith('/')) {
  209. headImg = config.baseUrl1 + headImg
  210. }
  211. // 使用 Vue.set 确保响应式更新
  212. that.$set(that.user, 'headImg', headImg)
  213. // 调用API更新用户信息到服务器
  214. let params={
  215. id:that.user.id,
  216. headImg: headImg
  217. }
  218. editLawyerUser(params).then(response => {
  219. console.log('更新响应:', response)
  220. }).catch(error => {
  221. console.error('更新失败:', error)
  222. })
  223. }).then(() => {
  224. // 更新成功提示
  225. uni.showToast({
  226. title: '头像更新成功'
  227. })
  228. }).catch(error => {
  229. uni.hideLoading()
  230. console.error('上传头像失败:', error)
  231. uni.showToast({
  232. title: error.message || '上传失败,请重试',
  233. icon: 'none'
  234. })
  235. })
  236. },
  237. fail: function(error) {
  238. console.error('选择图片失败:', error)
  239. uni.showToast({
  240. title: '选择图片失败',
  241. icon: 'none'
  242. })
  243. }
  244. })
  245. },
  246. handleEdit(field) {
  247. // 根据字段类型跳转到不同的编辑页面
  248. if (field === 'name') {
  249. // 跳转到姓名编辑页面
  250. const currentName = this.user.nickName || this.user.userName || ''
  251. const userId = this.user.id || 1
  252. this.$tab.navigateTo(`/pages/mine/info/name?name=${encodeURIComponent(currentName)}&userId=${userId}`)
  253. } else {
  254. // 其他字段跳转到通用编辑页面
  255. this.$tab.navigateTo('/pages/mine/info/edit')
  256. }
  257. },
  258. handleOrderStatusChange(e) {
  259. this.orderStatus = e.detail.value
  260. // 这里可以调用API更新接单状态
  261. // updateOrderStatus(this.orderStatus)
  262. },
  263. handleDeregister() {
  264. this.$modal.confirm('确定要注销账号吗?注销后将无法恢复。').then(() => {
  265. // 调用注销账号API
  266. this.$modal.showToast('注销账号功能开发中')
  267. })
  268. },
  269. handleBack() {
  270. uni.navigateBack()
  271. }
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. page {
  277. background-color: #f5f5f5;
  278. }
  279. .container {
  280. min-height: 100vh;
  281. padding: 0 30rpx 20rpx 30rpx;
  282. background-color: #f5f5f5;
  283. position: relative;
  284. // 顶部渐变背景
  285. .top-gradient {
  286. position: fixed;
  287. top: 0;
  288. left: 0;
  289. right: 0;
  290. height: 800rpx;
  291. background: linear-gradient(180deg, rgba(59, 130, 246, 0.1) 0%, rgba(147, 197, 253, 0.05) 50%, transparent 100%);
  292. z-index: 0;
  293. pointer-events: none;
  294. }
  295. // 自定义导航栏
  296. .custom-navbar {
  297. position: fixed;
  298. top: 0;
  299. left: 0;
  300. right: 0;
  301. z-index: 999;
  302. background-color: transparent;
  303. pointer-events: none;
  304. .navbar-content {
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. height: 88rpx;
  309. pointer-events: auto;
  310. position: relative;
  311. .navbar-back {
  312. position: absolute;
  313. left: 30rpx;
  314. width: 60rpx;
  315. height: 60rpx;
  316. display: flex;
  317. align-items: center;
  318. justify-content: center;
  319. .back-icon {
  320. font-size: 36rpx;
  321. color: #000000;
  322. transform: rotate(180deg);
  323. }
  324. }
  325. .navbar-title {
  326. font-size: 36rpx;
  327. font-weight: 500;
  328. color: #000000;
  329. }
  330. .navbar-placeholder {
  331. position: absolute;
  332. right: 30rpx;
  333. width: 60rpx;
  334. height: 60rpx;
  335. }
  336. }
  337. }
  338. }
  339. .info-card {
  340. background-color: #ffffff;
  341. border-radius: 16rpx;
  342. margin-bottom: 20rpx;
  343. overflow: hidden;
  344. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  345. .info-item {
  346. display: flex;
  347. align-items: center;
  348. justify-content: space-between;
  349. padding: 32rpx 30rpx;
  350. min-height: 100rpx;
  351. .item-label {
  352. font-size: 32rpx;
  353. color: #000000;
  354. font-weight: 400;
  355. }
  356. .item-value {
  357. display: flex;
  358. align-items: center;
  359. flex: 1;
  360. justify-content: flex-end;
  361. .avatar-img {
  362. width: 80rpx;
  363. height: 80rpx;
  364. border-radius: 50%;
  365. margin-right: 20rpx;
  366. }
  367. .avatar-placeholder {
  368. width: 80rpx;
  369. height: 80rpx;
  370. border-radius: 50%;
  371. background-color: #e0e0e0;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. margin-right: 20rpx;
  376. .iconfont {
  377. font-size: 40rpx;
  378. color: #999999;
  379. }
  380. }
  381. .value-text {
  382. font-size: 32rpx;
  383. color: #000000;
  384. margin-right: 20rpx;
  385. &.placeholder {
  386. color: #999999;
  387. }
  388. }
  389. .status-text {
  390. font-size: 32rpx;
  391. color: #999999;
  392. margin-right: 20rpx;
  393. &.active {
  394. color: #007AFF;
  395. }
  396. }
  397. .arrow-icon {
  398. font-size: 28rpx;
  399. color: #cccccc;
  400. }
  401. }
  402. }
  403. .info-divider {
  404. height: 1rpx;
  405. background-color: #f0f0f0;
  406. margin: 0 30rpx;
  407. }
  408. }
  409. </style>