index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="部门详情"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 详情内容 -->
  10. <view>
  11. <wd-cell-group border>
  12. <wd-cell title="部门名称" :value="formData?.name || '-'" />
  13. <wd-cell title="上级部门" :value="getParentName() || '-'" />
  14. <wd-cell title="负责人" :value="getLeaderName() || '-'" />
  15. <wd-cell title="联系电话" :value="formData?.phone || '-'" />
  16. <wd-cell title="邮箱" :value="formData?.email || '-'" />
  17. <wd-cell title="显示顺序" :value="String(formData?.sort ?? '-')" />
  18. <wd-cell title="状态">
  19. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="formData?.status" />
  20. </wd-cell>
  21. <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
  22. </wd-cell-group>
  23. </view>
  24. <!-- 底部操作按钮 -->
  25. <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
  26. <view class="w-full flex gap-24rpx">
  27. <wd-button class="flex-1" type="warning" @click="handleEdit">
  28. 编辑
  29. </wd-button>
  30. <wd-button class="flex-1" type="error" :loading="deleting" @click="handleDelete">
  31. 删除
  32. </wd-button>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script lang="ts" setup>
  38. import type { Dept } from '@/api/system/dept'
  39. import type { User } from '@/api/system/user'
  40. import { onMounted, ref } from 'vue'
  41. import { useToast } from 'wot-design-uni'
  42. import { deleteDept, getDept, getSimpleDeptList } from '@/api/system/dept'
  43. import { getSimpleUserList } from '@/api/system/user'
  44. import { navigateBackPlus } from '@/utils'
  45. import { DICT_TYPE } from '@/utils/constants'
  46. import { formatDateTime } from '@/utils/date'
  47. const props = defineProps<{
  48. id: number | any
  49. }>()
  50. definePage({
  51. style: {
  52. navigationBarTitleText: '',
  53. navigationStyle: 'custom',
  54. },
  55. })
  56. const toast = useToast()
  57. const formData = ref<Dept>() // 详情数据
  58. const deleting = ref(false) // 删除中
  59. const deptList = ref<Dept[]>([]) // 部门列表
  60. const userList = ref<User[]>([]) // 用户列表
  61. /** 返回上一页 */
  62. function handleBack() {
  63. navigateBackPlus()
  64. }
  65. /** 获取上级部门名称 */
  66. function getParentName(): string {
  67. if (!formData.value?.parentId || formData.value.parentId === 0) {
  68. return '顶级部门'
  69. }
  70. const parent = deptList.value.find(d => d.id === formData.value?.parentId)
  71. return parent?.name || '未知'
  72. }
  73. /** 获取负责人名称 */
  74. function getLeaderName(): string {
  75. if (!formData.value?.leaderUserId) {
  76. return '未设置'
  77. }
  78. const user = userList.value.find(u => u.id === formData.value?.leaderUserId)
  79. return user?.nickname || '未知'
  80. }
  81. /** 加载部门详情 */
  82. async function getDetail() {
  83. if (!props.id) {
  84. return
  85. }
  86. toast.loading('加载中...')
  87. try {
  88. formData.value = await getDept(props.id)
  89. } finally {
  90. toast.close()
  91. }
  92. }
  93. /** 编辑部门 */
  94. function handleEdit() {
  95. uni.navigateTo({
  96. url: `/pages-system/dept/form/index?id=${props.id}`,
  97. })
  98. }
  99. /** 删除部门 */
  100. function handleDelete() {
  101. if (!props.id) {
  102. return
  103. }
  104. uni.showModal({
  105. title: '提示',
  106. content: '确定要删除该部门吗?',
  107. success: async (res) => {
  108. if (!res.confirm) {
  109. return
  110. }
  111. deleting.value = true
  112. try {
  113. await deleteDept(props.id)
  114. toast.success('删除成功')
  115. setTimeout(() => {
  116. handleBack()
  117. }, 500)
  118. } finally {
  119. deleting.value = false
  120. }
  121. },
  122. })
  123. }
  124. /** 初始化 */
  125. onMounted(async () => {
  126. // 获取部门列表
  127. deptList.value = await getSimpleDeptList()
  128. // 获取用户列表
  129. userList.value = await getSimpleUserList()
  130. // 获取详情
  131. await getDetail()
  132. })
  133. </script>
  134. <style lang="scss" scoped>
  135. </style>