detail.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <!-- 优惠券详情 -->
  2. <template>
  3. <s-layout title="优惠券详情">
  4. <view class="bg-white">
  5. <!-- 详情卡片 -->
  6. <view class="detail-wrap ss-p-20">
  7. <view class="detail-box">
  8. <view class="tag-box ss-flex ss-col-center ss-row-center">
  9. <image class="tag-image" :src="sheep.$url.static('/static/img/shop/app/coupon_icon.png')"
  10. mode="aspectFit"></image>
  11. </view>
  12. <view class="top ss-flex-col ss-col-center">
  13. <view class="title ss-m-t-50 ss-m-b-20 ss-m-x-20">{{ state.list.name }}</view>
  14. <view class="subtitle ss-m-b-50">满{{ state.list.enough }}减{{ state.list.amount }}</view>
  15. <!-- (state.list.get_status != 'can_get' && state.list.get_status != 'can_use') ||
  16. state.userCouponId -->
  17. <button class="ss-reset-button ss-m-b-30" :class="
  18. state.list.get_status == 'can_get' || state.list.get_status == 'can_use'
  19. ? 'use-btn'
  20. : 'disable-btn' " :disabled="state.list.status_text=='已过期'" @click="getCoupon">
  21. <!-- {{ state.list.get_status_text }} -->
  22. 立即使用
  23. </button>
  24. <view class="time ss-m-y-30" v-if="
  25. state.list.get_status == 'can_get' ||
  26. state.list.get_status == 'cannot_get' ||
  27. state.list.get_status == 'get_over'
  28. ">
  29. 领取时间:{{ state.list.get_start_time }}至{{ state.list.get_end_time }}
  30. </view>
  31. <view class="time ss-m-y-30" v-else>
  32. 有效期:{{ state.list.use_start_time }}至{{ state.list.use_end_time }}
  33. </view>
  34. <view class="coupon-line ss-m-t-14"></view>
  35. </view>
  36. <view class="bottom">
  37. <view class="type ss-flex ss-col-center ss-row-between ss-p-x-30">
  38. <view>优惠券类型</view>
  39. <view>{{ state.list.type_text }}</view>
  40. </view>
  41. <uni-collapse>
  42. <uni-collapse-item title="优惠券说明" v-if="state.list.description">
  43. <view class="content ss-p-b-20">
  44. <text class="des ss-p-l-30">{{ state.list.description }}</text>
  45. </view>
  46. </uni-collapse-item>
  47. </uni-collapse>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 适用商品 -->
  52. <view class="all-user ss-flex ss-row-center ss-col-center" v-if="state.list.use_scope == 'all_use'">
  53. {{ state.list.use_scope_text }}
  54. </view>
  55. <su-sticky v-else bgColor="#fff">
  56. <view class="goods-title ss-p-20">{{ state.list.use_scope_text }}</view>
  57. <su-tabs :scrollable="true" :list="state.tabMaps" @change="onTabsChange" :current="state.currentTab"
  58. v-if="state.list.use_scope == 'category'"></su-tabs>
  59. </su-sticky>
  60. <view v-if="state.list.use_scope == 'goods' || state.list.use_scope == 'disabled_goods'">
  61. <view v-for="(item, index) in state.list.items_value" :key="index">
  62. <s-goods-column class="ss-m-20" size="lg" :data="item"
  63. :titleColor="props.goodsFieldsStyle?.title?.color"
  64. :subTitleColor="props.goodsFieldsStyle?.subtitle?.color"
  65. @click="sheep.$router.go('/pages/goods/index', { id: item.id })" :goodsFields="{
  66. title: { show: true },
  67. subtitle: { show: true },
  68. price: { show: true },
  69. original_price: { show: true },
  70. sales: { show: true },
  71. stock: { show: false },
  72. }" :buttonShow="state.list.use_scope != 'disabled_goods'"></s-goods-column>
  73. </view>
  74. </view>
  75. <view v-if="state.list.use_scope == 'category'">
  76. <view v-for="(item, index) in state.pagination.data" :key="index">
  77. <s-goods-column class="ss-m-20" size="lg" :data="item"
  78. :titleColor="props.goodsFieldsStyle?.title?.color"
  79. :subTitleColor="props.goodsFieldsStyle?.subtitle?.color"
  80. @click="sheep.$router.go('/pages/goods/index', { id: item.id })" :goodsFields="{
  81. title: { show: true },
  82. subtitle: { show: true },
  83. price: { show: true },
  84. original_price: { show: true },
  85. sales: { show: true },
  86. stock: { show: false },
  87. }" :buttonShow="state.list.use_scope != 'disabled_goods'"></s-goods-column>
  88. </view>
  89. </view>
  90. <uni-load-more v-if="state.pagination.total > 0 && state.list.use_scope == 'category'"
  91. :status="state.loadStatus" :content-text="{
  92. contentdown: '上拉加载更多',
  93. }" @tap="loadmore" />
  94. <s-empty v-if="state.list.use_scope == 'category' && state.pagination.total === 0" paddingTop="0"
  95. icon="/static/soldout-empty.png" text="暂无商品">
  96. </s-empty>
  97. </view>
  98. </s-layout>
  99. </template>
  100. <script setup>
  101. import sheep from '@/sheep';
  102. import {
  103. onLoad,
  104. onReachBottom
  105. } from '@dcloudio/uni-app';
  106. import {
  107. reactive
  108. } from 'vue';
  109. import _ from 'lodash';
  110. const pagination = {
  111. data: [],
  112. current_page: 1,
  113. total: 1,
  114. last_page: 1,
  115. };
  116. const state = reactive({
  117. list: {},
  118. couponId: 0,
  119. userCouponId: 0,
  120. pagination: {
  121. data: [],
  122. current_page: 1,
  123. total: 1,
  124. last_page: 1,
  125. },
  126. tabMaps: [],
  127. loadStatus: '',
  128. categoryId: 0,
  129. });
  130. // 接收参数
  131. const props = defineProps({
  132. includes: {
  133. type: Array,
  134. default () {
  135. return [];
  136. },
  137. },
  138. list: {
  139. type: Array,
  140. default: () => [],
  141. },
  142. goodsFieldsStyle: {
  143. type: Object,
  144. default () {},
  145. },
  146. buyData: {
  147. type: Object,
  148. default () {},
  149. },
  150. });
  151. function onTabsChange(e) {
  152. state.pagination = pagination;
  153. state.currentTab = e.index;
  154. state.categoryId = e.value;
  155. getGoodsList(state.categoryId);
  156. }
  157. async function getGoodsList(categoryId, page = 1, list_rows = 5) {
  158. state.loadStatus = 'loading';
  159. const res = await sheep.$api.goods.list({
  160. category_id: categoryId,
  161. list_rows,
  162. page,
  163. is_category_deep: false,
  164. });
  165. if (res.error === 0) {
  166. let couponlist = _.concat(state.pagination.data, res.data.data);
  167. state.pagination = {
  168. ...res.data,
  169. data: couponlist,
  170. };
  171. if (state.pagination.current_page < state.pagination.last_page) {
  172. state.loadStatus = 'more';
  173. } else {
  174. state.loadStatus = 'noMore';
  175. }
  176. }
  177. }
  178. async function getCoupon() {
  179. const {
  180. error,
  181. msg
  182. } = await sheep.$api.coupon.get(state.couponId);
  183. if (error === 0) {
  184. uni.showToast({
  185. title: msg,
  186. });
  187. setTimeout(() => {
  188. getCouponContent(state.couponId, state.userCouponId);
  189. }, 1000);
  190. }
  191. }
  192. async function getCouponContent(id, c) {
  193. const {
  194. data
  195. } = await sheep.$api.coupon.detail(id, c);
  196. state.list = data;
  197. data.items_value.forEach((i) => {
  198. state.tabMaps.push({
  199. name: i.name,
  200. value: i.id
  201. });
  202. });
  203. state.pagination = pagination;
  204. if (state.list.use_scope == 'category') {
  205. getGoodsList(state.tabMaps[0].value);
  206. }
  207. }
  208. // 加载更多
  209. function loadmore() {
  210. if (state.loadStatus !== 'noMore') {
  211. getGoodsList(state.categoryId, state.pagination.current_page + 1);
  212. }
  213. }
  214. onLoad((options) => {
  215. if (options.data) {
  216. let data = JSON.parse(options.data);
  217. console.log(data);
  218. state.list = data;
  219. return;
  220. }
  221. state.couponId = options.id;
  222. state.userCouponId = options.user_coupon_id;
  223. getCouponContent(state.couponId, state.userCouponId);
  224. });
  225. // 上拉加载更多
  226. onReachBottom(() => {
  227. loadmore();
  228. });
  229. </script>
  230. <style lang="scss" scoped>
  231. .goods-title {
  232. font-size: 34rpx;
  233. font-weight: bold;
  234. color: #333333;
  235. }
  236. .detail-wrap {
  237. background: linear-gradient(180deg,
  238. var(--ui-BG-Main),
  239. var(--ui-BG-Main-gradient),
  240. var(--ui-BG-Main),
  241. #fff);
  242. }
  243. .detail-box {
  244. // background-color: var(--ui-BG);
  245. border-radius: 6rpx;
  246. position: relative;
  247. margin-top: 100rpx;
  248. .tag-box {
  249. width: 140rpx;
  250. height: 140rpx;
  251. background: var(--ui-BG);
  252. border-radius: 50%;
  253. position: absolute;
  254. top: -70rpx;
  255. left: 50%;
  256. z-index: 6;
  257. transform: translateX(-50%);
  258. .tag-image {
  259. width: 104rpx;
  260. height: 104rpx;
  261. border-radius: 50%;
  262. }
  263. }
  264. .top {
  265. background-color: #fff;
  266. border-radius: 20rpx 20rpx 0 0;
  267. -webkit-mask: radial-gradient(circle at 16rpx 100%, #0000 16rpx, red 0) -16rpx;
  268. padding: 110rpx 0 0 0;
  269. position: relative;
  270. z-index: 5;
  271. .title {
  272. font-size: 40rpx;
  273. color: #333;
  274. font-weight: bold;
  275. }
  276. .subtitle {
  277. font-size: 28rpx;
  278. color: #333333;
  279. }
  280. .use-btn {
  281. width: 386rpx;
  282. height: 80rpx;
  283. line-height: 80rpx;
  284. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  285. border-radius: 40rpx;
  286. color: $white;
  287. }
  288. .disable-btn {
  289. width: 386rpx;
  290. height: 80rpx;
  291. line-height: 80rpx;
  292. background: #e5e5e5;
  293. border-radius: 40rpx;
  294. color: $white;
  295. }
  296. .time {
  297. font-size: 26rpx;
  298. font-weight: 400;
  299. color: #999999;
  300. }
  301. .coupon-line {
  302. width: 95%;
  303. border-bottom: 2rpx solid #eeeeee;
  304. }
  305. }
  306. .bottom {
  307. background-color: #fff;
  308. border-radius: 0 0 20rpx 20rpx;
  309. -webkit-mask: radial-gradient(circle at 16rpx 0%, #0000 16rpx, red 0) -16rpx;
  310. padding: 40rpx 30rpx;
  311. .type {
  312. height: 96rpx;
  313. border-bottom: 2rpx solid #eeeeee;
  314. }
  315. }
  316. .des {
  317. font-size: 24rpx;
  318. font-weight: 400;
  319. color: #666666;
  320. }
  321. }
  322. .all-user {
  323. width: 100%;
  324. height: 300rpx;
  325. font-size: 34rpx;
  326. font-weight: bold;
  327. color: #333333;
  328. }
  329. </style>