index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="min-h-screen bg-[#f5f5f5]">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="岗位管理"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. >
  9. <template #right>
  10. <view class="flex items-center" @click="searchVisible = !searchVisible">
  11. <wd-icon name="search" size="20px" />
  12. </view>
  13. </template>
  14. </wd-navbar>
  15. <!-- 岗位列表 -->
  16. <view class="p-24rpx">
  17. <view
  18. v-for="item in list"
  19. :key="item.id"
  20. class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
  21. @click="handleDetail(item)"
  22. >
  23. <view class="p-24rpx">
  24. <view class="mb-16rpx flex items-center justify-between">
  25. <view class="text-32rpx text-[#333] font-semibold">
  26. {{ item.name }}
  27. </view>
  28. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="item.status" />
  29. </view>
  30. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  31. <text class="mr-8rpx text-[#999]">岗位编码:</text>
  32. <text>{{ item.code }}</text>
  33. </view>
  34. <view v-if="item.remark" class="mb-12rpx flex items-center text-28rpx text-[#666]">
  35. <text class="mr-8rpx text-[#999]">备注:</text>
  36. <text class="line-clamp-1">{{ item.remark }}</text>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 加载更多 -->
  41. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  42. <wd-status-tip image="content" tip="暂无岗位数据" />
  43. </view>
  44. <wd-loadmore
  45. v-if="list.length > 0"
  46. :state="loadMoreState"
  47. @reload="loadMore"
  48. />
  49. </view>
  50. <!-- 搜索弹窗 -->
  51. <SearchForm
  52. v-model="searchVisible"
  53. :search-params="queryParams"
  54. @search="handleQuery"
  55. @reset="handleReset"
  56. />
  57. <!-- 新增按钮 -->
  58. <view
  59. class="fixed bottom-100rpx right-32rpx z-10 h-100rpx w-100rpx flex items-center justify-center rounded-full bg-[#1890ff] shadow-lg"
  60. @click="handleAdd"
  61. >
  62. <wd-icon name="add" size="24px" color="#fff" />
  63. </view>
  64. </view>
  65. </template>
  66. <script lang="ts" setup>
  67. import type { Post } from '@/api/system/post'
  68. import type { LoadMoreState } from '@/http/types'
  69. import { onReachBottom } from '@dcloudio/uni-app'
  70. import { onMounted, reactive, ref } from 'vue'
  71. import { getPostPage } from '@/api/system/post'
  72. import { DICT_TYPE } from '@/utils/constants'
  73. import SearchForm from './components/search-form.vue'
  74. definePage({
  75. style: {
  76. navigationBarTitleText: '',
  77. navigationStyle: 'custom',
  78. },
  79. })
  80. const total = ref(0) // 列表的总页数
  81. const list = ref<Post[]>([]) // 列表的数据
  82. const loadMoreState = ref<LoadMoreState>('loading') // 加载更多状态
  83. const searchVisible = ref(false) // 搜索弹窗
  84. const queryParams = reactive({
  85. pageNo: 1,
  86. pageSize: 10,
  87. name: undefined as string | undefined,
  88. code: undefined as string | undefined,
  89. status: -1 as number, // -1 表示全部
  90. })
  91. /** 返回上一页 */
  92. function handleBack() {
  93. uni.navigateBack()
  94. }
  95. /** 查询岗位列表 */
  96. async function getList() {
  97. loadMoreState.value = 'loading'
  98. try {
  99. const data = await getPostPage({
  100. ...queryParams,
  101. status: queryParams.status === -1 ? undefined : queryParams.status,
  102. })
  103. list.value = [...list.value, ...data.list]
  104. total.value = data.total
  105. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  106. } catch {
  107. queryParams.pageNo = queryParams.pageNo > 1 ? queryParams.pageNo - 1 : 1
  108. loadMoreState.value = 'error'
  109. }
  110. }
  111. /** 搜索按钮操作 */
  112. function handleQuery(data?: { name?: string, code?: string, status?: number }) {
  113. queryParams.name = data?.name
  114. queryParams.code = data?.code
  115. queryParams.status = data?.status ?? -1
  116. queryParams.pageNo = 1
  117. list.value = [] // 清空列表
  118. getList()
  119. }
  120. /** 重置按钮操作 */
  121. function handleReset() {
  122. handleQuery()
  123. }
  124. /** 加载更多 */
  125. function loadMore() {
  126. if (loadMoreState.value === 'finished') {
  127. return
  128. }
  129. queryParams.pageNo++
  130. getList()
  131. }
  132. /** 新增岗位 */
  133. function handleAdd() {
  134. uni.navigateTo({
  135. url: '/pages-system/post/form/index',
  136. })
  137. }
  138. /** 查看详情 */
  139. function handleDetail(item: Post) {
  140. uni.navigateTo({
  141. url: `/pages-system/post/detail/index?id=${item.id}`,
  142. })
  143. }
  144. /** 触底加载更多 */
  145. onReachBottom(() => {
  146. loadMore()
  147. })
  148. /** 初始化 */
  149. onMounted(() => {
  150. getList()
  151. })
  152. </script>
  153. <style lang="scss" scoped>
  154. </style>