retail.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 = "handleSearch"
  12. />
  13. </view>
  14. </view>
  15. <!-- 修改1: 为scroll-view添加scrolltolower事件 -->
  16. <scroll-view scroll-y="true" class="list-container with-padding-bottom" @scrolltolower="loadMoreData">
  17. <view v-if="storeList.length === 0" class="empty-list">
  18. <text>没有找到相关门店</text>
  19. </view>
  20. <view v-for="store in storeList" :key="store.id" class="store-card">
  21. <view class="card-decorator"></view>
  22. <view class="card-content">
  23. <view class="card-header">
  24. <uni-icons type="shop-filled" size="20" color="#3c82f8"></uni-icons>
  25. <text class="store-name">{{ store.store_name }}</text>
  26. </view>
  27. <view class="info-grid">
  28. <view class="info-row">
  29. <text class="info-label">店主名称:</text>
  30. <text class="info-value">{{ store.contact_name }}</text>
  31. </view>
  32. <view class="info-row">
  33. <text class="info-label">联系方式:</text>
  34. <text class="info-value">{{ store.contact_phone }}</text>
  35. </view>
  36. <view class="info-row">
  37. <text class="info-label">门店地址:</text>
  38. <text class="info-value">{{ store.address }}</text>
  39. </view>
  40. </view>
  41. <view class="action-buttons">
  42. <view class="action-btn" @click="viewDetails(store.id)">
  43. <uni-icons type="eye-filled" size="18" color="#3c82f8"></uni-icons>
  44. <text>详情</text>
  45. </view>
  46. <view class="action-btn" @click="dataDetail(store.id)" v-if="ywyId > 0">
  47. <uni-icons type="compose" size="18" color="#3c82f8"></uni-icons>
  48. <text>数据查看</text>
  49. </view>
  50. <view class="action-btn" @click="editStore(store.id)" v-if="ywyId === 0">
  51. <uni-icons type="tune-filled" size="18" color="#3c82f8"></uni-icons>
  52. <text>编辑</text>
  53. </view>
  54. <view class="action-btn" @click="patrolStore(store.id)" v-if="ywyId === 0">
  55. <uni-icons type="home-filled" size="18" color="#3c82f8"></uni-icons>
  56. <text>巡店</text>
  57. </view>
  58. <view class="action-btn delete-btn" @click="deleteStore(store.id)" v-if="ywyId === 0">
  59. <uni-icons type="trash-filled" size="18" color="#e54d42"></uni-icons>
  60. <text>删除</text>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </scroll-view>
  66. <view class="fixed-footer" v-if="ywyId === 0">
  67. <button class="add-store-btn" @click="addNewStore">新增门店</button>
  68. </view>
  69. <CustomTabbar v-if="ywyId === 0" :current="1"/>
  70. </view>
  71. </template>
  72. <script>
  73. // 您自定义tabBar的路径,请确保正确
  74. import CustomTabbar from '@/components/cjx/tabbar_hexiao_ywy.vue';
  75. import {getStoreList,removeRetail} from "@/api/hexiao";
  76. export default {
  77. components: {
  78. CustomTabbar
  79. },
  80. data() {
  81. return {
  82. searchQuery: '',
  83. storeList: [],
  84. filteredList: [],
  85. pagination: {
  86. page: 1,
  87. limit: 10,
  88. },
  89. ywyId: 0,
  90. // 修改2: 初始化加载状态变量
  91. isLoading: false,
  92. loadStatus: 'more' // more: 可以继续加载, loading: 加载中, noMore: 没有更多数据
  93. };
  94. },
  95. onShow(){
  96. this.fetchStoreList(true);
  97. },
  98. onLoad(opt) {
  99. if(opt.id){
  100. this.ywyId = opt.id;
  101. }
  102. this.fetchStoreList(true);
  103. },
  104. methods: {
  105. fetchStoreList(isRefresh = false) {
  106. if (this.isLoading || (this.loadStatus === 'noMore' && !isRefresh)) {
  107. return; // 防止重复加载
  108. }
  109. if (isRefresh) {
  110. this.pagination.page = 1;
  111. this.storeList = [];
  112. this.loadStatus = 'more';
  113. }
  114. this.isLoading = true;
  115. this.loadStatus = 'loading';
  116. // --- [模拟API请求] ---
  117. // 在这里替换成您真实的 uni.request API 调用
  118. console.log(`正在请求第 ${this.pagination.page} 页数据, 搜索词: "${this.searchQuery}"`);
  119. getStoreList(this.pagination.page,this.pagination.limit,this.searchQuery,this.ywyId).then(res=>{
  120. let data = res.data;
  121. let mockData = data.records;
  122. if (mockData.length > 0) {
  123. this.storeList = [...this.storeList, ...mockData];
  124. this.pagination.page++;
  125. this.loadStatus = mockData.length < this.pagination.limit ? 'noMore' : 'more';
  126. } else {
  127. this.loadStatus = 'noMore';
  128. }
  129. this.isLoading = false;
  130. });
  131. },
  132. handleSearch() {
  133. this.pagination.page = 1;
  134. this.fetchStoreList(true);
  135. },
  136. viewDetails(id) {
  137. uni.navigateTo({ url: '/pages/hexiao/ywy/add_retail?edit=0&id='+id });
  138. console.log('查看详情 ID:', id);
  139. },
  140. dataDetail(id){
  141. uni.navigateTo({ url: '/pages/hexiao/ywy/retail_detail?id='+id });
  142. console.log('查看数据 ID:', id);
  143. },
  144. editStore(id) { uni.navigateTo({ url: '/pages/hexiao/ywy/add_retail?edit=1&id='+id });},
  145. patrolStore(id) {
  146. uni.navigateTo({ url: '/pages/hexiao/ywy/add_patrol?edit=1&id='+id });
  147. },
  148. deleteStore(id) {
  149. let self = this;
  150. uni.showModal({
  151. title: '确认删除',
  152. content: '您确定要删除这家门店吗?此操作不可恢复。',
  153. confirmColor: '#e54d42',
  154. success: (res) => {
  155. if (res.confirm) {
  156. removeRetail(id).then(() => {
  157. self.resetSearch();
  158. uni.showToast({ title: '删除成功', icon: 'success' });
  159. });
  160. }
  161. }
  162. });
  163. },
  164. resetSearch(){
  165. this.fetchStoreList(true);
  166. },
  167. addNewStore() {
  168. uni.navigateTo({ url: `/pages/hexiao/ywy/add_retail?edit=1` });
  169. },
  170. // 修改:将方法名改为loadMoreData
  171. loadMoreData() {
  172. // 当滚动到底部时,调用fetchStoreList加载下一页数据
  173. // 传入false表示不是刷新操作,而是加载更多
  174. this.fetchStoreList(false);
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .page-container {
  181. background-color: #f5f6fa;
  182. height: 100vh;
  183. display: flex;
  184. flex-direction: column;
  185. }
  186. .search-wrapper {
  187. padding: 20rpx;
  188. background-color: #ffffff;
  189. position: sticky; top: 0; z-index: 100;
  190. }
  191. .search-bar {
  192. display: flex; align-items: center; background-color: #f5f6fa;
  193. border-radius: 50rpx; padding: 0 25rpx; height: 70rpx;
  194. }
  195. .search-input { flex: 1; font-size: 28rpx; margin-left: 15rpx; }
  196. .placeholder { color: #b0b0b0; }
  197. .list-container {
  198. flex: 1; padding: 0 20rpx; box-sizing: border-box;
  199. }
  200. /* --- 关键改动 2 --- */
  201. .list-container.with-padding-bottom {
  202. /* 按钮高度(90+40=130) + tabBar高度(100) + 一点富余 = 250rpx */
  203. padding-bottom: 250rpx;
  204. }
  205. .empty-list { text-align: center; color: #999; padding-top: 100rpx; }
  206. .store-card { background-color: #ffffff; border-radius: 16rpx; margin-top: 20rpx; position: relative; overflow: hidden; box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04); }
  207. .card-decorator { position: absolute; left: 0; top: 0; bottom: 0; width: 8rpx; background-color: #e3efff; }
  208. .card-content { padding: 30rpx; padding-left: 40rpx; }
  209. .card-header { display: flex; align-items: center; }
  210. .store-name { font-size: 32rpx; font-weight: bold; color: #333; margin-left: 15rpx; }
  211. .info-grid { margin-top: 20rpx; font-size: 26rpx; color: #666; }
  212. .info-row { margin-top: 10rpx; }
  213. .action-buttons { display: flex; justify-content: space-around; border-top: 1rpx solid #f5f5f5; margin-top: 30rpx; padding-top: 25rpx; }
  214. .action-btn { display: flex; align-items: center; font-size: 26rpx; color: #3c82f8; }
  215. .action-btn text { margin-left: 8rpx; }
  216. .delete-btn { color: #e54d42; }
  217. .fixed-footer {
  218. position: fixed;
  219. /* --- 关键改动 1 --- */
  220. /* bottom值 = 自定义tabBar的高度(100rpx) + iPhone等机型的底部安全区 */
  221. bottom: calc(100rpx + constant(safe-area-inset-bottom));
  222. bottom: calc(100rpx + env(safe-area-inset-bottom));
  223. left: 0;
  224. width: 100%;
  225. background-color: #f5f6fa;
  226. padding: 20rpx 30rpx;
  227. box-sizing: border-box;
  228. z-index: 90; // z-index比tabBar低,但比页面内容高
  229. }
  230. .add-store-btn {
  231. background-color: #3c82f8;
  232. color: white;
  233. border-radius: 50rpx;
  234. font-size: 32rpx;
  235. height: 90rpx;
  236. line-height: 90rpx;
  237. &::after {
  238. border: none;
  239. }
  240. }
  241. </style>