shareStore.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <view class="page">
  3. <u-navbar title="共享门店" :autoBack="true" :placeholder="true"></u-navbar>
  4. <view class="list-wrap">
  5. <ListScrollView
  6. ref="listScroll"
  7. :api="api"
  8. :init="initParams"
  9. :pageSize="10"
  10. @afterFetch="afterFetch"
  11. >
  12. <template v-slot:list="{ data }">
  13. <view class="list">
  14. <view class="store-card" v-for="item in data" :key="item.id">
  15. <view class="del-btn" @click.stop="onDelete(item)">
  16. <image class="del-bg" src="/static/topUp/del.png" mode="scaleToFill"></image>
  17. <text class="del-text">删除</text>
  18. </view>
  19. <image class="logo" :src="item.logo || defaultLogo" mode="aspectFill"></image>
  20. <view class="info">
  21. <view class="name u-line-1">{{ item.name }}</view>
  22. <view class="meta">
  23. <view class="stars">
  24. <u-icon
  25. v-for="n in 5"
  26. :key="n"
  27. name="heart-fill"
  28. :color="n <= Math.round(item.rating) ? '#FF4D4F' : '#E5E5E5'"
  29. size="20"
  30. ></u-icon>
  31. </view>
  32. <text class="meta-text">{{ formatRating(item) }}</text>
  33. </view>
  34. <view class="addr u-line-1">{{ item.address || '暂无地址' }}</view>
  35. <view class="distance" v-if="item.distance">距您{{ item.distance }}</view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. </ListScrollView>
  41. </view>
  42. <view class="footer">
  43. <view class="add-btn" :class="{ disabled: !canAdd }" @click="goAdd">添加</view>
  44. </view>
  45. <!-- 删除确认弹窗 -->
  46. <u-popup v-model="confirmVisible" mode="center" border-radius="24" :mask-close-able="false">
  47. <view class="confirm-dialog">
  48. <view class="confirm-title">提示</view>
  49. <view class="confirm-body">
  50. <text class="confirm-text">是否确认删除该共享门店?</text>
  51. </view>
  52. <view class="confirm-footer">
  53. <view class="btn cancel" @click="onConfirmCancel">取消</view>
  54. <view class="btn ok" @click="confirmDelete">确定</view>
  55. </view>
  56. </view>
  57. </u-popup>
  58. </view>
  59. </template>
  60. <script>
  61. import prepaidApi, { getMerchantId } from '@/api/memberPrepaid.js'
  62. import ListScrollView from '@/components/list-scroll-view/index.vue'
  63. const DEFAULT_LOGO = '/static/index/shop.png'
  64. const BASE = '/memberPrepaidMerchant'
  65. export default {
  66. components: {
  67. ListScrollView
  68. },
  69. data() {
  70. return {
  71. defaultLogo: DEFAULT_LOGO,
  72. canAdd: false,
  73. confirmVisible: false,
  74. pendingDelete: null,
  75. deleting: false,
  76. api: {
  77. url: `${BASE}/store/shared/page`,
  78. method: 'GET'
  79. },
  80. initParams: {
  81. merchantId: getMerchantId()
  82. },
  83. _listReady: false
  84. };
  85. },
  86. onShow() {
  87. this.confirmVisible = false;
  88. this.pendingDelete = null;
  89. this.refreshEnabled();
  90. this.initParams = { merchantId: getMerchantId() };
  91. // 首次由 ListScrollView 自动加载;从添加页返回时刷新
  92. if (this._listReady && this.$refs.listScroll && this.$refs.listScroll.mescroll) {
  93. this.$refs.listScroll.reloadList(this.initParams);
  94. } else {
  95. this._listReady = true;
  96. }
  97. },
  98. methods: {
  99. formatRating(item) {
  100. const score = Number(item.rating) || 0;
  101. const count = item.reviewCount;
  102. let countText = '';
  103. if (count === undefined || count === null || count === '') {
  104. countText = '暂无评论';
  105. } else if (typeof count === 'string') {
  106. countText = /评价|评论/.test(count) ? count : `${count}条评论`;
  107. } else {
  108. countText = `${count}条评论`;
  109. }
  110. return `${score.toFixed(1)}分 | ${countText}`;
  111. },
  112. mapStore(item) {
  113. return {
  114. id: item.merchantId || item.id,
  115. name: item.storeName || item.name || '',
  116. logo: item.headPhoto || item.logo || DEFAULT_LOGO,
  117. address: item.address || '',
  118. rating: Number(item.grade || item.rating || 0),
  119. reviewCount: item.commentNum ?? item.reviewCount ?? '',
  120. distance: item.distance || item.distanceText || ''
  121. };
  122. },
  123. afterFetch(result) {
  124. const records = Array.isArray(result.records)
  125. ? result.records
  126. : (result.page && Array.isArray(result.page.records) ? result.page.records : []);
  127. records.forEach((item) => {
  128. Object.assign(item, this.mapStore(item));
  129. });
  130. },
  131. refreshEnabled() {
  132. const merchantId = getMerchantId();
  133. if (!merchantId) {
  134. this.canAdd = false;
  135. return;
  136. }
  137. prepaidApi.getFeatureStatus(merchantId).then((res) => {
  138. if (res.data.code !== 200) return;
  139. const data = res.data.result || {};
  140. this.canAdd = Number(data.auditStatus) === 2 && Number(data.operationStatus) === 1;
  141. });
  142. },
  143. goAdd() {
  144. if (!this.canAdd) {
  145. uni.showToast({ title: '请先开启储值功能', icon: 'none' });
  146. return;
  147. }
  148. uni.navigateTo({ url: '/pages/topUp/shareStoreAdd' });
  149. },
  150. onDelete(item) {
  151. this.pendingDelete = item;
  152. this.confirmVisible = true;
  153. },
  154. onConfirmCancel() {
  155. this.confirmVisible = false;
  156. this.pendingDelete = null;
  157. },
  158. confirmDelete() {
  159. const item = this.pendingDelete;
  160. this.confirmVisible = false;
  161. this.pendingDelete = null;
  162. if (!item || this.deleting) return;
  163. this.deleting = true;
  164. prepaidApi
  165. .removeSharedStore(item.id)
  166. .then((res) => {
  167. if (res.data.code === 200) {
  168. uni.showToast({ title: '已删除共享', icon: 'none' });
  169. if (this.$refs.listScroll) {
  170. this.$refs.listScroll.reloadList(this.initParams);
  171. }
  172. } else {
  173. uni.showToast({ title: res.data.message || '删除失败', icon: 'none' });
  174. }
  175. })
  176. .catch(() => {
  177. uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
  178. })
  179. .then(() => {
  180. this.deleting = false;
  181. });
  182. }
  183. }
  184. };
  185. </script>
  186. <style scoped lang="scss">
  187. .page {
  188. height: 100vh;
  189. background: #f7f7f7;
  190. display: flex;
  191. flex-direction: column;
  192. box-sizing: border-box;
  193. }
  194. .list-wrap {
  195. flex: 1;
  196. min-height: 0;
  197. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  198. box-sizing: border-box;
  199. }
  200. .list {
  201. padding: 24rpx;
  202. }
  203. .store-card {
  204. position: relative;
  205. display: flex;
  206. align-items: flex-start;
  207. background: #fff;
  208. border-radius: 16rpx;
  209. padding: 24rpx;
  210. margin-bottom: 20rpx;
  211. overflow: hidden;
  212. .del-btn {
  213. position: absolute;
  214. top: 0;
  215. right: 0;
  216. width: 96rpx;
  217. height: 44rpx;
  218. z-index: 2;
  219. .del-bg {
  220. position: absolute;
  221. left: 0;
  222. top: 0;
  223. width: 100%;
  224. height: 100%;
  225. }
  226. .del-text {
  227. position: relative;
  228. z-index: 1;
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. width: 100%;
  233. height: 100%;
  234. font-size: 22rpx;
  235. color: #1C7CF9;
  236. line-height: 1;
  237. padding-left: 8rpx;
  238. box-sizing: border-box;
  239. }
  240. }
  241. .logo {
  242. width: 120rpx;
  243. height: 120rpx;
  244. border-radius: 12rpx;
  245. background: #f0f0f0;
  246. flex-shrink: 0;
  247. margin-right: 20rpx;
  248. }
  249. .info {
  250. flex: 1;
  251. min-width: 0;
  252. padding-right: 80rpx;
  253. position: relative;
  254. .name {
  255. font-size: 30rpx;
  256. font-weight: 600;
  257. color: #333;
  258. line-height: 1.35;
  259. margin-bottom: 10rpx;
  260. }
  261. .meta {
  262. display: flex;
  263. align-items: center;
  264. gap: 8rpx;
  265. margin-bottom: 10rpx;
  266. .stars {
  267. display: flex;
  268. align-items: center;
  269. gap: 2rpx;
  270. }
  271. .meta-text {
  272. font-size: 22rpx;
  273. color: #FF4D4F;
  274. line-height: 1.2;
  275. }
  276. }
  277. .addr {
  278. font-size: 22rpx;
  279. color: #999;
  280. line-height: 1.4;
  281. padding-right: 120rpx;
  282. }
  283. .distance {
  284. position: absolute;
  285. right: 0;
  286. bottom: 0;
  287. font-size: 22rpx;
  288. color: #666;
  289. line-height: 1.4;
  290. }
  291. }
  292. }
  293. .footer {
  294. position: fixed;
  295. left: 0;
  296. right: 0;
  297. bottom: 0;
  298. padding: 16rpx 32rpx calc(16rpx + env(safe-area-inset-bottom));
  299. background: #fff;
  300. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.04);
  301. z-index: 20;
  302. .add-btn {
  303. height: 88rpx;
  304. line-height: 88rpx;
  305. text-align: center;
  306. background: linear-gradient(269deg, #2260F6 0%, #0FB0FF 100%);
  307. border-radius: 160rpx;
  308. color: #fff;
  309. font-size: 32rpx;
  310. font-weight: 500;
  311. &.disabled {
  312. background: #B7D4FF;
  313. color: #fff;
  314. }
  315. }
  316. }
  317. .confirm-dialog {
  318. width: 560rpx;
  319. background: #fff;
  320. border-radius: 24rpx;
  321. overflow: hidden;
  322. padding: 48rpx 40rpx 40rpx;
  323. box-sizing: border-box;
  324. .confirm-title {
  325. text-align: center;
  326. font-size: 34rpx;
  327. font-weight: 600;
  328. color: #333;
  329. line-height: 1.4;
  330. margin-bottom: 28rpx;
  331. }
  332. .confirm-body {
  333. padding: 0 8rpx 40rpx;
  334. .confirm-text {
  335. display: block;
  336. text-align: center;
  337. font-size: 28rpx;
  338. color: #333;
  339. line-height: 1.6;
  340. }
  341. }
  342. .confirm-footer {
  343. display: flex;
  344. align-items: center;
  345. justify-content: space-between;
  346. gap: 24rpx;
  347. .btn {
  348. flex: 1;
  349. height: 80rpx;
  350. line-height: 80rpx;
  351. text-align: center;
  352. border-radius: 40rpx;
  353. font-size: 30rpx;
  354. box-sizing: border-box;
  355. }
  356. .cancel {
  357. color: #999;
  358. background: #fff;
  359. border: 2rpx solid #dcdcdc;
  360. }
  361. .ok {
  362. color: #fff;
  363. background: linear-gradient(90deg, #3ab3ff 0%, #2472ff 100%);
  364. border: none;
  365. }
  366. }
  367. }
  368. </style>