s-consumptionPoints-pop.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!-- 订单确认的使用消费分弹窗 -->
  2. <template>
  3. <su-popup :show="show" type="bottom" round="10" @close="emits('close')" showClose backgroundColor="#ffffff">
  4. <view class="title ss-m-t-16 ss-m-l-20 ss-flex">使用消费分</view>
  5. <view class="model-box ss-p-x-30">
  6. <input v-model.number="state.points" class="uni-input input-points ss-m-b-10" type="number"
  7. placeholder="请输入抵扣消费分" oninput="this.value=this.value.replace(/\D/g);" :disabled="state.disabled"/>
  8. </view>
  9. <view class="modal-footer text-center">
  10. <view class="subtitle text-disabled">您的可用消费分<text class="text-red">{{currentMemberConsumptionPoints}}</text></view>
  11. <view class="subtitle text-disabled">当前订单价格<text class="text-red">¥{{currentOrderTotalPrice}}</text>,可使用最高<text class="text-red"> {{canUesPoint}} </text>消费分 </view>
  12. <view class="ss-flex ss-m-y-20 ss-col-center">
  13. <button class="confirm-btn ss-reset-button"
  14. @tap="state.points = 0;emits('confirm', state.points)">取消</button>
  15. <button class="confirm-btn ss-reset-button" @tap="onConfirm">确认</button>
  16. </view>
  17. </view>
  18. </su-popup>
  19. </template>
  20. <script setup>
  21. import {
  22. computed,
  23. reactive,
  24. ref,
  25. watch,
  26. nextTick,
  27. watchEffect
  28. } from 'vue';
  29. const props = defineProps({
  30. modelValue: { // 优惠劵列表
  31. type: Object,
  32. default () {},
  33. },
  34. show: {
  35. type: Boolean,
  36. default: false,
  37. },
  38. currentMemberConsumptionPoints: {
  39. type: Number,
  40. default: 0
  41. },
  42. currentTotalPrice: {
  43. type: Number,
  44. default: 0
  45. },
  46. currentDeliveryPrice:{
  47. type: Number,
  48. default: 0
  49. }
  50. });
  51. const emits = defineEmits(['confirm', 'close']);
  52. const state = reactive({
  53. points: 0,
  54. disabled:false
  55. });
  56. const currentOrderMemberPoints = computed(()=>{
  57. return parseFloat(props.currentMemberConsumptionPoints)
  58. })
  59. const currentOrderTotalPrice = computed(()=>{
  60. return parseFloat(props.currentTotalPrice)
  61. })
  62. const currentOrderDeliveryPrice= computed(()=>{
  63. return parseFloat(props.currentDeliveryPrice)
  64. })
  65. // 当前可使用的最高消费分 = 当前的总价格(即最低也要给1分钱) 并且消费分只能是正数 且不能抵扣运费
  66. const canUesPoint = computed(()=>{
  67. // console.log("state.currentTotalPrice",currentOrderTotalPrice.value - 1)
  68. if(!currentOrderTotalPrice.value) return currentOrderTotalPrice.value
  69. // - 0.01 - 0.01分钱
  70. return (currentOrderTotalPrice.value - currentOrderDeliveryPrice.value).toFixed(2)
  71. })
  72. watchEffect(() => {
  73. // 分割整数部分和小数部分
  74. const strPoints = state.points.toString()
  75. const [integerPart, decimalPart] = strPoints.split('.')
  76. if (decimalPart) {
  77. const points = parseFloat(`${integerPart}.${decimalPart.slice(0, 2)}`);
  78. // 使用 nextTick 确保 DOM 更新
  79. nextTick(() => {
  80. state.points = points;
  81. });
  82. }
  83. // 使用消费分不能大于可用消费分
  84. if (state.points > currentOrderMemberPoints.value) {
  85. // 使用 nextTick 确保 DOM 更新
  86. nextTick(() => {
  87. state.points = currentOrderMemberPoints.value;
  88. });
  89. }
  90. // 使用消费分不能大于当前可以使用的最大消费分
  91. if (state.points > canUesPoint.value) {
  92. nextTick(() => {
  93. state.points = canUesPoint.value;
  94. });
  95. }
  96. // 如果计算出来的当前可以使用的最大消费分等于小于0 则不给输入
  97. if(canUesPoint.value == 0 || canUesPoint.value < 0){
  98. state.disabled = true
  99. }
  100. if(canUesPoint.value > 0){
  101. state.disabled = false
  102. }
  103. })
  104. // 确认
  105. const onConfirm = () => {
  106. if(state.points === ''){
  107. state.points = 0
  108. }
  109. emits('confirm', state.points);
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. :deep() {
  114. .uni-checkbox-input {
  115. background-color: var(--ui-BG-Main);
  116. }
  117. .uni-input-wrapper {
  118. width: 100% !important
  119. }
  120. }
  121. .model-box {
  122. // height: 10vh;
  123. text-align: center;
  124. font-size: 30rpx;
  125. .input-points {
  126. text-align: left;
  127. text-indent: 20rpx;
  128. height: 80rpx;
  129. border: 1px solid #bbbbbb;
  130. border-radius: 10rpx;
  131. }
  132. }
  133. .text-disabled {
  134. color: #bbbbbb;
  135. }
  136. .title {
  137. font-size: 36rpx;
  138. height: 80rpx;
  139. font-weight: bold;
  140. color: #333333;
  141. }
  142. .subtitle {
  143. // font-size: 26rpx;
  144. font-weight: 500;
  145. color: #333333;
  146. }
  147. .model-content {
  148. height: 10vh;
  149. }
  150. .modal-footer {
  151. width: 100%;
  152. // height: 120rpx;
  153. // background: #fff;
  154. }
  155. .confirm-btn {
  156. width: 710rpx;
  157. margin:0 20rpx;
  158. height: 80rpx;
  159. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  160. border-radius: 40rpx;
  161. color: #fff;
  162. }
  163. .reason-title {
  164. font-weight: 600;
  165. font-size: 20rpx;
  166. line-height: 26rpx;
  167. color: #ff0003;
  168. }
  169. .reason-desc {
  170. font-weight: 600;
  171. font-size: 20rpx;
  172. line-height: 26rpx;
  173. color: #434343;
  174. }
  175. </style>