index.vue 20 KB

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