index.vue 7.5 KB

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