index.vue 6.9 KB

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