index.vue 6.7 KB

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