buyComponent.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div>
  3. <button style="z-index: 1000;"
  4. class="btn btn-primary btn-buy-now"
  5. :style="btnColor ? `background:${btnColor};border-color:${btnColor};` : ''"
  6. :class="{'disabled': disabledFlag}"
  7. @click="buyNow(true, $event)">
  8. <span class="watch">立即购买</span>
  9. </button>
  10. <button style="z-index: 1000;"
  11. ref="addCartBtn"
  12. class="btn btn-add-cart"
  13. @mouseenter="setHoverStyle(true)"
  14. @mouseleave="setHoverStyle(false)"
  15. :style="btnColor ? `color:${btnColor};border-color:${btnColor};` : ''"
  16. :class="{'disabled': disabledFlag}"
  17. @click="buyNow(false, $event)">
  18. <span class="watch">加入购物车</span>
  19. </button>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. props: ['item', 'disabledFlag', 'btnColor'],
  25. methods: {
  26. drop(el) {
  27. this.$store.commit('option/SET_BALLSLIST_SUCCESS', el)
  28. },
  29. buyNow: function (isBuy, event) {
  30. // let $el = this.$refs.ballCard
  31. // let transform = whichTransitionEvent()
  32. // let _shopCar = document.getElementById('shopCar')
  33. // let _eltop = event.currentTarget.getBoundingClientRect().top - 22
  34. // let _elleft = event.currentTarget.getBoundingClientRect().left - 278
  35. // // $el.style = `left: ${_elleft}px;top:${_eltop}px`
  36. // $el.style[transform] = `translate3d(${_elleft}px,${_eltop}px,0)`
  37. // $el.style.transition = 'all 0.5s'
  38. // let _shopCarTop = _shopCar.getBoundingClientRect().top
  39. // let _shopCarLeft = _shopCar.getBoundingClientRect().left
  40. // $el.style[transform] = `translate3d(${_shopCarLeft}px,${_shopCarTop}px,0)`
  41. event.stopPropagation()
  42. if (!this.$store.state.option.user.logged) {
  43. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  44. if (response.data) {
  45. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  46. }
  47. })
  48. } else {
  49. if (this.item && !this.disabledFlag) {
  50. if (isBuy) {
  51. this.$http.post('/trade/order/buyNow', [{
  52. uuid: this.item.uuid,
  53. batchCode: this.item.batchCode,
  54. number: this.item.minBuyQty,
  55. storeid: this.item.storeid ? this.item.storeid : this.item.storeId,
  56. storeUuid: this.item.storeid ? this.item.storeid : this.item.storeId,
  57. currencyName: this.item.currencyName,
  58. minPackQty: this.item.minPackQty
  59. }])
  60. .then(response => {
  61. if (response.data.success) {
  62. if (response.data.message) {
  63. this.$message({
  64. message: response.data.message,
  65. type: 'success'
  66. })
  67. window.setTimeout(function () {
  68. window.location.href = '/user#/order/pay/' + this.baseUtils.enidfilter(response.data.data.orderid)
  69. }, 1000)
  70. } else {
  71. window.location.href = '/user#/order/pay/' + this.baseUtils.enidfilter(response.data.data.orderid)
  72. }
  73. } else {
  74. if (response.data.data && response.data.data.unvailable === 1) {
  75. this.$message.error('产品信息已失效,请刷新页面')
  76. } else {
  77. this.$message.error(response.data.message)
  78. }
  79. }
  80. }, err => {
  81. console.log(err)
  82. if (this.item.minBuyQty > this.item.reserve) {
  83. this.$message.error('商品' + this.item.code + '的库存已经不满足最小起订量')
  84. }
  85. })
  86. } else {
  87. this.$http.post('/trade/cart/add', {
  88. uuid: this.item.uuid,
  89. batchCode: this.item.batchCode,
  90. number: this.item.minBuyQty,
  91. storeid: this.item.storeid ? this.item.storeid : this.item.storeId,
  92. storeUuid: this.item.storeid ? this.item.storeid : this.item.storeId,
  93. currencyName: this.item.currencyName,
  94. minPackQty: this.item.minPackQty
  95. })
  96. .then(response => {
  97. if (response.data.success) {
  98. if (response.data.message) {
  99. this.$message({
  100. message: '添加购物车成功,但商品信息有更新',
  101. type: 'success'
  102. })
  103. } else {
  104. this.$message({
  105. message: '添加购物车成功',
  106. type: 'success'
  107. })
  108. }
  109. } else {
  110. if (response.data.code === 2) {
  111. this.$message.error('库存已不满足最小起订量')
  112. } else if (response.data.message === '该产品已失效') {
  113. this.$message.error(response.data.message + ',请刷新页面')
  114. } else {
  115. this.$message.error(response.data.message)
  116. }
  117. }
  118. })
  119. }
  120. }
  121. }
  122. },
  123. setHoverStyle: function (isShow) {
  124. if (this.btnColor) {
  125. this.$refs.addCartBtn.style.color = isShow ? '#fff' : this.btnColor
  126. this.$refs.addCartBtn.style.background = isShow ? this.btnColor : '#fff'
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. /* 物品列表按钮 */
  134. .btn-buy-now {
  135. background-color: #5078CB;
  136. color: #fff;
  137. width: 80px;
  138. height: 30px;
  139. font-size: 12px;
  140. border: 1px solid #5078cb;
  141. position: relative;
  142. }
  143. .btn-add-cart {
  144. margin-top: 10px;
  145. color: #214797;
  146. width: 80px;
  147. height: 30px;
  148. font-size: 12px;
  149. background-color: #fff;
  150. border: 1px solid #e8e8e8;
  151. }
  152. .btn-buy-now:hover{
  153. background: #214797;
  154. }
  155. .btn-add-cart:hover{
  156. background-color: #5078CB;
  157. color: #fff;
  158. }
  159. .btn-buy-now.disabled,
  160. .btn-buy-now.disabled:focus,
  161. .btn-add-cart.disabled,
  162. .btn-add-cart.disabled:focus{
  163. background-color: #d1d2d3!important;
  164. border: none!important;
  165. outline: none;
  166. color: #fff!important;
  167. cursor: not-allowed;
  168. }
  169. </style>