index.vue 7.6 KB

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