give.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <app-layout>
  3. <view class="give" v-if="coupon">
  4. <view class="content" :style="contentStyle">
  5. <view class="avatar dir-left-nowrap main-center cross-center">
  6. <image :src="coupon.avatar"></image>
  7. </view>
  8. <view class="nickname">{{coupon.nickname}}</view>
  9. <view class="title">送你一张优惠券</view>
  10. <template v-if="coupon.status == 1">
  11. <view class="pic dir-left-nowrap cross-between main-center">
  12. <view class="box-grow-0 coupon-left main-center cross-center">
  13. <view class="discount" v-if="coupon.type == 1">{{coupon.discount}}</view>
  14. <view class="sub t-omit" v-else>{{coupon.sub_price}}</view>
  15. </view>
  16. <view class="box-grow-0 coupon-right dir-top-nowrap main-center cross-center">
  17. <view v-if="coupon.min_price > 0">满¥{{coupon.min_price}}可用</view>
  18. <view v-else>无门槛使用</view>
  19. <view class="margin-top">{{coupon.appoint_type_text}}</view>
  20. </view>
  21. <view class="box-grow-1"></view>
  22. </view>
  23. <template v-if="coupon.expire_type == 1">
  24. <view class="time">有效期:领取后{{coupon.expire_day}}天有效</view>
  25. </template>
  26. <template v-else>
  27. <view class="time">有效期:{{coupon.begin_time}} - {{coupon.end_time}}</view>
  28. </template>
  29. <view class="card-btn-group dir-left-nowrap main-center">
  30. <view class="card-btn btn-0 box-grow-0" @click="shareShow = true">
  31. <app-image :img-src="coupon.img_share" width="100%" height="100%"></app-image>
  32. </view>
  33. <view class="card-btn btn-0 box-grow-0" @click="toGoods">
  34. <app-image :img-src="coupon.img_use" width="100%" height="100%"></app-image>
  35. </view>
  36. </view>
  37. <view>
  38. <app-share-qr-code v-model="shareShow" title="生成优惠券海报"
  39. :poster-url="`/pages/poster/poster?coupon_id=` + coupon.id"
  40. :has-poster-nav="true"
  41. ></app-share-qr-code>
  42. </view>
  43. </template>
  44. <view class="card-btn btn-1" v-else @click="receive">
  45. <app-image :img-src="coupon.img_receive" width="100%" height="100%"></app-image>
  46. </view>
  47. </view>
  48. <view>
  49. <app-related-suggestion-product v-if="recommendGoodsList && recommendGoodsList.length"
  50. :list="recommendGoodsList"
  51. text="您或许会喜欢"
  52. :theme="getTheme"
  53. ></app-related-suggestion-product>
  54. </view>
  55. </view>
  56. <view class="card-modal dir-top-nowrap cross-center main-center" v-if="modal.show">
  57. <view class="modal-content" :style="{backgroundImage: `url(`+img_finish_receiving+`)`}">
  58. <view class="error">{{modal.msg}}</view>
  59. <view class="modal-btn" @click="btnClick"></view>
  60. </view>
  61. </view>
  62. </app-layout>
  63. </template>
  64. <script>
  65. import {mapGetters, mapState} from 'vuex';
  66. import AppRelatedSuggestionProduct
  67. from '../../../components/page-component/app-related-suggestion-product/app-related-suggestion-product';
  68. import appShareQrCode from '../../../components/page-component/app-share-qr-code-poster/app-share-qr-code-poster.vue';
  69. import jump from '../../../core/jump.js';
  70. export default {
  71. name: "give",
  72. components: {
  73. AppRelatedSuggestionProduct,appShareQrCode
  74. },
  75. data() {
  76. return {
  77. recommendGoodsList: null,
  78. shareShow: false,
  79. modal: {
  80. show: false,
  81. msg: '',
  82. is_show_back: false
  83. },
  84. coupon: null,
  85. user_id: 0,
  86. img_finish_receiving: null,
  87. };
  88. },
  89. computed: {
  90. ...mapState({
  91. couponImg: state => state.mallConfig.__wxapp_img.coupon,
  92. }),
  93. ...mapGetters('mallConfig', {
  94. getTheme: 'getTheme',
  95. }),
  96. contentStyle() {
  97. let style = '';
  98. if (!this.coupon) {
  99. return '';
  100. }
  101. if (this.coupon.status === 1) {
  102. style = `background-image: url(`+this.coupon.receive_coupon_bg+`)`;
  103. } else {
  104. style = `background-image: url(`+this.coupon.coupon_bg+`)`;
  105. }
  106. return style;
  107. }
  108. },
  109. onLoad(options) { this.$commonLoad.onload(options);
  110. if (typeof options.user_id !== 'undefined') {
  111. this.user_id = options.user_id;
  112. }
  113. this.getList(options.coupon_id);
  114. this.loadRecommendGoodsList();
  115. },
  116. methods: {
  117. getList(coupon_id) {
  118. this.$showLoading();
  119. this.$request({
  120. url: this.$api.coupon.give,
  121. data: {
  122. coupon_id: coupon_id,
  123. user_id: this.user_id
  124. }
  125. }).then(response => {
  126. this.$hideLoading();
  127. this.img_finish_receiving = response.data.img_finish_receiving
  128. if (response.code == 0) {
  129. this.coupon = response.data;
  130. } else {
  131. this.modal = {
  132. show: true,
  133. msg: response.msg,
  134. is_show_back: true,
  135. }
  136. }
  137. }).catch(response => {
  138. this.$hideLoading();
  139. })
  140. },
  141. loadRecommendGoodsList() {
  142. this.$request({
  143. url: this.$api.goods.new_recommend,
  144. method: 'get',
  145. data: {
  146. type: 'order_pay',
  147. },
  148. }).then(response => {
  149. if (response.code === 0) {
  150. this.recommendGoodsList = response.data.list;
  151. }
  152. }).catch(e => {
  153. });
  154. },
  155. btnClick() {
  156. if (this.modal.is_show_back) {
  157. jump({
  158. open_type: 'redirect',
  159. url: '/pages/index/index'
  160. })
  161. } else {
  162. this.modal.show = false;
  163. }
  164. },
  165. receive() {
  166. this.$showLoading();
  167. this.$request({
  168. url: this.$api.coupon.receive,
  169. method: 'get',
  170. data: {
  171. coupon_id: this.coupon.id
  172. }
  173. }).then(response => {
  174. this.$hideLoading();
  175. if (response.code === 0) {
  176. this.getList(this.coupon.id);
  177. } else {
  178. this.modal = {
  179. show: true,
  180. msg: response.msg,
  181. is_show_back: false,
  182. }
  183. }
  184. })
  185. },
  186. toGoods() {
  187. uni.redirectTo({
  188. url: this.coupon.page_url
  189. });
  190. },
  191. },
  192. // #ifdef MP
  193. onShareAppMessage() {
  194. return this.$shareAppMessage({
  195. title: this.coupon.app_share_title,
  196. imageUrl: this.coupon.app_share_pic ? this.coupon.app_share_pic : this.couponImg.img_coupon_2,
  197. path: '/pages/coupon/give/give',
  198. params: {
  199. coupon_id: this.coupon.id
  200. }
  201. });
  202. }
  203. // #endif
  204. }
  205. </script>
  206. <style scoped lang="scss">
  207. .give {
  208. background-color: #ffffff;
  209. }
  210. .content {
  211. width: #{750rpx};
  212. height: #{880rpx};
  213. background-size: 100% 100%;
  214. background-repeat: no-repeat;
  215. background-position: center;
  216. padding-top: #{46rpx};
  217. text-align: center;
  218. .avatar {
  219. width: #{130rpx};
  220. height: #{130rpx};
  221. margin: #{0 auto 30rpx auto};
  222. border-radius: #{130rpx};
  223. overflow: hidden;
  224. image {
  225. width: 100%;
  226. height: 100%;
  227. display: block;
  228. }
  229. }
  230. .nickname {
  231. font-size: $uni-font-size-general-one;
  232. line-height: 1;
  233. }
  234. .title {
  235. margin-top: #{40rpx};
  236. font-size: $uni-line-height-general-two;
  237. line-height: 1;
  238. }
  239. .pic {
  240. margin: #{90rpx auto 0 auto};
  241. width: #{636rpx};
  242. height: #{200rpx};
  243. padding: #{0 16rpx 0 24rpx};
  244. .coupon-left {
  245. width: #{174rpx};
  246. height: 100%;
  247. color: #ffffff;
  248. font-size: #{56rpx};
  249. .discount {
  250. &:after {
  251. content: '折';
  252. font-size: #{32rpx};
  253. }
  254. }
  255. .sub {
  256. &:before {
  257. content: '¥';
  258. font-size: #{32rpx};
  259. }
  260. }
  261. }
  262. .coupon-right {
  263. width: #{300rpx};
  264. height: 100%;
  265. font-size: $uni-font-size-import-two;
  266. .margin-top {
  267. margin-top: #{16rpx};
  268. font-size: $uni-font-size-general-one;
  269. }
  270. }
  271. }
  272. .time {
  273. margin: #{45rpx 0};
  274. font-size: $uni-font-size-weak-one;
  275. }
  276. .card-btn {
  277. width: #{284rpx};
  278. height: #{76rpx};
  279. &.btn-1 {
  280. margin: #{410rpx auto 0 auto};
  281. }
  282. &.btn-0 {
  283. &:first-child {
  284. margin-right: #{38rpx};
  285. }
  286. }
  287. }
  288. }
  289. .card-modal {
  290. background-color: rgba(0, 0, 0, 0.5);
  291. width: 100%;
  292. height: 100%;
  293. position: fixed;
  294. top: 0;
  295. left: 0;
  296. z-index: 1000;
  297. .modal-content {
  298. width: #{600rpx};
  299. height: #{528rpx};
  300. background-size: contain;
  301. background-repeat: no-repeat;
  302. background-position: center;
  303. .error {
  304. margin: #{290rpx auto 0 auto};
  305. text-align: center;
  306. font-size: $uni-font-size-import-one;
  307. }
  308. .modal-btn {
  309. margin: #{62rpx auto 0 auto};
  310. width: #{520rpx};
  311. height: #{90rpx};
  312. border-radius: #{90rpx};
  313. }
  314. }
  315. }
  316. </style>