index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <Water></Water>
  3. <view class="scan-range-page">
  4. <view class="loading-page" v-if="getLoading()">
  5. <image class="loading-icon" src="../../../static/images/loading.png" />
  6. </view>
  7. <scroll-view v-else class="content" scroll-y="true" @scrolltolower="onScrollToLower">
  8. <view class="item" v-for="(item, i) in companyList" :key="i" @click="toggle(i)">
  9. <view class="item-header">
  10. <text class="item-title">{{ i + 1 }}.&nbsp;{{ item.entName || "" }}</text>
  11. <view style="color: #2c69ff">{{ expanded[i] ? "收起" : "展开" }}</view>
  12. </view>
  13. <scroll-view class="item-collapse" scroll-y="true" :style="{
  14. height: getCollapseHeight(i),
  15. }" @scrolltolower="getDrugInfoNameList(i)">
  16. <view class="cv-item" v-for="(d, di) in products[i]" :key="'drug-' + di">
  17. <text class="cv-index">{{ di + 1 }}</text>
  18. <text class="cv-label">药品名称:</text>
  19. <text class="cv-value">{{ d.physicName || "" }}</text>
  20. </view>
  21. </scroll-view>
  22. </view>
  23. <view class="loading-row" v-if="companyHasMore">
  24. <view class="loading-wrapper">
  25. <image class="loading-icon" src="../../../static/images/loading.png" />
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. </template>
  31. <script>
  32. import request from '../../../request/index.js'
  33. import { getPaginatedList } from '../../../utils/utils.js'
  34. import Water from "@/components/water/water.vue";
  35. export default {
  36. components: {
  37. Water,
  38. },
  39. data() {
  40. return {
  41. companyList: [],
  42. companyPageNum: 1,
  43. companyPageSize: 20,
  44. companyTotalCount: 0,
  45. companyHasMore: true,
  46. companyLoading: false,
  47. allCompanies: [],
  48. loading: true,
  49. expanded: {},
  50. products: {},
  51. productPages: [],
  52. };
  53. },
  54. onLoad() {
  55. this.fetchInitial();
  56. },
  57. methods: {
  58. getDrugInfoNameList(i) {
  59. // if (!this.products[i]) this.products[i] = [];
  60. // if (
  61. // this.products[i].length >= this.companyList[i].drugInfoNameList?.length
  62. // ) {
  63. // return;
  64. // }
  65. // const size = 10;
  66. // const page = (this.productPages[i] || 0) + 1;
  67. // const start = (page - 1) * size;
  68. // const end = Math.min(
  69. // start + size,
  70. // this.companyList[i].drugInfoNameList?.length || 0
  71. // );
  72. // this.products[i] = [
  73. // ...(this.products[i] || []),
  74. // ...(this.companyList[i].drugInfoNameList?.slice(start, end) || []),
  75. // ];
  76. // this.productPages[i] = page;
  77. const {page: nextPage, data: nextData} = getPaginatedList({
  78. page: this.productPages[i] || 0,
  79. initData: this.companyList[i].drugInfoNameList || [],
  80. data: this.products[i] || [],
  81. })
  82. this.productPages[i] = nextPage;
  83. this.products[i] = nextData;
  84. },
  85. getCollapseHeight(i) {
  86. return this.expanded[i]
  87. ? Math.min(7.3 * 70, this.companyList[i].drugInfoNameList.length * 70) +
  88. "rpx"
  89. : "0";
  90. },
  91. getLoading() {
  92. return this.loading;
  93. },
  94. fetchInitial() {
  95. // this.genMockAll();
  96. // this.companyTotalCount = this.allCompanies.length;
  97. this.fetchCustomers();
  98. },
  99. fetchCustomers() {
  100. if (!this.companyHasMore || this.companyLoading) return;
  101. this.companyLoading = true;
  102. // const start = (this.companyPageNum - 1) * this.companyPageSize;
  103. // const next = this.allCompanies.slice(start, start + this.companyPageSize);
  104. // this.companyList = [...this.companyList, ...next];
  105. // if (this.companyList.length < this.companyTotalCount) {
  106. // this.companyPageNum++;
  107. // this.companyHasMore = true;
  108. // } else {
  109. // this.companyHasMore = false;
  110. // }
  111. // this.companyLoading = false;
  112. // this.loading = false;
  113. request('/customer/info/getEnterpriseData', {
  114. pageNum: this.companyPageNum,
  115. pageSize: this.companyPageSize,
  116. path: '/traceabilityCodeQuery/pages/scanRange/index.vue',
  117. }).then(res => {
  118. if (res.code == 200) {
  119. const { total, list } = res.data || {};
  120. this.companyTotalCount = total || 0;
  121. this.companyList = Array.isArray(list)
  122. ? [...this.companyList, ...list]
  123. : [...this.companyList];
  124. if (this.companyList.length < this.companyTotalCount) {
  125. this.companyPageNum++;
  126. this.companyHasMore = true;
  127. } else {
  128. this.companyHasMore = false;
  129. }
  130. this.companyList.forEach((item, i) => {
  131. this.getDrugInfoNameList(i);
  132. });
  133. }
  134. this.companyLoading = false;
  135. this.loading = false;
  136. })
  137. },
  138. onScrollToLower() {
  139. this.fetchCustomers();
  140. },
  141. toggle(i) {
  142. this.$set(this.expanded, i, !this.expanded[i]);
  143. },
  144. genMockAll() {
  145. const companies = [];
  146. const names = [
  147. "华润三九医药股份有限公司",
  148. "华润三九(枣庄)药业有限公司",
  149. "华润三九(南昌)药业有限公司",
  150. "合肥华润神鹿药业有限公司",
  151. "杭州华润老桐君药业有限公司",
  152. "吉林三九金复康药业有限公司",
  153. "华润三九(郴州)制药有限公司",
  154. ];
  155. const drugs = [
  156. "益气清肺颗粒6袋",
  157. "维E胶囊30*100mg",
  158. "右美沙芬糖浆180",
  159. "赐多康西洋参片40",
  160. "麝香3*27*2",
  161. "牦牛骨钙VD片60",
  162. "畅生源胶丸120",
  163. "多种矿物质口服液7支",
  164. "三七提取物软胶囊30粒",
  165. "拉曼布拉氏益生菌20",
  166. "维生素AD滴剂700U*50",
  167. "锌钙特铝塑盒120",
  168. ];
  169. for (let i = 0; i < 80; i++) {
  170. const dn = [];
  171. const count = 3 + (i % 4);
  172. for (let j = 0; j < count; j++) {
  173. dn.push({ physicName: drugs[(i + j) % drugs.length] });
  174. }
  175. companies.push({ customerName: names[i % names.length], drugs: dn });
  176. }
  177. this.allCompanies = companies;
  178. },
  179. },
  180. };
  181. </script>
  182. <style>
  183. .scan-range-page {
  184. box-sizing: border-box;
  185. padding: 24rpx;
  186. height: 100vh;
  187. background: #f3f6f9;
  188. }
  189. .content {
  190. max-height: calc(100vh - 48rpx - 92rpx - 20rpx - env(safe-area-inset-bottom));
  191. background: #fff;
  192. border-radius: 16rpx;
  193. }
  194. .item {
  195. padding: 10rpx 20rpx;
  196. border-bottom: 1rpx solid #eef0f4;
  197. }
  198. .item-header {
  199. display: flex;
  200. align-items: center;
  201. justify-content: space-between;
  202. line-height: 60rpx;
  203. }
  204. .item-title {
  205. font-size: 30rpx;
  206. color: #333;
  207. }
  208. .item-collapse {
  209. margin-top: 12rpx;
  210. height: 0;
  211. transition: height 0.3s ease-in-out;
  212. }
  213. .cv-item {
  214. padding: 16rpx;
  215. display: flex;
  216. align-items: center;
  217. color: #666;
  218. }
  219. .cv-index {
  220. width: 24rpx;
  221. height: 24rpx;
  222. line-height: 24rpx;
  223. font-size: 18rpx;
  224. text-align: center;
  225. border-radius: 50%;
  226. margin-right: 8rpx;
  227. border: 1rpx solid #666;
  228. }
  229. .cv-label {
  230. width: 140rpx;
  231. font-size: 28rpx;
  232. }
  233. .cv-value {
  234. width: 0;
  235. flex: 1;
  236. font-size: 28rpx;
  237. overflow: hidden;
  238. text-overflow: ellipsis;
  239. white-space: nowrap;
  240. }
  241. .loading-page {
  242. width: 100%;
  243. height: 200rpx;
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. }
  248. .loading-row {
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. padding: 20rpx;
  253. }
  254. .loading-wrapper {
  255. width: 100%;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. }
  260. .loading-icon {
  261. width: 50rpx;
  262. height: 50rpx;
  263. animation: spin 1s linear infinite;
  264. }
  265. @keyframes spin {
  266. from {
  267. transform: rotate(0deg);
  268. }
  269. to {
  270. transform: rotate(360deg);
  271. }
  272. }
  273. </style>