index.vue 20 KB

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