select-store-drawer.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view v-if="show" class="drawer-wrapper" @touchmove.stop.prevent>
  3. <view class="drawer-overlay" @click="close"></view>
  4. <view class="drawer-content">
  5. <view class="drawer-header">
  6. <text class="title">选择门店</text>
  7. <uni-icons class="close-icon" type="closeempty" size="22" color="#999" @click="close"></uni-icons>
  8. </view>
  9. <view class="search-bar">
  10. <uni-icons type="search" size="20" color="#999"></uni-icons>
  11. <input
  12. class="search-input"
  13. v-model="searchQuery"
  14. placeholder="输入门店名称"
  15. placeholder-class="placeholder"
  16. confirm-type="search"
  17. @confirm="handleSearch"
  18. />
  19. </view>
  20. <scroll-view class="store-list-scroll" scroll-y="true" @scrolltolower="handleScrollToLower">
  21. <view v-if="storeList.length === 0 && loadStatus !== 'loading'" class="empty-tip">
  22. 暂无门店数据
  23. </view>
  24. <view
  25. v-for="store in storeList"
  26. :key="store.id"
  27. class="store-card"
  28. :class="{ 'selected': store.id === selectedId }"
  29. @click="handleStoreSelect(store)"
  30. >
  31. <view class="card-header">
  32. <uni-icons type="shop-filled" size="20" color="#3c82f8"></uni-icons>
  33. <text class="store-name">{{ store.store_name }}</text>
  34. </view>
  35. <view class="info-row">
  36. <text class="info-label">店主名称:</text>
  37. <text class="info-value">{{ store.contact_name }}</text>
  38. </view>
  39. <view class="info-row">
  40. <text class="info-label">联系方式:</text>
  41. <text class="info-value">{{ store.contact_phone }}</text>
  42. </view>
  43. <view class="info-row">
  44. <text class="info-label">门店地址:</text>
  45. <text class="info-value">{{ store.address }}</text>
  46. </view>
  47. </view>
  48. <uni-load-more :status="loadStatus"></uni-load-more>
  49. </scroll-view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import { getStoreList } from '@/api/hexiao.js';
  55. export default {
  56. name: "select-store-drawer",
  57. props: {
  58. // 控制抽屉显示
  59. show: {
  60. type: Boolean,
  61. default: false
  62. },
  63. // 当前选中的门店ID,用于高亮显示
  64. selectedId: {
  65. type: [Number, String],
  66. default: null
  67. }
  68. },
  69. data() {
  70. return {
  71. searchQuery: '',
  72. storeList: [],
  73. pagination: {
  74. page: 1,
  75. limit: 10,
  76. },
  77. // 加载状态: 'loading'-加载中, 'more'-有更多, 'noMore'-没有更多了
  78. loadStatus: 'more',
  79. isLoading: false,
  80. };
  81. },
  82. watch: {
  83. // 监听 show 属性的变化
  84. show(newVal) {
  85. if (newVal && this.storeList.length === 0) {
  86. // 当抽屉第一次打开时,加载初始数据
  87. this.fetchStoreList(true);
  88. }
  89. }
  90. },
  91. methods: {
  92. // 核心:获取门店列表数据
  93. fetchStoreList(isRefresh = false) {
  94. if (this.isLoading || (this.loadStatus === 'noMore' && !isRefresh)) {
  95. return; // 防止重复加载
  96. }
  97. if (isRefresh) {
  98. this.pagination.page = 1;
  99. this.storeList = [];
  100. this.loadStatus = 'more';
  101. }
  102. this.isLoading = true;
  103. this.loadStatus = 'loading';
  104. // --- [模拟API请求] ---
  105. // 在这里替换成您真实的 uni.request API 调用
  106. console.log(`正在请求第 ${this.pagination.page} 页数据, 搜索词: "${this.searchQuery}"`);
  107. getStoreList(this.pagination.page,this.pagination.limit,this.searchQuery).then(res=>{
  108. let data = res.data;
  109. let mockData = data.records;
  110. if (mockData.length > 0) {
  111. this.storeList = [...this.storeList, ...mockData];
  112. this.pagination.page++;
  113. this.loadStatus = mockData.length < this.pagination.limit ? 'noMore' : 'more';
  114. } else {
  115. this.loadStatus = 'noMore';
  116. }
  117. this.isLoading = false;
  118. });
  119. },
  120. // 滚动到底部加载更多
  121. handleScrollToLower() {
  122. this.fetchStoreList();
  123. },
  124. // 点击搜索按钮
  125. handleSearch() {
  126. this.fetchStoreList(true);
  127. },
  128. // 选择了一个门店
  129. handleStoreSelect(store) {
  130. // 通过 $emit 将选中的门店数据传递给父组件
  131. this.$emit('select', store);
  132. this.close();
  133. },
  134. // 关闭抽屉
  135. close() {
  136. // 通知父组件关闭
  137. this.$emit('close');
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .drawer-wrapper {
  144. position: fixed;
  145. top: 0;
  146. left: 0;
  147. width: 100%;
  148. height: 100%;
  149. z-index: 999;
  150. }
  151. .drawer-overlay {
  152. position: absolute;
  153. top: 0;
  154. left: 0;
  155. width: 100%;
  156. height: 100%;
  157. background-color: rgba(0, 0, 0, 0.4);
  158. }
  159. .drawer-content {
  160. position: absolute;
  161. bottom: 0;
  162. left: 0;
  163. width: 100%;
  164. height: 85vh; // 抽屉高度
  165. background-color: #f5f6fa;
  166. border-top-left-radius: 20rpx;
  167. border-top-right-radius: 20rpx;
  168. display: flex;
  169. flex-direction: column;
  170. }
  171. .drawer-header {
  172. position: relative;
  173. text-align: center;
  174. padding: 30rpx 0;
  175. .title {
  176. font-size: 32rpx;
  177. font-weight: bold;
  178. }
  179. .close-icon {
  180. position: absolute;
  181. right: 30rpx;
  182. top: 50%;
  183. transform: translateY(-50%);
  184. }
  185. }
  186. .search-bar {
  187. display: flex;
  188. align-items: center;
  189. background-color: #ffffff;
  190. border-radius: 50rpx;
  191. padding: 0 25rpx;
  192. height: 70rpx;
  193. margin: 0 30rpx 20rpx;
  194. .search-input {
  195. flex: 1;
  196. font-size: 28rpx;
  197. margin-left: 15rpx;
  198. }
  199. .placeholder {
  200. color: #b0b0b0;
  201. }
  202. }
  203. .store-list-scroll {
  204. flex: 1;
  205. height: 100%;
  206. padding: 0 30rpx;
  207. }
  208. .empty-tip {
  209. text-align: center;
  210. color: #999;
  211. padding-top: 100rpx;
  212. }
  213. .store-card {
  214. background-color: #ffffff;
  215. border-radius: 16rpx;
  216. margin-bottom: 20rpx;
  217. padding: 30rpx;
  218. border: 2rpx solid transparent; // 占位边框
  219. transition: border-color 0.2s;
  220. &.selected {
  221. border-color: #3c82f8; // 选中时的蓝色边框
  222. }
  223. .card-header {
  224. display: flex;
  225. align-items: center;
  226. .store-name {
  227. font-size: 30rpx;
  228. font-weight: bold;
  229. color: #333;
  230. margin-left: 15rpx;
  231. }
  232. }
  233. .info-row {
  234. margin-top: 15rpx;
  235. font-size: 26rpx;
  236. .info-label { color: #999; }
  237. .info-value { color: #333; }
  238. }
  239. }
  240. </style>