index.vue 12 KB

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