retail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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)" v-if="ywyId === 0">
  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)" v-if="ywyId === 0">
  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)" v-if="ywyId === 0">
  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" v-if="ywyId === 0">
  62. <button class="add-store-btn" @click="addNewStore">新增门店</button>
  63. </view>
  64. <CustomTabbar v-if="ywyId === 0" :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. ywyId:0,
  87. };
  88. },
  89. onShow(){
  90. this.fetchStoreList(true);
  91. },
  92. onLoad(opt) {
  93. if(opt.id){
  94. this.ywyId = opt.id;
  95. }
  96. this.fetchStoreList(true);
  97. },
  98. methods: {
  99. fetchStoreList(isRefresh = false) {
  100. if (this.isLoading || (this.loadStatus === 'noMore' && !isRefresh)) {
  101. return; // 防止重复加载
  102. }
  103. if (isRefresh) {
  104. this.pagination.page = 1;
  105. this.storeList = [];
  106. this.loadStatus = 'more';
  107. }
  108. this.isLoading = true;
  109. this.loadStatus = 'loading';
  110. // --- [模拟API请求] ---
  111. // 在这里替换成您真实的 uni.request API 调用
  112. console.log(`正在请求第 ${this.pagination.page} 页数据, 搜索词: "${this.searchQuery}"`);
  113. getStoreList(this.pagination.page,this.pagination.limit,this.searchQuery,this.ywyId).then(res=>{
  114. let data = res.data;
  115. let mockData = data.records;
  116. if (mockData.length > 0) {
  117. this.storeList = [...this.storeList, ...mockData];
  118. this.pagination.page++;
  119. this.loadStatus = mockData.length < this.pagination.limit ? 'noMore' : 'more';
  120. } else {
  121. this.loadStatus = 'noMore';
  122. }
  123. this.isLoading = false;
  124. });
  125. },
  126. handleSearch() {
  127. this.pagination.page = 1;
  128. this.fetchStoreList(true);
  129. },
  130. viewDetails(id) {
  131. uni.navigateTo({ url: '/pages/cjx/hexiao/ywy/add_retail?edit=0&id='+id });
  132. console.log('查看详情 ID:', id);
  133. },
  134. editStore(id) { uni.navigateTo({ url: '/pages/cjx/hexiao/ywy/add_retail?edit=1&id='+id });},
  135. patrolStore(id) {
  136. uni.navigateTo({ url: '/pages/cjx/hexiao/ywy/add_patrol?edit=1&id='+id });
  137. },
  138. deleteStore(id) {
  139. let self = this;
  140. uni.showModal({
  141. title: '确认删除',
  142. content: '您确定要删除这家门店吗?此操作不可恢复。',
  143. confirmColor: '#e54d42',
  144. success: (res) => {
  145. if (res.confirm) {
  146. removeRetail(id).then(() => {
  147. self.resetSearch();
  148. uni.showToast({ title: '删除成功', icon: 'success' });
  149. });
  150. }
  151. }
  152. });
  153. },
  154. resetSearch(){
  155. this.fetchStoreList(true);
  156. },
  157. addNewStore() {
  158. uni.navigateTo({ url: `/pages/cjx/hexiao/ywy/add_retail?edit=1` });
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .page-container {
  165. background-color: #f5f6fa;
  166. height: 100vh;
  167. display: flex;
  168. flex-direction: column;
  169. }
  170. .search-wrapper {
  171. padding: 20rpx;
  172. background-color: #ffffff;
  173. position: sticky; top: 0; z-index: 100;
  174. }
  175. .search-bar {
  176. display: flex; align-items: center; background-color: #f5f6fa;
  177. border-radius: 50rpx; padding: 0 25rpx; height: 70rpx;
  178. }
  179. .search-input { flex: 1; font-size: 28rpx; margin-left: 15rpx; }
  180. .placeholder { color: #b0b0b0; }
  181. .list-container {
  182. flex: 1; padding: 0 20rpx; box-sizing: border-box;
  183. }
  184. /* --- 关键改动 2 --- */
  185. .list-container.with-padding-bottom {
  186. /* 按钮高度(90+40=130) + tabBar高度(100) + 一点富余 = 250rpx */
  187. padding-bottom: 250rpx;
  188. }
  189. .empty-list { text-align: center; color: #999; padding-top: 100rpx; }
  190. .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); }
  191. .card-decorator { position: absolute; left: 0; top: 0; bottom: 0; width: 8rpx; background-color: #e3efff; }
  192. .card-content { padding: 30rpx; padding-left: 40rpx; }
  193. .card-header { display: flex; align-items: center; }
  194. .store-name { font-size: 32rpx; font-weight: bold; color: #333; margin-left: 15rpx; }
  195. .info-grid { margin-top: 20rpx; font-size: 26rpx; color: #666; }
  196. .info-row { margin-top: 10rpx; }
  197. .action-buttons { display: flex; justify-content: space-around; border-top: 1rpx solid #f5f5f5; margin-top: 30rpx; padding-top: 25rpx; }
  198. .action-btn { display: flex; align-items: center; font-size: 26rpx; color: #3c82f8; }
  199. .action-btn text { margin-left: 8rpx; }
  200. .delete-btn { color: #e54d42; }
  201. .fixed-footer {
  202. position: fixed;
  203. /* --- 关键改动 1 --- */
  204. /* bottom值 = 自定义tabBar的高度(100rpx) + iPhone等机型的底部安全区 */
  205. bottom: calc(100rpx + constant(safe-area-inset-bottom));
  206. bottom: calc(100rpx + env(safe-area-inset-bottom));
  207. left: 0;
  208. width: 100%;
  209. background-color: #f5f6fa;
  210. padding: 20rpx 30rpx;
  211. box-sizing: border-box;
  212. z-index: 90; // z-index比tabBar低,但比页面内容高
  213. }
  214. .add-store-btn {
  215. background-color: #3c82f8;
  216. color: white;
  217. border-radius: 50rpx;
  218. font-size: 32rpx;
  219. height: 90rpx;
  220. line-height: 90rpx;
  221. &::after {
  222. border: none;
  223. }
  224. }
  225. </style>