index.vue 19 KB

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