index.vue 8.0 KB

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