index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <view class="detail-page">
  3. <view class="tip">数据更新时间:{{ formatDate(new Date().setDate(new Date().getDate() - 1), 'YYYY-MM-DD') || '--' }}</view>
  4. <view class="card" :style="{ height: tableBodyHeight + 'rpx' }">
  5. <scroll-view class="grid-scroll" scroll-y="true" scroll-x="true" :show-scrollbar="false"
  6. :style="{ maxHeight: tableBodyHeight + 'rpx' }" enhanced @scrolltolower="onTableScrollToLower">
  7. <view :style="{
  8. width: '2685rpx',
  9. }">
  10. <view class="grid-header">
  11. <!-- Row 1 -->
  12. <text class="hcell header-group hcell-sticky-left" style="grid-column: 1 / 2; grid-row: 1 / 2; z-index: 12;">该企业累计预警次数</text>
  13. <text class="hcell header-group" style="grid-column: 2 / 7; grid-row: 1 / 2;">客户基础信息</text>
  14. <text class="hcell header-group" style="grid-column: 7 / 16; grid-row: 1 / 2;">流转信息</text>
  15. <!-- Row 2 -->
  16. <text class="hcell hcell-sticky-left" style="grid-column: 1 / 2; grid-row: 2 / 3;">累计预警次数</text>
  17. <text class="hcell" style="grid-column: 2 / 3; grid-row: 2 / 3;">客户名称</text>
  18. <text class="hcell" style="grid-column: 3 / 4; grid-row: 2 / 3;">客户所在省份</text>
  19. <text class="hcell" style="grid-column: 4 / 5; grid-row: 2 / 3;">客户级别</text>
  20. <text class="hcell" style="grid-column: 5 / 6; grid-row: 2 / 3;">客户性质</text>
  21. <text class="hcell" style="grid-column: 6 / 7; grid-row: 2 / 3;">责任经理</text>
  22. <text class="hcell" style="grid-column: 7 / 8; grid-row: 2 / 3;">收货企业名称</text>
  23. <text class="hcell" style="grid-column: 8 / 9; grid-row: 2 / 3;">收货企业所在省份</text>
  24. <text class="hcell" style="grid-column: 9 / 10; grid-row: 2 / 3;">单据时间</text>
  25. <text class="hcell" style="grid-column: 10 / 11; grid-row: 2 / 3;">单据类型</text>
  26. <text class="hcell" style="grid-column: 11 / 12; grid-row: 2 / 3;">产品名称</text>
  27. <text class="hcell" style="grid-column: 12 / 13; grid-row: 2 / 3;">批号</text>
  28. <text class="hcell" style="grid-column: 13 / 14; grid-row: 2 / 3;">发货地</text>
  29. <text class="hcell" style="grid-column: 14 / 15; grid-row: 2 / 3;">数量</text>
  30. <text class="hcell" style="grid-column: 15 / 16; grid-row: 2 / 3;">链路</text>
  31. </view>
  32. <view v-if="!loading && rows.length > 0" class="grid-body">
  33. <view v-for="(row, idx) in rows" :key="idx" class="grow">
  34. <!-- Common Columns (merged) -->
  35. <view v-if="row.flags.common" class="gcell gcol-1 sticky-left gspan"
  36. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.alertCount }}</view>
  37. <view v-if="row.flags.common" class="gcell gcol-2 gspan"
  38. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.customerName }}</view>
  39. <view v-if="row.flags.common" class="gcell gcol-3 gspan"
  40. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.customerProvince }}</view>
  41. <view v-if="row.flags.common" class="gcell gcol-4 gspan"
  42. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.customerLevel }}</view>
  43. <view v-if="row.flags.common" class="gcell gcol-5 gspan"
  44. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.customerNature }}</view>
  45. <view v-if="row.flags.common" class="gcell gcol-6 gspan"
  46. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.manager }}</view>
  47. <view v-if="row.flags.common" class="gcell gcol-7 gspan"
  48. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.receiverName }}</view>
  49. <view v-if="row.flags.common" class="gcell gcol-8 gspan"
  50. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.receiverProvince }}</view>
  51. <view v-if="row.flags.common" class="gcell gcol-9 gspan"
  52. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.docTime }}</view>
  53. <view v-if="row.flags.common" class="gcell gcol-10 gspan"
  54. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.docType }}</view>
  55. <view v-if="row.flags.common" class="gcell gcol-11 gspan"
  56. :style="{ gridRowEnd: 'span ' + row.spans.common }">{{ row.productName }}</view>
  57. <!-- Detail Columns (not merged) -->
  58. <view class="gcell gcol-12">{{ row.batchNo }}</view>
  59. <view class="gcell gcol-13">{{ row.sourceRegion }}</view>
  60. <view class="gcell gcol-14">{{ row.quantity }}</view>
  61. <!-- Link Column (merged) -->
  62. <view v-if="row.flags.common" class="gcell gcol-15 gspan"
  63. :style="{ gridRowEnd: 'span ' + row.spans.common, borderRight: 'none' }">{{ row.traceLink }}</view>
  64. </view>
  65. <view class="gcell gcell-full loading-row" v-if="hasMore">
  66. <view class="loading-wrapper">
  67. <image class="loading-icon" src="../../../static/images/loading.png" />
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </scroll-view>
  73. <view v-if="loading" class="loading-wrap">
  74. <view class="loading-row">
  75. <view class="loading-wrapper">
  76. <image class="loading-icon" src="../../../static/images/loading.png" />
  77. </view>
  78. </view>
  79. </view>
  80. <view v-if="showEmptyData" class="empty-data">
  81. <EmptyView text="无相关数据" />
  82. </view>
  83. </view>
  84. <view class="fab-btn" @click="downloadTable">
  85. <text class="fab-text">下载表格</text>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import EmptyView from "../../../wigets/empty.vue";
  91. import request, { downloadFile } from '../../../request/index.js'
  92. import { formatDate } from '../../../utils/utils.js'
  93. export default {
  94. components: {
  95. EmptyView,
  96. },
  97. data() {
  98. return {
  99. isLoading: false,
  100. tableBodyHeight: 0,
  101. baseRowHeight: 76,
  102. loading: false,
  103. rows: [],
  104. totalCount: 0,
  105. fetchLoading: false,
  106. hasMore: false,
  107. pageNum: 1,
  108. pageSize: 15,
  109. };
  110. },
  111. created() {
  112. this.tableBodyHeight = 14 * 80;
  113. // this.fetchList();
  114. this.generateFakeData();
  115. },
  116. computed: {
  117. showEmptyData() {
  118. if (this.loading) return false;
  119. if (this.rows.length === 0) {
  120. return true;
  121. }
  122. return false;
  123. },
  124. },
  125. methods: {
  126. formatDate,
  127. generateFakeData() {
  128. const fakeRows = [];
  129. const baseCommonData = {
  130. customerProvince: '广东',
  131. customerLevel: '一级',
  132. customerNature: '商业',
  133. manager: '张三',
  134. receiverProvince: '广西',
  135. docTime: '2023-01-01',
  136. docType: '销售出库',
  137. productName: '感冒灵颗粒',
  138. traceLink: 'A -> B -> C'
  139. };
  140. for (let i = 0; i < 15; i++) {
  141. // 模拟一个单据有 1-3 个批号明细
  142. const detailCount = Math.floor(Math.random() * 3) + 1;
  143. const details = [];
  144. for (let j = 0; j < detailCount; j++) {
  145. details.push({
  146. batchNo: 'BATCH' + i + '-' + j,
  147. sourceRegion: j % 2 === 0 ? '华南片区' : '华东片区',
  148. quantity: 100 + j * 50
  149. });
  150. }
  151. // 公共数据
  152. const commonData = {
  153. ...baseCommonData,
  154. alertCount: String(i + 1), // 显式转为字符串
  155. customerName: '测试客户' + i,
  156. receiverName: '测试收货企业' + i,
  157. };
  158. // 生成扁平化行数据
  159. details.forEach((detail, index) => {
  160. fakeRows.push({
  161. ...commonData,
  162. ...detail,
  163. spans: {
  164. common: index === 0 ? detailCount : 0 // 首行 span 为明细总数,其他为 0
  165. },
  166. flags: {
  167. common: index === 0 // 仅首行显示公共列
  168. }
  169. });
  170. });
  171. }
  172. this.rows = fakeRows;
  173. this.loading = false;
  174. },
  175. // computeBlackLeafCount(node) {
  176. // if (!node || !node.dataList || !node.dataList.length) return 1;
  177. // let sum = 0;
  178. // node.dataList.forEach((c) => {
  179. // sum += this.computeBlackLeafCount(c);
  180. // });
  181. // node.leafCount = sum;
  182. // return sum;
  183. // },
  184. // buildBlackRows(data) {
  185. // const res = [];
  186. // (data || []).forEach((companyNode) => {
  187. // const cLeaves = this.computeBlackLeafCount(companyNode);
  188. // let companyStarted = false;
  189. // (companyNode.dataList || []).forEach((expNode) => {
  190. // const eLeaves = this.computeBlackLeafCount(expNode);
  191. // let exporterStarted = false;
  192. // const groups = {};
  193. // (expNode.dataList || []).forEach((item) => {
  194. // const key = item.currentENTName || "";
  195. // if (!groups[key]) groups[key] = [];
  196. // groups[key].push(item);
  197. // });
  198. // Object.keys(groups).forEach((prodName) => {
  199. // const group = groups[prodName];
  200. // let productStarted = false;
  201. // group.forEach((batch) => {
  202. // res.push({
  203. // entName: companyNode.entName,
  204. // orgCode: companyNode.orgCode,
  205. // time: batch.time,
  206. // physicName: expNode.physicName,
  207. // currentENTName: prodName,
  208. // fromRegionName: batch.fromRegionName,
  209. // fromQuantity: batch.fromQuantity,
  210. // produceBatchNo: batch.produceBatchNo,
  211. // tracCode: batch.tracCode,
  212. // toQuantity: batch.toQuantity,
  213. // spans: {
  214. // entName: companyStarted ? 0 : cLeaves,
  215. // physicName: exporterStarted ? 0 : eLeaves,
  216. // currentENTName: productStarted ? 0 : group.length,
  217. // },
  218. // flags: {
  219. // entName: !companyStarted,
  220. // physicName: !exporterStarted,
  221. // currentENTName: !productStarted,
  222. // },
  223. // });
  224. // companyStarted = true;
  225. // exporterStarted = true;
  226. // productStarted = true;
  227. // });
  228. // });
  229. // });
  230. // });
  231. // return res;
  232. // },
  233. onTableScrollToLower(e) {
  234. if (e?.detail?.direction === 'right') return
  235. // if (this.isLoading) return;
  236. // if (this.rows.length >= this.totalCount) return;
  237. // this.isLoading = true;
  238. // const remain = this.totalCount - this.rows.length;
  239. // const toAdd = Math.min(15, remain);
  240. // setTimeout(() => {
  241. // const more = this.rows.slice(0, toAdd);
  242. // this.rows = this.rows.concat(more);
  243. // this.isLoading = false;
  244. // }, 800);
  245. // this.fetchList();
  246. },
  247. resetFetch() {
  248. // this.loading = true;
  249. // this.rows = [];
  250. // this.totalCount = 0;
  251. // this.fetchLoading = false;
  252. // this.hasMore = true;
  253. // this.pageNum = 1;
  254. // this.fetchList();
  255. this.generateFakeData();
  256. },
  257. fetchList() {
  258. if (this.fetchLoading || !this.hasMore) return;
  259. this.fetchLoading = true;
  260. let url = `/report/getBlacklistReport`;
  261. try {
  262. request(url, {
  263. pageNum: this.pageNum,
  264. pageSize: this.pageSize,
  265. path: '/blacklist/index.vue',
  266. }).then(res => {
  267. if (res.code == 200) {
  268. const { total, list } = res.data || {};
  269. this.totalCount = total || 0;
  270. let _list = [];
  271. if (Array.isArray(list)) {
  272. // _list = this.buildBlackRows(list);
  273. }
  274. this.rows = [...this.rows, ..._list];
  275. if (this.rows.length < this.totalCount) {
  276. this.hasMore = true;
  277. this.pageNum++;
  278. } else {
  279. this.hasMore = false;
  280. }
  281. }
  282. this.isLoading = false;
  283. this.loading = false;
  284. this.fetchLoading = false;
  285. }).catch(() => {
  286. this.isLoading = false;
  287. this.loading = false;
  288. this.fetchLoading = false;
  289. })
  290. } catch (res) {
  291. this.isLoading = false;
  292. this.loading = false;
  293. this.fetchLoading = false;
  294. }
  295. },
  296. downloadTable() {
  297. downloadFile('', {
  298. id: '',
  299. path: '/blacklist/index.vue',
  300. })
  301. },
  302. },
  303. };
  304. </script>
  305. <style scoped>
  306. .detail-page {
  307. box-sizing: border-box;
  308. padding: 24rpx;
  309. position: relative;
  310. background: #f3f6f9;
  311. padding-bottom: calc(50rpx + env(safe-area-inset-bottom));
  312. }
  313. .tip {
  314. font-size: 24rpx;
  315. color: #999;
  316. margin-bottom: 30rpx;
  317. }
  318. .card {
  319. position: relative;
  320. margin-top: 12rpx;
  321. font-size: 30rpx;
  322. overflow: hidden;
  323. }
  324. .grid-header {
  325. position: sticky;
  326. top: 0;
  327. z-index: 10;
  328. display: grid;
  329. grid-template-columns: 200rpx 220rpx 160rpx 140rpx 140rpx 140rpx 220rpx 160rpx 200rpx 140rpx 200rpx 180rpx 160rpx 140rpx 300rpx;
  330. grid-auto-rows: 76rpx;
  331. }
  332. .grid-header .hcell {
  333. background: #eaf2ff;
  334. font-weight: bold;
  335. color: #2c69ff;
  336. border-bottom: 1rpx solid #d0d7de;
  337. border-right: 1rpx solid #d0d7de;
  338. }
  339. .header-group {
  340. display: flex;
  341. align-items: center;
  342. justify-content: center;
  343. background: #dae8ff !important;
  344. }
  345. .hcell {
  346. height: 100%;
  347. display: flex;
  348. align-items: center;
  349. justify-content: center;
  350. text-align: center;
  351. font-size: 26rpx;
  352. padding: 0 10rpx;
  353. }
  354. .hcell:last-child {
  355. border-right: none;
  356. }
  357. .hcell-sticky-left {
  358. position: sticky;
  359. left: 0;
  360. z-index: 11;
  361. }
  362. .grid-scroll {
  363. border-radius: 16rpx;
  364. margin-top: 8rpx;
  365. overflow: hidden;
  366. }
  367. .grid-body {
  368. background: #fff;
  369. display: grid;
  370. grid-template-columns: 200rpx 220rpx 160rpx 140rpx 140rpx 140rpx 220rpx 160rpx 200rpx 140rpx 200rpx 180rpx 160rpx 140rpx 300rpx;
  371. grid-auto-rows: auto;
  372. }
  373. .grow {
  374. display: contents;
  375. }
  376. .gcell {
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. border-bottom: 1rpx solid #d0d7de;
  381. border-right: 1rpx solid #d0d7de;
  382. background: #fff;
  383. color: #333;
  384. padding: 0 10rpx;
  385. text-align: center;
  386. line-height: 40rpx;
  387. min-height: 76rpx;
  388. font-size: 26rpx;
  389. word-break: break-all;
  390. }
  391. .gcell:last-child {
  392. /* border-right: none; */
  393. }
  394. .gcell.gcell-full {
  395. grid-column: 1 / -1;
  396. background: transparent;
  397. border: none;
  398. }
  399. .gspan {
  400. background: #fff;
  401. }
  402. .gcol-1 {
  403. grid-column: 1;
  404. }
  405. .gcol-2 {
  406. grid-column: 2;
  407. }
  408. .gcol-3 {
  409. grid-column: 3;
  410. }
  411. .gcol-4 {
  412. grid-column: 4;
  413. }
  414. .gcol-5 {
  415. grid-column: 5;
  416. }
  417. .gcol-6 {
  418. grid-column: 6;
  419. }
  420. .gcol-7 {
  421. grid-column: 7;
  422. }
  423. .gcol-8 {
  424. grid-column: 8;
  425. }
  426. .gcol-9 {
  427. grid-column: 9;
  428. }
  429. .gcol-10 {
  430. grid-column: 10;
  431. }
  432. .gcol-11 {
  433. grid-column: 11;
  434. }
  435. .gcol-12 {
  436. grid-column: 12;
  437. }
  438. .gcol-13 {
  439. grid-column: 13;
  440. }
  441. .gcol-14 {
  442. grid-column: 14;
  443. }
  444. .gcol-15 {
  445. grid-column: 15;
  446. }
  447. .sticky-left {
  448. position: sticky;
  449. left: 0;
  450. z-index: 9;
  451. background: #fff;
  452. }
  453. .loading-row {
  454. justify-content: flex-start;
  455. }
  456. .loading-wrapper {
  457. position: sticky;
  458. top: 50%;
  459. left: 0;
  460. width: calc(100vw - 48rpx);
  461. height: 76rpx;
  462. display: flex;
  463. align-items: center;
  464. justify-content: center;
  465. }
  466. .loading-icon {
  467. width: 40rpx;
  468. height: 40rpx;
  469. animation: spin 1s linear infinite;
  470. }
  471. @keyframes spin {
  472. from {
  473. transform: rotate(0deg);
  474. }
  475. to {
  476. transform: rotate(360deg);
  477. }
  478. }
  479. .empty-data,
  480. .loading-wrap {
  481. position: absolute;
  482. left: 0;
  483. top: 85rpx;
  484. z-index: 999;
  485. width: 100%;
  486. background-color: #fff;
  487. border-bottom-left-radius: 16rpx;
  488. border-bottom-right-radius: 16rpx;
  489. }
  490. .fab-btn {
  491. position: fixed;
  492. bottom: calc(50rpx + env(safe-area-inset-bottom));
  493. right: 30rpx;
  494. background-color: #007aff;
  495. color: #ffffff;
  496. padding: 20rpx 40rpx;
  497. border-radius: 50rpx;
  498. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2);
  499. z-index: 100;
  500. }
  501. .fab-text {
  502. font-size: 28rpx;
  503. font-weight: bold;
  504. }
  505. </style>