regular-list.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view class="page-no-tab">
  3. <view class="tabs">
  4. <view
  5. v-for="item in REGULARIZATION_STATUS_FILTERS"
  6. :key="item.value"
  7. class="tab press"
  8. :class="{ active: active === item.value }"
  9. @click="active = item.value"
  10. >{{ item.label }}</view>
  11. </view>
  12. <view class="summary">
  13. <text>共 {{ records.length }} 名试用期 / 转正人员</text>
  14. <text class="muted">{{ summaryTip }}</text>
  15. </view>
  16. <view v-if="loading" class="empty">加载中…</view>
  17. <view v-else-if="list.length" class="list">
  18. <view
  19. v-for="item in list"
  20. :key="item.userId"
  21. class="regular-card card press"
  22. @click="openItem(item)"
  23. >
  24. <view class="card-head">
  25. <view class="card-icon" :style="{ color: meta.color, background: meta.color + '18' }">正</view>
  26. <view class="card-title">
  27. <text>{{ item.name || '—' }}<text class="muted small"> {{ item.employeeNo || '' }}</text></text>
  28. <text>{{ item.department || '—' }} · {{ item.position || '—' }}</text>
  29. </view>
  30. <text class="status-tag" :class="item.statusClass">{{ item.statusLabel }}</text>
  31. </view>
  32. <view class="card-meta">
  33. <view><text>计划转正日期</text><text>{{ item.plannedRegularDate || '—' }}</text></view>
  34. <view><text>生效日期</text><text>{{ item.effectiveDate || '—' }}</text></view>
  35. </view>
  36. <view class="card-foot">
  37. <text class="type-tag">{{ item.regularizationTypeLabel }}</text>
  38. <text class="approval muted">{{ item.approvalComment || item.approvalStatusLabel || '未提交' }}</text>
  39. </view>
  40. <view class="card-actions">
  41. <text class="link" @click.stop="openItem(item)">查看</text>
  42. <text v-if="canApplyRegularization(item)" class="link" @click.stop="openCreate(item)">申请转正</text>
  43. <text v-if="canWithdrawRegularization(item)" class="link" @click.stop="onWithdraw(item)">撤回</text>
  44. <text v-if="canCancelRegularization(item)" class="link danger" @click.stop="onCancel(item)">取消</text>
  45. </view>
  46. </view>
  47. </view>
  48. <view v-else class="empty">
  49. <view>□</view>
  50. <text>{{ active === 'all' ? '暂无试用期员工或转正单据' : '该状态下暂无记录' }}</text>
  51. </view>
  52. <view class="bottom-action">
  53. <view class="primary-btn press" @click="onCreate()">发起转正申请</view>
  54. </view>
  55. </view>
  56. </template>
  57. <script setup>
  58. import { computed, ref } from 'vue'
  59. import { onShow } from '@dcloudio/uni-app'
  60. import { useAuthGuard } from '@/hooks/useAuthGuard'
  61. import { applicationTypes } from '@/data/mock'
  62. import { go } from '@/utils/router'
  63. import { getServerConfig } from '@/utils/auth'
  64. import {
  65. REGULARIZATION_STATUS_FILTERS,
  66. actCancelRegularization,
  67. actWithdrawRegularization,
  68. canApplyRegularization,
  69. canCancelRegularization,
  70. canWithdrawRegularization,
  71. loadRegularizationList,
  72. matchDisplayStatus,
  73. } from '@/api/regularization'
  74. useAuthGuard()
  75. const meta = applicationTypes.regular || { title: '转正申请', color: '#269a99' }
  76. const active = ref('all')
  77. const records = ref([])
  78. const loading = ref(false)
  79. const list = computed(() =>
  80. records.value.filter((row) => matchDisplayStatus(row, active.value)),
  81. )
  82. const summaryTip = computed(() =>
  83. getServerConfig().mode === 'server'
  84. ? '数据来自 /main/regularizations'
  85. : '演示数据保存在本机',
  86. )
  87. async function loadList() {
  88. loading.value = true
  89. try {
  90. const page = await loadRegularizationList({ scope: 'all' })
  91. records.value = page.list || []
  92. } catch (error) {
  93. records.value = []
  94. uni.showToast({ title: error.message || '转正列表加载失败', icon: 'none' })
  95. } finally {
  96. loading.value = false
  97. }
  98. }
  99. function openCreate(item) {
  100. const userId = item?.userId ? `?userId=${item.userId}` : ''
  101. go(`/pages/manage/regular-create${userId}`)
  102. }
  103. function openItem(item) {
  104. if (item?.regularizationId) {
  105. go(`/pages/manage/regular-detail?id=${item.regularizationId}`)
  106. return
  107. }
  108. if (item?.userId) {
  109. openCreate(item)
  110. return
  111. }
  112. uni.showToast({ title: '未找到该员工的转正单', icon: 'none' })
  113. }
  114. function promptReason(title, required) {
  115. return new Promise((resolve) => {
  116. uni.showModal({
  117. title,
  118. editable: true,
  119. placeholderText: required ? '请输入原因(必填)' : '请输入原因(选填)',
  120. success: (r) => {
  121. if (!r.confirm) return resolve(null)
  122. const reason = String(r.content || '').trim()
  123. if (required && !reason) {
  124. uni.showToast({ title: '请填写原因', icon: 'none' })
  125. return resolve(null)
  126. }
  127. resolve(reason)
  128. },
  129. fail: () => resolve(null),
  130. })
  131. })
  132. }
  133. async function exec(title, task) {
  134. uni.showLoading({ title: '处理中...' })
  135. try {
  136. await task()
  137. uni.hideLoading()
  138. uni.showToast({ title: `${title}成功`, icon: 'success' })
  139. await loadList()
  140. } catch (error) {
  141. uni.hideLoading()
  142. uni.showToast({ title: error.message || `${title}失败`, icon: 'none' })
  143. }
  144. }
  145. async function onWithdraw(item) {
  146. const reason = await promptReason('撤回转正审批', false)
  147. if (reason === null) return
  148. await exec('撤回', () => actWithdrawRegularization(item, reason))
  149. }
  150. async function onCancel(item) {
  151. const reason = await promptReason('取消转正单', true)
  152. if (reason === null) return
  153. await exec('取消', () => actCancelRegularization(item, reason))
  154. }
  155. onShow(loadList)
  156. </script>
  157. <style scoped>
  158. .page-no-tab {
  159. padding-bottom: 150rpx;
  160. }
  161. .tabs {
  162. display: flex;
  163. overflow-x: auto;
  164. background: #fff;
  165. border-bottom: 1rpx solid #edf0f2;
  166. }
  167. .tab {
  168. position: relative;
  169. flex: 1;
  170. min-width: 120rpx;
  171. height: 92rpx;
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. color: #6f7782;
  176. font-size: 26rpx;
  177. white-space: nowrap;
  178. }
  179. .tab.active {
  180. color: #1677ff;
  181. font-weight: 500;
  182. }
  183. .tab.active:after {
  184. content: '';
  185. position: absolute;
  186. bottom: 0;
  187. width: 40rpx;
  188. height: 5rpx;
  189. border-radius: 3rpx;
  190. background: #1677ff;
  191. }
  192. .summary {
  193. padding: 22rpx 28rpx 6rpx;
  194. display: flex;
  195. align-items: center;
  196. justify-content: space-between;
  197. font-size: 24rpx;
  198. }
  199. .list {
  200. padding: 18rpx 24rpx;
  201. }
  202. .regular-card {
  203. margin-bottom: 20rpx;
  204. padding: 26rpx;
  205. }
  206. .card-head {
  207. display: flex;
  208. align-items: center;
  209. }
  210. .card-icon {
  211. width: 68rpx;
  212. height: 68rpx;
  213. border-radius: 15rpx;
  214. display: flex;
  215. align-items: center;
  216. justify-content: center;
  217. font-size: 28rpx;
  218. font-weight: 600;
  219. flex-shrink: 0;
  220. }
  221. .card-title {
  222. flex: 1;
  223. min-width: 0;
  224. margin-left: 18rpx;
  225. }
  226. .card-title text {
  227. display: block;
  228. font-size: 29rpx;
  229. font-weight: 600;
  230. }
  231. .card-title text + text {
  232. margin-top: 8rpx;
  233. color: #a0a7b0;
  234. font-size: 21rpx;
  235. font-weight: 400;
  236. }
  237. .small {
  238. font-size: 21rpx;
  239. font-weight: 400;
  240. }
  241. .card-meta {
  242. display: flex;
  243. gap: 16rpx;
  244. margin-top: 18rpx;
  245. }
  246. .card-meta view {
  247. flex: 1;
  248. padding: 16rpx 18rpx;
  249. border-radius: 12rpx;
  250. background: #fafbfc;
  251. }
  252. .card-meta text {
  253. display: block;
  254. font-size: 22rpx;
  255. }
  256. .card-meta text + text {
  257. margin-top: 8rpx;
  258. color: #1f2329;
  259. font-size: 26rpx;
  260. font-weight: 500;
  261. }
  262. .card-foot {
  263. margin-top: 16rpx;
  264. display: flex;
  265. align-items: center;
  266. gap: 16rpx;
  267. }
  268. .type-tag {
  269. padding: 6rpx 14rpx;
  270. border-radius: 999rpx;
  271. background: #eef6f5;
  272. color: #269a99;
  273. font-size: 22rpx;
  274. }
  275. .approval {
  276. flex: 1;
  277. min-width: 0;
  278. font-size: 22rpx;
  279. overflow: hidden;
  280. white-space: nowrap;
  281. text-overflow: ellipsis;
  282. }
  283. .card-actions {
  284. margin-top: 18rpx;
  285. padding-top: 18rpx;
  286. border-top: 1rpx solid #f2f3f5;
  287. display: flex;
  288. justify-content: flex-end;
  289. gap: 30rpx;
  290. }
  291. .link {
  292. color: #1677ff;
  293. font-size: 25rpx;
  294. }
  295. .link.danger {
  296. color: #ee4d4d;
  297. }
  298. .empty {
  299. padding-top: 180rpx;
  300. text-align: center;
  301. color: #a0a7b0;
  302. }
  303. .empty view {
  304. font-size: 80rpx;
  305. color: #cfd4da;
  306. }
  307. .empty text {
  308. display: block;
  309. margin-top: 20rpx;
  310. }
  311. .bottom-action {
  312. position: fixed;
  313. z-index: 10;
  314. left: 0;
  315. right: 0;
  316. bottom: 0;
  317. height: 120rpx;
  318. padding: 16rpx 24rpx;
  319. background: #fff;
  320. border-top: 1rpx solid #e8e9eb;
  321. }
  322. .bottom-action .primary-btn {
  323. height: 84rpx;
  324. font-size: 30rpx;
  325. }
  326. @media (min-width: 800px) {
  327. .bottom-action {
  328. max-width: 520px;
  329. left: 50%;
  330. transform: translateX(-50%);
  331. }
  332. }
  333. </style>