index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. :showHeader="false" bodyFontColor="#000" summaryBold="true" tableType="customerDetail" :params="queryParams" />
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import ScanRateTable from "../wigets/ScanRateTable.vue";
  55. import Water from "@/components/water/water.vue";
  56. import request from '../../../../request/index.js'
  57. export default {
  58. components: {
  59. ScanRateTable,
  60. Water,
  61. },
  62. data() {
  63. return {
  64. customerLevel: "",
  65. rangeType: "",
  66. regionCode: "",
  67. drugEntBaseInfoId: "",
  68. scanType: "",
  69. statusBarHeight: 20,
  70. regionName: "",
  71. physicName: "",
  72. customerPage: 1,
  73. customerPageSize: 10,
  74. customerTotal: null,
  75. customerHasMore: true,
  76. customerLoading: false,
  77. customers: [],
  78. customerInput: { customerName: '' },
  79. customerDebounceTimer: null,
  80. selectedCustomer: "",
  81. dropdownOpen: false,
  82. totalCount: 30,
  83. isLoading: false,
  84. list: [],
  85. columns: [
  86. {
  87. key: "custemerName",
  88. title: "客户名称",
  89. underline: false,
  90. fixed: false,
  91. width: "",
  92. },
  93. {
  94. key: "outScanRate",
  95. title: "出库扫码率",
  96. fixed: false,
  97. width: "",
  98. unit: '%'
  99. },
  100. {
  101. key: "inScanRate",
  102. title: "入库扫码率",
  103. fixed: false,
  104. width: "",
  105. unit: '%'
  106. },
  107. {
  108. key: "selfExaminationRate",
  109. title: "自验证率",
  110. fixed: false,
  111. width: "",
  112. unit: '%'
  113. },
  114. ],
  115. };
  116. },
  117. onLoad(options) {
  118. const info = uni.getSystemInfoSync();
  119. this.statusBarHeight = info.statusBarHeight || 20;
  120. // this.list = this.genRows(Math.min(10, this.totalCount));
  121. this.rangeType = options.type || 1;
  122. this.regionCode = options.regionCode || "";
  123. this.drugEntBaseInfoId = options.drugEntBaseInfoId || "";
  124. this.scanType = options.scanType || "1";
  125. this.physicName = decodeURIComponent(options.physicName || "");
  126. this.regionName = decodeURIComponent(options.regionName || "");
  127. this.customerLevel =
  128. this.scanType == 1 ? "VIP" : this.scanType == 2 ? "二级" : "三级";
  129. this.getCustomerInfo();
  130. },
  131. watch: {
  132. 'customerInput.customerName': {
  133. handler(newVal, oldVal) {
  134. if (
  135. !newVal ||
  136. newVal !== oldVal
  137. ) {
  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. };
  188. },
  189. tableBodyHeight() {
  190. const rowHeight = 76; // rpx
  191. if (this.totalCount >= 9) return `${rowHeight * 8.5}rpx`;
  192. return "auto";
  193. },
  194. },
  195. methods: {
  196. getCustomerInfo() {
  197. if (!this.customerHasMore || this.customerLoading) return;
  198. this.customerLoading = true;
  199. request('/customer/info/getCustomerInfo', {
  200. customerName: this.customerInput?.customerName,
  201. name: this.physicName,
  202. pageNum: this.customerPage,
  203. pageSize: this.customerPageSize,
  204. customerLevel: this.customerLevel,
  205. provinceCode: this.regionCode,
  206. path: '/traceabilityReport/pages/customerScanningRate/detail/index.vue',
  207. }).then(res => {
  208. if (res.code == 200) {
  209. const _data = res.data || {};
  210. this.customerTotal = _data.total;
  211. if (this.customerTotal <= this.customers.length) {
  212. this.customerHasMore = false;
  213. return;
  214. } else {
  215. const list = Array.isArray(_data.list) ? _data.list : [];
  216. this.customers = [...this.customers, ...list];
  217. if (this.customerTotal <= this.customers.length) {
  218. this.customerHasMore = false;
  219. } else {
  220. this.customerPage++;
  221. this.customerHasMore = true;
  222. }
  223. // }
  224. }
  225. }
  226. setTimeout(() => {
  227. this.customerLoading = false;
  228. }, 200)
  229. })
  230. },
  231. openDropdown() {
  232. this.dropdownOpen = true;
  233. },
  234. toggleDropdown() {
  235. this.dropdownOpen = !this.dropdownOpen;
  236. },
  237. onInputChange(e) {
  238. const v = e?.detail?.value ?? this.customerInput;
  239. this.customerInput.customerName = v;
  240. },
  241. selectCustomer(c) {
  242. this.selectedCustomer = c;
  243. this.customerInput = c;
  244. this.dropdownOpen = false;
  245. },
  246. closeDropdown() {
  247. this.dropdownOpen = false;
  248. },
  249. onBack() {
  250. try {
  251. uni.navigateBack();
  252. } catch (e) { }
  253. },
  254. onTableScrollToLower() {
  255. if (this.isLoading) return;
  256. if (this.list.length >= this.totalCount) return;
  257. this.isLoading = true;
  258. const remain = this.totalCount - this.list.length;
  259. const toAdd = Math.min(10, remain);
  260. setTimeout(() => {
  261. const more = this.genRows(toAdd);
  262. this.list = this.list.concat(more);
  263. this.isLoading = false;
  264. }, 800);
  265. },
  266. genRows(n) {
  267. const res = [];
  268. const regions = [
  269. "山东医药",
  270. "江苏医药",
  271. "浙江医药",
  272. "广东医药",
  273. "湖南医药",
  274. "湖北医药",
  275. ];
  276. const base = this.list.length;
  277. for (let i = 0; i < n; i++) {
  278. const name = regions[(base + i) % regions.length];
  279. res.push({ region: name, outRate: "0%", inRate: "0%" });
  280. }
  281. return res;
  282. },
  283. },
  284. };
  285. </script>
  286. <style scoped>
  287. .nav {
  288. position: fixed;
  289. top: 0;
  290. left: 0;
  291. right: 0;
  292. height: 44px;
  293. background-color: #2c69ff;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. }
  298. .nav-title {
  299. font-size: 36rpx;
  300. color: #fff;
  301. font-weight: 700;
  302. }
  303. .nav-back {
  304. position: absolute;
  305. left: 40rpx;
  306. top: 12rpx;
  307. width: 20rpx;
  308. height: 20rpx;
  309. color: #fff;
  310. border-left: 3rpx solid #fff;
  311. border-bottom: 3rpx solid #fff;
  312. transform: rotate(45deg) translateY(56rpx);
  313. margin-left: 40rpx;
  314. }
  315. .page {
  316. height: 100vh;
  317. }
  318. .card {
  319. margin: 24rpx;
  320. background: #fff;
  321. border-radius: 16rpx;
  322. font-size: 32rpx;
  323. }
  324. /* .table-header {
  325. display: flex;
  326. background: #eaf2ff;
  327. font-weight: bold;
  328. color: #2c69ff;
  329. border-top-left-radius: 16rpx;
  330. border-top-right-radius: 16rpx;
  331. }
  332. .table-body {
  333. margin-top: 8rpx;
  334. }
  335. .row {
  336. display: flex;
  337. align-items: center;
  338. }
  339. .row:last-child {
  340. border-bottom: none;
  341. }
  342. .cell {
  343. flex: 1;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. height: 76rpx;
  348. } */
  349. .loading-row {
  350. justify-content: center;
  351. }
  352. .loading-wrapper {
  353. width: 100%;
  354. height: 76rpx;
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. }
  359. .loading-icon {
  360. width: 40rpx;
  361. height: 40rpx;
  362. animation: spin 1s linear infinite;
  363. }
  364. @keyframes spin {
  365. from {
  366. transform: rotate(0deg);
  367. }
  368. to {
  369. transform: rotate(360deg);
  370. }
  371. }
  372. /* .total-row {
  373. font-weight: bold;
  374. color: #2c69ff;
  375. } */
  376. .header-card {
  377. background: #2c69ff;
  378. border-bottom-left-radius: 32rpx;
  379. border-bottom-right-radius: 32rpx;
  380. padding: 36rpx;
  381. color: #fff;
  382. }
  383. .meta {
  384. display: flex;
  385. align-items: center;
  386. margin: 14rpx 0;
  387. }
  388. .dot {
  389. width: 8rpx;
  390. height: 8rpx;
  391. border-radius: 50%;
  392. background: #fff;
  393. margin-right: 20rpx;
  394. }
  395. .meta-text {
  396. font-size: 32rpx;
  397. }
  398. .selector-wrap {
  399. position: relative;
  400. margin-top: 16rpx;
  401. }
  402. .selector-input {
  403. width: 100%;
  404. height: 64rpx;
  405. border-radius: 32rpx;
  406. background: #fff;
  407. color: #333;
  408. padding: 0 72rpx 0 30rpx;
  409. box-sizing: border-box;
  410. font-size: 28rpx;
  411. }
  412. .selector-arrow {
  413. position: absolute;
  414. right: 24rpx;
  415. bottom: 25rpx;
  416. width: 16rpx;
  417. height: 16rpx;
  418. border: 5rpx solid #2c69ff;
  419. border-top: none;
  420. border-left: none;
  421. transform-origin: 50% 50%;
  422. transform: rotate(45deg);
  423. transition: transform 0.2s;
  424. }
  425. .selector-arrow.open {
  426. bottom: 18rpx;
  427. transform: rotate(225deg);
  428. }
  429. .dropdown {
  430. position: absolute;
  431. left: 0;
  432. right: 0;
  433. top: 70rpx;
  434. background: #fff;
  435. border: 1rpx solid #eef0f4;
  436. border-radius: 12rpx;
  437. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
  438. z-index: 10;
  439. max-height: none;
  440. }
  441. .dropdown-item {
  442. padding: 16rpx 24rpx;
  443. font-size: 28rpx;
  444. color: #333;
  445. }
  446. .dropdown-item+.dropdown-item {
  447. border-top: 1rpx solid #f0f2f5;
  448. }
  449. .customer-loading-wrap {
  450. width: 100%;
  451. height: 70rpx;
  452. display: flex;
  453. align-items: center;
  454. justify-content: center;
  455. }
  456. </style>