index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <view class="history-page">
  3. <view class="header-section">
  4. <view class="header-title">历史记录</view>
  5. <view class="filter-tabs">
  6. <view
  7. class="tab-item"
  8. v-for="(tab, index) in timeFilters"
  9. :key="index"
  10. :class="{ active: currentFilter === tab.value }"
  11. @click="switchFilter(tab.value)"
  12. >
  13. {{ tab.label }}
  14. </view>
  15. </view>
  16. </view>
  17. <scroll-view
  18. class="list-scroll"
  19. scroll-y="true"
  20. refresher-enabled
  21. :refresher-triggered="isRefreshing"
  22. @refresherrefresh="onRefresh"
  23. @scrolltolower="onLoadMore"
  24. >
  25. <view class="list-container">
  26. <view
  27. class="card-item"
  28. v-for="(item, index) in displayRows"
  29. :key="index"
  30. >
  31. <view class="card-header">
  32. <view class="header-left">
  33. <text class="date-text">{{ item.date }}</text>
  34. </view>
  35. <view class="header-right">
  36. <text class="alert-count" v-if="item.alertCount > 0"
  37. >{{ item.alertCount }}次预警</text
  38. >
  39. </view>
  40. </view>
  41. <view class="card-body">
  42. <view class="row">
  43. <text class="label">公司名称:</text>
  44. <text class="value">{{ item.receiverName }}</text>
  45. <text
  46. class="level-tag"
  47. :class="getLevelClass(item.customerLevel)"
  48. >
  49. {{ item.customerLevel }}
  50. </text>
  51. </view>
  52. <view class="info-grid">
  53. <view class="info-item">
  54. <text class="label">省份</text>
  55. <text class="value">{{ item.receiverProvince }}</text>
  56. </view>
  57. <view class="info-item">
  58. <text class="label">性质</text>
  59. <text class="value">{{ item.customerNature }}</text>
  60. </view>
  61. <view class="info-item">
  62. <text class="label">责任人</text>
  63. <text class="value">{{ item.responderName }}</text>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="loading-more" v-if="loading">
  69. <image
  70. class="loading-icon"
  71. src="../../../../static/images/loading.png"
  72. />
  73. <text class="loading-text">加载中...</text>
  74. </view>
  75. <view v-if="!loading && displayRows.length === 0" class="empty-data">
  76. <EmptyView text="暂无历史记录" />
  77. </view>
  78. <view v-if="!hasMore && displayRows.length > 0" class="no-more">
  79. <text>没有更多数据了</text>
  80. </view>
  81. </view>
  82. </scroll-view>
  83. </view>
  84. </template>
  85. <script>
  86. import EmptyView from "../../../../wigets/empty.vue";
  87. import { formatDate } from "../../../../utils/utils.js";
  88. const PROVINCES = ["北京市", "上海市", "广东省", "浙江省", "江苏省"];
  89. export default {
  90. components: {
  91. EmptyView,
  92. },
  93. data() {
  94. return {
  95. isRefreshing: false,
  96. loading: false,
  97. rows: [],
  98. hasMore: true,
  99. pageNum: 1,
  100. pageSize: 20,
  101. currentFilter: "all",
  102. timeFilters: [
  103. { label: "全部", value: "all" },
  104. { label: "近7天", value: "7" },
  105. { label: "近15天", value: "15" },
  106. { label: "近30天", value: "30" },
  107. ],
  108. };
  109. },
  110. computed: {
  111. displayRows() {
  112. return this.rows;
  113. },
  114. },
  115. created() {
  116. this.resetFetch();
  117. },
  118. methods: {
  119. formatDate,
  120. getLevelClass(level) {
  121. if (level === "VIP") return "tag-vip";
  122. if (level === "二级") return "tag-l2";
  123. if (level === "三级") return "tag-l3";
  124. return "tag-default";
  125. },
  126. switchFilter(value) {
  127. if (this.currentFilter === value) return;
  128. this.currentFilter = value;
  129. this.resetFetch();
  130. },
  131. generateFakeData() {
  132. const newRows = [];
  133. const count = 15;
  134. const today = new Date();
  135. for (let i = 0; i < count; i++) {
  136. const date = new Date(today);
  137. // Random date within last 30 days
  138. const daysBack = Math.floor(Math.random() * 30);
  139. // Filter logic simulation
  140. if (this.currentFilter !== "all") {
  141. const limit = parseInt(this.currentFilter);
  142. if (daysBack > limit) continue;
  143. }
  144. date.setDate(date.getDate() - daysBack);
  145. newRows.push({
  146. id: Math.random().toString(36).substr(2, 9),
  147. date: formatDate(date, "YYYY-MM-DD"),
  148. receiverName: `历史收货企业${Math.floor(Math.random() * 100)}有限公司`,
  149. receiverProvince:
  150. PROVINCES[Math.floor(Math.random() * PROVINCES.length)],
  151. customerNature: Math.random() > 0.5 ? "协议客户" : "非协议客户",
  152. alertCount: Math.floor(Math.random() * 5),
  153. customerLevel: ["VIP", "二级", "三级"][Math.floor(Math.random() * 3)],
  154. });
  155. }
  156. // Sort by date descending
  157. newRows.sort((a, b) => new Date(b.date) - new Date(a.date));
  158. return newRows;
  159. },
  160. async onRefresh() {
  161. this.isRefreshing = true;
  162. this.pageNum = 1;
  163. this.hasMore = true;
  164. setTimeout(() => {
  165. this.rows = this.generateFakeData();
  166. this.isRefreshing = false;
  167. }, 1000);
  168. },
  169. onLoadMore() {
  170. if (this.loading || !this.hasMore) return;
  171. this.loading = true;
  172. this.pageNum++;
  173. setTimeout(() => {
  174. const more = this.generateFakeData();
  175. if (more.length > 0) {
  176. this.rows = [...this.rows, ...more];
  177. } else {
  178. this.hasMore = false;
  179. }
  180. this.loading = false;
  181. }, 800);
  182. },
  183. resetFetch() {
  184. this.loading = true;
  185. this.pageNum = 1;
  186. this.hasMore = true;
  187. this.rows = [];
  188. setTimeout(() => {
  189. this.rows = this.generateFakeData();
  190. this.loading = false;
  191. }, 500);
  192. },
  193. },
  194. };
  195. </script>
  196. <style scoped>
  197. .level-tag {
  198. font-size: 20rpx;
  199. padding: 4rpx 12rpx;
  200. border-radius: 8rpx;
  201. white-space: nowrap;
  202. line-height: 1.2;
  203. margin-left: 10rpx;
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. }
  208. .header-right {
  209. flex-shrink: 0;
  210. }
  211. .tag-vip {
  212. background: linear-gradient(135deg, #e6f7ff, #bae7ff);
  213. color: #096dd9;
  214. }
  215. .tag-l2 {
  216. background: linear-gradient(135deg, #f6ffed, #d9f7be);
  217. color: #389e0d;
  218. }
  219. .tag-l3 {
  220. background: linear-gradient(135deg, #fff7e6, #ffe7ba);
  221. color: #d46b08;
  222. }
  223. .history-page {
  224. display: flex;
  225. flex-direction: column;
  226. height: 100vh;
  227. background: #f5f7fa;
  228. }
  229. .header-section {
  230. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  231. padding: 30rpx 30rpx 60rpx;
  232. color: #fff;
  233. border-bottom-left-radius: 40rpx;
  234. border-bottom-right-radius: 40rpx;
  235. box-shadow: 0 10rpx 30rpx rgba(24, 144, 255, 0.2);
  236. z-index: 10;
  237. position: relative;
  238. }
  239. .header-title {
  240. font-size: 36rpx;
  241. font-weight: bold;
  242. text-align: center;
  243. margin-bottom: 30rpx;
  244. }
  245. .filter-tabs {
  246. display: flex;
  247. background: rgba(255, 255, 255, 0.2);
  248. border-radius: 16rpx;
  249. padding: 8rpx;
  250. }
  251. .tab-item {
  252. flex: 1;
  253. text-align: center;
  254. font-size: 26rpx;
  255. padding: 12rpx 0;
  256. border-radius: 12rpx;
  257. color: rgba(255, 255, 255, 0.8);
  258. transition: all 0.3s;
  259. }
  260. .tab-item.active {
  261. background: #fff;
  262. color: #1890ff;
  263. font-weight: 600;
  264. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  265. }
  266. .list-scroll {
  267. flex: 1;
  268. height: 0;
  269. margin-top: -40rpx;
  270. z-index: 11;
  271. padding: 0 24rpx;
  272. box-sizing: border-box;
  273. }
  274. .list-container {
  275. padding-bottom: 40rpx;
  276. }
  277. .card-item {
  278. background: #fff;
  279. border-radius: 20rpx;
  280. padding: 30rpx;
  281. margin-bottom: 24rpx;
  282. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
  283. }
  284. .card-header {
  285. display: flex;
  286. justify-content: space-between;
  287. align-items: center;
  288. margin-bottom: 20rpx;
  289. padding-bottom: 20rpx;
  290. border-bottom: 1rpx solid #f5f5f5;
  291. }
  292. .date-text {
  293. font-size: 28rpx;
  294. font-weight: 600;
  295. color: #333;
  296. }
  297. .alert-count {
  298. font-size: 22rpx;
  299. color: #ff4d4f;
  300. background: rgba(255, 77, 79, 0.1);
  301. padding: 4rpx 12rpx;
  302. border-radius: 8rpx;
  303. }
  304. .card-body {
  305. font-size: 26rpx;
  306. }
  307. .row {
  308. display: flex;
  309. margin-bottom: 16rpx;
  310. }
  311. .info-grid {
  312. display: flex;
  313. justify-content: space-between;
  314. }
  315. .info-item {
  316. display: flex;
  317. align-items: center;
  318. width: 48%;
  319. }
  320. .label {
  321. color: #999;
  322. margin-right: 12rpx;
  323. }
  324. .value {
  325. color: #666;
  326. font-weight: 500;
  327. }
  328. .loading-more,
  329. .no-more,
  330. .empty-data {
  331. display: flex;
  332. justify-content: center;
  333. align-items: center;
  334. padding: 30rpx 0;
  335. color: #999;
  336. font-size: 24rpx;
  337. }
  338. .loading-icon {
  339. width: 32rpx;
  340. height: 32rpx;
  341. margin-right: 12rpx;
  342. animation: spin 1s linear infinite;
  343. }
  344. @keyframes spin {
  345. from {
  346. transform: rotate(0deg);
  347. }
  348. to {
  349. transform: rotate(360deg);
  350. }
  351. }
  352. </style>