index.vue 12 KB

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