detail.vue 11 KB

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