index.vue 20 KB

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