index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <Water></Water>
  3. <view class="detail-page">
  4. <view class="tabs">
  5. <view class="tab" v-for="(t, i) in tabs" :key="t.label" :class="{ active: category == t.value }"
  6. :style="{ opacity: isLoading ? 0.5 : 1 }" @click="selectTab(t)">
  7. {{ t.label }}
  8. </view>
  9. </view>
  10. <view class="grid-scroll">
  11. <scroll-view v-show="category == 1" scroll-y class="grid-scroll-view" @scrolltolower="onTableScrollToLower">
  12. <view>
  13. <view v-if="!loading && rows.length > 0" class="card-list">
  14. <view class="company-card" v-for="(company, cIdx) in rows" :key="cIdx">
  15. <view class="company-header" @click="toggleExpand(company)">
  16. <view class="company-title">
  17. <text class="company-name">{{ company.name }}</text>
  18. <view class="company-products" v-if="company.products && company.products.length">
  19. <text class="company-product-item" v-for="(prod, pIdx) in company.products" :key="pIdx">
  20. {{ prod.name }} {{ prod.spec }}
  21. </text>
  22. </view>
  23. <!-- <text class="company-total">总数量:{{ company.totalQty }}</text> -->
  24. </view>
  25. <uni-icons :type="company.expanded ? 'up' : 'down'" size="20" color="#999"></uni-icons>
  26. </view>
  27. <view v-if="company.expanded" class="company-body">
  28. <view class="exporter-section" v-for="(exp, eIdx) in company.exporters" :key="eIdx">
  29. <view class="exporter-title" @click="toggleSubExpand(exp)">
  30. <text>{{ category == 1 ? '出库方' : '入库方' }}:{{ exp.name }}</text>
  31. <uni-icons :type="exp.expanded ? 'up' : 'down'" size="16" color="#666"></uni-icons>
  32. </view>
  33. <view v-if="exp.expanded" class="product-group" v-for="(pg, pIdx) in exp.products" :key="pIdx">
  34. <!-- Product Header Removed as requested, info is now in company header -->
  35. <!-- <view class="product-header">
  36. <text class="product-name">{{ pg.name }}</text>
  37. <text class="product-spec">{{ pg.spec }}</text>
  38. </view> -->
  39. <scroll-view scroll-x class="batch-scroll">
  40. <view class="batch-table">
  41. <view class="batch-header-row">
  42. <text class="th-cell col-batch">批号</text>
  43. <text class="th-cell col-region">货源地区</text>
  44. <text class="th-cell col-qty">货源数量</text>
  45. <text class="th-cell col-qty">终端到达数量</text>
  46. <text class="th-cell col-time">出库时间</text>
  47. <text class="th-cell col-code">追溯码抽样</text>
  48. </view>
  49. <view class="batch-row" v-for="(batch, bIdx) in pg.batches" :key="bIdx">
  50. <text class="td-cell col-batch">{{ batch.produceBatchNo }}</text>
  51. <text class="td-cell col-region">{{ batch.regionName }}</text>
  52. <text class="td-cell col-qty">{{ batch.fromQty }}</text>
  53. <text class="td-cell col-qty">{{ batch.toQty }}</text>
  54. <text class="td-cell col-time">{{ batch.billTime }}</text>
  55. <text class="td-cell col-code copyable-code" @click="copyTraceCode(batch.tracCode)">
  56. {{ batch.tracCode }}
  57. </text>
  58. </view>
  59. </view>
  60. </scroll-view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="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. <scroll-view v-show="category == 2" class="grid-scroll" scroll-y="true" scroll-x="true" :show-scrollbar="false"
  74. enhanced @scrolltolower="onTableScrollToLower">
  75. <view>
  76. <view v-if="!_loading && _rows.length > 0" class="card-list">
  77. <view class="company-card" v-for="(company, cIdx) in _rows" :key="cIdx">
  78. <view class="company-header" @click="toggleExpand(company)">
  79. <view class="company-title">
  80. <text class="company-name">{{ company.name }}</text>
  81. <view class="company-products" v-if="company.products && company.products.length">
  82. <text class="company-product-item" v-for="(prod, pIdx) in company.products" :key="pIdx">
  83. {{ prod.name }} {{ prod.spec }}
  84. </text>
  85. </view>
  86. <!-- <text class="company-total">总数量:{{ company.totalQty }}</text> -->
  87. </view>
  88. <uni-icons :type="company.expanded ? 'up' : 'down'" size="20" color="#999"></uni-icons>
  89. </view>
  90. <view v-if="company.expanded" class="company-body">
  91. <view class="exporter-section" v-for="(exp, eIdx) in company.exporters" :key="eIdx">
  92. <view class="exporter-title" @click="toggleSubExpand(exp)">
  93. <text>{{ category == 1 ? '出库方' : '入库方' }}:{{ exp.name }}</text>
  94. <uni-icons :type="exp.expanded ? 'up' : 'down'" size="16" color="#666"></uni-icons>
  95. </view>
  96. <view v-if="exp.expanded" class="product-group" v-for="(pg, pIdx) in exp.products" :key="pIdx">
  97. <scroll-view scroll-x class="batch-scroll">
  98. <view class="batch-table">
  99. <view class="batch-header-row">
  100. <text class="th-cell col-batch">批号</text>
  101. <text class="th-cell col-region">货源地区</text>
  102. <text class="th-cell col-qty">货源数量</text>
  103. <text class="th-cell col-qty">终端到达数量</text>
  104. <text class="th-cell col-time">入库时间</text>
  105. <text class="th-cell col-code">追溯码抽样</text>
  106. </view>
  107. <view class="batch-row" v-for="(batch, bIdx) in pg.batches" :key="bIdx">
  108. <text class="td-cell col-batch">{{ batch.produceBatchNo }}</text>
  109. <text class="td-cell col-region">{{ batch.regionName }}</text>
  110. <text class="td-cell col-qty">{{ batch.fromQty }}</text>
  111. <text class="td-cell col-qty">{{ batch.toQty }}</text>
  112. <text class="td-cell col-time">{{ batch.billTime }}</text>
  113. <text class="td-cell col-code copyable-code" @click="copyTraceCode(batch.tracCode)">
  114. {{ batch.tracCode }}
  115. </text>
  116. </view>
  117. </view>
  118. </scroll-view>
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. <view class="loading-row" v-if="_hasMore">
  124. <view class="loading-wrapper">
  125. <image class="loading-icon" src="../../../../static/images/loading.png" />
  126. </view>
  127. </view>
  128. </view>
  129. </view>
  130. </scroll-view>
  131. <view v-if="isLoading" class="loading-wrap">
  132. <view class="loading-row">
  133. <view class="loading-wrapper">
  134. <image class="loading-icon" src="../../../../static/images/loading.png" />
  135. </view>
  136. </view>
  137. </view>
  138. <view v-if="showEmptyData" class="empty-data">
  139. <EmptyView text="无相关数据" />
  140. </view>
  141. </view>
  142. </view>
  143. <BottomScrollTip :text="'左右滑动表格查看更多内容'" />
  144. </template>
  145. <script>
  146. import EmptyView from "../../../../wigets/empty.vue";
  147. import BottomScrollTip from "../../../../wigets/BottomScrollTip.vue";
  148. import Water from "@/components/water/water.vue";
  149. import request from "../../../../request/index.js";
  150. import { formatDate } from "../../../../utils/utils.js";
  151. export default {
  152. components: {
  153. EmptyView,
  154. BottomScrollTip,
  155. Water,
  156. },
  157. data() {
  158. return {
  159. taskId: "",
  160. tableBodyHeight: 0,
  161. baseRowHeight: 76,
  162. tabs: [
  163. {
  164. label: "药品购进",
  165. value: "1",
  166. },
  167. {
  168. label: "药品销售",
  169. value: "2",
  170. },
  171. ],
  172. category: "1",
  173. loading: true,
  174. rows: [],
  175. totalCount: 0,
  176. fetchLoading: false,
  177. hasMore: true,
  178. pageNum: 1,
  179. pageSize: 10,
  180. _loading: true,
  181. _rows: [],
  182. _totalCount: 0,
  183. _fetchLoading: false,
  184. _hasMore: true,
  185. _pageNum: 1,
  186. _pageSize: 10,
  187. };
  188. },
  189. onLoad(options) {
  190. const title =
  191. options && options.title ? decodeURIComponent(options.title) : "报表详情";
  192. this.taskId = options && options.id ? options.id : "";
  193. uni.setNavigationBarTitle({ title });
  194. this.tableBodyHeight = 14 * 80;
  195. this.fetchList();
  196. },
  197. computed: {
  198. isLoading() {
  199. return (
  200. (this.loading && this.category == 1) ||
  201. (this._loading && this.category == 2)
  202. );
  203. },
  204. showEmptyData() {
  205. if (this.isLoading) return false;
  206. if (
  207. (this.category == 1 && this.rows.length === 0) ||
  208. (this.category == 2 && this._rows.length === 0)
  209. )
  210. return true;
  211. return false;
  212. },
  213. },
  214. methods: {
  215. selectTab(t) {
  216. if (this.isLoading) return;
  217. this.category = t.value;
  218. this.fetchList();
  219. },
  220. computeLeafCount(node) {
  221. if (!node || !node.enterpriseList || !node.enterpriseList.length)
  222. return 1;
  223. let sum = 0;
  224. node.enterpriseList.forEach((c) => {
  225. sum += this.computeLeafCount(c);
  226. });
  227. node.leafCount = sum;
  228. return sum;
  229. },
  230. processData(list) {
  231. const res = [];
  232. if (!list || !list.length) return res;
  233. list.forEach((company) => {
  234. const companyNode = {
  235. name: company.enterpriseName,
  236. totalQty: 0,
  237. expanded: false, // Default collapsed
  238. exporters: [],
  239. products: [], // Collect unique products here
  240. };
  241. const uniqueProducts = {};
  242. (company.enterpriseList || []).forEach((exp) => {
  243. const expNode = {
  244. name: exp.fromEntName,
  245. expanded: false, // Default collapsed
  246. products: [],
  247. };
  248. const productGroups = {};
  249. (exp.enterpriseList || []).forEach((item) => {
  250. const key = (item.physicName || "") + "|" + (item.pkgSpec || "");
  251. // Collect global unique products for the company header
  252. if (!uniqueProducts[key]) {
  253. uniqueProducts[key] = {
  254. name: item.physicName,
  255. spec: item.pkgSpec || "",
  256. };
  257. }
  258. if (!productGroups[key]) {
  259. productGroups[key] = {
  260. name: item.physicName,
  261. spec: item.pkgSpec || "",
  262. batches: [],
  263. };
  264. }
  265. const { minBillTime, maxBillTime } = item;
  266. const billTime = `${formatDate(minBillTime, "YYYY-MM-DD")}——${formatDate(maxBillTime, "YYYY-MM-DD")}`;
  267. const qty = Number(item.toQty) || 0;
  268. companyNode.totalQty += qty;
  269. productGroups[key].batches.push({
  270. ...item,
  271. billTime,
  272. });
  273. });
  274. Object.values(productGroups).forEach((pg) => {
  275. expNode.products.push(pg);
  276. });
  277. companyNode.exporters.push(expNode);
  278. });
  279. companyNode.products = Object.values(uniqueProducts);
  280. res.push(companyNode);
  281. });
  282. return res;
  283. },
  284. toggleExpand(item) {
  285. this.$set(item, "expanded", !item.expanded);
  286. },
  287. toggleSubExpand(item) {
  288. this.$set(item, "expanded", !item.expanded);
  289. },
  290. copyTraceCode(code) {
  291. const text = String(code || "").trim();
  292. if (!text) {
  293. uni.showToast({ title: "无可复制内容", icon: "none" });
  294. return;
  295. }
  296. uni.setClipboardData({
  297. data: text,
  298. success: () => {
  299. uni.showToast({ title: "追溯码已复制", icon: "none" });
  300. },
  301. });
  302. },
  303. onTableScrollToLower(e) {
  304. if (e?.detail?.direction === "right") return;
  305. // if (this.isLoading) return;
  306. // if (this.rows.length >= this.totalCount) return;
  307. // this.isLoading = true;
  308. // const remain = this.totalCount - this.rows.length;
  309. // const toAdd = Math.min(15, remain);
  310. // setTimeout(() => {
  311. // const more = this.rows.slice(0, toAdd);
  312. // this.rows = this.rows.concat(more);
  313. // this.isLoading = false;
  314. // }, 800);
  315. this.fetchList();
  316. },
  317. fetchList() {
  318. let obj = {
  319. pageNum: "pageNum",
  320. pageSize: "pageSize",
  321. totalCount: "totalCount",
  322. hasMore: "hasMore",
  323. fetchLoading: "fetchLoading",
  324. rows: "rows",
  325. loading: "loading",
  326. };
  327. if (this.category == 2) {
  328. obj.pageNum = "_pageNum";
  329. obj.pageSize = "_pageSize";
  330. obj.totalCount = "_totalCount";
  331. obj.hasMore = "_hasMore";
  332. obj.fetchLoading = "_fetchLoading";
  333. obj.rows = "_rows";
  334. obj.loading = "_loading";
  335. }
  336. if (this[obj.fetchLoading] || !this[obj.hasMore]) return;
  337. this[obj.fetchLoading] = true;
  338. let url = `/report/getTaskTableData`;
  339. try {
  340. request(url, {
  341. id: this.taskId,
  342. category: this.category,
  343. pageNum: this[obj.pageNum],
  344. pageSize: this[obj.pageSize],
  345. path: "/reportExport/detail/index.vue",
  346. }).then((res) => {
  347. if (res.code == 200) {
  348. const { total, list } = res.data || {};
  349. this[obj.totalCount] = total || 0;
  350. let _list = [];
  351. if (Array.isArray(list)) {
  352. _list = this.processData(list);
  353. }
  354. this[obj.rows] = [...this[obj.rows], ..._list];
  355. if (this[obj.rows].length < this[obj.totalCount]) {
  356. this[obj.hasMore] = true;
  357. this[obj.pageNum]++;
  358. } else {
  359. this[obj.hasMore] = false;
  360. }
  361. }
  362. this[obj.fetchLoading] = false;
  363. this[obj.loading] = false;
  364. });
  365. } catch (res) {
  366. console.log(res);
  367. this[obj.fetchLoading] = false;
  368. this[obj.loading] = false;
  369. }
  370. // this.rows = [];
  371. // setTimeout(() => {
  372. // const n = Math.min(15, this.totalCount);
  373. // this.rows = this.buildRows(this.genHierData()).slice(0, n);
  374. // this.fetchLoading = false;
  375. // }, 1000);
  376. },
  377. },
  378. };
  379. </script>
  380. <style scoped>
  381. .detail-page {
  382. box-sizing: border-box;
  383. padding: 24rpx;
  384. position: relative;
  385. min-height: 100vh;
  386. background: #f3f6f9;
  387. padding-bottom: calc(50rpx + env(safe-area-inset-bottom));
  388. }
  389. .grid-scroll {
  390. padding-bottom: 80rpx;
  391. }
  392. .tabs {
  393. display: flex;
  394. align-items: center;
  395. background: #fff;
  396. border-radius: 90rpx;
  397. padding: 10rpx;
  398. margin-bottom: 30rpx;
  399. }
  400. .tab {
  401. flex: 1;
  402. height: 70rpx;
  403. display: flex;
  404. align-items: center;
  405. justify-content: center;
  406. padding: 0 24rpx;
  407. border-radius: 70rpx;
  408. font-size: 28rpx;
  409. color: #333;
  410. }
  411. .tab+.tab {
  412. margin-left: 12rpx;
  413. }
  414. .tab.active {
  415. background: #2c69ff;
  416. color: #fff;
  417. }
  418. .card {
  419. position: relative;
  420. margin-top: 12rpx;
  421. font-size: 30rpx;
  422. overflow: hidden;
  423. }
  424. /* New Card Styles */
  425. .card-list {
  426. padding: 24rpx;
  427. background: #f5f7fa;
  428. min-height: 100vh;
  429. }
  430. .company-card {
  431. background: #fff;
  432. border-radius: 16rpx;
  433. margin-bottom: 24rpx;
  434. overflow: hidden;
  435. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  436. }
  437. .company-header {
  438. padding: 24rpx 30rpx;
  439. background: #fff;
  440. display: flex;
  441. justify-content: space-between;
  442. align-items: center;
  443. border-bottom: 1rpx solid #f0f0f0;
  444. }
  445. .company-title {
  446. display: flex;
  447. flex-direction: column;
  448. }
  449. .company-name {
  450. font-size: 32rpx;
  451. font-weight: bold;
  452. color: #333;
  453. margin-bottom: 8rpx;
  454. }
  455. .company-products {
  456. margin-bottom: 8rpx;
  457. }
  458. .company-product-item {
  459. font-size: 26rpx;
  460. color: #666;
  461. margin-right: 16rpx;
  462. display: inline-block;
  463. }
  464. .company-total {
  465. font-size: 24rpx;
  466. color: #999;
  467. }
  468. .company-body {
  469. background: #fff;
  470. padding: 0 24rpx 24rpx;
  471. }
  472. .exporter-section {
  473. margin-top: 24rpx;
  474. border: 1rpx solid #eef0f4;
  475. border-radius: 12rpx;
  476. overflow: hidden;
  477. }
  478. .exporter-title {
  479. background: #f8f9fb;
  480. padding: 16rpx 24rpx;
  481. font-size: 28rpx;
  482. font-weight: 600;
  483. color: #333;
  484. display: flex;
  485. justify-content: space-between;
  486. align-items: center;
  487. border-bottom: 1rpx solid #eef0f4;
  488. }
  489. .product-group {
  490. padding: 0;
  491. }
  492. .product-header {
  493. padding: 16rpx 24rpx;
  494. display: flex;
  495. justify-content: space-between;
  496. font-size: 26rpx;
  497. color: #666;
  498. border-bottom: 1rpx solid #f0f0f0;
  499. }
  500. .batch-scroll {
  501. width: 100%;
  502. }
  503. .batch-table {
  504. min-width: 1410rpx;
  505. }
  506. .batch-header-row {
  507. display: flex;
  508. background: #f7f9fc;
  509. color: #2c69ff;
  510. }
  511. .batch-row {
  512. display: flex;
  513. border-bottom: 1rpx solid #f0f0f0;
  514. }
  515. .batch-row:nth-child(even) {
  516. background-color: #f7f9fc;
  517. }
  518. .batch-row:last-child {
  519. border-bottom: none;
  520. }
  521. .th-cell {
  522. padding: 16rpx 10rpx;
  523. font-size: 24rpx;
  524. text-align: center;
  525. flex-shrink: 0;
  526. font-weight: 600;
  527. }
  528. .td-cell {
  529. padding: 16rpx 10rpx;
  530. font-size: 24rpx;
  531. color: #333;
  532. text-align: center;
  533. flex-shrink: 0;
  534. word-break: break-all;
  535. display: flex;
  536. align-items: center;
  537. justify-content: center;
  538. }
  539. .col-batch {
  540. width: 220rpx;
  541. }
  542. .col-region {
  543. width: 180rpx;
  544. }
  545. .col-qty {
  546. width: 140rpx;
  547. }
  548. .col-time {
  549. width: 340rpx;
  550. }
  551. .col-code {
  552. width: 280rpx;
  553. }
  554. .copyable-code {
  555. color: #2c69ff;
  556. }
  557. .loading-row {
  558. padding: 24rpx;
  559. display: flex;
  560. justify-content: center;
  561. }
  562. .loading-wrapper {
  563. position: sticky;
  564. top: 50%;
  565. left: 0;
  566. width: calc(100vw - 48rpx);
  567. height: 76rpx;
  568. display: flex;
  569. align-items: center;
  570. justify-content: center;
  571. }
  572. .loading-icon {
  573. width: 40rpx;
  574. height: 40rpx;
  575. animation: spin 1s linear infinite;
  576. }
  577. @keyframes spin {
  578. from {
  579. transform: rotate(0deg);
  580. }
  581. to {
  582. transform: rotate(360deg);
  583. }
  584. }
  585. .empty-data,
  586. .loading-wrap {
  587. position: absolute;
  588. left: 0;
  589. top: 280rpx;
  590. z-index: 91;
  591. width: 100%;
  592. background-color: transparent;
  593. border-bottom-left-radius: 16rpx;
  594. border-bottom-right-radius: 16rpx;
  595. }
  596. .empty-data {
  597. top: 280rpx;
  598. display: flex;
  599. align-items: center;
  600. justify-content: center;
  601. background-color: transparent;
  602. }
  603. </style>