detail-discount.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="detail-discount">
  3. <view class="top dir-left-nowrap main-between">
  4. <view class="text">
  5. <template v-if="activeIndex === 0 && ladder_rules.length === 1">
  6. <view>
  7. 再抢购{{ladder_rules[0].num-sales}}件
  8. </view>
  9. <view>
  10. 可享
  11. <text>{{ladder_rules[0].discount}}</text>
  12. 折优惠
  13. </view>
  14. </template>
  15. <template v-if="activeIndex === 0 && ladder_rules.length > 1">
  16. <view>
  17. 再抢购{{ladder_rules[0].num-sales}}件
  18. </view>
  19. <view>
  20. 可享
  21. <text>{{ladder_rules[0].discount}}</text>
  22. 折优惠
  23. </view>
  24. </template>
  25. <template v-if="activeIndex > 0">
  26. <view>
  27. 当前{{ladder_rules[activeIndex-1].discount}}折,再抢购{{ladder_rules[activeIndex].num-sales}}件
  28. </view>
  29. <view>
  30. 可享
  31. <text>{{ladder_rules[activeIndex].discount}}</text>
  32. 折优惠
  33. </view>
  34. </template>
  35. <template v-if="activeIndex === -1">
  36. <view >已满足抢购条件</view>
  37. 可享
  38. <text>{{ladder_rules[ladder_rules.length - 1].discount}}</text>
  39. 折优惠
  40. </template>
  41. </view>
  42. <view class="button" >
  43. <app-jump-button form open_type="share">邀请好友购买</app-jump-button>
  44. </view>
  45. </view>
  46. <view class="bottom">
  47. <view :scroll-x="true" class="textss" v-if="ladder_rules.length === 1">
  48. <view class="scroll-empty"></view>
  49. <view class="content-d border-radius-right border-radius-left" style="width:702rpx;">
  50. <view class="content-d-d-d border-radius-left border-radius-right" :style="{width: `${ activeIndex === -1 ? '702' : (702/Number(ladder_rules[0].num)) * sales}rpx`}"></view>
  51. <text class="content-text-o">满{{ladder_rules[0].num}}件,享{{Number(ladder_rules[0].discount)}}折</text>
  52. </view>
  53. <view class="scroll-empty after"></view>
  54. </view>
  55. <scroll-view :scroll-x="true" class="textss" v-if="ladder_rules.length !== 1" >
  56. <view class="scroll-empty"></view>
  57. <view class="content-d" v-for="(item, index) in ladder_rules" :key="index" :class="{'border-radius-left': index === 0, 'border-radius-right': index === ladder_rules.length - 1}">
  58. <view class="content-d-d-d" :style="{width: `${getNum(item, index)}rpx`}" :class="{'border-radius-left': index === 0, 'border-radius-right': index === ladder_rules.length - 1}"></view>
  59. <text class="content-text">满{{item.num}}件,享{{item.discount}}折</text>
  60. <view class="yuan-default" :class="{'yuan' : activeIndex > index || activeIndex === -1}" ></view>
  61. </view>
  62. <view class="scroll-empty after"></view>
  63. </scroll-view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. export default {
  69. name: "detail-discount",
  70. data() {
  71. return {
  72. shareShow: false,
  73. x: 0,
  74. y: 0,
  75. old: {
  76. x: 0,
  77. y: 0
  78. }
  79. }
  80. },
  81. props: {
  82. url: String,
  83. ladder_rules: Array,
  84. sales: Number,
  85. },
  86. computed: {
  87. activeIndex() {
  88. let index = 0;
  89. for (let i = 0; i < this.ladder_rules.length; i++) {
  90. if (this.ladder_rules[i].num > this.sales) {
  91. return i;
  92. } else {
  93. index += 1;
  94. }
  95. }
  96. if (index === this.ladder_rules.length) {
  97. return -1;
  98. }
  99. }
  100. },
  101. methods: {
  102. open_share() {
  103. this.shareShow = true;
  104. },
  105. onChange: function(e) {
  106. this.old.x = e.detail.x;
  107. },
  108. getNum(item, index) {
  109. if (this.activeIndex > index) {
  110. return 320;
  111. } else if (this.activeIndex === index) {
  112. if (index === 0) {
  113. return 320/Number(item.num) * this.sales;
  114. } else {
  115. return 320/(Number(item.num)-Number(this.ladder_rules[index-1].num)) * (this.sales-Number(this.ladder_rules[index-1].num));
  116. }
  117. } else if (this.activeIndex === -1) {
  118. return 320;
  119. } else if (this.activeIndex < index) {
  120. return 0;
  121. }
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped lang="scss">
  127. .detail-discount {
  128. width: #{702rpx};
  129. background:linear-gradient(45deg,#ff8c40, #ff6d40);
  130. height: #{210rpx};
  131. border-radius: 15upx;
  132. margin: 24upx 24upx 0 24upx;
  133. .top {
  134. color: #ffffff;
  135. padding: #{ 30rpx 24rpx 0 24rpx};
  136. .text {
  137. font-size: #{26rpx};
  138. text {
  139. font-size: #{32rpx};
  140. }
  141. }
  142. .button {
  143. margin-top: #{8rpx};
  144. width: #{213rpx};
  145. height: #{56rpx};
  146. line-height: #{54rpx};
  147. font-size: #{26rpx};
  148. color: #ffffff;
  149. border-radius: #{30rpx};
  150. text-align: center;
  151. border: #{1rpx} solid #ffffff;
  152. }
  153. }
  154. .bottom {
  155. height: #{100rpx};
  156. width: #{702rpx};
  157. }
  158. }
  159. .textss {
  160. height: #{100rpx};
  161. white-space: nowrap;
  162. }
  163. .content {
  164. height: #{10rpx};
  165. width: #{702rpx};
  166. background-color: #b24c2d;
  167. border-radius: #{5rpx};
  168. position: relative;
  169. .content-nei {
  170. height: #{10rpx};
  171. border-radius: #{5rpx};
  172. background-color: #ffffff;
  173. }
  174. .content-text {
  175. position: absolute;
  176. font-size: #{24rpx};
  177. color: #ffffff;
  178. margin-top: #{16rpx};
  179. right: 0;
  180. }
  181. }
  182. .content-d {
  183. display: inline-block;
  184. width: #{320rpx};
  185. height: #{10rpx};
  186. position: relative;
  187. margin-top: #{5rpx};
  188. background-color: rgba(204, 94, 51, .8);
  189. .content-text {
  190. position: absolute;
  191. font-size: #{24rpx};
  192. color: #ffffff;
  193. margin-top: #{16rpx};
  194. right: 0;
  195. transform: translateX(50%);
  196. }
  197. .content-text-o {
  198. position: absolute;
  199. font-size: #{24rpx};
  200. color: #ffffff;
  201. margin-top: #{16rpx};
  202. right: 0;
  203. }
  204. }
  205. .content-d-d {
  206. height: #{10rpx};
  207. border-radius: #{5rpx};
  208. }
  209. .content-d-d-d {
  210. height: #{10rpx};
  211. background-color: #f7f7f7;
  212. }
  213. .yuan {
  214. background-color: #ff8c40 !important;
  215. border: #{5rpx} solid #ffffff !important;
  216. }
  217. .scroll-empty {
  218. height: #{10upx};
  219. width: #{25upx};
  220. display: inline-block;
  221. }
  222. .after {
  223. width: #{125upx};
  224. }
  225. .yuan-default {
  226. border-radius: 50%;
  227. position: absolute;
  228. z-index: 1400;
  229. top: 50%;
  230. transform: translateY(-50%);
  231. right: 0;
  232. width: #{20rpx};
  233. height: #{20rpx};
  234. background-color: rgba(204, 94, 51, .8);
  235. border: #{5rpx} solid rgba(204, 94, 51, .8) ;
  236. }
  237. .border-radius-left {
  238. border-top-left-radius: #{5rpx};
  239. border-bottom-left-radius: #{5rpx};
  240. }
  241. .border-radius-right {
  242. border-top-right-radius: #{5rpx};
  243. border-bottom-right-radius: #{5rpx};
  244. }
  245. </style>