app-details.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view class="page" v-if="list">
  3. <view>
  4. <!-- 优惠券信息 -->
  5. <view class="info-top">
  6. <view class="name">{{list.name}}</view>
  7. <template v-if="list.type == 2">
  8. <view class="price">¥{{list.sub_price | reservedNum}}</view>
  9. </template>
  10. <template v-else-if="list.type == 1">
  11. <view class="price">{{list.discount | reservedNum}}折</view>
  12. </template>
  13. <view v-if="isShowShare" class="share-img">
  14. <image src="/static/image/coupon/btn_share.png" @click="shareShow = true"></image>
  15. <view>
  16. <app-share-qr-code v-model="shareShow" title="生成优惠券海报"
  17. @share="hShareAppMessage"
  18. :poster-url="`/pages/poster/poster?coupon_id=` + list.id"
  19. :has-poster-nav="true"
  20. ></app-share-qr-code>
  21. </view>
  22. </view>
  23. <view v-if="list.min_price > 0">满{{list.min_price | reservedNum}}可用</view>
  24. <view v-else-if="list.min_price == 0">无门槛使用</view>
  25. <view v-if="list.discount_limit">优惠上限:¥{{list.discount_limit | reservedNum}}</view>
  26. <view v-if="list.appoint_type == 4">
  27. <view class="scan-code">仅限当面付活动使用</view>
  28. </view>
  29. <view v-if="list.appoint_type == 5">
  30. <view class="scan-code">仅限礼品卡使用</view>
  31. </view>
  32. <view @click="toGoods" v-if="list.status == 1">
  33. <button style="background-color: #fff;color: #ff4544;border: 1rpx solid #ff4544"
  34. :class="[`btn`]">
  35. 立即使用
  36. </button>
  37. </view>
  38. <view @click="receive(list.id)" v-else-if="list.status == 0">
  39. <button style="color:#fff;border: 1rpx solid #ff4544;background: #ff4544;" :class="[`btn`]">立即领取
  40. </button>
  41. </view>
  42. <button class="btn used" v-else-if="list.status == 2">已使用</button>
  43. <button class="btn used" v-else-if="list.status == 3">已过期</button>
  44. <button class="btn used" v-else-if="list.status == 4">已领取</button>
  45. </view>
  46. <!-- 分割线 -->
  47. <view class="line">
  48. <image src="/static/image/line.png"></image>
  49. </view>
  50. <!-- 优惠券使用信息 -->
  51. <view class="details">
  52. <view class="title">有效期</view>
  53. <view v-if="list.expire_type == '2'">{{list.begin_time}} - {{list.end_time}}
  54. </view>
  55. <view v-else-if="list.expire_day > 0">领取后{{list.expire_day}}天内有效</view>
  56. <view class="title">使用规则</view>
  57. <view v-if="list.appoint_type == '1'">本券仅限购买
  58. <text v-for="(cat,index) in list.cat" :key="cat.id">{{cat.name}}
  59. <text v-if="index !== list.cat.length -1">、</text>
  60. </text>
  61. 分类下的商品。
  62. </view>
  63. <view v-if="list.appoint_type == '2'">本券仅限购买
  64. <text v-for="(good,index) in list.goods" :key="good.id">{{good.name}}
  65. <text v-if="index !== list.goods.length -1">、</text>
  66. </text>
  67. </view>
  68. <view v-if="list.appoint_type == '3'">本券全场通用。</view>
  69. <view v-if="list.appoint_type == '4'">本券仅限当面付活动使用。</view>
  70. <view v-if="list.appoint_type == '5'">本券仅限礼品卡使用。</view>
  71. <view class="title">使用说明</view>
  72. <view>
  73. <text style="word-break: break-all;">{{list.rule}}</text>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import {mapGetters} from "vuex";
  81. import appShareQrCode from '@/components/page-component/app-share-qr-code-poster/app-share-qr-code-poster.vue';
  82. export default {
  83. name: "app-details",
  84. components: {appShareQrCode},
  85. props: {
  86. isShowShare: Boolean,
  87. couponId: {
  88. type: String,
  89. default() {
  90. return '0';
  91. }
  92. },
  93. // 入口类型 0--领券中心 1--会员专享 2--我的优惠券
  94. type: {
  95. type: Number,
  96. default() {
  97. return 0;
  98. }
  99. },
  100. detailList: {
  101. type: Object,
  102. default() {
  103. return null;
  104. }
  105. }
  106. },
  107. data() {
  108. return {
  109. list: {},
  110. shareShow: false,
  111. };
  112. },
  113. computed: {
  114. ...mapGetters({
  115. userInfo: 'user/info',
  116. })
  117. },
  118. watch: {
  119. // #ifndef H5
  120. couponId() {
  121. if (this.couponId > 0) {
  122. this.getList(this.couponId);
  123. }
  124. },
  125. // #endif
  126. detailList() {
  127. if (this.detailList) {
  128. this.list = this.detailList;
  129. }
  130. }
  131. },
  132. created() {
  133. // #ifdef H5
  134. if (this.couponId > 0) {
  135. this.getList(this.couponId);
  136. }
  137. // #endif
  138. },
  139. // #ifdef MP
  140. onShareAppMessage() {
  141. return this.hShareAppMessage();
  142. },
  143. // #endif
  144. methods: {
  145. hShareAppMessage(s= false){
  146. return this.$shareAppMessage({
  147. title: this.list.name,
  148. imageUrl:"",
  149. path: "/pages/coupon/details/details",
  150. params: {
  151. id: this.list.id
  152. }
  153. }, s);
  154. },
  155. getList(id) {
  156. let that = this;
  157. that.$showLoading({
  158. type: 'global',
  159. text: '加载中...'
  160. });
  161. let url = that.$api.coupon.detail;
  162. let para = {
  163. coupon_id: id
  164. };
  165. if (this.type === 2) {
  166. url = that.$api.coupon.user_coupon_detail;
  167. para = {
  168. user_coupon_id: id
  169. };
  170. }
  171. that.$request({
  172. url: url,
  173. data: para
  174. }).then(response => {
  175. that.$hideLoading();
  176. if (response.code === 0) {
  177. that.list = response.data.list;
  178. } else {
  179. uni.showToast({
  180. title: response.msg,
  181. icon: 'none',
  182. duration: 1000
  183. });
  184. }
  185. }).catch(() => {
  186. that.$hideLoading();
  187. });
  188. },
  189. toGoods() {
  190. uni.navigateTo({
  191. url: this.list.page_url
  192. });
  193. },
  194. receive(id) {
  195. let that = this;
  196. if (this.type === 2) {
  197. return false;
  198. }
  199. if (that.loading) {
  200. return false
  201. }
  202. that.loading = true;
  203. uni.showLoading({
  204. title: '领取中...'
  205. });
  206. that.$request({
  207. url: that.type === 1 ? that.$api.member.receive : that.$api.coupon.receive,
  208. data: {
  209. coupon_id: id
  210. },
  211. }).then(response => {
  212. that.loading = false;
  213. uni.hideLoading();
  214. if (response.code === 0) {
  215. uni.showToast({
  216. title: response.msg,
  217. duration: 1000,
  218. mask: true,
  219. });
  220. } else {
  221. uni.showToast({
  222. title: response.msg,
  223. icon: 'none',
  224. duration: 1000,
  225. mask: true,
  226. });
  227. }
  228. this.getList(id);
  229. }).catch(() => {
  230. uni.hideLoading();
  231. that.$event.on(that.$const.EVENT_USER_LOGIN).then(() => {
  232. that.receive(id);
  233. });
  234. });
  235. },
  236. },
  237. filters: {
  238. reservedNum(data) {
  239. return Number(data);
  240. }
  241. }
  242. }
  243. </script>
  244. <style scoped lang="scss">
  245. .page {
  246. height: 100%;
  247. background-color: #d6b985;
  248. width: 100%;
  249. padding: #{20rpx} 0;
  250. position: absolute;
  251. }
  252. .info-top {
  253. background-color: #fff;
  254. margin: 0 #{25rpx};
  255. text-align: center;
  256. padding-top: #{60rpx};
  257. padding-bottom: #{8rpx};
  258. border-top-left-radius: #{25rpx};
  259. border-top-right-radius: #{25rpx};
  260. color: #353535;
  261. font-size: #{32rpx};
  262. position: relative;
  263. }
  264. .name {
  265. font-size: #{28rpx};
  266. color: #666;
  267. }
  268. .price {
  269. font-size: #{56rpx};
  270. margin-top: #{28rpx};
  271. margin-bottom: #{10rpx};
  272. }
  273. .scan-code {
  274. height: #{56rpx};
  275. line-height: #{52rpx};
  276. margin: #{35rpx} auto 0;
  277. color: #ff4544;
  278. font-size: #{30rpx};
  279. border: none;
  280. }
  281. .btn {
  282. height: #{56rpx};
  283. line-height: #{52rpx};
  284. width: #{240rpx};
  285. margin: #{35rpx} auto 0;
  286. font-size: #{30rpx};
  287. border-radius: #{28rpx};
  288. border: #{2rpx} solid;
  289. }
  290. .btn.used {
  291. background-color: #f7f7f7;
  292. color: #acacac;
  293. border: #{2rpx} solid #f7f7f7;
  294. }
  295. .btn::after {
  296. border: 0;
  297. }
  298. .line {
  299. height: #{50rpx};
  300. margin: #{-4rpx} #{25rpx} 0;
  301. background-color: #fff;
  302. }
  303. .line image {
  304. height: 100%;
  305. width: 100%;
  306. }
  307. .details {
  308. background-color: #fff;
  309. margin: #{-4rpx} #{25rpx} 0;
  310. font-size: #{28rpx};
  311. padding: #{25rpx} #{40rpx} #{65rpx};
  312. border-bottom-left-radius: #{25rpx};
  313. border-bottom-right-radius: #{25rpx};
  314. }
  315. .details .title {
  316. color: #b0b0b0;
  317. font-size: #{26rpx};
  318. margin-bottom: #{25rpx};
  319. margin-top: #{50rpx};
  320. }
  321. .scan-code {
  322. height: #{56rpx};
  323. line-height: #{52rpx};
  324. margin: #{35rpx} auto 0;
  325. color: #ff4544;
  326. font-size: #{30rpx};
  327. border: none;
  328. }
  329. .info-top .share-img {
  330. position: absolute;
  331. right: #{32rpx};
  332. top: #{32rpx};
  333. z-index: 5;
  334. width: #{94rpx};
  335. height: #{94rpx};
  336. image {
  337. width: 100%;
  338. height: 100%;
  339. display: block;
  340. }
  341. }
  342. </style>