detail.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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.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. getGoodsList(state.tabMaps[0].value);
  232. }
  233. // 加载更多
  234. function loadmore() {
  235. if (state.loadStatus !== 'noMore') {
  236. getGoodsList(state.categoryId, state.pagination.current_page + 1);
  237. }
  238. }
  239. onLoad((options) => {
  240. state.couponId = options.id;
  241. state.userCouponId = options.user_coupon_id;
  242. getCouponContent(state.couponId, state.userCouponId);
  243. });
  244. // 上拉加载更多
  245. onReachBottom(() => {
  246. loadmore();
  247. });
  248. </script>
  249. <style lang="scss" scoped>
  250. .goods-title {
  251. font-size: 34rpx;
  252. font-weight: bold;
  253. color: #333333;
  254. }
  255. .detail-wrap {
  256. background: linear-gradient(
  257. 180deg,
  258. var(--ui-BG-Main),
  259. var(--ui-BG-Main-gradient),
  260. var(--ui-BG-Main),
  261. #fff
  262. );
  263. }
  264. .detail-box {
  265. // background-color: var(--ui-BG);
  266. border-radius: 6rpx;
  267. position: relative;
  268. margin-top: 100rpx;
  269. .tag-box {
  270. width: 140rpx;
  271. height: 140rpx;
  272. background: var(--ui-BG);
  273. border-radius: 50%;
  274. position: absolute;
  275. top: -70rpx;
  276. left: 50%;
  277. z-index: 6;
  278. transform: translateX(-50%);
  279. .tag-image {
  280. width: 104rpx;
  281. height: 104rpx;
  282. border-radius: 50%;
  283. }
  284. }
  285. .top {
  286. background-color: #fff;
  287. border-radius: 20rpx 20rpx 0 0;
  288. -webkit-mask: radial-gradient(circle at 16rpx 100%, #0000 16rpx, red 0) -16rpx;
  289. padding: 110rpx 0 0 0;
  290. position: relative;
  291. z-index: 5;
  292. .title {
  293. font-size: 40rpx;
  294. color: #333;
  295. font-weight: bold;
  296. }
  297. .subtitle {
  298. font-size: 28rpx;
  299. color: #333333;
  300. }
  301. .use-btn {
  302. width: 386rpx;
  303. height: 80rpx;
  304. line-height: 80rpx;
  305. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  306. border-radius: 40rpx;
  307. color: $white;
  308. }
  309. .disable-btn {
  310. width: 386rpx;
  311. height: 80rpx;
  312. line-height: 80rpx;
  313. background: #e5e5e5;
  314. border-radius: 40rpx;
  315. color: $white;
  316. }
  317. .time {
  318. font-size: 26rpx;
  319. font-weight: 400;
  320. color: #999999;
  321. }
  322. .coupon-line {
  323. width: 95%;
  324. border-bottom: 2rpx solid #eeeeee;
  325. }
  326. }
  327. .bottom {
  328. background-color: #fff;
  329. border-radius: 0 0 20rpx 20rpx;
  330. -webkit-mask: radial-gradient(circle at 16rpx 0%, #0000 16rpx, red 0) -16rpx;
  331. padding: 40rpx 30rpx;
  332. .type {
  333. height: 96rpx;
  334. border-bottom: 2rpx solid #eeeeee;
  335. }
  336. }
  337. .des {
  338. font-size: 24rpx;
  339. font-weight: 400;
  340. color: #666666;
  341. }
  342. }
  343. .all-user {
  344. width: 100%;
  345. height: 300rpx;
  346. font-size: 34rpx;
  347. font-weight: bold;
  348. color: #333333;
  349. }
  350. </style>