index.vue 11 KB

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