PayIntegral.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="family-createOrder__page">
  3. <!-- 地址模块 -->
  4. <address-part
  5. :showIcon="showIcon"
  6. :addressDetail="addressDetail"
  7. :count="count"
  8. :isIntegral="isIntegral" />
  9. <!-- 商品模块 -->
  10. <div class="family-createOrder__product">
  11. <div class="product-top clearfix">
  12. <van-image class="product-img" fit="cover" :src="productDetail.img_thumb_url" />
  13. <div class="product-info">
  14. <p class="product-name">{{productDetail.title}}</p>
  15. <p class="product-dec">{{productDetail.sub_title}}</p>
  16. <p class="product-money">
  17. <span class="money-text">{{!userCheck.is_vip? productDetail.price : productDetail.vip_price}}</span> 积分
  18. </p>
  19. </div>
  20. </div>
  21. </div>
  22. <!-- 积分消耗 -->
  23. <div class="family-createOrder__integral">
  24. <p>积分消耗<span>{{!userCheck.is_vip? productDetail.price : productDetail.vip_price}} 积分</span></p>
  25. </div>
  26. <div class="family-createOrder__footer">
  27. <div class="pay-bottom1 clearfix">
  28. <van-button class="pay-btn" round type="primary" @click="postApi" :disabled="!userCheck.is_vip">{{userCheck.is_vip ? '确认兑换':'非会员不可兑换'}}</van-button>
  29. <div class="pay-sum"><span style="color:#4c4c4c">合计</span>: <span class="money-text">{{!userCheck.is_vip? productDetail.price : productDetail.vip_price}}</span> 积分</div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import Vue from 'vue'
  36. import { mapGetters } from 'vuex'
  37. import { Image as VanImage, Divider, Cell, CellGroup } from 'vant'
  38. import AddressPart from './components/Address'
  39. import filters from '@/common/filter'
  40. export default {
  41. name: 'payIntegral',
  42. data () {
  43. return {
  44. productId: Number(this.$route.params.product_id),
  45. addressId: Number(this.$route.query.address_id),
  46. count: 1,
  47. addressDetail: {},
  48. integralTotal: 0,
  49. isIntegral: true,
  50. showIcon: false
  51. }
  52. },
  53. computed: {
  54. ...mapGetters(['productDetail', 'userCheck']),
  55. isEnoughIntegral: function () {
  56. if (this.integralTotal >= this.productDetail.vip_price) {
  57. return true
  58. } else {
  59. return false
  60. }
  61. }
  62. },
  63. methods: {
  64. postApi () {
  65. if (!this.isEnoughIntegral) {
  66. this.$dialog({
  67. title: '提示',
  68. message: '您的积分不足,请是否前往获得更多积分',
  69. }).then((action) => {
  70. if (action === 'confirm') {
  71. this.$router.push('/article')
  72. }
  73. })
  74. return
  75. }
  76. this.$post({
  77. url: 'v1/spirit/order/integral',
  78. data: {
  79. address_id: this.addressDetail.id || 0,
  80. quantity: this.count,
  81. product_id: this.productId
  82. }
  83. }).then((resp) => {
  84. if (resp) {
  85. this.$toast('兑换成功~')
  86. this.$router.replace(`/order/${resp.order_id}`)
  87. }
  88. })
  89. },
  90. getProductDetail () {
  91. this.$store.dispatch('getProductDetail', {id: this.productId})
  92. },
  93. getIntegralInfo () {
  94. this.$get({
  95. url: 'v1/user/mall/balance/info'
  96. }).then((resp) => {
  97. this.integralTotal = resp.total
  98. })
  99. },
  100. getAddressDefault () {
  101. this.$get({
  102. url: 'v1/user/address/default'
  103. }).then((resp) => {
  104. if (resp) {
  105. this.addressDetail = resp
  106. }
  107. })
  108. },
  109. getAddressDetail () {
  110. this.$get({
  111. url: `v1/address/${this.addressId}`
  112. }).then((resp) => {
  113. if (resp) {
  114. this.addressDetail = resp
  115. }
  116. })
  117. }
  118. },
  119. created () {
  120. Vue.use(VanImage).use(Divider).use(Cell).use(CellGroup)
  121. if (this.addressId) {
  122. this.getAddressDetail()
  123. } else {
  124. this.getAddressDefault()
  125. }
  126. this.getIntegralInfo()
  127. if (this.productDetail && !this.productDetail.id) {
  128. this.getProductDetail()
  129. }
  130. },
  131. watch: {
  132. },
  133. components: {
  134. AddressPart
  135. }
  136. }
  137. </script>
  138. <style lang="less">
  139. .family-createOrder {
  140. &__integral {
  141. box-sizing: border-box;
  142. padding: 0.28rem 0.2rem;
  143. background: #fff;
  144. margin-bottom: 0.3rem;
  145. font-size: .28rem;
  146. color: #4c4c4c;
  147. margin-top: .24rem;
  148. span {
  149. float: right;
  150. color: #f14f4f;
  151. }
  152. }
  153. &__footer {
  154. background: #fff;
  155. box-sizing: border-box;
  156. padding: 0.2rem;
  157. position: fixed;
  158. bottom: 0;
  159. width: 100%;
  160. z-index: 999;
  161. .pay-btn {
  162. height: 0.74rem;
  163. min-width: 2.62rem;
  164. background: #07c160;
  165. float: right;
  166. color: #fff;
  167. font-size: 0.28rem;
  168. margin-left: 0.4rem;
  169. border: 1px solid #07c160;
  170. }
  171. .pay-sum {
  172. color: #f47b7b;
  173. font-size: 0.28rem;
  174. float: right;
  175. margin-top: 0.2rem;
  176. .money-text {
  177. font-size: 0.34rem;
  178. }
  179. }
  180. }
  181. }
  182. </style>