add_goods_record.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="page-container">
  3. <view class="search-wrapper">
  4. <view class="search-bar">
  5. <uni-icons type="search" size="20" color="#999"></uni-icons>
  6. <input
  7. class="search-input"
  8. v-model="searchQuery"
  9. placeholder="输入门店名称/上货日期搜索"
  10. placeholder-class="placeholder"
  11. confirm-type="search"
  12. @confirm="handleSearch"
  13. />
  14. </view>
  15. </view>
  16. <scroll-view class="list-container" scroll-y="true" @scrolltolower="loadMore">
  17. <view v-if="recordList.length === 0 && loadStatus !== 'loading'" class="empty-list">
  18. <text>暂无上货记录</text>
  19. </view>
  20. <view v-for="record in recordList" :key="record.id" class="record-card">
  21. <view class="card-decorator"></view>
  22. <view class="card-content">
  23. <view class="card-header">
  24. <uni-icons type="calendar-filled" size="20" color="#3c82f8"></uni-icons>
  25. <text class="record-id">{{ record.id }}</text>
  26. </view>
  27. <view class="details-section">
  28. <view class="detail-row">
  29. <text class="detail-label">上货商品总数</text>
  30. <text class="detail-value">{{ record.totalNum }}</text>
  31. </view>
  32. <view class="detail-row product-item" v-for="(product, index) in record.products" :key="index">
  33. <text class="detail-label product-name">{{ product.name }}</text>
  34. <text class="detail-value">{{ product.quantity }}{{ product.unit }}</text>
  35. </view>
  36. <view class="detail-row">
  37. <text class="detail-label">上货门店</text>
  38. <text class="detail-value">{{ record.storeName }}</text>
  39. </view>
  40. <view class="detail-row">
  41. <text class="detail-label">上货时间</text>
  42. <text class="detail-value">{{ record.activeTime }}</text>
  43. </view>
  44. <view class="detail-row">
  45. <text class="detail-label">上货奖励</text>
  46. <text class="detail-value reward">{{ record.reward==null?"0":record.reward }}积分</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <uni-load-more :status="loadStatus"></uni-load-more>
  52. </scroll-view>
  53. </view>
  54. </template>
  55. <script>
  56. import {queryActiveRecord} from "../../../../api/hexiao";
  57. export default {
  58. data() {
  59. return {
  60. searchQuery: '',
  61. recordList: [],
  62. pagination: {
  63. page: 1,
  64. limit: 10,
  65. },
  66. loadStatus: 'more', // 'more'-加载前, 'loading'-加载中, 'noMore'-没有更多了
  67. isLoading: false,
  68. };
  69. },
  70. onLoad() {
  71. // 页面加载时获取第一页数据
  72. this.fetchRecords(true);
  73. },
  74. // 监听下拉刷新
  75. onPullDownRefresh() {
  76. this.fetchRecords(true);
  77. },
  78. methods: {
  79. // 核心:获取记录列表数据
  80. async fetchRecords(isRefresh = false) {
  81. if (this.isLoading || (this.loadStatus === 'noMore' && !isRefresh)) {
  82. return;
  83. }
  84. if (isRefresh) {
  85. this.pagination.page = 1;
  86. this.recordList = [];
  87. this.loadStatus = 'more';
  88. }
  89. this.isLoading = true;
  90. this.loadStatus = 'loading';
  91. // 在这里替换成您真实的 uni.request API 调用
  92. console.log(`正在请求第 ${this.pagination.page} 页数据...`);
  93. queryActiveRecord(this.pagination.page,this.pagination.limit).then(res=>{
  94. let mockData = res.data.records;
  95. if (mockData.length > 0) {
  96. this.recordList = [...this.recordList, ...mockData];
  97. this.pagination.page++;
  98. this.loadStatus = 'more';
  99. } else {
  100. this.loadStatus = 'noMore';
  101. }
  102. this.isLoading = false;
  103. uni.stopPullDownRefresh(); // 停止下拉刷新动画
  104. });
  105. // --- [模拟API请求结束] ---
  106. },
  107. // 上拉加载更多
  108. loadMore() {
  109. this.fetchRecords();
  110. },
  111. // 搜索
  112. handleSearch() {
  113. // 在实际项目中,搜索应该调用API,这里为简单起见只做前端筛选
  114. // this.fetchRecords(true);
  115. uni.showToast({ title: '触发搜索', icon: 'none' });
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .page-container {
  122. display: flex;
  123. flex-direction: column;
  124. height: 100vh;
  125. background-color: #f5f6fa;
  126. }
  127. .search-wrapper {
  128. padding: 20rpx;
  129. background-color: #ffffff;
  130. border-bottom: 1rpx solid #f0f0f0;
  131. }
  132. .search-bar {
  133. display: flex;
  134. align-items: center;
  135. background-color: #f5f6fa;
  136. border-radius: 50rpx;
  137. padding: 0 25rpx;
  138. height: 70rpx;
  139. }
  140. .search-input {
  141. flex: 1;
  142. font-size: 28rpx;
  143. margin-left: 15rpx;
  144. }
  145. .placeholder {
  146. color: #b0b0b0;
  147. }
  148. .list-container {
  149. flex: 1;
  150. height: 100%; // 必须给scroll-view一个明确的高度
  151. }
  152. .empty-list {
  153. text-align: center;
  154. color: #999;
  155. padding-top: 150rpx;
  156. }
  157. .record-card {
  158. background-color: #ffffff;
  159. border-radius: 16rpx;
  160. margin: 20rpx;
  161. position: relative;
  162. overflow: hidden;
  163. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  164. }
  165. .card-decorator {
  166. position: absolute;
  167. left: 0;
  168. top: 0;
  169. bottom: 0;
  170. width: 8rpx;
  171. background-color: #e3efff;
  172. }
  173. .card-content {
  174. padding: 30rpx;
  175. padding-left: 40rpx;
  176. }
  177. .card-header {
  178. display: flex;
  179. align-items: center;
  180. padding-bottom: 20rpx;
  181. border-bottom: 1rpx solid #f5f5f5;
  182. .record-id {
  183. font-size: 30rpx;
  184. font-weight: bold;
  185. color: #333;
  186. margin-left: 15rpx;
  187. }
  188. }
  189. .details-section {
  190. padding-top: 10rpx;
  191. }
  192. .detail-row {
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. padding: 15rpx 0;
  197. font-size: 28rpx;
  198. .detail-label {
  199. color: #666;
  200. }
  201. .detail-value {
  202. color: #333;
  203. }
  204. &.product-item .detail-label {
  205. color: #333; // 商品名称颜色深一些
  206. font-weight: 400;
  207. }
  208. .reward {
  209. color: #ff9900;
  210. font-weight: 500;
  211. }
  212. }
  213. </style>