retail.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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="dataDetail(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/hexiao/ywy/add_retail?edit=0&id='+id });
  132. console.log('查看详情 ID:', id);
  133. },
  134. dataDetail(id){
  135. uni.navigateTo({ url: '/pages/hexiao/ywy/retail_detail?id='+id });
  136. console.log('查看数据 ID:', id);
  137. },
  138. editStore(id) { uni.navigateTo({ url: '/pages/hexiao/ywy/add_retail?edit=1&id='+id });},
  139. patrolStore(id) {
  140. uni.navigateTo({ url: '/pages/hexiao/ywy/add_patrol?edit=1&id='+id });
  141. },
  142. deleteStore(id) {
  143. let self = this;
  144. uni.showModal({
  145. title: '确认删除',
  146. content: '您确定要删除这家门店吗?此操作不可恢复。',
  147. confirmColor: '#e54d42',
  148. success: (res) => {
  149. if (res.confirm) {
  150. removeRetail(id).then(() => {
  151. self.resetSearch();
  152. uni.showToast({ title: '删除成功', icon: 'success' });
  153. });
  154. }
  155. }
  156. });
  157. },
  158. resetSearch(){
  159. this.fetchStoreList(true);
  160. },
  161. addNewStore() {
  162. uni.navigateTo({ url: `/pages/hexiao/ywy/add_retail?edit=1` });
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .page-container {
  169. background-color: #f5f6fa;
  170. height: 100vh;
  171. display: flex;
  172. flex-direction: column;
  173. }
  174. .search-wrapper {
  175. padding: 20rpx;
  176. background-color: #ffffff;
  177. position: sticky; top: 0; z-index: 100;
  178. }
  179. .search-bar {
  180. display: flex; align-items: center; background-color: #f5f6fa;
  181. border-radius: 50rpx; padding: 0 25rpx; height: 70rpx;
  182. }
  183. .search-input { flex: 1; font-size: 28rpx; margin-left: 15rpx; }
  184. .placeholder { color: #b0b0b0; }
  185. .list-container {
  186. flex: 1; padding: 0 20rpx; box-sizing: border-box;
  187. }
  188. /* --- 关键改动 2 --- */
  189. .list-container.with-padding-bottom {
  190. /* 按钮高度(90+40=130) + tabBar高度(100) + 一点富余 = 250rpx */
  191. padding-bottom: 250rpx;
  192. }
  193. .empty-list { text-align: center; color: #999; padding-top: 100rpx; }
  194. .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); }
  195. .card-decorator { position: absolute; left: 0; top: 0; bottom: 0; width: 8rpx; background-color: #e3efff; }
  196. .card-content { padding: 30rpx; padding-left: 40rpx; }
  197. .card-header { display: flex; align-items: center; }
  198. .store-name { font-size: 32rpx; font-weight: bold; color: #333; margin-left: 15rpx; }
  199. .info-grid { margin-top: 20rpx; font-size: 26rpx; color: #666; }
  200. .info-row { margin-top: 10rpx; }
  201. .action-buttons { display: flex; justify-content: space-around; border-top: 1rpx solid #f5f5f5; margin-top: 30rpx; padding-top: 25rpx; }
  202. .action-btn { display: flex; align-items: center; font-size: 26rpx; color: #3c82f8; }
  203. .action-btn text { margin-left: 8rpx; }
  204. .delete-btn { color: #e54d42; }
  205. .fixed-footer {
  206. position: fixed;
  207. /* --- 关键改动 1 --- */
  208. /* bottom值 = 自定义tabBar的高度(100rpx) + iPhone等机型的底部安全区 */
  209. bottom: calc(100rpx + constant(safe-area-inset-bottom));
  210. bottom: calc(100rpx + env(safe-area-inset-bottom));
  211. left: 0;
  212. width: 100%;
  213. background-color: #f5f6fa;
  214. padding: 20rpx 30rpx;
  215. box-sizing: border-box;
  216. z-index: 90; // z-index比tabBar低,但比页面内容高
  217. }
  218. .add-store-btn {
  219. background-color: #3c82f8;
  220. color: white;
  221. border-radius: 50rpx;
  222. font-size: 32rpx;
  223. height: 90rpx;
  224. line-height: 90rpx;
  225. &::after {
  226. border: none;
  227. }
  228. }
  229. </style>