app-goods-full-reduce.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view @click="route" class="reduce dir-left-nowrap main-between cross-center" :class="sign === 'gift' ? theme + '-full ' : theme + '-m-back-full ' + theme">
  3. <view :class="sign === 'gift' ? theme + '-color' : theme+'-m-text bd-name ' + theme">满减优惠</view>
  4. <view class="dir-left-nowrap cross-center">
  5. <view class="bd-item" v-if="full_reduce.rule_type === 2">
  6. <text :class="theme+'-m-back ' + theme" class="text" >
  7. 每满{{full_reduce.rule.min_money}}减{{full_reduce.rule.cut}}
  8. </text>
  9. </view>
  10. <view :class="!opacity ? 'bd-opacity-0' : 'bd-opacity-1'" v-else-if="full_reduce.rule_type === 1" class="bd-item u-line-1 dir-left-nowrap cross-center">
  11. <text :class="[sign === 'gift' ? theme + '-background ' : theme+'-m-back ' + theme]"
  12. :id="'bd-'+index + '-text'"
  13. class="text " v-for="(item, index) in list" :key="index">
  14. 满{{item.min_money}}{{item.discount_type === '1' ? '减' + item.cut : '打' + item.discount + '折'}}
  15. </text>
  16. </view>
  17. <view class="arrow"></view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: "app-goods-full-reduce",
  24. props: {
  25. theme: String,
  26. full_reduce: Object,
  27. sign: String
  28. },
  29. data() {
  30. return {
  31. textWidth: 0,
  32. resultWidth: 0,
  33. list: [],
  34. opacity: false
  35. }
  36. },
  37. methods: {
  38. route() {
  39. uni.navigateTo({
  40. url: '/pages/full_reduce/index/index'
  41. })
  42. },
  43. initSize: function () {
  44. let query = [];
  45. for (let i = 0; i < this.list.length; i++) {
  46. query.push(
  47. new Promise(resolve => {
  48. let query = uni.createSelectorQuery().in(this);
  49. query.select(`#bd-${i}-text`).boundingClientRect().exec(ret => {
  50. if (ret[0]) {
  51. this.textWidth += (ret[0].width + uni.upx2px(10));
  52. }
  53. resolve();
  54. });
  55. })
  56. )
  57. }
  58. Promise.all(query).then(() => {
  59. this.resultWidth = this.textWidth;
  60. });
  61. }
  62. },
  63. watch: {
  64. 'full_reduce.rule' : {
  65. immediate: true,
  66. handler(newVal) {
  67. this.list = newVal;
  68. this.textWidth = 0;
  69. setTimeout(() => {
  70. this.initSize();
  71. }, 500);
  72. },
  73. deep: true
  74. },
  75. resultWidth: {
  76. handler(newVal) {
  77. if (newVal > uni.upx2px(552)) {
  78. this.list = this.list.slice(0, this.list.length - 1);
  79. this.textWidth = 0;
  80. this.$nextTick(() => {
  81. this.initSize();
  82. });
  83. } else {
  84. this.opacity = true;
  85. }
  86. }
  87. }
  88. },
  89. mounted() {
  90. setTimeout(() => {
  91. this.list = this.full_reduce.rule;
  92. this.textWidth = 0;
  93. setTimeout(() => {
  94. this.initSize();
  95. }, 500);
  96. }, 500);
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. @import '../../../static/css/gift.scss';
  102. .reduce {
  103. width: 750upx;
  104. padding: 20upx 24upx;
  105. }
  106. .arrow {
  107. background-size: 100% 100%;
  108. background-repeat: no-repeat;
  109. width: 12upx;
  110. height: 22upx;
  111. background-image: url("../../../static/image/icon/arrow-right.png");
  112. }
  113. .text {
  114. padding: 5rpx 10rpx;
  115. border-radius: 15rpx;
  116. font-size: 21upx;
  117. color: #ffffff;
  118. margin-right: 10rpx;
  119. }
  120. .bd-name {
  121. font-size: 28rpx;
  122. width: 150rpx;
  123. }
  124. .bd-item {
  125. width: 552upx;
  126. }
  127. .a.a-m-back-full {
  128. background: #ffecec;
  129. }
  130. .b.b-m-back-full {
  131. background: #fff9e5;
  132. }
  133. .c.c-m-back-full {
  134. background: #ffeef2;
  135. }
  136. .d.d-m-back-full {
  137. background: #fcf8ef;
  138. }
  139. .e.e-m-back-full {
  140. background: #f1f2fd;
  141. }
  142. .f.f-m-back-full {
  143. background: #ffecec;
  144. }
  145. .g.g-m-back-full{
  146. background: #eff8f1;
  147. }
  148. .h.h-m-back-full {
  149. background: #edf4fc;
  150. }
  151. .i.i-m-back-full {
  152. background: #eaeaea;
  153. }
  154. .j.j-m-back-full {
  155. background: #ffecec;
  156. }
  157. .streamer-gold-gift-full {
  158. background: #fcf6ec;
  159. }
  160. .romantic-powder-gift-full {
  161. background: #ffeef2;
  162. }
  163. .taste-red-gift-full {
  164. background: #ffecec;
  165. }
  166. .elegant-purple-gift-full {
  167. background: #f1f2fd;
  168. }
  169. .fresh-green-gift-full {
  170. background: #eff8f1;
  171. }
  172. .business-blue-gift-full {
  173. background: #edf4fc;
  174. }
  175. .bd-opacity-0 {
  176. opacity: 0;
  177. }
  178. .bd-opacity-1 {
  179. opacity: 1;
  180. }
  181. </style>