index.vue 7.2 KB

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