contract.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="app-container list-page pb-24">
  3. <TopBar title="合同管理" show-back />
  4. <!-- 工具栏:搜索 + 新增 -->
  5. <view class="toolbar px-4 py-3 sticky top-0 z-40 flex items-center gap-2">
  6. <view class="search-box flex-1 min-w-0 flex items-center rounded-2xl px-4 py-2" :class="{ 'search-focus': focusedSearch }">
  7. <text class="uni-icons uniui-search search-icon mr-2 text-base"></text>
  8. <input
  9. class="flex-1 bg-transparent text-sm text-gray-800"
  10. placeholder="搜索合同号/备注"
  11. placeholder-class="search-ph"
  12. v-model="searchKeyword"
  13. confirm-type="search"
  14. @focus="focusedSearch = true"
  15. @blur="focusedSearch = false"
  16. @confirm="onSearch"
  17. />
  18. </view>
  19. <view
  20. class="add-btn w-9 h-9 rounded-full flex items-center justify-center flex-shrink-0"
  21. hover-class="add-btn-hover"
  22. :hover-start-time="0"
  23. :hover-stay-time="120"
  24. @click="goToAdd"
  25. >
  26. <text class="uni-icons uniui-plusempty text-white text-xl"></text>
  27. </view>
  28. </view>
  29. <!-- 状态筛选 -->
  30. <scroll-view scroll-x class="filter-bar" :show-scrollbar="false" enhanced>
  31. <view class="flex items-center gap-2 px-4 py-3">
  32. <view
  33. v-for="(t, i) in filterTypes"
  34. :key="t.value"
  35. class="filter-tab flex-shrink-0 rounded-full px-4 py-1.5 text-sm border"
  36. :class="i === currentFilterIndex ? 'filter-tab--active' : 'filter-tab--normal'"
  37. @click="onFilterChange(i)"
  38. >
  39. {{ t.label }}
  40. </view>
  41. </view>
  42. </scroll-view>
  43. <!-- 列表 -->
  44. <view class="px-4 mt-3">
  45. <view v-if="contractStore.loading" class="py-16 text-center">
  46. <text class="loading-text">加载中...</text>
  47. </view>
  48. <view v-else-if="contractStore.contracts.length === 0">
  49. <EmptyState icon="uniui-file-text-filled" text="暂无合同" />
  50. </view>
  51. <view v-else class="gap-y-3">
  52. <uni-swipe-action
  53. v-for="contract in contractStore.contracts"
  54. :key="contract.id"
  55. :actions="swipeActions"
  56. @click="onSwipeAction(contract.id, $event)"
  57. >
  58. <view class="data-card" @click="goToDetail(contract.id)">
  59. <!-- 头部:合同号 + 状态 -->
  60. <view class="flex items-start justify-between">
  61. <view class="min-w-0">
  62. <text class="card-title block truncate">{{ contract.contractNo }}</text>
  63. <text class="card-sub block mt-0.5">合同编号</text>
  64. </view>
  65. <view
  66. class="status-pill flex-shrink-0 px-2.5 py-0.5 rounded-full text-xs ml-2"
  67. :style="{ backgroundColor: statusBg(contract.status), color: statusColor(contract.status) }"
  68. >
  69. {{ statusText(contract.status) }}
  70. </view>
  71. </view>
  72. <!-- 金额高亮条 -->
  73. <view class="amount-row mt-3 rounded-2xl px-3.5 py-2.5 flex items-center justify-between">
  74. <view class="flex items-center">
  75. <text class="uni-icons uniui-wallet-filled amount-icon text-sm mr-2"></text>
  76. <text class="amount-label text-xs">合同金额</text>
  77. </view>
  78. <text class="amount-value">{{ formatMoney(contract.contractAmount) }}</text>
  79. </view>
  80. <!-- 底部信息行 -->
  81. <view class="card-foot mt-3 pt-2.5 flex items-center justify-between">
  82. <view class="foot-item flex items-center min-w-0 mr-3">
  83. <text class="uni-icons uniui-wallet-filled foot-icon text-xs mr-1.5 flex-shrink-0"></text>
  84. <text class="foot-text text-xs truncate">{{ getPaymentMethodText(contract.paymentMethod) || '未约定' }}</text>
  85. </view>
  86. <view class="foot-item flex items-center flex-shrink-0">
  87. <text class="uni-icons uniui-calendar foot-icon text-xs mr-1.5"></text>
  88. <text class="foot-text text-xs">{{ contract.signDate || '未签约' }}</text>
  89. </view>
  90. </view>
  91. </view>
  92. </uni-swipe-action>
  93. </view>
  94. <!-- 加载更多 -->
  95. <view v-if="contractStore.contracts.length > 0" class="mt-2 mb-4">
  96. <view v-if="contractStore.hasMore" class="text-center py-4">
  97. <text class="load-more" @click="loadMore">
  98. {{ contractStore.loadingMore ? '加载中...' : '加载更多' }}
  99. </text>
  100. </view>
  101. <view v-else class="text-center py-4">
  102. <text class="text-xs text-gray-400">已经到底了</text>
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. </template>
  108. <script setup lang="ts">
  109. import { ref, onMounted, onUnmounted } from 'vue'
  110. import { onPullDownRefresh } from '@dcloudio/uni-app'
  111. import { useContractStore } from '@/stores/contract'
  112. import type { ContractStatus } from '@/types'
  113. import {
  114. formatMoney,
  115. getPaymentMethodText,
  116. getContractStatusText,
  117. getContractStatusColor,
  118. getContractStatusBgColor
  119. } from '@/utils'
  120. import TopBar from '@/components/common/TopBar.vue'
  121. import EmptyState from '@/components/common/EmptyState.vue'
  122. import UniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
  123. const contractStore = useContractStore()
  124. const searchKeyword = ref('')
  125. const currentFilterIndex = ref(0)
  126. const focusedSearch = ref(false)
  127. const filterTypes: { value: ContractStatus | ''; label: string }[] = [
  128. { value: '', label: '全部' },
  129. { value: 'draft', label: '草稿' },
  130. { value: 'pending', label: '待生效' },
  131. { value: 'active', label: '生效中' },
  132. { value: 'expired', label: '已过期' },
  133. { value: 'terminated', label: '已终止' }
  134. ]
  135. const swipeActions = [
  136. { text: '编辑', color: '#368f6f', key: 'edit' },
  137. { text: '删除', color: '#ff3b30', key: 'delete' }
  138. ]
  139. const statusText = getContractStatusText
  140. const statusColor = getContractStatusColor
  141. const statusBg = getContractStatusBgColor
  142. let searchTimer: ReturnType<typeof setTimeout> | null = null
  143. function onSearch() {
  144. if (searchTimer) clearTimeout(searchTimer)
  145. searchTimer = setTimeout(() => {
  146. contractStore.setKeyword(searchKeyword.value.trim())
  147. contractStore.fetchContracts(true)
  148. }, 300)
  149. }
  150. function onFilterChange(index: number) {
  151. currentFilterIndex.value = index
  152. contractStore.setStatus(filterTypes[index].value)
  153. contractStore.fetchContracts(true)
  154. }
  155. function goToDetail(id: number | string) {
  156. contractStore.setCurrentContract(id)
  157. uni.navigateTo({ url: `/subPackages/pages-contract/contractDetail?id=${id}` })
  158. }
  159. function goToAdd() {
  160. uni.navigateTo({ url: '/subPackages/pages-contract/contractForm' })
  161. }
  162. function onSwipeAction(id: number | string, action: { key?: string }) {
  163. if (action.key === 'edit') {
  164. uni.navigateTo({ url: `/subPackages/pages-contract/contractForm?id=${id}` })
  165. } else if (action.key === 'delete') {
  166. uni.showModal({
  167. title: '确认删除',
  168. content: '删除后无法恢复,是否继续?',
  169. success: async (res) => {
  170. if (res.confirm) {
  171. try {
  172. await contractStore.removeContract(id)
  173. uni.showToast({ title: '已删除', icon: 'success' })
  174. } catch (e) {
  175. uni.showToast({ title: '删除失败', icon: 'none' })
  176. }
  177. }
  178. }
  179. })
  180. }
  181. }
  182. function loadMore() {
  183. contractStore.loadMore()
  184. }
  185. async function refreshData() {
  186. await contractStore.fetchContracts(true)
  187. uni.stopPullDownRefresh()
  188. }
  189. onMounted(() => {
  190. contractStore.fetchContracts(true)
  191. })
  192. onUnmounted(() => {
  193. if (searchTimer) clearTimeout(searchTimer)
  194. })
  195. onPullDownRefresh(() => {
  196. refreshData()
  197. })
  198. </script>
  199. <style scoped>
  200. .list-page {
  201. background-color: #f6fbf9;
  202. }
  203. /* 工具栏:云雾白磨砂条 + 嫩芽浅底分割线 */
  204. .toolbar {
  205. background-color: rgba(246, 251, 249, 0.88);
  206. backdrop-filter: blur(12px);
  207. -webkit-backdrop-filter: blur(12px);
  208. border-bottom: 1px solid rgba(164, 216, 152, 0.28);
  209. }
  210. .search-box {
  211. background-color: #ffffff;
  212. border: 1px solid #e5e7eb;
  213. transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  214. }
  215. .search-focus {
  216. background-color: #ffffff;
  217. border-color: #368f6f;
  218. box-shadow: 0 0 0 3px rgba(164, 216, 152, 0.30);
  219. }
  220. .search-icon {
  221. color: #9ca3af;
  222. }
  223. .search-ph {
  224. color: #9ca3af;
  225. }
  226. .add-btn {
  227. background: linear-gradient(135deg, #368f6f 0%, #5ab8d0 100%);
  228. box-shadow: 0 8px 18px -8px rgba(54, 143, 111, 0.55);
  229. }
  230. .add-btn-hover {
  231. opacity: 0.92;
  232. transform: scale(0.94);
  233. }
  234. /* 筛选胶囊条 */
  235. .filter-bar {
  236. background-color: rgba(246, 251, 249, 0.88);
  237. border-bottom: 1px solid rgba(164, 216, 152, 0.20);
  238. white-space: nowrap;
  239. }
  240. .filter-tab {
  241. transition: all 0.15s ease;
  242. }
  243. .filter-tab--normal {
  244. background-color: #ffffff;
  245. border-color: #e5e7eb;
  246. color: #4b5563;
  247. }
  248. .filter-tab--active {
  249. background: linear-gradient(135deg, #368f6f 0%, #5ab8d0 100%);
  250. border-color: transparent;
  251. color: #ffffff;
  252. box-shadow: 0 6px 14px -8px rgba(54, 143, 111, 0.6);
  253. }
  254. /* 数据卡片 */
  255. .data-card {
  256. background-color: #ffffff;
  257. border-radius: 20px;
  258. padding: 14px 16px;
  259. box-shadow: 0 14px 34px -18px rgba(54, 143, 111, 0.35);
  260. border: 1px solid rgba(164, 216, 152, 0.28);
  261. }
  262. .data-card:active {
  263. transform: scale(0.99);
  264. background-color: #fbfefb;
  265. }
  266. .card-title {
  267. font-size: 15px;
  268. font-weight: 600;
  269. color: #1f2937;
  270. }
  271. .card-sub {
  272. font-size: 11px;
  273. color: #b6c9be;
  274. }
  275. .status-pill {
  276. font-weight: 500;
  277. }
  278. /* 金额高亮条 */
  279. .amount-row {
  280. background: linear-gradient(135deg, rgba(164, 216, 152, 0.22) 0%, rgba(90, 184, 208, 0.16) 100%);
  281. border: 1px solid rgba(164, 216, 152, 0.30);
  282. }
  283. .amount-icon {
  284. color: #368f6f;
  285. }
  286. .amount-label {
  287. color: #6b8a7a;
  288. font-weight: 500;
  289. }
  290. .amount-value {
  291. font-size: 17px;
  292. font-weight: 700;
  293. color: #2f7a5e;
  294. letter-spacing: 0.3px;
  295. }
  296. /* 底部信息行 */
  297. .card-foot {
  298. border-top: 1px dashed rgba(164, 216, 152, 0.45);
  299. }
  300. .foot-icon {
  301. color: #5ab8d0;
  302. }
  303. .foot-text {
  304. color: #6b7280;
  305. }
  306. .loading-text {
  307. color: #6b7280;
  308. }
  309. .load-more {
  310. font-size: 14px;
  311. font-weight: 500;
  312. color: #368f6f;
  313. }
  314. </style>