s-points-pop.vue 4.8 KB

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