list.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="bx-page">
  3. <view class="topbar" :style="safeAreaStyle">
  4. <view class="topbar-left">
  5. <text class="topbar-back" @click="goBack">←</text>
  6. <text class="topbar-title">备用金申请</text>
  7. </view>
  8. <view class="topbar-right" />
  9. </view>
  10. <view class="fab-add" @click="goApply()">
  11. <view class="fab-add__bar fab-add__bar--h" />
  12. <view class="fab-add__bar fab-add__bar--v" />
  13. </view>
  14. <view class="search-wrap">
  15. <view class="search-box">
  16. <input
  17. class="search-input"
  18. v-model="keyword"
  19. placeholder="搜索备用金申请"
  20. confirm-type="search"
  21. @confirm="onRefresh"
  22. />
  23. <view v-if="keyword.trim()" class="search-box__clear" @click="clearKeyword">×</view>
  24. </view>
  25. </view>
  26. <view class="search-wrap" style="padding-top: 0">
  27. <scroll-view scroll-x class="search-filter-scroll" :show-scrollbar="false">
  28. <view class="search-filter">
  29. <view
  30. v-for="tab in tabs"
  31. :key="tab.value === '' ? '__all' : tab.value"
  32. class="filter-tag"
  33. :class="{ active: activeTab === tab.value }"
  34. @click="onTabChange(tab.value)"
  35. >
  36. {{ tab.label }}
  37. </view>
  38. </view>
  39. </scroll-view>
  40. </view>
  41. <scroll-view
  42. class="page-padded list-scroll"
  43. scroll-y
  44. :style="{ height: listHeight }"
  45. refresher-enabled
  46. :refresher-triggered="refreshing"
  47. @refresherrefresh="onPullRefresh"
  48. @scrolltolower="onLoadMore"
  49. >
  50. <view v-if="!list.length && !loading" class="empty-state empty-state--fill">
  51. <text>暂无备用金记录</text>
  52. </view>
  53. <view
  54. v-for="item in list"
  55. :key="item.id"
  56. class="expense-card"
  57. @click="goDetail(item.id)"
  58. >
  59. <view class="ec-top">
  60. <view class="ec-type">
  61. <text class="advance-list-card__title">{{ item.reason || '—' }}</text>
  62. </view>
  63. <text class="status-tag" :class="workflowListStatusTagClass(item.status)">
  64. {{ statusLabel(item.status) }}
  65. </text>
  66. </view>
  67. <view class="ec-amount-label">申请金额</view>
  68. <view class="ec-amount">{{ formatAmount(item.amount) }}</view>
  69. <view class="advance-card-subs">
  70. <view class="advance-card-sub-row">
  71. <text class="k">实际发放金额</text>
  72. <text class="v">¥ {{ actualIssuedDisplay(item) }}</text>
  73. </view>
  74. <view class="advance-card-sub-row">
  75. <text class="k">实际冲抵</text>
  76. <text class="v">¥ {{ formatAmount(offsetTotal(item)) }}</text>
  77. </view>
  78. </view>
  79. <view class="list-card-kv">
  80. <view class="list-card-kv__row">
  81. <text class="list-card-kv__k">申请单号</text>
  82. <text class="list-card-kv__v">{{ item.applyCode || '—' }}</text>
  83. </view>
  84. <view class="list-card-kv__row">
  85. <text class="list-card-kv__k">申请人</text>
  86. <text class="list-card-kv__v">{{ item.applicantName || '-' }}</text>
  87. </view>
  88. <view v-if="item.currentNode" class="list-card-kv__row">
  89. <text class="list-card-kv__k">当前环节</text>
  90. <text class="list-card-kv__v">{{ item.currentNode }}</text>
  91. </view>
  92. <view v-if="item.remark" class="list-card-kv__row">
  93. <text class="list-card-kv__k">备注</text>
  94. <text class="list-card-kv__v">{{ item.remark }}</text>
  95. </view>
  96. </view>
  97. <view class="ec-meta">
  98. <text>{{ formatApplyDate(item) }}</text>
  99. </view>
  100. <view class="ec-bottom" @click.stop>
  101. <view v-if="item.status === 'draft' || item.status === 'rejected'" class="op-actions">
  102. <template v-if="item.status === 'draft'">
  103. <button class="btn btn-sm btn-danger" @click="handleDelete(item)">删除</button>
  104. <button class="btn btn-sm btn-primary" @click="goApply(item.id)">编辑</button>
  105. <button class="btn btn-sm btn-primary" @click="handleSubmit(item)">提交</button>
  106. </template>
  107. <template v-else>
  108. <button class="btn btn-sm btn-primary" @click="goDetail(item.id)">查看</button>
  109. <button class="btn btn-sm btn-primary" @click="goApply(item.id)">编辑</button>
  110. <button class="btn btn-sm btn-primary" @click="handleSubmit(item)">提交</button>
  111. </template>
  112. </view>
  113. <view v-else class="op-actions">
  114. <button class="btn btn-sm btn-primary" @click="goDetail(item.id)">查看</button>
  115. </view>
  116. </view>
  117. </view>
  118. <view v-if="list.length" class="list-footer-tip">
  119. {{ finished ? '没有更多了' : loading ? '加载中...' : '上拉加载更多' }}
  120. </view>
  121. </scroll-view>
  122. </view>
  123. </template>
  124. <script setup>
  125. import { ref } from 'vue'
  126. import { onShow } from '@dcloudio/uni-app'
  127. import { PAGE_PATHS } from '@/config/api'
  128. import { advanceApi } from '@/api/bx'
  129. import {
  130. statusLabel,
  131. workflowListStatusTagClass,
  132. formatAmount,
  133. formatApplyDate
  134. } from '@/utils/bxFormat'
  135. import { getSafeAreaStyle } from '@/utils/safeArea'
  136. const safeAreaStyle = getSafeAreaStyle()
  137. const tabs = [
  138. { label: '全部', value: '' },
  139. { label: '待提交', value: 'draft' },
  140. { label: '审批中', value: 'pending' },
  141. { label: '已通过', value: 'approved' },
  142. { label: '已驳回', value: 'rejected' },
  143. { label: '已发放', value: 'issued' }
  144. ]
  145. const keyword = ref('')
  146. const activeTab = ref('')
  147. const list = ref([])
  148. const loading = ref(false)
  149. const finished = ref(false)
  150. const refreshing = ref(false)
  151. const currentPage = ref(1)
  152. const pageSize = 10
  153. const listHeight = ref('60vh')
  154. function computeListHeight() {
  155. try {
  156. const sys = uni.getSystemInfoSync()
  157. const h = (sys.windowHeight || 600) - 210
  158. listHeight.value = `${Math.max(h, 320)}px`
  159. } catch (e) {
  160. listHeight.value = '60vh'
  161. }
  162. }
  163. function actualIssuedDisplay(item) {
  164. const raw = item.actualAmount ?? item.actual_amount
  165. if (raw == null || raw === '') return '—'
  166. const n = typeof raw === 'string' ? parseFloat(raw) : Number(raw)
  167. if (Number.isNaN(n)) return '—'
  168. return formatAmount(n)
  169. }
  170. function offsetTotal(item) {
  171. const raw = item.offsetAmount ?? item.offset_amount ?? 0
  172. const n = typeof raw === 'string' ? parseFloat(raw) : Number(raw)
  173. return Number.isNaN(n) ? 0 : n
  174. }
  175. async function fetchPage() {
  176. if (loading.value && !refreshing.value) return
  177. loading.value = true
  178. try {
  179. const params = {
  180. page: currentPage.value,
  181. pageSize
  182. }
  183. if (activeTab.value) params.status = activeTab.value
  184. if (keyword.value.trim()) params.keyword = keyword.value.trim()
  185. const res = await advanceApi.my(params)
  186. const rows = res.data?.rows || []
  187. const total = res.data?.total || 0
  188. if (currentPage.value === 1) {
  189. list.value = rows
  190. } else {
  191. list.value = list.value.concat(rows)
  192. }
  193. currentPage.value += 1
  194. finished.value = rows.length < pageSize || list.value.length >= total
  195. } catch (e) {
  196. finished.value = true
  197. } finally {
  198. loading.value = false
  199. refreshing.value = false
  200. }
  201. }
  202. function onRefresh() {
  203. currentPage.value = 1
  204. finished.value = false
  205. loading.value = false
  206. list.value = []
  207. fetchPage()
  208. }
  209. function onPullRefresh() {
  210. refreshing.value = true
  211. currentPage.value = 1
  212. finished.value = false
  213. fetchPage()
  214. }
  215. function onLoadMore() {
  216. if (finished.value || loading.value) return
  217. fetchPage()
  218. }
  219. function onTabChange(value) {
  220. activeTab.value = value
  221. onRefresh()
  222. }
  223. function clearKeyword() {
  224. keyword.value = ''
  225. onRefresh()
  226. }
  227. function goBack() {
  228. uni.navigateBack({ fail: () => uni.reLaunch({ url: PAGE_PATHS.workbench }) })
  229. }
  230. function goApply(id) {
  231. const q = id ? `?id=${id}` : ''
  232. uni.navigateTo({ url: `${PAGE_PATHS.bxAdvanceApplyForm}${q}` })
  233. }
  234. function goDetail(id) {
  235. uni.navigateTo({ url: `${PAGE_PATHS.bxAdvanceDetail}?id=${id}` })
  236. }
  237. async function handleSubmit(item) {
  238. try {
  239. await advanceApi.submit(item.id)
  240. uni.showToast({ title: '提交成功', icon: 'success' })
  241. onRefresh()
  242. } catch (e) {
  243. // bxRequest already toasted
  244. }
  245. }
  246. function handleDelete(item) {
  247. uni.showModal({
  248. title: '删除确认',
  249. content: '确定要删除该申请单吗?删除后不可恢复。',
  250. confirmText: '确定删除',
  251. confirmColor: '#ef4444',
  252. success: async (res) => {
  253. if (!res.confirm) return
  254. try {
  255. await advanceApi.delete(item.id)
  256. uni.showToast({ title: '删除成功', icon: 'success' })
  257. onRefresh()
  258. } catch (e) {
  259. // toasted
  260. }
  261. }
  262. })
  263. }
  264. onShow(() => {
  265. computeListHeight()
  266. onRefresh()
  267. })
  268. </script>
  269. <style lang="scss">
  270. @import '@/styles/bx-theme.scss';
  271. .list-scroll {
  272. box-sizing: border-box;
  273. }
  274. </style>