retail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. <!-- 新增:审核状态Tab筛选 -->
  15. <view class="filter-tabs">
  16. <!-- <view-->
  17. <!-- class="tab-item"-->
  18. <!-- :class="{ active: auditFilter === '' }"-->
  19. <!-- @click="changeAuditFilter('')"-->
  20. <!-- >-->
  21. <!-- <text>全部</text>-->
  22. <!-- </view>-->
  23. <view
  24. class="tab-item"
  25. :class="{ active: auditFilter === 0 }"
  26. @click="changeAuditFilter(0)"
  27. >
  28. <text>待审核</text>
  29. </view>
  30. <view
  31. class="tab-item"
  32. :class="{ active: auditFilter === 1 }"
  33. @click="changeAuditFilter(1)"
  34. >
  35. <text>已审核</text>
  36. </view>
  37. <view
  38. class="tab-item"
  39. :class="{ active: auditFilter === 2 }"
  40. @click="changeAuditFilter(2)"
  41. >
  42. <text>已驳回</text>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 修改:优化scroll-view的高度和滚动设置 -->
  47. <scroll-view
  48. scroll-y="true"
  49. class="list-container"
  50. :style="listContainerStyle"
  51. @scrolltolower="handleScrollToLower"
  52. :lower-threshold="100"
  53. >
  54. <!-- 添加加载状态提示 -->
  55. <view v-if="isLoading && pagination.page === 1" class="loading-wrapper">
  56. <text>加载中...</text>
  57. </view>
  58. <view v-if="storeList.length === 0 && !isLoading" class="empty-list">
  59. <text>没有找到相关门店</text>
  60. </view>
  61. <view v-for="store in storeList" :key="store.id" class="store-card">
  62. <!-- 新增:审核状态标签 -->
  63. <view v-if="store.audit_status" class="audit-tag" :class="store.audit_status">
  64. <text v-if="store.audit_status === 'pending'">待审核</text>
  65. <text v-if="store.audit_status === 'approved'">已审核</text>
  66. <text v-if="store.audit_status === 'rejected'">已驳回</text>
  67. </view>
  68. <view class="card-decorator"></view>
  69. <view class="card-content">
  70. <view class="card-header">
  71. <uni-icons type="shop-filled" size="20" color="#3c82f8"></uni-icons>
  72. <text class="store-name">{{ store.store_name }}</text>
  73. </view>
  74. <view class="info-grid">
  75. <view class="info-row">
  76. <text class="info-label">店主名称:</text>
  77. <text class="info-value">{{ store.contact_name }}</text>
  78. </view>
  79. <view class="info-row">
  80. <text class="info-label">联系方式:</text>
  81. <text class="info-value">{{ store.contact_phone }}</text>
  82. </view>
  83. <view class="info-row">
  84. <text class="info-label">门店地址:</text>
  85. <text class="info-value">{{ store.address }}</text>
  86. </view>
  87. <view class="info-row" v-if="store.review_status === 2">
  88. <text class="info-label">驳回原因:</text>
  89. <text class="info-value" style="color: red">{{ store.reject_reason }}</text>
  90. </view>
  91. </view>
  92. <view class="action-buttons">
  93. <view class="action-btn" @click="viewDetails(store.id)">
  94. <uni-icons type="eye-filled" size="18" color="#3c82f8"></uni-icons>
  95. <text>详情</text>
  96. </view>
  97. <view class="action-btn" @click="dataDetail(store.id)" v-if="ywyId > 0">
  98. <uni-icons type="compose" size="18" color="#3c82f8"></uni-icons>
  99. <text>数据查看</text>
  100. </view>
  101. <view class="action-btn" @click="editStore(store.id)" v-if="ywyId === 0">
  102. <uni-icons type="tune-filled" size="18" color="#3c82f8"></uni-icons>
  103. <text>编辑</text>
  104. </view>
  105. <view class="action-btn" @click="patrolStore(store.id)" v-if="ywyId === 0 && store.review_status === 1">
  106. <uni-icons type="home-filled" size="18" color="#3c82f8"></uni-icons>
  107. <text>巡店</text>
  108. </view>
  109. <view class="action-btn delete-btn" @click="deleteStore(store.id)" v-if="ywyId === 0">
  110. <uni-icons type="trash-filled" size="18" color="#e54d42"></uni-icons>
  111. <text>删除</text>
  112. </view>
  113. </view>
  114. </view>
  115. </view>
  116. <!-- 在列表最后添加一个空的占位元素 -->
  117. <view class="list-placeholder"></view>
  118. <!-- 添加底部加载状态 -->
  119. <view v-if="isLoading && pagination.page > 1" class="load-more">
  120. <text>加载更多...</text>
  121. </view>
  122. <view v-if="loadStatus === 'noMore' && storeList.length > 0" class="load-more">
  123. <text>没有更多数据了</text>
  124. </view>
  125. </scroll-view>
  126. <view class="fixed-footer" v-if="ywyId === 0">
  127. <button class="add-store-btn" @click="addNewStore">新增门店</button>
  128. </view>
  129. <CustomTabbar v-if="ywyId === 0" :current="1"/>
  130. </view>
  131. </template>
  132. <script>
  133. // 您自定义tabBar的路径,请确保正确
  134. import CustomTabbar from '@/components/cjx/tabbar_hexiao_ywy.vue';
  135. import {getStoreList,removeRetail} from "@/api/hexiao";
  136. export default {
  137. components: {
  138. CustomTabbar
  139. },
  140. data() {
  141. return {
  142. searchQuery: '',
  143. storeList: [],
  144. filteredList: [],
  145. pagination: {
  146. page: 1,
  147. limit: 10,
  148. },
  149. ywyId: 0,
  150. isLoading: false,
  151. loadStatus: 'more', // more: 可以继续加载, loading: 加载中, noMore: 没有更多数据
  152. auditFilter: 0, // 1 已审核 0 未审核 2 已驳回
  153. // 新增:防止重复触发滚动事件
  154. scrollTimer: null,
  155. isScrolling: false,
  156. };
  157. },
  158. computed: {
  159. // 计算列表容器高度
  160. listContainerStyle() {
  161. let bottomPadding = 0;
  162. if (this.ywyId === 0) {
  163. // 有底部按钮和tabbar时
  164. bottomPadding = 250; // rpx
  165. }
  166. return {
  167. height: `calc(100vh - ${this.getHeaderHeight()}px)`,
  168. paddingBottom: `${bottomPadding}rpx`
  169. };
  170. }
  171. },
  172. onShow(){
  173. this.fetchStoreList(true);
  174. },
  175. onLoad(opt) {
  176. if(opt.id){
  177. this.ywyId = opt.id;
  178. }
  179. this.fetchStoreList(true);
  180. },
  181. methods: {
  182. // 获取头部高度(搜索栏+筛选Tab)
  183. getHeaderHeight() {
  184. // 搜索栏高度大约 70rpx + 40rpx padding = 110rpx ≈ 55px
  185. // 筛选Tab高度大约 70rpx ≈ 35px
  186. // 总共约 90px
  187. return 90; // 可以根据实际情况调整
  188. },
  189. fetchStoreList(isRefresh = false) {
  190. if (this.isLoading || (this.loadStatus === 'noMore' && !isRefresh)) {
  191. return; // 防止重复加载
  192. }
  193. if (isRefresh) {
  194. this.pagination.page = 1;
  195. this.storeList = [];
  196. this.loadStatus = 'more';
  197. }
  198. this.isLoading = true;
  199. if (!isRefresh) {
  200. this.loadStatus = 'loading';
  201. }
  202. getStoreList(this.pagination.page, this.pagination.limit, this.searchQuery, this.ywyId, this.auditFilter).then(res=>{
  203. let data = res.data;
  204. let mockData = data.records;
  205. if (mockData.length > 0) {
  206. this.storeList = [...this.storeList, ...mockData];
  207. this.pagination.page++;
  208. this.loadStatus = mockData.length < this.pagination.limit ? 'noMore' : 'more';
  209. } else {
  210. this.loadStatus = 'noMore';
  211. }
  212. this.isLoading = false;
  213. // 新增:加载完成后重置滚动状态
  214. this.isScrolling = false;
  215. }).catch(err => {
  216. this.isLoading = false;
  217. this.isScrolling = false;
  218. console.error('加载数据失败:', err);
  219. });
  220. },
  221. handleSearch() {
  222. this.pagination.page = 1;
  223. this.fetchStoreList(true);
  224. },
  225. changeAuditFilter(status) {
  226. if (this.auditFilter !== status) {
  227. this.auditFilter = status;
  228. this.pagination.page = 1;
  229. this.fetchStoreList(true);
  230. }
  231. },
  232. // 优化滚动到底部事件处理
  233. handleScrollToLower() {
  234. // 防止重复触发
  235. if (this.isScrolling || this.isLoading || this.loadStatus === 'noMore') {
  236. return;
  237. }
  238. this.isScrolling = true;
  239. // 添加防抖处理
  240. if (this.scrollTimer) {
  241. clearTimeout(this.scrollTimer);
  242. }
  243. this.scrollTimer = setTimeout(() => {
  244. this.fetchStoreList(false);
  245. this.scrollTimer = null;
  246. }, 300);
  247. },
  248. viewDetails(id) {
  249. uni.navigateTo({ url: '/pages/hexiao/ywy/add_retail?edit=0&id='+id });
  250. console.log('查看详情 ID:', id);
  251. },
  252. dataDetail(id){
  253. uni.navigateTo({ url: '/pages/hexiao/ywy/retail_detail?id='+id });
  254. console.log('查看数据 ID:', id);
  255. },
  256. editStore(id) {
  257. uni.navigateTo({ url: '/pages/hexiao/ywy/add_retail?edit=1&id='+id });
  258. },
  259. patrolStore(id) {
  260. uni.navigateTo({ url: '/pages/hexiao/ywy/add_patrol?edit=1&id='+id });
  261. },
  262. deleteStore(id) {
  263. let self = this;
  264. uni.showModal({
  265. title: '确认删除',
  266. content: '您确定要删除这家门店吗?此操作不可恢复。',
  267. confirmColor: '#e54d42',
  268. success: (res) => {
  269. if (res.confirm) {
  270. removeRetail(id).then(() => {
  271. self.resetSearch();
  272. uni.showToast({ title: '删除成功', icon: 'success' });
  273. });
  274. }
  275. }
  276. });
  277. },
  278. resetSearch(){
  279. this.fetchStoreList(true);
  280. },
  281. addNewStore() {
  282. uni.navigateTo({ url: `/pages/hexiao/ywy/add_retail?edit=1` });
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. .page-container {
  289. background-color: #f5f6fa;
  290. height: 100vh;
  291. display: flex;
  292. flex-direction: column;
  293. overflow: hidden; /* 防止页面整体滚动 */
  294. }
  295. .search-wrapper {
  296. padding: 20rpx;
  297. background-color: #ffffff;
  298. position: sticky;
  299. top: 0;
  300. z-index: 100;
  301. flex-shrink: 0; /* 防止搜索区域被压缩 */
  302. }
  303. .search-bar {
  304. display: flex;
  305. align-items: center;
  306. background-color: #f5f6fa;
  307. border-radius: 50rpx;
  308. padding: 0 25rpx;
  309. height: 70rpx;
  310. }
  311. .search-input {
  312. flex: 1;
  313. font-size: 28rpx;
  314. margin-left: 15rpx;
  315. }
  316. .placeholder {
  317. color: #b0b0b0;
  318. }
  319. /* 新增:审核状态Tab筛选样式 */
  320. .filter-tabs {
  321. display: flex;
  322. background-color: #f5f6fa;
  323. border-radius: 10rpx;
  324. margin-top: 20rpx;
  325. padding: 8rpx;
  326. flex-shrink: 0; /* 防止Tab区域被压缩 */
  327. }
  328. .tab-item {
  329. flex: 1;
  330. text-align: center;
  331. padding: 16rpx 0;
  332. font-size: 26rpx;
  333. color: #666;
  334. border-radius: 8rpx;
  335. transition: all 0.3s;
  336. }
  337. .tab-item.active {
  338. background-color: #ffffff;
  339. color: #3c82f8;
  340. font-weight: bold;
  341. box-shadow: 0 2rpx 8rpx rgba(60, 130, 248, 0.2);
  342. }
  343. /* 新增:审核状态标签样式 */
  344. .audit-tag {
  345. position: absolute;
  346. top: 10rpx;
  347. right: 10rpx;
  348. padding: 6rpx 16rpx;
  349. border-radius: 20rpx;
  350. font-size: 22rpx;
  351. font-weight: bold;
  352. z-index: 1;
  353. }
  354. .audit-tag.pending {
  355. background-color: #fff8e1;
  356. color: #ff9800;
  357. border: 1rpx solid #ff9800;
  358. }
  359. .audit-tag.approved {
  360. background-color: #e8f5e9;
  361. color: #4caf50;
  362. border: 1rpx solid #4caf50;
  363. }
  364. .audit-tag.rejected {
  365. background-color: #ffebee;
  366. color: #f44336;
  367. border: 1rpx solid #f44336;
  368. }
  369. .list-container {
  370. flex: 1;
  371. padding: 0 20rpx;
  372. box-sizing: border-box;
  373. overflow: hidden; /* 确保滚动区域正常工作 */
  374. }
  375. /* 移除原来的padding-bottom设置,改用动态计算 */
  376. /* .list-container.with-padding-bottom {
  377. padding-bottom: 250rpx;
  378. } */
  379. /* 加载状态样式 */
  380. .loading-wrapper {
  381. text-align: center;
  382. padding: 40rpx 0;
  383. color: #999;
  384. font-size: 28rpx;
  385. }
  386. .load-more {
  387. text-align: center;
  388. padding: 30rpx 0;
  389. color: #999;
  390. font-size: 26rpx;
  391. border-top: 1rpx solid #f0f0f0;
  392. margin-top: 20rpx;
  393. }
  394. .empty-list {
  395. text-align: center;
  396. color: #999;
  397. padding-top: 100rpx;
  398. font-size: 28rpx;
  399. }
  400. .store-card {
  401. background-color: #ffffff;
  402. border-radius: 16rpx;
  403. margin-top: 20rpx;
  404. position: relative;
  405. overflow: hidden;
  406. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04);
  407. }
  408. .card-decorator {
  409. position: absolute;
  410. left: 0;
  411. top: 0;
  412. bottom: 0;
  413. width: 8rpx;
  414. background-color: #e3efff;
  415. }
  416. .card-content {
  417. padding: 30rpx;
  418. padding-left: 40rpx;
  419. }
  420. .card-header {
  421. display: flex;
  422. align-items: center;
  423. }
  424. .store-name {
  425. font-size: 32rpx;
  426. font-weight: bold;
  427. color: #333;
  428. margin-left: 15rpx;
  429. }
  430. .info-grid {
  431. margin-top: 20rpx;
  432. font-size: 26rpx;
  433. color: #666;
  434. }
  435. .info-row {
  436. margin-top: 10rpx;
  437. }
  438. .action-buttons {
  439. display: flex;
  440. justify-content: space-around;
  441. border-top: 1rpx solid #f5f5f5;
  442. margin-top: 30rpx;
  443. padding-top: 25rpx;
  444. }
  445. .action-btn {
  446. display: flex;
  447. align-items: center;
  448. font-size: 26rpx;
  449. color: #3c82f8;
  450. }
  451. .action-btn text {
  452. margin-left: 8rpx;
  453. }
  454. .delete-btn {
  455. color: #e54d42;
  456. }
  457. .fixed-footer {
  458. position: fixed;
  459. /* --- 关键改动 1 --- */
  460. /* bottom值 = 自定义tabBar的高度(100rpx) + iPhone等机型的底部安全区 */
  461. bottom: calc(100rpx + constant(safe-area-inset-bottom));
  462. bottom: calc(100rpx + env(safe-area-inset-bottom));
  463. left: 0;
  464. width: 100%;
  465. background-color: #f5f6fa;
  466. padding: 20rpx 30rpx;
  467. box-sizing: border-box;
  468. z-index: 90; // z-index比tabBar低,但比页面内容高
  469. flex-shrink: 0; /* 防止底部按钮区域被压缩 */
  470. }
  471. .add-store-btn {
  472. background-color: #3c82f8;
  473. color: white;
  474. border-radius: 50rpx;
  475. font-size: 32rpx;
  476. height: 90rpx;
  477. line-height: 90rpx;
  478. &::after {
  479. border: none;
  480. }
  481. }
  482. .list-placeholder {
  483. height: 150rpx; /* 这个高度应该等于底部按钮区域的高度 */
  484. width: 100%;
  485. }
  486. </style>