box-list.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="page">
  3. <u-navbar title="餐盒设置" :autoBack="true" :placeholder="true" :border-bottom="true"></u-navbar>
  4. <view class="list-wrap" :style="{ paddingBottom: listCount ? '160rpx' : '0' }">
  5. <ListScrollView
  6. ref="listScroll"
  7. :api="api"
  8. :init="initParams"
  9. :pageSize="50"
  10. emptyText="暂无内容~"
  11. emptyBtnText="去新建餐盒"
  12. @afterFetch="afterFetch"
  13. @emptyclick="goEdit()"
  14. >
  15. <template v-slot:list="{ data }">
  16. <view class="spec-block" v-for="(item, index) in data" :key="item.id">
  17. <view class="spec-head">
  18. <text class="spec-title">规格{{ index + 1 }}</text>
  19. <view class="spec-ops">
  20. <view class="op" @click="goEdit(item)">
  21. <u-icon name="edit-pen" color="#449AFF" size="28"></u-icon>
  22. <text>编辑</text>
  23. </view>
  24. <view class="op" @click="onDelete(item)">
  25. <u-icon name="trash" color="#449AFF" size="28"></u-icon>
  26. <text>删除</text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="spec-body">
  31. <view class="row">
  32. <text class="label">餐盒名称</text>
  33. <text class="value">{{ item.name || '-' }}</text>
  34. </view>
  35. <view class="row">
  36. <text class="label">餐盒价格</text>
  37. <text class="value">{{ item.price != null ? item.price : 0 }} 元</text>
  38. </view>
  39. <view class="row link" @click="goBind(item)">
  40. <text class="label">已绑商品</text>
  41. <view class="value-wrap">
  42. <text class="value">{{ item.bindCount || 0 }}个</text>
  43. <u-icon name="arrow-right" color="#C7C6CA" size="24"></u-icon>
  44. </view>
  45. </view>
  46. <view class="row last">
  47. <text class="label">餐盒图片</text>
  48. <image v-if="item.image" class="thumb" :src="item.image" mode="aspectFill"></image>
  49. <text v-else class="value muted">暂无图片</text>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. </ListScrollView>
  55. </view>
  56. <view class="footer" v-if="listCount">
  57. <view class="primary-btn" @click="goEdit()">新建餐盒</view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import ListScrollView from '@/components/list-scroll-view/index.vue';
  63. import merchantDishApi, { mapMealBoxItem, getMerchantId } from '@/api/merchantDish.js';
  64. export default {
  65. components: {
  66. ListScrollView
  67. },
  68. data() {
  69. return {
  70. api: {
  71. url: '/groupmeal/gmMerchantMealBox/list',
  72. method: 'GET'
  73. },
  74. listCount: 0,
  75. listReady: false
  76. };
  77. },
  78. computed: {
  79. initParams() {
  80. return {
  81. merchantId: getMerchantId()
  82. };
  83. }
  84. },
  85. onShow() {
  86. if (this.listReady) {
  87. this.reloadList();
  88. } else {
  89. this.listReady = true;
  90. }
  91. },
  92. methods: {
  93. afterFetch(result) {
  94. const records = Array.isArray(result.records) ? result.records : [];
  95. records.forEach((item) => {
  96. Object.assign(item, mapMealBoxItem(item));
  97. });
  98. this.$nextTick(() => {
  99. const scroll = this.$refs.listScroll;
  100. this.listCount = (scroll && scroll.dataList && scroll.dataList.length) || 0;
  101. });
  102. },
  103. reloadList() {
  104. this.$nextTick(() => {
  105. const scroll = this.$refs.listScroll;
  106. if (scroll && scroll.mescroll) {
  107. scroll.reloadList(this.initParams);
  108. }
  109. });
  110. },
  111. goEdit(item) {
  112. const q = item ? `?id=${item.id}` : '';
  113. uni.navigateTo({ url: `/pages/merchantDish/settings/box-form${q}` });
  114. },
  115. goBind(item) {
  116. uni.navigateTo({ url: `/pages/merchantDish/settings/box-bind?id=${item.id}` });
  117. },
  118. onDelete(item) {
  119. uni.showModal({
  120. content: '确定删除该餐盒?删除后商品绑定关系将解除',
  121. confirmColor: '#449AFF',
  122. success: (res) => {
  123. if (!res.confirm) return;
  124. merchantDishApi.mealBoxDelete(item.id).then((r) => {
  125. this.$tip.toast(r.data.message || (r.data.code === 200 ? '删除成功' : '删除失败'));
  126. if (r.data.code === 200) this.reloadList();
  127. });
  128. }
  129. });
  130. }
  131. }
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. .page {
  136. height: 100vh;
  137. background: #f7f8fa;
  138. display: flex;
  139. flex-direction: column;
  140. }
  141. .list-wrap {
  142. flex: 1;
  143. height: 0;
  144. box-sizing: border-box;
  145. }
  146. .spec-block {
  147. margin-bottom: 16rpx;
  148. }
  149. .spec-head {
  150. display: flex;
  151. align-items: center;
  152. justify-content: space-between;
  153. padding: 20rpx 24rpx;
  154. background: #eef3f8;
  155. .spec-title {
  156. font-size: 30rpx;
  157. font-weight: 600;
  158. color: #333;
  159. }
  160. .spec-ops {
  161. display: flex;
  162. align-items: center;
  163. .op {
  164. display: flex;
  165. align-items: center;
  166. margin-left: 28rpx;
  167. font-size: 26rpx;
  168. color: #449aff;
  169. text {
  170. margin-left: 6rpx;
  171. }
  172. }
  173. }
  174. }
  175. .spec-body {
  176. background: #fff;
  177. }
  178. .row {
  179. display: flex;
  180. align-items: center;
  181. justify-content: space-between;
  182. min-height: 96rpx;
  183. padding: 0 24rpx;
  184. border-bottom: 1rpx solid #f0f0f0;
  185. &.last {
  186. border-bottom: none;
  187. }
  188. &.link:active {
  189. background: #fafafa;
  190. }
  191. .label {
  192. font-size: 28rpx;
  193. color: #333;
  194. flex-shrink: 0;
  195. }
  196. .value {
  197. font-size: 28rpx;
  198. color: #333;
  199. text-align: right;
  200. &.muted {
  201. color: #999;
  202. }
  203. }
  204. .value-wrap {
  205. display: flex;
  206. align-items: center;
  207. .value {
  208. margin-right: 4rpx;
  209. }
  210. }
  211. .thumb {
  212. width: 72rpx;
  213. height: 72rpx;
  214. border-radius: 8rpx;
  215. background: #eee;
  216. }
  217. }
  218. .footer {
  219. position: fixed;
  220. left: 0;
  221. right: 0;
  222. bottom: 0;
  223. z-index: 20;
  224. padding: 20rpx 40rpx calc(20rpx + env(safe-area-inset-bottom));
  225. background: #fff;
  226. }
  227. .primary-btn {
  228. height: 88rpx;
  229. line-height: 88rpx;
  230. text-align: center;
  231. color: #fff;
  232. font-size: 32rpx;
  233. border-radius: 44rpx;
  234. background: linear-gradient( 89deg, #10ABFE 0%, #2260F6 100%);
  235. }
  236. /* 空态按钮对齐设计:蓝描边胶囊 */
  237. ::v-deep .mescroll-empty .empty-tip {
  238. font-size: 28rpx;
  239. color: #999;
  240. margin-top: 0;
  241. }
  242. ::v-deep .mescroll-empty .empty-btn {
  243. margin-top: 40rpx;
  244. min-width: 260rpx;
  245. padding: 16rpx 40rpx;
  246. font-size: 28rpx;
  247. color: #449aff;
  248. border: 2rpx solid #449aff;
  249. border-radius: 36rpx;
  250. background: #fff;
  251. }
  252. </style>