index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="detail-page">
  3. <view class="tip">数据更新时间:{{ formatDate(new Date().setDate(new Date().getDate() - 1), 'YYYY-MM-DD') || '--' }}</view>
  4. <scroll-view
  5. class="list-scroll"
  6. scroll-y="true"
  7. refresher-enabled
  8. :refresher-triggered="isRefreshing"
  9. @refresherrefresh="onRefresh"
  10. @scrolltolower="onLoadMore"
  11. >
  12. <view class="list-container">
  13. <view
  14. class="card-item"
  15. v-for="(item, index) in rows"
  16. :key="index"
  17. @click="toDetail(item)"
  18. >
  19. <view class="left-info">
  20. <view class="row1-name">{{ item.receiverName }}</view>
  21. <view class="row2-info">
  22. <text class="province">{{ item.receiverProvince }}</text>
  23. <view class="level-tag" :class="getLevelClass(item.customerLevel)">
  24. {{ item.customerLevel }}
  25. </view>
  26. </view>
  27. <view class="row3-nature">{{ item.customerNature }}</view>
  28. <view class="row4-manager">{{ item.manager }}</view>
  29. </view>
  30. <view class="right-info">
  31. <text class="alert-count">{{ item.alertCount }}次预警</text>
  32. </view>
  33. </view>
  34. <view class="loading-more" v-if="loading">
  35. <image class="loading-icon" src="../../../static/images/loading.png" />
  36. </view>
  37. <view v-if="!loading && rows.length === 0" class="empty-data">
  38. <EmptyView text="无相关数据" />
  39. </view>
  40. <view v-if="!hasMore && rows.length > 0" class="no-more">
  41. <text>没有更多数据了</text>
  42. </view>
  43. </view>
  44. </scroll-view>
  45. </view>
  46. </template>
  47. <script>
  48. import EmptyView from "../../../wigets/empty.vue";
  49. import request from '../../../request/index.js'
  50. import { formatDate } from '../../../utils/utils.js'
  51. export default {
  52. components: {
  53. EmptyView,
  54. },
  55. data() {
  56. return {
  57. isRefreshing: false,
  58. loading: false,
  59. rows: [],
  60. totalCount: 60, // Simulated total count
  61. hasMore: true,
  62. pageNum: 1,
  63. pageSize: 20,
  64. };
  65. },
  66. created() {
  67. this.resetFetch();
  68. },
  69. methods: {
  70. formatDate,
  71. getLevelClass(level) {
  72. if (level === 'VIP') return 'tag-vip';
  73. if (level === '二级') return 'tag-l2';
  74. if (level === '三级') return 'tag-l3';
  75. return 'tag-default';
  76. },
  77. generateFakeData() {
  78. const newRows = [];
  79. const levels = ['VIP', '二级', '三级'];
  80. const provinces = ['北京市', '上海市', '广东省', '浙江省', '江苏省'];
  81. const natures = ['协议客户', '非协议客户'];
  82. const managers = ['张明华', '李建华', '王丽萍', '陈大文'];
  83. const startIdx = (this.pageNum - 1) * this.pageSize;
  84. const endIdx = Math.min(startIdx + this.pageSize, this.totalCount);
  85. if (startIdx >= this.totalCount) {
  86. this.hasMore = false;
  87. return [];
  88. }
  89. for (let i = startIdx; i < endIdx; i++) {
  90. newRows.push({
  91. id: i,
  92. receiverName: `测试收货企业${i + 1}有限公司`,
  93. receiverProvince: provinces[i % provinces.length],
  94. customerLevel: levels[i % levels.length],
  95. customerNature: natures[i % natures.length],
  96. manager: managers[i % managers.length],
  97. alertCount: Math.floor(Math.random() * 10) + 1,
  98. });
  99. }
  100. return newRows;
  101. },
  102. async onRefresh() {
  103. this.isRefreshing = true;
  104. this.pageNum = 1;
  105. this.hasMore = true;
  106. // Simulate network request
  107. setTimeout(() => {
  108. this.rows = this.generateFakeData();
  109. this.isRefreshing = false;
  110. }, 1000);
  111. },
  112. onLoadMore() {
  113. if (this.loading || !this.hasMore) return;
  114. this.loading = true;
  115. this.pageNum++;
  116. // Simulate network request
  117. setTimeout(() => {
  118. const more = this.generateFakeData();
  119. if (more.length > 0) {
  120. this.rows = [...this.rows, ...more];
  121. } else {
  122. this.hasMore = false;
  123. }
  124. this.loading = false;
  125. }, 800);
  126. },
  127. resetFetch() {
  128. this.loading = true;
  129. this.pageNum = 1;
  130. this.hasMore = true;
  131. // Simulate initial load
  132. setTimeout(() => {
  133. this.rows = this.generateFakeData();
  134. this.loading = false;
  135. }, 500);
  136. },
  137. toDetail(item) {
  138. uni.navigateTo({
  139. url: `/traceCodePackages/traceabilityReport/pages/ganmaoling/detail/index?id=${item.id}&name=${encodeURIComponent(item.receiverName)}`
  140. });
  141. }
  142. },
  143. };
  144. </script>
  145. <style scoped>
  146. .detail-page {
  147. display: flex;
  148. flex-direction: column;
  149. height: calc(100vh - 116rpx - env(safe-area-inset-bottom));
  150. box-sizing: border-box;
  151. background: #f3f6f9;
  152. }
  153. .tip {
  154. font-size: 24rpx;
  155. color: #999;
  156. padding: 24rpx;
  157. background: #f3f6f9;
  158. }
  159. .list-scroll {
  160. flex: 1;
  161. height: 0; /* Important for flex expansion */
  162. padding: 0 24rpx;
  163. box-sizing: border-box;
  164. }
  165. .list-container {
  166. padding-bottom: calc(50rpx + env(safe-area-inset-bottom));
  167. padding-left: 24rpx;
  168. padding-right: 24rpx;
  169. }
  170. .card-item {
  171. display: flex;
  172. justify-content: space-between;
  173. align-items: flex-start; /* Align top */
  174. background: #fff;
  175. border-radius: 16rpx;
  176. padding: 30rpx;
  177. margin-bottom: 20rpx;
  178. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  179. }
  180. .left-info {
  181. flex: 1;
  182. margin-right: 20rpx;
  183. }
  184. .row1-name {
  185. font-size: 30rpx;
  186. font-weight: bold;
  187. color: #333;
  188. margin-bottom: 16rpx;
  189. }
  190. .row2-info {
  191. display: flex;
  192. align-items: center;
  193. margin-bottom: 12rpx;
  194. }
  195. .province {
  196. font-size: 26rpx;
  197. color: #666;
  198. margin-right: 20rpx;
  199. }
  200. .level-tag {
  201. font-size: 22rpx;
  202. padding: 4rpx 12rpx;
  203. border-radius: 6rpx;
  204. background: #f0f0f0;
  205. color: #666;
  206. }
  207. .tag-vip {
  208. background: #e6f7ff;
  209. color: #1890ff;
  210. }
  211. .tag-l2 {
  212. background: #f6ffed;
  213. color: #52c41a;
  214. }
  215. .tag-l3 {
  216. background: #fff7e6;
  217. color: #fa8c16;
  218. }
  219. .row3-nature {
  220. font-size: 26rpx;
  221. color: #666;
  222. margin-bottom: 12rpx;
  223. }
  224. .row4-manager {
  225. font-size: 26rpx;
  226. color: #666;
  227. }
  228. .right-info {
  229. display: flex;
  230. align-items: center;
  231. align-self: center; /* Center vertically relative to card */
  232. }
  233. .alert-count {
  234. background: #fff2f0;
  235. color: #ff4d4f;
  236. font-size: 24rpx;
  237. padding: 8rpx 20rpx;
  238. border-radius: 30rpx;
  239. font-weight: bold;
  240. }
  241. .loading-more {
  242. display: flex;
  243. justify-content: center;
  244. align-items: center;
  245. padding: 20rpx 0;
  246. }
  247. .loading-icon {
  248. width: 32rpx;
  249. height: 32rpx;
  250. margin-right: 10rpx;
  251. animation: spin 1s linear infinite;
  252. }
  253. .empty-data {
  254. display: flex;
  255. justify-content: center;
  256. padding-top: 100rpx;
  257. }
  258. .no-more {
  259. text-align: center;
  260. color: #999;
  261. font-size: 24rpx;
  262. padding: 20rpx 0;
  263. }
  264. @keyframes spin {
  265. from { transform: rotate(0deg); }
  266. to { transform: rotate(360deg); }
  267. }
  268. </style>