index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <template>
  2. <Water></Water>
  3. <view class="history-page">
  4. <view class="header-section">
  5. <view class="header-title">历史记录</view>
  6. <view class="filter-tabs">
  7. <view class="tab-item" v-for="(tab, index) in timeFilters" :key="index"
  8. :class="{ active: currentFilter === tab.value }" @click="switchFilter(tab.value)">
  9. {{ tab.label }}
  10. </view>
  11. </view>
  12. </view>
  13. <scroll-view class="list-scroll" scroll-y="true" refresher-enabled :refresher-triggered="isRefreshing"
  14. @refresherrefresh="onRefresh">
  15. <view class="list-container">
  16. <view class="date-group" v-for="groupItem in groupedRows" :key="groupItem.date">
  17. <view class="date-group-card">
  18. <view class="group-left">
  19. <!-- <text class="calendar-icon">📅</text> -->
  20. <text class="date-label">{{ groupItem.date }}</text>
  21. </view>
  22. <button class="group-export-btn" @click.stop="handleExportByDate(groupItem.date)">
  23. 导出
  24. </button>
  25. </view>
  26. <view class="card-item" v-for="(item, index) in groupItem.list" :key="index" @click="toDetail(item)">
  27. <view class="card-header">
  28. <view class="header-left">
  29. <text class="index-num">{{ index + 1 }}</text>
  30. <text class="company-name">{{ item.customerName }}</text>
  31. <text class="level-tag" :class="getLevelClass(item.customerLevel)">
  32. {{ item.customerLevel }}
  33. </text>
  34. </view>
  35. <view class="header-right">
  36. <text class="alert-count" v-if="item.totalWarningAmount > 0">{{ item.totalWarningAmount }}次预警</text>
  37. </view>
  38. </view>
  39. <view class="card-body">
  40. <view class="info-grid">
  41. <view class="info-item">
  42. <text class="label">省份</text>
  43. <text class="value">{{ item.customerProvinceName }}</text>
  44. </view>
  45. <view class="info-item">
  46. <text class="label">性质</text>
  47. <text class="value">{{ item.customerCategory }}</text>
  48. </view>
  49. <view class="info-item">
  50. <text class="label">责任人</text>
  51. <text class="value">{{ item.responsibleManager }}</text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view v-if="loading" class="loading-more">
  58. <image class="loading-icon" src="../../../../static/images/loading.png" />
  59. <text class="loading-text">加载中...</text>
  60. </view>
  61. <view v-if="!loading && rows.length === 0" class="empty-data">
  62. <EmptyView text="暂无历史记录" />
  63. </view>
  64. </view>
  65. </scroll-view>
  66. <!-- 蒙层 -->
  67. <view class="report-export-create-modal-mask" v-if="emailModalOpen" @click="closeEmailModal"
  68. @touchmove.stop.prevent></view>
  69. <!-- 邮箱导出弹窗 -->
  70. <view class="report-export-create-modal report-export-create-email-modal"
  71. :class="{ 'report-export-create-modal--open': emailModalOpen }" v-if="emailModalOpen">
  72. <view class="report-export-create-modal-title">
  73. <text>发送至邮箱</text>
  74. <view class="report-export-create-modal-close" @click.stop="closeEmailModal">×</view>
  75. </view>
  76. <view class="report-export-create-modal-body">
  77. <view class="export-date-tip">导出日期:{{ currentExportDate }}</view>
  78. <up-input v-model="emailForm.email" border="none" :customStyle="{
  79. backgroundColor: '#ebf3fb',
  80. height: '80rpx',
  81. paddingLeft: '20rpx',
  82. }" placeholder="请填写邮箱" @input="emailError = false" disabled>
  83. <template #suffix>
  84. <view style="margin-right: 20rpx; color: #666">@999.com.cn</view>
  85. </template>
  86. </up-input>
  87. <text v-if="emailError" class="report-export-error-text">请输入邮箱</text>
  88. </view>
  89. <view class="report-export-create-modal-footer">
  90. <view class="report-export-create-modal-btn cancel-btn" @click.stop="closeEmailModal">取消</view>
  91. <view class="report-export-create-modal-btn confirm-btn" @click.stop="handleSendEmail">发送</view>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. import EmptyView from "../../../../wigets/empty.vue";
  98. import { formatDate } from "../../../../utils/utils.js";
  99. import request from "../../../../request/index.js";
  100. import Water from "@/components/water/water.vue";
  101. export default {
  102. components: {
  103. EmptyView,
  104. Water
  105. },
  106. data() {
  107. return {
  108. isRefreshing: false,
  109. loading: false,
  110. rows: [],
  111. currentFilter: "all",
  112. timeFilters: [
  113. { label: "全部", value: "all" },
  114. { label: "近7天", value: "7" },
  115. { label: "近15天", value: "15" },
  116. { label: "近30天", value: "30" },
  117. ],
  118. emailModalOpen: false,
  119. emailForm: {
  120. email: "",
  121. },
  122. emailError: false,
  123. currentExportDate: "",
  124. };
  125. },
  126. computed: {
  127. groupedRows() {
  128. const groups = {};
  129. this.rows.forEach((item) => {
  130. // 假设接口返回的时间字段为 updatedTime
  131. const fullTime = item.updatedTime || "";
  132. const date = fullTime.split(" ")[0] || fullTime.split("T")[0] || "未知日期";
  133. if (!groups[date]) {
  134. groups[date] = [];
  135. }
  136. groups[date].push(item);
  137. });
  138. // 按日期倒序排列
  139. return Object.keys(groups)
  140. .sort((a, b) => new Date(b.replace(/-/g, "/")) - new Date(a.replace(/-/g, "/")))
  141. .map((date) => ({
  142. date,
  143. list: groups[date],
  144. }));
  145. },
  146. },
  147. created() {
  148. this.resetFetch();
  149. const userEmail = uni.getStorageSync('traceCode_useremail')
  150. this.emailForm.email = userEmail
  151. },
  152. methods: {
  153. formatDate,
  154. getLevelClass(level) {
  155. if (level === "VIP") return "tag-vip";
  156. if (level === "二级") return "tag-l2";
  157. if (level === "三级") return "tag-l3";
  158. return "tag-default";
  159. },
  160. switchFilter(value) {
  161. if (this.currentFilter === value) return;
  162. this.currentFilter = value;
  163. this.resetFetch();
  164. },
  165. fetchList() {
  166. if (this.loading) return;
  167. this.loading = true;
  168. let url = '/report/ganmaoling/list?days=-1';
  169. if (this.currentFilter !== "all") {
  170. url = `/report/ganmaoling/list?days=${this.currentFilter}`
  171. }
  172. request(url, {}, "get").then((res) => {
  173. if (res.code == 200) {
  174. this.rows = res.data || [];
  175. }
  176. this.loading = false;
  177. this.isRefreshing = false;
  178. });
  179. },
  180. async onRefresh() {
  181. this.isRefreshing = true;
  182. this.fetchList();
  183. },
  184. resetFetch() {
  185. this.rows = [];
  186. this.fetchList();
  187. },
  188. toDetail(item) {
  189. uni.navigateTo({
  190. url: `/traceCodePackages/traceabilityReport/pages/ganmaoling/detail/index?name=${encodeURIComponent(item.customerName)}&updatedTime=${item.updatedTime || ""}`,
  191. });
  192. },
  193. handleExportByDate(date) {
  194. this.currentExportDate = date;
  195. this.emailModalOpen = true;
  196. this.emailError = false;
  197. },
  198. closeEmailModal() {
  199. this.emailModalOpen = false;
  200. },
  201. handleSendEmail() {
  202. if (!this.emailForm.email) {
  203. this.emailError = true;
  204. return;
  205. }
  206. uni.showLoading({ title: "发送中..." });
  207. // 根据实际接口文档,如果支持按日期导出,则传日期
  208. request(
  209. `/report/ganmaoling/sendemail`,
  210. {
  211. updatedTime: this.currentExportDate,
  212. emailAddress: this.emailForm.email + "@999.com.cn",
  213. path: "traceabilityReport/pages/ganmaoling/history/index.vue",
  214. },
  215. "post",
  216. ).then((res) => {
  217. uni.hideLoading();
  218. if (res.code == 200) {
  219. uni.showToast({
  220. title: "发送成功",
  221. icon: "success",
  222. });
  223. this.closeEmailModal();
  224. } else {
  225. uni.showToast({
  226. title: res.msg || "发送失败",
  227. icon: "none",
  228. });
  229. }
  230. });
  231. },
  232. },
  233. };
  234. </script>
  235. <style scoped>
  236. .level-tag {
  237. font-size: 20rpx;
  238. padding: 4rpx 12rpx;
  239. border-radius: 8rpx;
  240. white-space: nowrap;
  241. line-height: 1.2;
  242. margin-left: 10rpx;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. }
  247. .header-right {
  248. flex-shrink: 0;
  249. }
  250. .header-left {
  251. flex: 1;
  252. display: flex;
  253. align-items: center;
  254. flex-wrap: wrap;
  255. margin-right: 20rpx;
  256. gap: 12rpx;
  257. }
  258. .index-num {
  259. font-size: 24rpx;
  260. color: #999;
  261. font-family: monospace;
  262. }
  263. .company-name {
  264. font-size: 32rpx;
  265. font-weight: 600;
  266. color: #096dd9;
  267. line-height: 1.4;
  268. text-decoration: underline;
  269. }
  270. .tag-vip {
  271. background: linear-gradient(135deg, #e6f7ff, #bae7ff);
  272. color: #096dd9;
  273. }
  274. .tag-l2 {
  275. background: linear-gradient(135deg, #f6ffed, #d9f7be);
  276. color: #389e0d;
  277. }
  278. .tag-l3 {
  279. background: linear-gradient(135deg, #fff7e6, #ffe7ba);
  280. color: #d46b08;
  281. }
  282. .history-page {
  283. display: flex;
  284. flex-direction: column;
  285. height: 100vh;
  286. background: #f5f7fa;
  287. }
  288. .header-section {
  289. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  290. padding: 30rpx 30rpx 60rpx;
  291. color: #fff;
  292. border-bottom-left-radius: 40rpx;
  293. border-bottom-right-radius: 40rpx;
  294. box-shadow: 0 10rpx 30rpx rgba(24, 144, 255, 0.2);
  295. z-index: 10;
  296. position: relative;
  297. }
  298. .header-title {
  299. font-size: 36rpx;
  300. font-weight: bold;
  301. text-align: center;
  302. margin-bottom: 30rpx;
  303. }
  304. .filter-tabs {
  305. display: flex;
  306. background: rgba(255, 255, 255, 0.2);
  307. border-radius: 16rpx;
  308. padding: 8rpx;
  309. }
  310. .tab-item {
  311. flex: 1;
  312. text-align: center;
  313. font-size: 26rpx;
  314. padding: 12rpx 0;
  315. border-radius: 12rpx;
  316. color: rgba(255, 255, 255, 0.8);
  317. transition: all 0.3s;
  318. }
  319. .tab-item.active {
  320. background: #fff;
  321. color: #1890ff;
  322. font-weight: 600;
  323. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  324. }
  325. .list-scroll {
  326. flex: 1;
  327. height: 0;
  328. margin-top: -40rpx;
  329. z-index: 11;
  330. padding: 0 24rpx;
  331. box-sizing: border-box;
  332. }
  333. .list-container {
  334. padding-top: 50rpx;
  335. padding-bottom: 40rpx;
  336. }
  337. .date-group {
  338. margin-bottom: 40rpx;
  339. }
  340. .date-group-card {
  341. display: flex;
  342. align-items: center;
  343. justify-content: space-between;
  344. background: #fff;
  345. padding: 20rpx 30rpx;
  346. border-radius: 16rpx;
  347. margin-bottom: 20rpx;
  348. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
  349. border-left: 8rpx solid #1890ff;
  350. }
  351. .group-left {
  352. display: flex;
  353. align-items: center;
  354. }
  355. .calendar-icon {
  356. font-size: 32rpx;
  357. margin-right: 16rpx;
  358. }
  359. .date-label {
  360. font-size: 30rpx;
  361. font-weight: 600;
  362. color: #333;
  363. }
  364. .group-export-btn {
  365. margin: 0;
  366. padding: 0 24rpx;
  367. height: 52rpx;
  368. line-height: 50rpx;
  369. font-size: 24rpx;
  370. color: #1890ff;
  371. background: #fff;
  372. border: 2rpx solid #1890ff;
  373. border-radius: 26rpx;
  374. font-weight: 500;
  375. }
  376. .group-export-btn::after {
  377. border: none;
  378. }
  379. .group-export-btn:active {
  380. opacity: 0.7;
  381. transform: scale(0.95);
  382. }
  383. .card-item {
  384. background: #fff;
  385. border-radius: 20rpx;
  386. padding: 30rpx;
  387. margin-bottom: 24rpx;
  388. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
  389. }
  390. .card-header {
  391. display: flex;
  392. justify-content: space-between;
  393. align-items: center;
  394. margin-bottom: 20rpx;
  395. padding-bottom: 20rpx;
  396. border-bottom: 1rpx solid #f5f5f5;
  397. }
  398. .date-text {
  399. font-size: 28rpx;
  400. font-weight: 600;
  401. color: #333;
  402. }
  403. .alert-count {
  404. font-size: 22rpx;
  405. color: #ff4d4f;
  406. background: rgba(255, 77, 79, 0.1);
  407. padding: 4rpx 12rpx;
  408. border-radius: 8rpx;
  409. }
  410. .card-body {
  411. font-size: 26rpx;
  412. }
  413. .row {
  414. display: flex;
  415. margin-bottom: 16rpx;
  416. }
  417. .info-grid {
  418. display: flex;
  419. justify-content: space-between;
  420. }
  421. .info-item {
  422. display: flex;
  423. align-items: center;
  424. width: 48%;
  425. }
  426. .label {
  427. color: #999;
  428. margin-right: 12rpx;
  429. }
  430. .value {
  431. color: #666;
  432. font-weight: 500;
  433. }
  434. .loading-more,
  435. .no-more,
  436. .empty-data {
  437. display: flex;
  438. justify-content: center;
  439. align-items: center;
  440. padding: 30rpx 0;
  441. color: #999;
  442. font-size: 24rpx;
  443. }
  444. .loading-icon {
  445. width: 32rpx;
  446. height: 32rpx;
  447. margin-right: 12rpx;
  448. animation: spin 1s linear infinite;
  449. }
  450. @keyframes spin {
  451. from {
  452. transform: rotate(0deg);
  453. }
  454. to {
  455. transform: rotate(360deg);
  456. }
  457. }
  458. /* 弹窗样式 */
  459. .report-export-create-modal-mask {
  460. position: fixed;
  461. top: 0;
  462. left: 0;
  463. right: 0;
  464. bottom: 0;
  465. background: rgba(0, 0, 0, 0.6);
  466. z-index: 999;
  467. backdrop-filter: blur(2px);
  468. }
  469. .report-export-create-modal {
  470. position: fixed;
  471. z-index: 1000;
  472. background: #fff;
  473. transition: all 0.3s ease;
  474. }
  475. .report-export-create-email-modal {
  476. top: 50%;
  477. left: 50%;
  478. transform: translate(-50%, -50%);
  479. width: 620rpx;
  480. border-radius: 24rpx;
  481. opacity: 0;
  482. visibility: hidden;
  483. overflow: hidden;
  484. }
  485. .report-export-create-email-modal.report-export-create-modal--open {
  486. opacity: 1;
  487. visibility: visible;
  488. }
  489. .report-export-create-modal-title {
  490. padding: 36rpx 32rpx;
  491. font-size: 36rpx;
  492. color: #333;
  493. text-align: center;
  494. font-weight: 600;
  495. border-bottom: 1rpx solid #f0f0f0;
  496. position: relative;
  497. }
  498. .report-export-create-modal-close {
  499. position: absolute;
  500. right: 32rpx;
  501. top: 50%;
  502. transform: translateY(-50%);
  503. font-size: 44rpx;
  504. color: #999;
  505. line-height: 1;
  506. padding: 10rpx;
  507. }
  508. .report-export-create-modal-body {
  509. padding: 40rpx 40rpx 32rpx;
  510. }
  511. .export-date-tip {
  512. font-size: 26rpx;
  513. color: #1890ff;
  514. margin-bottom: 32rpx;
  515. background: #e6f7ff;
  516. padding: 20rpx 24rpx;
  517. border-radius: 12rpx;
  518. border-left: 6rpx solid #1890ff;
  519. font-weight: 500;
  520. }
  521. .report-export-error-text {
  522. font-size: 24rpx;
  523. color: #ff4d4f;
  524. margin-top: 12rpx;
  525. display: block;
  526. }
  527. .report-export-create-modal-footer {
  528. padding: 0 40rpx 48rpx;
  529. display: flex;
  530. justify-content: space-between;
  531. gap: 24rpx;
  532. }
  533. .report-export-create-modal-btn {
  534. height: 88rpx;
  535. line-height: 88rpx;
  536. border-radius: 44rpx;
  537. text-align: center;
  538. font-size: 30rpx;
  539. font-weight: 600;
  540. flex: 1;
  541. margin: 0;
  542. }
  543. .cancel-btn {
  544. background: #f5f7fa;
  545. color: #666;
  546. border: 1rpx solid #e4e7ed;
  547. }
  548. .confirm-btn {
  549. background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  550. color: #fff;
  551. box-shadow: 0 6rpx 16rpx rgba(24, 144, 255, 0.3);
  552. }
  553. </style>