index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <Water></Water>
  3. <view class="nav" :style="{ paddingTop: statusBarHeight + 'px' }">
  4. <text class="nav-back" :style="{ top: statusBarHeight + 'px' }" @click="onBack"></text>
  5. <view class="nav-title">客户扫码率</view>
  6. </view>
  7. <view class="page" @click="closeDropdown">
  8. <view class="header-card" :style="{ paddingTop: statusBarHeight + 60 + 'px' }">
  9. <view class="meta">
  10. <view class="dot"></view>
  11. <text class="meta-text">等级:{{
  12. scanType == 1 ? "VIP" : scanType == 2 ? "二级" : "三级"
  13. }}客户</text>
  14. </view>
  15. <view class="meta">
  16. <view class="dot"></view>
  17. <text class="meta-text">片区:{{ regionName }}</text>
  18. </view>
  19. <view class="meta">
  20. <view class="dot"></view>
  21. <text class="meta-text">品种:{{ physicName || "全品种" }}</text>
  22. </view>
  23. <view class="meta">
  24. <view class="dot"></view>
  25. <text class="meta-text">时间区间:{{ dateRange }}</text>
  26. </view>
  27. <view class="selector-wrap" @click.stop>
  28. <input class="selector-input" v-model="customerInput.customerName" placeholder="选择客户" @focus="openDropdown"
  29. @input="onInputChange" />
  30. <view class="selector-arrow" :class="{ open: dropdownOpen }" @click="toggleDropdown"></view>
  31. <view class="dropdown" v-show="dropdownOpen" @click.stop>
  32. <scroll-view v-if="customers.length && !customerLoading" scroll-y :style="{ maxHeight: '300rpx' }"
  33. lower-threshold="20" @scrolltolower="getCustomerInfo">
  34. <view class="dropdown-item" v-for="(c, i) in customers" :key="i" @click="selectCustomer(c)">{{
  35. c.customerName || "--" }}</view>
  36. <view v-if="customerHasMore" class="customer-loading-wrap">
  37. <image src="../../../../static/images/loading.png" mode="scaleToFill" class="loading-icon" />
  38. </view>
  39. </scroll-view>
  40. <view v-else-if="customerLoading" class="customer-loading-wrap">
  41. <image src="../../../../static/images/loading.png" mode="scaleToFill" class="loading-icon" />
  42. </view>
  43. <view v-else class="dropdown-item">暂无数据</view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="card">
  48. <ScanRateTable :api="`/bills/getScanRateDetail`" :columns="columns" :tableBodyHeight="tableBodyHeight"
  49. :pageSize="20" :showHeader="false" summaryBold="true" tableType="customerDetail" :params="queryParams"
  50. :summaryFontColor="'#2c69ff'" />
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import ScanRateTable from "../wigets/ScanRateTable.vue";
  56. import Water from "@/components/water/water.vue";
  57. import request from "../../../../request/index.js";
  58. export default {
  59. components: {
  60. ScanRateTable,
  61. Water,
  62. },
  63. data() {
  64. return {
  65. customerLevel: "",
  66. rangeType: "",
  67. regionCode: "",
  68. drugEntBaseInfoId: "",
  69. scanType: "",
  70. statusBarHeight: 20,
  71. regionName: "",
  72. physicName: "",
  73. customerPage: 1,
  74. customerPageSize: 20,
  75. customerTotal: null,
  76. customerHasMore: true,
  77. customerLoading: false,
  78. customers: [],
  79. customerInput: { customerName: "" },
  80. customerDebounceTimer: null,
  81. selectedCustomer: "",
  82. dropdownOpen: false,
  83. totalCount: 30,
  84. isLoading: false,
  85. list: [],
  86. windowHeight: 0,
  87. columns: [
  88. {
  89. key: "custemerName",
  90. title: "客户名称",
  91. underline: false,
  92. fixed: false,
  93. width: "",
  94. },
  95. {
  96. key: "inScanRate",
  97. title: "入库扫码率",
  98. fixed: false,
  99. width: "",
  100. unit: "%",
  101. },
  102. {
  103. key: "outScanRate",
  104. title: "出库扫码率",
  105. fixed: false,
  106. width: "",
  107. unit: "%",
  108. },
  109. {
  110. key: "selfExaminationRate",
  111. title: "自验证率",
  112. fixed: false,
  113. width: "",
  114. unit: "%",
  115. },
  116. ],
  117. };
  118. },
  119. onLoad(options) {
  120. const info = uni.getSystemInfoSync();
  121. this.statusBarHeight = info.statusBarHeight || 20;
  122. this.windowHeight = info.windowHeight;
  123. // this.list = this.genRows(Math.min(10, this.totalCount));
  124. this.rangeType = options.type || 1;
  125. this.regionCode = options.regionCode || "";
  126. this.drugEntBaseInfoId = options.drugEntBaseInfoId || "";
  127. this.scanType = options.scanType || "1";
  128. this.physicName = decodeURIComponent(options.physicName || "");
  129. this.regionName = decodeURIComponent(options.regionName || "");
  130. this.customerLevel =
  131. this.scanType == 1 ? "VIP" : this.scanType == 2 ? "二级" : "三级";
  132. this.getCustomerInfo();
  133. },
  134. watch: {
  135. "customerInput.customerName": {
  136. handler(newVal, oldVal) {
  137. if (!newVal || newVal !== oldVal) {
  138. if (this.customerDebounceTimer)
  139. clearTimeout(this.customerDebounceTimer);
  140. this.customerDebounceTimer = setTimeout(() => {
  141. this.customerPage = 1;
  142. this.customers = [];
  143. this.customerHasMore = true;
  144. this.getCustomerInfo();
  145. }, 500);
  146. }
  147. },
  148. deep: true,
  149. },
  150. },
  151. computed: {
  152. dateRange() {
  153. const t = Number(this.rangeType) || 1;
  154. const now = new Date();
  155. const pad = (n) => (n < 10 ? "0" + n : "" + n);
  156. const fmt = (d) =>
  157. `${d.getFullYear()}.${pad(d.getMonth() + 1)}.${pad(d.getDate())}`;
  158. let start;
  159. let end;
  160. if (t === 2) {
  161. const y = now.getFullYear();
  162. const m = now.getMonth();
  163. start = new Date(y, m, 1);
  164. end = new Date(y, m + 1, 0);
  165. } else if (t === 3) {
  166. const y = now.getFullYear();
  167. const m = now.getMonth();
  168. start = new Date(y, m - 1, 1);
  169. end = new Date(y, m, 0);
  170. } else if (t === 4) {
  171. end = now;
  172. start = new Date(now.getTime() - 59 * 24 * 60 * 60 * 1000);
  173. } else {
  174. end = now;
  175. start = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000);
  176. }
  177. return `${fmt(start)}-${fmt(end)}`;
  178. },
  179. queryParams() {
  180. return {
  181. type: this.rangeType,
  182. regionCode: this.regionCode,
  183. drugEntBaseInfoId: this.drugEntBaseInfoId,
  184. customerName: this.customerInput?.customerName,
  185. scanType: this.scanType,
  186. levelType: this.customerLevel,
  187. physicName: this.physicName,
  188. };
  189. },
  190. tableBodyHeight() {
  191. // const rowHeight = 76; // rpx
  192. // if (this.totalCount >= 9) return `${rowHeight * 8.5}rpx`;
  193. // return "auto";
  194. const info = uni.getSystemInfoSync();
  195. const pixelRatio = 750 / info.windowWidth;
  196. const windowHeightRpx = this.windowHeight * pixelRatio;
  197. // Header card approx height: (statusBar + 60)px + content(approx 356rpx)
  198. const topPx = this.statusBarHeight + 60;
  199. const topRpx = topPx * pixelRatio + 356 + 24 + 24; // + margins
  200. const headerHeight = 80; // Table header
  201. return windowHeightRpx - topRpx - headerHeight - 20; // -20 safety
  202. },
  203. },
  204. methods: {
  205. getCustomerInfo() {
  206. if (!this.customerHasMore || this.customerLoading) return;
  207. this.customerLoading = true;
  208. request("/customer/info/getCustomerInfo", {
  209. customerName: this.customerInput?.customerName,
  210. name: this.physicName,
  211. pageNum: this.customerPage,
  212. pageSize: this.customerPageSize,
  213. customerLevel: this.customerLevel,
  214. provinceCode: this.regionCode,
  215. path: "/traceabilityReport/pages/customerScanningRate/detail/index.vue",
  216. }).then((res) => {
  217. if (res.code == 200) {
  218. const _data = res.data || {};
  219. this.customerTotal = _data.total;
  220. if (this.customerTotal <= this.customers.length) {
  221. this.customerHasMore = false;
  222. return;
  223. } else {
  224. const list = Array.isArray(_data.list) ? _data.list : [];
  225. this.customers = [...this.customers, ...list];
  226. if (this.customerTotal <= this.customers.length) {
  227. this.customerHasMore = false;
  228. } else {
  229. this.customerPage++;
  230. this.customerHasMore = true;
  231. }
  232. // }
  233. }
  234. }
  235. setTimeout(() => {
  236. this.customerLoading = false;
  237. }, 200);
  238. });
  239. },
  240. openDropdown() {
  241. this.dropdownOpen = true;
  242. },
  243. toggleDropdown() {
  244. this.dropdownOpen = !this.dropdownOpen;
  245. },
  246. onInputChange(e) {
  247. const v = e?.detail?.value ?? this.customerInput;
  248. this.customerInput.customerName = v;
  249. },
  250. selectCustomer(c) {
  251. this.selectedCustomer = c;
  252. this.customerInput = c;
  253. this.dropdownOpen = false;
  254. },
  255. closeDropdown() {
  256. this.dropdownOpen = false;
  257. },
  258. onBack() {
  259. try {
  260. uni.navigateBack();
  261. } catch (e) { }
  262. },
  263. onTableScrollToLower() {
  264. if (this.isLoading) return;
  265. if (this.list.length >= this.totalCount) return;
  266. this.isLoading = true;
  267. const remain = this.totalCount - this.list.length;
  268. const toAdd = Math.min(10, remain);
  269. setTimeout(() => {
  270. const more = this.genRows(toAdd);
  271. this.list = this.list.concat(more);
  272. this.isLoading = false;
  273. }, 800);
  274. },
  275. genRows(n) {
  276. const res = [];
  277. const regions = [
  278. "山东医药",
  279. "江苏医药",
  280. "浙江医药",
  281. "广东医药",
  282. "湖南医药",
  283. "湖北医药",
  284. ];
  285. const base = this.list.length;
  286. for (let i = 0; i < n; i++) {
  287. const name = regions[(base + i) % regions.length];
  288. res.push({ region: name, outRate: "0%", inRate: "0%" });
  289. }
  290. return res;
  291. },
  292. },
  293. };
  294. </script>
  295. <style scoped>
  296. .nav {
  297. position: fixed;
  298. top: 0;
  299. left: 0;
  300. right: 0;
  301. height: 44px;
  302. background-color: #2c69ff;
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. }
  307. .nav-title {
  308. font-size: 36rpx;
  309. color: #fff;
  310. font-weight: 700;
  311. }
  312. .nav-back {
  313. position: absolute;
  314. left: 40rpx;
  315. top: 12rpx;
  316. width: 20rpx;
  317. height: 20rpx;
  318. color: #fff;
  319. border-left: 3rpx solid #fff;
  320. border-bottom: 3rpx solid #fff;
  321. transform: rotate(45deg) translateY(56rpx);
  322. margin-left: 40rpx;
  323. }
  324. .page {
  325. height: 100vh;
  326. }
  327. .card {
  328. margin: 24rpx;
  329. background: #fff;
  330. border-radius: 16rpx;
  331. font-size: 32rpx;
  332. }
  333. /* .table-header {
  334. display: flex;
  335. background: #eaf2ff;
  336. font-weight: bold;
  337. color: #2c69ff;
  338. border-top-left-radius: 16rpx;
  339. border-top-right-radius: 16rpx;
  340. }
  341. .table-body {
  342. margin-top: 8rpx;
  343. }
  344. .row {
  345. display: flex;
  346. align-items: center;
  347. }
  348. .row:last-child {
  349. border-bottom: none;
  350. }
  351. .cell {
  352. flex: 1;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. height: 76rpx;
  357. } */
  358. .loading-row {
  359. justify-content: center;
  360. }
  361. .loading-wrapper {
  362. width: 100%;
  363. height: 76rpx;
  364. display: flex;
  365. align-items: center;
  366. justify-content: center;
  367. }
  368. .loading-icon {
  369. width: 40rpx;
  370. height: 40rpx;
  371. animation: spin 1s linear infinite;
  372. }
  373. @keyframes spin {
  374. from {
  375. transform: rotate(0deg);
  376. }
  377. to {
  378. transform: rotate(360deg);
  379. }
  380. }
  381. /* .total-row {
  382. font-weight: bold;
  383. color: #2c69ff;
  384. } */
  385. .header-card {
  386. background: #2c69ff;
  387. border-bottom-left-radius: 32rpx;
  388. border-bottom-right-radius: 32rpx;
  389. padding: 36rpx;
  390. color: #fff;
  391. }
  392. .meta {
  393. display: flex;
  394. align-items: center;
  395. margin: 14rpx 0;
  396. }
  397. .dot {
  398. width: 8rpx;
  399. height: 8rpx;
  400. border-radius: 50%;
  401. background: #fff;
  402. margin-right: 20rpx;
  403. }
  404. .meta-text {
  405. font-size: 32rpx;
  406. }
  407. .selector-wrap {
  408. position: relative;
  409. margin-top: 16rpx;
  410. }
  411. .selector-input {
  412. width: 100%;
  413. height: 64rpx;
  414. border-radius: 32rpx;
  415. background: #fff;
  416. color: #333;
  417. padding: 0 72rpx 0 30rpx;
  418. box-sizing: border-box;
  419. font-size: 28rpx;
  420. }
  421. .selector-arrow {
  422. position: absolute;
  423. right: 24rpx;
  424. bottom: 25rpx;
  425. width: 16rpx;
  426. height: 16rpx;
  427. border: 5rpx solid #2c69ff;
  428. border-top: none;
  429. border-left: none;
  430. transform-origin: 50% 50%;
  431. transform: rotate(45deg);
  432. transition: transform 0.2s;
  433. }
  434. .selector-arrow.open {
  435. bottom: 18rpx;
  436. transform: rotate(225deg);
  437. }
  438. .dropdown {
  439. position: absolute;
  440. left: 0;
  441. right: 0;
  442. top: 70rpx;
  443. background: #fff;
  444. border: 1rpx solid #eef0f4;
  445. border-radius: 12rpx;
  446. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
  447. z-index: 10;
  448. max-height: none;
  449. }
  450. .dropdown-item {
  451. padding: 16rpx 24rpx;
  452. font-size: 28rpx;
  453. color: #333;
  454. }
  455. .dropdown-item+.dropdown-item {
  456. border-top: 1rpx solid #f0f2f5;
  457. }
  458. .customer-loading-wrap {
  459. width: 100%;
  460. height: 70rpx;
  461. display: flex;
  462. align-items: center;
  463. justify-content: center;
  464. }
  465. </style>