index.uvue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view class="list-page">
  3. <!-- 搜索栏 -->
  4. <view class="search-bar">
  5. <view class="search-box">
  6. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  7. <input class="search-input" type="text" placeholder="请输入关键字查询" v-model="keyword" @confirm="handleSearch" />
  8. </view>
  9. </view>
  10. <!-- 列表内容 -->
  11. <common-list
  12. :dataList="dataList"
  13. :loading="loading"
  14. :refreshing="refreshing"
  15. :hasMore="hasMore"
  16. @refresh="handleRefresh"
  17. @loadMore="loadMore"
  18. @itemClick="handleItemClick"
  19. >
  20. <template #default="{ item, index }">
  21. <view class="list-item">
  22. <view class="item-container">
  23. <view class="item-header">
  24. <image class="location-icon" src="/static/images/workbench/list/2.png" mode="aspectFit"></image>
  25. <text class="item-title">{{ getContractorName(item) }}</text>
  26. <text class="detail-link">详情 ›</text>
  27. </view>
  28. <text class="item-address">{{ getCompanyAddress(item) }}</text>
  29. <view class="item-info">
  30. <view class="info-row">
  31. <view class="info-item">
  32. <text class="info-label">法定代表人</text>
  33. <text class="info-value">{{ getLegalRepresentative(item) }}</text>
  34. </view>
  35. <view class="info-item">
  36. <text class="info-label">资质等级</text>
  37. <text class="info-value">{{ getQualificationLevel(item) }}</text>
  38. </view>
  39. </view>
  40. <view class="info-row">
  41. <view class="info-item">
  42. <text class="info-label">联系电话</text>
  43. <text class="info-value">{{ getContactPhone(item) }}</text>
  44. </view>
  45. <view class="info-item">
  46. <text class="info-label">创建时间</text>
  47. <text class="info-value">{{ getCreateTime(item) }}</text>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. </common-list>
  55. </view>
  56. </template>
  57. <script setup lang="uts">
  58. import { ref, computed, onBeforeUnmount } from 'vue'
  59. import type { ContractorInfo, ContractorListResponse } from '../../../types/workbench'
  60. import { getContractorList } from '../../../api/workbench/list'
  61. // 列表数据
  62. const dataList = ref<ContractorInfo[]>([])
  63. const keyword = ref<string>("")
  64. const page = ref<number>(1)
  65. const pageSize: number = 10
  66. const hasMore = ref<boolean>(true)
  67. const loading = ref<boolean>(false)
  68. const refreshing = ref<boolean>(false)
  69. const total = ref<number>(0)
  70. // 辅助函数:从 any 类型提取属性
  71. const getContractorName = (item: any | null): string => {
  72. if (item == null) return ''
  73. const contractorItem = item as ContractorInfo
  74. return contractorItem.contractorName
  75. }
  76. const getCompanyAddress = (item: any | null): string => {
  77. if (item == null) return ''
  78. const contractorItem = item as ContractorInfo
  79. return contractorItem.companyAddress
  80. }
  81. const getLegalRepresentative = (item: any | null): string => {
  82. if (item == null) return ''
  83. const contractorItem = item as ContractorInfo
  84. return contractorItem.legalRepresentative
  85. }
  86. const getQualificationLevel = (item: any | null): string => {
  87. if (item == null) return ''
  88. const contractorItem = item as ContractorInfo
  89. return contractorItem.qualificationLevel
  90. }
  91. const getContactPhone = (item: any | null): string => {
  92. if (item == null) return ''
  93. const contractorItem = item as ContractorInfo
  94. return contractorItem.contactPhone
  95. }
  96. const getCreateTime = (item: any | null): string => {
  97. if (item == null) return ''
  98. const contractorItem = item as ContractorInfo
  99. return contractorItem.createTime
  100. }
  101. // 加载列表数据
  102. const loadData = async (isRefresh: boolean | null): Promise<void> => {
  103. if (loading.value) {
  104. // 如果正在加载,直接重置刷新状态
  105. refreshing.value = false
  106. return
  107. }
  108. try {
  109. loading.value = true
  110. // 处理默认值
  111. const shouldRefresh = isRefresh != null ? isRefresh : false
  112. if (shouldRefresh) {
  113. page.value = 1
  114. }
  115. // 调用 API
  116. const searchKeyword = keyword.value.length > 0 ? keyword.value : null
  117. const result = await getContractorList(page.value, pageSize, searchKeyword)
  118. // 提取响应数据
  119. const resultObj = result as UTSJSONObject
  120. const success = resultObj['success'] as boolean
  121. const responseData = resultObj['data'] as any[]
  122. const responseTotal = resultObj['total'] as number
  123. if (success) {
  124. // 将 any[] 转换为 ContractorInfo[]
  125. const newData: ContractorInfo[] = []
  126. for (let i = 0; i < responseData.length; i++) {
  127. const item = responseData[i] as UTSJSONObject
  128. const contractorItem: ContractorInfo = {
  129. id: item['id'] as string,
  130. createBy: item['createBy'] as string,
  131. createTime: item['createTime'] as string,
  132. updateBy: item['updateBy'] as string | null,
  133. updateTime: item['updateTime'] as string | null,
  134. isDeleted: item['isDeleted'] as number,
  135. remark: item['remark'] as string,
  136. creditCode: item['creditCode'] as string,
  137. contractorName: item['contractorName'] as string,
  138. companyAddress: item['companyAddress'] as string,
  139. legalRepresentative: item['legalRepresentative'] as string,
  140. contactPhone: item['contactPhone'] as string,
  141. qualificationLevel: item['qualificationLevel'] as string,
  142. qualificationCertNo: item['qualificationCertNo'] as string,
  143. businessScope: item['businessScope'] as string,
  144. bankName: item['bankName'] as string,
  145. bankAccount: item['bankAccount'] as string
  146. }
  147. newData.push(contractorItem)
  148. }
  149. if (shouldRefresh) {
  150. dataList.value = newData
  151. } else {
  152. dataList.value = [...dataList.value, ...newData]
  153. }
  154. total.value = responseTotal
  155. hasMore.value = dataList.value.length < responseTotal
  156. } else {
  157. const msg = resultObj['msg'] as string | null
  158. uni.showToast({
  159. title: msg ?? '加载失败',
  160. icon: 'none'
  161. })
  162. }
  163. } catch (e: any) {
  164. uni.showToast({
  165. title: e.message ?? '加载失败',
  166. icon: 'none'
  167. })
  168. } finally {
  169. loading.value = false
  170. // #ifdef WEB
  171. // Web 平台立即重置
  172. refreshing.value = false
  173. // #endif
  174. // #ifndef WEB
  175. // App 平台延迟重置刷新状态,确保 UI 更新
  176. setTimeout(() => {
  177. refreshing.value = false
  178. }, 100)
  179. // #endif
  180. }
  181. // #ifdef WEB
  182. // Web 平台额外确保重置
  183. refreshing.value = false
  184. // #endif
  185. }
  186. // 下拉刷新
  187. const handleRefresh = async (): Promise<void> => {
  188. refreshing.value = true
  189. await loadData(true as boolean | null)
  190. }
  191. // 加载更多
  192. const loadMore = (): void => {
  193. if (!hasMore.value || loading.value) {
  194. return
  195. }
  196. page.value++
  197. loadData(false as boolean | null)
  198. }
  199. // 搜索
  200. const handleSearch = (): void => {
  201. page.value = 1
  202. loadData(true as boolean | null)
  203. }
  204. // 点击列表项
  205. const handleItemClick = (item: any | null, index: number): void => {
  206. if (item == null) return
  207. const contractorItem = item as ContractorInfo
  208. uni.navigateTo({
  209. url: `/pages/workbench/detail/index?id=${contractorItem.id}`
  210. })
  211. }
  212. // 组件卸载前清理
  213. onBeforeUnmount(() => {
  214. refreshing.value = false
  215. loading.value = false
  216. })
  217. // 初始化
  218. loadData(true as boolean | null)
  219. </script>
  220. <style lang="scss">
  221. .list-page {
  222. flex: 1;
  223. background-color: #e8f0f9;
  224. }
  225. .search-bar {
  226. padding: 20rpx 30rpx;
  227. background-color: #d7eafe;
  228. }
  229. .search-box {
  230. flex-direction: row;
  231. align-items: center;
  232. height: 72rpx;
  233. padding: 0 24rpx;
  234. background-color: #f5f5f5;
  235. border-radius: 36rpx;
  236. .search-icon {
  237. width: 32rpx;
  238. height: 32rpx;
  239. margin-right: 12rpx;
  240. }
  241. .search-input {
  242. flex: 1;
  243. font-size: 28rpx;
  244. color: #333333;
  245. }
  246. }
  247. .list-item {
  248. margin: 24rpx 30rpx;
  249. background-color: #ffffff;
  250. border-radius: 16rpx;
  251. }
  252. .item-container {
  253. padding: 30rpx;
  254. }
  255. .item-header {
  256. flex-direction: row;
  257. align-items: center;
  258. margin-bottom: 16rpx;
  259. .location-icon {
  260. width: 32rpx;
  261. height: 32rpx;
  262. margin-right: 8rpx;
  263. }
  264. .item-title {
  265. flex: 1;
  266. font-size: 32rpx;
  267. color: #333333;
  268. font-weight: bold;
  269. }
  270. .detail-link {
  271. font-size: 28rpx;
  272. color: #999999;
  273. }
  274. }
  275. .item-address {
  276. font-size: 26rpx;
  277. color: #999999;
  278. margin-bottom: 20rpx;
  279. line-height: 40rpx;
  280. }
  281. .item-info {
  282. padding: 20rpx;
  283. background-color: #f8f9fa;
  284. border-radius: 8rpx;
  285. .info-row {
  286. flex-direction: row;
  287. margin-bottom: 16rpx;
  288. &:last-child {
  289. margin-bottom: 0;
  290. }
  291. .info-item {
  292. flex: 1;
  293. flex-direction: row;
  294. align-items: center;
  295. .info-label {
  296. font-size: 26rpx;
  297. color: #666666;
  298. margin-right: 8rpx;
  299. white-space: nowrap;
  300. }
  301. .info-value {
  302. flex: 1;
  303. font-size: 26rpx;
  304. color: #333333;
  305. }
  306. }
  307. }
  308. }
  309. </style>