index.uvue 12 KB

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