retail.vue 7.7 KB

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