buy.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view v-show="!isLoading" class="container">
  3. <!-- 卡券信息 -->
  4. <view v-if="!isLoading" class="coupon-info m-top20">
  5. <!-- 标题、分享 -->
  6. <view class="info-item info-item__name dis-flex flex-y-center">
  7. <view class="coupon-name flex-box">
  8. <text class="twolist-hidden">{{ couponInfo.name }}</text>
  9. </view>
  10. <!-- #ifdef MP-WEIXIN -->
  11. <view class="coupon-share__line"></view>
  12. <view class="coupon-share">
  13. <button class="share-btn dis-flex flex-dir-column" open-type="share">
  14. <text class="share__icon iconfont icon-fenxiang-post"></text>
  15. <text class="f-24">分享</text>
  16. </button>
  17. </view>
  18. <!-- #endif -->
  19. </view>
  20. <!-- 卡券预存规则 -->
  21. <view class="store-rule">
  22. <view class="title">预存规则:</view>
  23. <view v-for="(item, index) in storeRule" :key="index" class="item">
  24. <text>预存¥{{ item.store }} 到账 ¥{{ item.upStore }}</text>
  25. </view>
  26. </view>
  27. <view class="info-item">
  28. <text>已有<text class="number">{{ couponInfo.gotNum }}</text>人预存,剩余<text class="number">{{ couponInfo.limitNum }}</text>名额</text>
  29. </view>
  30. <view class="info-item">
  31. <text>有效期:{{ couponInfo.effectiveDate }}</text>
  32. </view>
  33. </view>
  34. <!-- 选择卡券规格 -->
  35. <view class="coupon-choice m-top20 b-f" @click="onShowPopup()">
  36. <view class="spec-list">
  37. <view class="flex-box">
  38. <text class="col-8">选择:</text>
  39. <text class="spec-name" key="index">预存金额、数量</text>
  40. </view>
  41. <view class="f-26 col-9 t-r">
  42. <text class="iconfont icon-xiangyoujiantou"></text>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 预存选项弹窗 -->
  47. <Popup v-if="!isLoading" v-model="showPopup" :couponInfo="couponInfo" :storeRule="storeRule"/>
  48. <!-- 卡券描述 -->
  49. <view v-if="!isLoading" class="coupon-content m-top20">
  50. <view class="item-title b-f">
  51. <text>卡券描述</text>
  52. </view>
  53. <block v-if="couponInfo.description != ''">
  54. <view class="coupon-content-detail b-f">
  55. <jyf-parser :html="couponInfo.description"></jyf-parser>
  56. </view>
  57. </block>
  58. <empty v-else tips="亲,暂无卡券描述" />
  59. </view>
  60. <!-- 底部选项卡 -->
  61. <view class="footer-fixed">
  62. <view class="footer-container">
  63. <!-- 导航图标 -->
  64. <view class="foo-item-fast">
  65. <!-- 客服 (仅微信小程序端显示) -->
  66. <!-- #ifdef MP-WEIXIN -->
  67. <button class="btn-normal" open-type="contact">
  68. <view class="fast-item">
  69. <view class="fast-icon">
  70. <text class="iconfont icon-kefu1"></text>
  71. </view>
  72. <view class="fast-text">
  73. <text>客服</text>
  74. </view>
  75. </view>
  76. </button>
  77. <!-- #endif -->
  78. </view>
  79. <!-- 操作按钮 -->
  80. <view class="foo-item-btn">
  81. <view class="btn-wrapper">
  82. <view class="btn-item btn-item-main" @click="onShowPopup()">
  83. <text>立即预存</text>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import * as CouponApi from '@/api/coupon'
  93. import jyfParser from '@/components/jyf-parser/jyf-parser'
  94. import Shortcut from '@/components/shortcut'
  95. import Popup from './components/Popup'
  96. export default {
  97. components: {
  98. jyfParser,
  99. Shortcut,
  100. Popup
  101. },
  102. data() {
  103. return {
  104. // 正在加载
  105. isLoading: true,
  106. // 当前卡券ID
  107. couponId: null,
  108. // 卡券详情
  109. couponInfo: null,
  110. // 预存规则
  111. storeRule: [],
  112. // 显示/隐藏弹窗
  113. showPopup: false
  114. }
  115. },
  116. /**
  117. * 生命周期函数--监听页面加载
  118. */
  119. onLoad(options) {
  120. // 卡券ID
  121. this.couponId = parseInt(options.couponId)
  122. // 加载页面数据
  123. this.onRefreshPage()
  124. },
  125. methods: {
  126. // 刷新页面数据
  127. onRefreshPage() {
  128. const app = this
  129. app.isLoading = true
  130. Promise.all([app.getCouponDetail()])
  131. .finally(() => app.isLoading = false)
  132. },
  133. // 获取卡券信息
  134. getCouponDetail() {
  135. const app = this
  136. return new Promise((resolve, reject) => {
  137. CouponApi.detail(app.couponId)
  138. .then(result => {
  139. app.couponInfo = result.data
  140. let ruleItem = app.couponInfo.inRule.split(",");
  141. ruleItem.forEach(function(item) {
  142. let rule = item.split("_")
  143. app.storeRule.push({"store": rule[0], "upStore": rule[1]})
  144. })
  145. resolve(result)
  146. })
  147. .catch(err => reject(err))
  148. })
  149. },
  150. /**
  151. * 显示/隐藏预存弹窗
  152. */
  153. onShowPopup() {
  154. this.showPopup = !this.showPopup
  155. },
  156. // 跳转到首页
  157. onTargetHome(e) {
  158. this.$navTo('pages/index/index')
  159. }
  160. },
  161. /**
  162. * 分享当前页面
  163. */
  164. onShareAppMessage() {
  165. const app = this
  166. // 构建页面参数
  167. const params = app.$getShareUrlParams({
  168. couponId: app.couponId
  169. })
  170. return {
  171. title: app.couponInfo.name,
  172. path: `/pages/prestore/buy?${params}`
  173. }
  174. },
  175. /**
  176. * 分享到朋友圈
  177. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  178. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  179. */
  180. onShareTimeline() {
  181. const app = this
  182. // 构建页面参数
  183. const params = app.$getShareUrlParams({
  184. couponId: app.couponId,
  185. })
  186. return {
  187. title: app.couponInfo.name,
  188. path: `/pages/prestore/buy?${params}`
  189. }
  190. }
  191. }
  192. </script>
  193. <style>
  194. page {
  195. background: #fafafa;
  196. }
  197. </style>
  198. <style lang="scss" scoped>
  199. @import "./buy.scss";
  200. </style>