index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <view class="goods-stock-page">
  3. <erp-nav-bar title="库存信息" />
  4. <!-- 客户分类标签 -->
  5. <scroll-view scroll-x class="client-tabs" :show-scrollbar="false" :scroll-with-animation="true"
  6. :scroll-into-view="'ctab-' + currentTab">
  7. <view class="client-tabs-box">
  8. <view v-for="(tab, index) in clientTabs" :key="index" :id="'ctab-' + index" class="client-tab-item"
  9. :class="{ active: currentTab === index }" @click="switchTab(index)">
  10. <text class="client-tab-txt">{{ tab.label }}</text>
  11. </view>
  12. </view>
  13. </scroll-view>
  14. <!-- 库存列表滚动区 -->
  15. <scroll-view scroll-y class="stock-scroll-view" :style="{ height: scrollHeight }" @scrolltolower="onReachEnd"
  16. :refresher-enabled="true" :refresher-triggered="refresherTriggered" @refresherrefresh="onPullDownRefresh"
  17. :show-scrollbar="false">
  18. <view class="stock-list-inner">
  19. <view class="stock-card" v-for="(item, index) in displayList" :key="index">
  20. <view class="stock-card-head">
  21. <!-- 全部:客户名称为主标题;锁定客户:型号为主标题 -->
  22. <view class="stock-model-info" v-if="currentTab === 0">
  23. <text class="stock-model">{{ item.clientName || '-' }}</text>
  24. <text class="stock-client" v-if="item.saleCode">{{ item.saleCode }}</text>
  25. </view>
  26. <view class="stock-model-info" v-else>
  27. <text class="stock-model">{{ item.saleCode }}</text>
  28. <text class="stock-client">{{ item.clientName || '-' }}</text>
  29. </view>
  30. </view>
  31. <view class="stock-card-body">
  32. <view class="stock-info-row">
  33. <text class="stock-label">支数</text>
  34. <text class="stock-value highlight">{{ item.sumQty != null ? item.sumQty : '-' }} 支</text>
  35. </view>
  36. <view class="stock-info-row">
  37. <text class="stock-label">重量</text>
  38. <text class="stock-value">{{ item.sumWt != null ? Number(item.sumWt).toFixed(2) + ' kg' :
  39. '-' }}</text>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 加载提示 -->
  44. <view class="list-status-info" v-if="displayList.length > 0">
  45. <view class="loading-wrap" v-if="loading">
  46. <view class="load-dot"></view><text>加载中...</text>
  47. </view>
  48. <view class="nomore-wrap" v-if="noMore">
  49. <text class="nomore-line"></text>
  50. <text class="nomore-text">已加载全部数据</text>
  51. <text class="nomore-line"></text>
  52. </view>
  53. </view>
  54. <!-- 缺省态 -->
  55. <view class="empty-state" v-if="displayList.length === 0 && !loading">
  56. <image src="https://img.icons8.com/clouds/200/open-box.png" mode="aspectFit"></image>
  57. <text>暂无库存记录</text>
  58. </view>
  59. <view class="safe-bottom"></view>
  60. </view>
  61. </scroll-view>
  62. </view>
  63. </template>
  64. <script>
  65. import ErpNavBar from '@/components/erp-nav-bar.vue';
  66. import { getGoodsStockSummaryPage } from '@/api/erp/goodsStock.js';
  67. import { getMyInfo } from '@/api/system/employee.js';
  68. import { getClientByIds } from '@/api/erp/client.js';
  69. export default {
  70. components: { ErpNavBar },
  71. data() {
  72. return {
  73. statusBarHeight: 20,
  74. navBarHeight: 44,
  75. currentTab: 0,
  76. loading: false,
  77. noMore: false,
  78. refresherTriggered: false,
  79. pageNum: 1,
  80. pageSize: 10,
  81. clientTabs: [{ label: '全部', clientId: '' }],
  82. displayList: []
  83. }
  84. },
  85. computed: {
  86. scrollHeight() {
  87. return `calc(100vh - ${this.statusBarHeight + this.navBarHeight + 40}px)`;
  88. }
  89. },
  90. onLoad() {
  91. const winInfo = uni.getWindowInfo ? uni.getWindowInfo() : uni.getSystemInfoSync();
  92. this.statusBarHeight = winInfo.statusBarHeight;
  93. this.loadClientTabs();
  94. },
  95. methods: {
  96. async loadClientTabs() {
  97. try {
  98. const res = await getMyInfo();
  99. const employee = res.data;
  100. if (employee && employee.authClientFRowIDs) {
  101. const ids = employee.authClientFRowIDs.split(',').map(s => s.trim()).filter(Boolean);
  102. if (ids.length > 0) {
  103. const clientRes = await getClientByIds(ids.join(','));
  104. const clients = clientRes.data || [];
  105. const tabs = [{ label: '全部', clientId: '' }];
  106. clients.forEach(c => {
  107. tabs.push({ label: c.name || c.num || '-', clientId: c.frowId || c.rowId || '' });
  108. });
  109. this.clientTabs = tabs;
  110. }
  111. }
  112. } catch (e) {
  113. console.error('加载授权客户失败', e);
  114. }
  115. this.refresh();
  116. },
  117. switchTab(i) {
  118. this.currentTab = i;
  119. this.refresh();
  120. },
  121. refresh() {
  122. this.displayList = [];
  123. this.noMore = false;
  124. this.pageNum = 1;
  125. this.loadData();
  126. },
  127. onPullDownRefresh() {
  128. this.refresherTriggered = true;
  129. this.refresh();
  130. setTimeout(() => { this.refresherTriggered = false; }, 500);
  131. },
  132. onReachEnd() {
  133. if (!this.loading && !this.noMore) this.loadData();
  134. },
  135. async loadData() {
  136. if (this.loading || this.noMore) return;
  137. this.loading = true;
  138. try {
  139. const currentClient = this.clientTabs[this.currentTab];
  140. const params = {
  141. pageNum: this.pageNum,
  142. pageSize: this.pageSize
  143. };
  144. if (currentClient && currentClient.clientId) {
  145. params.clientId = currentClient.clientId;
  146. }
  147. const res = await getGoodsStockSummaryPage(params);
  148. const rows = res.rows || [];
  149. this.displayList = [...this.displayList, ...rows];
  150. this.pageNum++;
  151. this.noMore = rows.length === 0 || this.displayList.length >= (res.total || 0);
  152. } catch (e) {
  153. console.error('加载库存列表失败', e);
  154. uni.showToast({ title: e || '加载失败', icon: 'none' });
  155. } finally {
  156. this.loading = false;
  157. }
  158. }
  159. }
  160. }
  161. </script>
  162. <style scoped>
  163. .goods-stock-page {
  164. width: 100vw;
  165. height: 100vh;
  166. background: #f7f8fa;
  167. display: flex;
  168. flex-direction: column;
  169. overflow: hidden;
  170. }
  171. /* ========== 客户标签栏 ========== */
  172. .client-tabs {
  173. flex-shrink: 0;
  174. background: #fff;
  175. border-bottom: 1rpx solid #f0f0f0;
  176. white-space: nowrap;
  177. }
  178. .client-tabs-box {
  179. display: flex;
  180. padding: 0 20rpx;
  181. height: 80rpx;
  182. align-items: center;
  183. gap: 10rpx;
  184. }
  185. .client-tab-item {
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. padding: 0 28rpx;
  190. height: 56rpx;
  191. border-radius: 28rpx;
  192. background: #f5f6f7;
  193. flex-shrink: 0;
  194. transition: all 0.2s;
  195. }
  196. .client-tab-item.active {
  197. background: #C1001C;
  198. }
  199. .client-tab-txt {
  200. font-size: 26rpx;
  201. color: #666;
  202. }
  203. .client-tab-item.active .client-tab-txt {
  204. color: #fff;
  205. font-weight: 600;
  206. }
  207. /* ========== 滚动列表区 ========== */
  208. .stock-scroll-view {
  209. width: 100%;
  210. flex: 1;
  211. }
  212. .stock-list-inner {
  213. padding: 20rpx 30rpx;
  214. }
  215. /* ========== 库存卡片 ========== */
  216. .stock-card {
  217. background: #fff;
  218. border-radius: 20rpx;
  219. padding: 30rpx;
  220. margin-bottom: 20rpx;
  221. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
  222. }
  223. .stock-card-head {
  224. display: flex;
  225. justify-content: space-between;
  226. align-items: flex-start;
  227. margin-bottom: 24rpx;
  228. padding-bottom: 20rpx;
  229. border-bottom: 1rpx solid #f5f5f5;
  230. }
  231. .stock-model-info {
  232. display: flex;
  233. flex-direction: column;
  234. gap: 6rpx;
  235. }
  236. .stock-model {
  237. font-size: 30rpx;
  238. font-weight: bold;
  239. color: #1a1a1a;
  240. }
  241. .stock-client {
  242. font-size: 24rpx;
  243. color: #999;
  244. }
  245. .stock-card-body {
  246. display: flex;
  247. flex-direction: column;
  248. gap: 16rpx;
  249. }
  250. .stock-info-row {
  251. display: flex;
  252. justify-content: space-between;
  253. align-items: center;
  254. }
  255. .stock-label {
  256. font-size: 26rpx;
  257. color: #999;
  258. }
  259. .stock-value {
  260. font-size: 26rpx;
  261. color: #333;
  262. font-weight: 500;
  263. }
  264. .stock-value.highlight {
  265. color: #C1001C;
  266. font-weight: bold;
  267. font-size: 30rpx;
  268. }
  269. /* ========== 加载状态 ========== */
  270. .list-status-info {
  271. padding: 30rpx 0;
  272. }
  273. .loading-wrap {
  274. display: flex;
  275. align-items: center;
  276. justify-content: center;
  277. gap: 16rpx;
  278. font-size: 26rpx;
  279. color: #aaa;
  280. }
  281. .load-dot {
  282. width: 12rpx;
  283. height: 12rpx;
  284. border-radius: 50%;
  285. background: #ccc;
  286. animation: dot-blink 1s infinite;
  287. }
  288. @keyframes dot-blink {
  289. 0%,
  290. 100% {
  291. opacity: 0.3;
  292. }
  293. 50% {
  294. opacity: 1;
  295. }
  296. }
  297. .nomore-wrap {
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. gap: 16rpx;
  302. }
  303. .nomore-line {
  304. width: 60rpx;
  305. height: 1rpx;
  306. background: #e0e0e0;
  307. }
  308. .nomore-text {
  309. font-size: 24rpx;
  310. color: #ccc;
  311. }
  312. /* ========== 空状态 ========== */
  313. .empty-state {
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. justify-content: center;
  318. padding: 120rpx 0;
  319. }
  320. .empty-state image {
  321. width: 160rpx;
  322. height: 160rpx;
  323. margin-bottom: 30rpx;
  324. opacity: 0.5;
  325. }
  326. .empty-state text {
  327. font-size: 28rpx;
  328. color: #bbb;
  329. }
  330. .safe-bottom {
  331. height: 60rpx;
  332. }
  333. </style>