detail-discount.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. <!-- #ifdef MP -->
  44. <app-jump-button form open_type="share">邀请好友购买</app-jump-button>
  45. <!-- #endif -->
  46. <!-- #ifdef H5 -->
  47. <app-jump-button form @click.native="shareUrl">邀请好友购买</app-jump-button>
  48. <!-- #endif -->
  49. </view>
  50. </view>
  51. <view class="bottom">
  52. <view :scroll-x="true" class="textss" v-if="ladder_rules.length === 1">
  53. <view class="scroll-empty"></view>
  54. <view class="content-d border-radius-right border-radius-left" style="width:654rpx;">
  55. <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>
  56. <text class="content-text-o">满{{ladder_rules[0].num}}件,享{{Number(ladder_rules[0].discount)}}折</text>
  57. </view>
  58. <view class="scroll-empty after"></view>
  59. </view>
  60. <scroll-view :scroll-x="true" class="textss" v-if="ladder_rules.length !== 1" >
  61. <view class="scroll-empty"></view>
  62. <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}">
  63. <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>
  64. <text class="content-text">满{{item.num}}件,享{{item.discount}}折</text>
  65. <view class="yuan-default" :class="{'yuan' : activeIndex > index || activeIndex === -1}" ></view>
  66. </view>
  67. <view class="scroll-empty after"></view>
  68. </scroll-view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. export default {
  74. name: "detail-discount",
  75. data() {
  76. return {
  77. shareShow: false,
  78. x: 0,
  79. y: 0,
  80. old: {
  81. x: 0,
  82. y: 0
  83. }
  84. }
  85. },
  86. props: {
  87. url: String,
  88. ladder_rules: Array,
  89. sales: Number,
  90. },
  91. computed: {
  92. activeIndex() {
  93. let index = 0;
  94. for (let i = 0; i < this.ladder_rules.length; i++) {
  95. if (this.ladder_rules[i].num > this.sales) {
  96. return i;
  97. } else {
  98. index += 1;
  99. }
  100. }
  101. if (index === this.ladder_rules.length) {
  102. return -1;
  103. }
  104. }
  105. },
  106. methods: {
  107. open_share() {
  108. this.shareShow = true;
  109. },
  110. onChange: function(e) {
  111. this.old.x = e.detail.x;
  112. },
  113. getNum(item, index) {
  114. if (this.activeIndex > index) {
  115. return 320;
  116. } else if (this.activeIndex === index) {
  117. if (index === 0) {
  118. return 320/Number(item.num) * this.sales;
  119. } else {
  120. return 320/(Number(item.num)-Number(this.ladder_rules[index-1].num)) * (this.sales-Number(this.ladder_rules[index-1].num));
  121. }
  122. } else if (this.activeIndex === -1) {
  123. return 320;
  124. } else if (this.activeIndex < index) {
  125. return 0;
  126. }
  127. },
  128. // #ifdef H5
  129. shareUrl() {
  130. this.$utils.uniCopy({
  131. data: window.location.href,
  132. success() {
  133. uni.showToast({
  134. icon: 'none',
  135. title: '链接已复制'
  136. });
  137. }
  138. });
  139. }
  140. // #endif
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. .detail-discount {
  146. width: #{702rpx};
  147. background:linear-gradient(45deg,#ff8c40, #ff6d40);
  148. height: #{210rpx};
  149. border-radius: 15upx;
  150. margin: 24upx 24upx 0 24upx;
  151. .top {
  152. color: #ffffff;
  153. padding: #{ 30rpx 24rpx 0 24rpx};
  154. .text {
  155. font-size: #{26rpx};
  156. text {
  157. font-size: #{32rpx};
  158. }
  159. }
  160. .button {
  161. margin-top: #{8rpx};
  162. width: #{213rpx};
  163. height: #{56rpx};
  164. line-height: #{54rpx};
  165. font-size: #{26rpx};
  166. color: #ffffff;
  167. border-radius: #{30rpx};
  168. text-align: center;
  169. border: #{1rpx} solid #ffffff;
  170. }
  171. }
  172. .bottom {
  173. height: #{100rpx};
  174. width: #{702rpx};
  175. }
  176. }
  177. .textss {
  178. height: #{100rpx};
  179. white-space: nowrap;
  180. }
  181. .content {
  182. height: #{10rpx};
  183. width: #{702rpx};
  184. background-color: #b24c2d;
  185. border-radius: #{5rpx};
  186. position: relative;
  187. .content-nei {
  188. height: #{10rpx};
  189. border-radius: #{5rpx};
  190. background-color: #ffffff;
  191. }
  192. .content-text {
  193. position: absolute;
  194. font-size: #{24rpx};
  195. color: #ffffff;
  196. margin-top: #{16rpx};
  197. right: 0;
  198. }
  199. }
  200. .content-d {
  201. display: inline-block;
  202. width: #{320rpx};
  203. height: #{10rpx};
  204. position: relative;
  205. margin-top: #{5rpx};
  206. background-color: rgba(204, 94, 51, .8);
  207. .content-text {
  208. position: absolute;
  209. font-size: #{24rpx};
  210. color: #ffffff;
  211. margin-top: #{16rpx};
  212. right: 0;
  213. transform: translateX(50%);
  214. }
  215. .content-text-o {
  216. position: absolute;
  217. font-size: #{24rpx};
  218. color: #ffffff;
  219. margin-top: #{16rpx};
  220. right: 0;
  221. }
  222. }
  223. .content-d-d {
  224. height: #{10rpx};
  225. border-radius: #{5rpx};
  226. }
  227. .content-d-d-d {
  228. height: #{10rpx};
  229. background-color: #f7f7f7;
  230. }
  231. .yuan {
  232. background-color: #ff8c40 !important;
  233. border: #{5rpx} solid #ffffff !important;
  234. }
  235. .scroll-empty {
  236. height: #{10upx};
  237. width: #{25upx};
  238. display: inline-block;
  239. }
  240. .after {
  241. width: #{125upx};
  242. }
  243. .yuan-default {
  244. border-radius: 50%;
  245. position: absolute;
  246. z-index: 1400;
  247. top: 50%;
  248. transform: translateY(-50%);
  249. right: 0;
  250. width: #{20rpx};
  251. height: #{20rpx};
  252. background-color: rgba(204, 94, 51, .8);
  253. border: #{5rpx} solid rgba(204, 94, 51, .8) ;
  254. }
  255. .border-radius-left {
  256. border-top-left-radius: #{5rpx};
  257. border-bottom-left-radius: #{5rpx};
  258. }
  259. .border-radius-right {
  260. border-top-right-radius: #{5rpx};
  261. border-bottom-right-radius: #{5rpx};
  262. }
  263. </style>