detail.vue 10 KB

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