index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <view class="page-no-tab">
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. left-icon="back"
  7. title="审批中心"
  8. background-color="#157A2C"
  9. color="#fff"
  10. @clickLeft="back"
  11. ></uni-nav-bar>
  12. <view class="tabs">
  13. <view
  14. v-for="t in tabs"
  15. :key="t"
  16. class="tab"
  17. :class="{ active: tab === t }"
  18. @click="switchTab(t)"
  19. >{{ t }}<text v-if="t === tabTodo && pendingCount">{{ pendingCount }}</text></view>
  20. </view>
  21. <view v-if="current.length" class="approval-list">
  22. <view
  23. v-for="item in current"
  24. :key="item.id"
  25. class="approval card press"
  26. @click="openDetail(item)"
  27. >
  28. <view class="approval-top">
  29. <view class="avatar list-avatar">{{ item.avatar }}</view>
  30. <view class="who">
  31. <text><b>{{ item.applicant }}</b> 的{{ item.type }}</text>
  32. <text>{{ item.time ? item.dept + " · " + item.time : item.dept }}</text>
  33. </view>
  34. <text class="status-tag" :class="item.statusClass">{{ item.statusLabel }}</text>
  35. </view>
  36. <view class="summary">
  37. <text>{{ item.summary }}</text>
  38. <text v-if="item.days" class="summary-extra">{{ item.days }}</text>
  39. </view>
  40. <view v-if="!item.result" class="approval-actions">
  41. <button class="reject" @click.stop="action(item, false)">驳回</button>
  42. <button class="approve" @click.stop="action(item, true)">同意</button>
  43. </view>
  44. <view v-else class="handled">
  45. {{ item.readonly ? "抄送时间:" : "处理时间:" }}{{ item.result.handledAt || "—" }}
  46. </view>
  47. </view>
  48. </view>
  49. <view v-else class="empty">
  50. <view>{{ error ? "!" : "✓" }}</view>
  51. <text>{{
  52. error
  53. ? error
  54. : loading || !loaded
  55. ? "加载中…"
  56. : tab === tabTodo
  57. ? "所有审批均已处理"
  58. : "暂无相关审批记录"
  59. }}</text>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. APPROVAL_TAB_TODO,
  66. APPROVAL_TABS,
  67. actApproveApproval,
  68. actRejectApproval,
  69. fetchPendingApprovalCount,
  70. loadApprovalList,
  71. } from "@/api/hr/approval";
  72. export default {
  73. data() {
  74. return {
  75. tabs: APPROVAL_TABS,
  76. tabTodo: APPROVAL_TAB_TODO,
  77. tab: APPROVAL_TAB_TODO,
  78. items: [],
  79. pendingCount: 0,
  80. loading: false,
  81. loaded: false,
  82. error: "",
  83. };
  84. },
  85. computed: {
  86. current() {
  87. return this.items;
  88. },
  89. },
  90. onShow() {
  91. this.load();
  92. },
  93. methods: {
  94. async load() {
  95. this.loading = true;
  96. this.error = "";
  97. try {
  98. const res = await loadApprovalList(this.tab);
  99. this.items = (res && res.list) || [];
  100. } catch (error) {
  101. this.items = [];
  102. this.error = (error && error.message) || "审批列表加载失败";
  103. } finally {
  104. this.loading = false;
  105. this.loaded = true;
  106. }
  107. this.refreshBadge();
  108. },
  109. async refreshBadge() {
  110. try {
  111. this.pendingCount = await fetchPendingApprovalCount();
  112. } catch (error) {
  113. this.pendingCount = 0;
  114. }
  115. },
  116. switchTab(next) {
  117. if (this.tab === next) return;
  118. this.tab = next;
  119. this.items = [];
  120. this.loaded = false;
  121. this.load();
  122. },
  123. openDetail(item) {
  124. uni.navigateTo({ url: "/pages/hr/approval/detail?id=" + item.id });
  125. },
  126. action(item, ok) {
  127. uni.showModal({
  128. title: ok ? "确认同意" : "确认驳回",
  129. content: `确认${ok ? "同意" : "驳回"}${item.applicant}的${item.type}?`,
  130. success: async (r) => {
  131. if (!r.confirm) return;
  132. uni.showLoading({ title: "提交中", mask: true });
  133. try {
  134. if (ok) await actApproveApproval(item);
  135. else await actRejectApproval(item, "信息不完整,请补充");
  136. uni.hideLoading();
  137. uni.showToast({ title: ok ? "已同意" : "已驳回", icon: "success" });
  138. this.load();
  139. } catch (error) {
  140. uni.hideLoading();
  141. uni.showToast({ title: (error && error.message) || "操作失败", icon: "none" });
  142. }
  143. },
  144. });
  145. },
  146. },
  147. };
  148. </script>
  149. <style scoped lang="scss">
  150. @import "@/pages/hr/common-style.scss";
  151. .tabs {
  152. height: 92rpx;
  153. display: flex;
  154. background: #fff;
  155. border-bottom: 1rpx solid #edf0f2;
  156. }
  157. .tab {
  158. position: relative;
  159. flex: 1;
  160. display: flex;
  161. align-items: center;
  162. justify-content: center;
  163. color: #6f7782;
  164. font-size: 27rpx;
  165. }
  166. .tab.active {
  167. color: #157a2c;
  168. font-weight: 500;
  169. }
  170. .tab.active:after {
  171. content: "";
  172. position: absolute;
  173. bottom: 0;
  174. width: 44rpx;
  175. height: 5rpx;
  176. background: #157a2c;
  177. border-radius: 3rpx;
  178. }
  179. .tab text {
  180. margin-left: 7rpx;
  181. min-width: 28rpx;
  182. height: 28rpx;
  183. padding: 0 6rpx;
  184. border-radius: 15rpx;
  185. background: #ee4d4d;
  186. color: #fff;
  187. font-size: 18rpx;
  188. line-height: 28rpx;
  189. text-align: center;
  190. }
  191. .approval-list {
  192. padding: 24rpx;
  193. }
  194. .approval {
  195. margin-bottom: 20rpx;
  196. padding: 26rpx;
  197. }
  198. .approval-top {
  199. display: flex;
  200. align-items: center;
  201. }
  202. .list-avatar {
  203. width: 72rpx;
  204. height: 72rpx;
  205. font-size: 27rpx;
  206. }
  207. .who {
  208. flex: 1;
  209. margin-left: 18rpx;
  210. }
  211. .who text {
  212. display: block;
  213. font-size: 27rpx;
  214. }
  215. .who > text + text {
  216. margin-top: 8rpx;
  217. color: #a0a7b0;
  218. font-size: 21rpx;
  219. }
  220. .summary {
  221. margin: 24rpx 0;
  222. padding: 20rpx;
  223. border-radius: 10rpx;
  224. background: #f7f8fa;
  225. color: #4b5563;
  226. font-size: 25rpx;
  227. }
  228. .summary text {
  229. display: block;
  230. }
  231. .summary .summary-extra {
  232. margin-top: 10rpx;
  233. color: #8b939f;
  234. font-size: 22rpx;
  235. }
  236. .approval-actions {
  237. display: flex;
  238. justify-content: flex-end;
  239. }
  240. .approval-actions button {
  241. width: 140rpx;
  242. height: 60rpx;
  243. margin-left: 18rpx;
  244. border-radius: 9rpx;
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. font-size: 25rpx;
  249. }
  250. .reject {
  251. border: 1rpx solid #d8dce2;
  252. color: #555d68;
  253. }
  254. .approve {
  255. background: #157a2c;
  256. color: #fff;
  257. }
  258. .handled {
  259. text-align: right;
  260. color: #a0a7b0;
  261. font-size: 21rpx;
  262. }
  263. .empty {
  264. padding-top: 250rpx;
  265. text-align: center;
  266. color: #a0a7b0;
  267. }
  268. .empty view {
  269. width: 96rpx;
  270. height: 96rpx;
  271. margin: auto;
  272. border-radius: 50%;
  273. background: #eaf8ef;
  274. color: #07a44d;
  275. line-height: 96rpx;
  276. font-size: 45rpx;
  277. }
  278. .empty text {
  279. display: block;
  280. margin-top: 25rpx;
  281. }
  282. </style>