RedeemPoints.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <uv-popup
  3. ref="popupRef"
  4. mode="bottom"
  5. closeable
  6. round="40rpx"
  7. @change="handleClose"
  8. >
  9. <view
  10. class="exchange-content"
  11. :style="{
  12. paddingBottom: keyboardHeight ? keyboardHeight + 'px' : '40rpx',
  13. }"
  14. >
  15. <view class="exchange-content-top">
  16. <view class="popup-title">{{ $props.title + "积分" }}</view>
  17. <view class="exchange-view u-flex-center">
  18. <text class="exchange-text"
  19. >请输入<text>{{ $props.title }}</text
  20. >积分数:</text
  21. >
  22. <view class="exchange-view-input u-flex-center">
  23. <input
  24. class="exchange-input"
  25. v-model="formData.exchangePoints"
  26. placeholder="请输入"
  27. type="digit"
  28. :adjust-position="false"
  29. @blur="handleBlur"
  30. />
  31. <text class="exchange-btn" @click="handleExchangeAll">全部</text>
  32. </view>
  33. </view>
  34. <view class="exchange-num"
  35. >可<text>{{ $props.title }}</text
  36. >积分数:{{ formData.totalNum || 0 }}</view
  37. >
  38. </view>
  39. <view class="exchange-content-bottom">
  40. <view class="popup-title">请输入密码:</view>
  41. <uv-code-input
  42. v-model="formData.payPassword"
  43. size="82rpx"
  44. space="25rpx"
  45. dot
  46. @finish="handleFinish"
  47. v-if="formData.totalNum != null"
  48. :adjustPosition="false"
  49. ></uv-code-input>
  50. <view class="popup-btn u-flex-center-sb">
  51. <view class="popup-confirm" @click.stop="handleExchangeConfirm"
  52. >确认{{ $props.title }}</view
  53. >
  54. <view class="popup-cancel" @click="popupRef.close()">取消</view>
  55. </view>
  56. </view>
  57. </view>
  58. </uv-popup>
  59. </template>
  60. <script setup name="RedeemPoints">
  61. import { ref } from "vue";
  62. const $props = defineProps({
  63. title: {
  64. type: String,
  65. default: "兑换",
  66. },
  67. });
  68. const $emit = defineEmits(["confirm"]);
  69. const popupRef = ref(null);
  70. const formData = ref({
  71. exchangePoints: "",
  72. payPassword: "",
  73. totalNum: 0,
  74. });
  75. const handleExchangeAll = () => {
  76. formData.value.exchangePoints = formData.value.totalNum;
  77. };
  78. const handleExchangeConfirm = () => {
  79. if (!formData.value.exchangePoints) {
  80. uni.$uv.toast(`请输入${$props.title}积分数`);
  81. return;
  82. }
  83. if (formData.value.exchangePoints * 1 > formData.value.totalNum * 1) {
  84. uni.$uv.toast(`${$props.title}积分数不能大于可${$props.title}积分数`);
  85. return;
  86. }
  87. if (!formData.value.payPassword) {
  88. uni.$uv.toast("请输入密码");
  89. return;
  90. }
  91. $emit("confirm", formData.value);
  92. };
  93. // 输入框失焦处理数据
  94. const handleBlur = () => {
  95. if (formData.value.exchangePoints) {
  96. formData.value.exchangePoints = (formData.value.exchangePoints * 1).toFixed(
  97. 2
  98. );
  99. }
  100. };
  101. const keyboardHeight = ref(0);
  102. const listener = (res) => {
  103. // console.log(res.height);
  104. keyboardHeight.value = res.height || 0;
  105. };
  106. // 关闭弹窗处理数据
  107. const handleClose = (e) => {
  108. if (!e.show) {
  109. // console.log("关闭");
  110. formData.value = {};
  111. uni.offKeyboardHeightChange(listener); // 需传入与监听时同一个的函数对象
  112. }
  113. };
  114. // 输入完成处理数据
  115. const handleFinish = () => {
  116. console.log("输入完成");
  117. try {
  118. uni.hideKeyboard();
  119. } catch (error) {}
  120. formData.value.focusShow = false;
  121. handleExchangeConfirm();
  122. };
  123. const open = (data) => {
  124. formData.value = data;
  125. popupRef.value.open();
  126. uni.onKeyboardHeightChange(listener);
  127. };
  128. const close = () => {
  129. popupRef.value.close();
  130. };
  131. defineExpose({
  132. open,
  133. close,
  134. });
  135. </script>
  136. <style lang="scss" scoped>
  137. .exchange-content {
  138. padding: 40rpx 0;
  139. // text-align: center;
  140. background-color: #ffffff;
  141. .exchange-content-top {
  142. padding: 0 50rpx 40rpx 50rpx;
  143. border-bottom: 12rpx solid #f7f7f7;
  144. .exchange-view {
  145. border-bottom: 1rpx solid #f0f0f0;
  146. padding-bottom: 18rpx;
  147. margin-top: 20rpx;
  148. .exchange-text {
  149. flex-shrink: 0;
  150. font-size: 28rpx;
  151. }
  152. .exchange-view-input {
  153. flex: 1;
  154. .exchange-input {
  155. flex: 1;
  156. text-align: right;
  157. }
  158. .exchange-btn {
  159. flex-shrink: 0;
  160. color: #333333;
  161. font-size: 28rpx;
  162. margin-left: 20rpx;
  163. }
  164. }
  165. }
  166. .exchange-num {
  167. text-align: right;
  168. margin-top: 20rpx;
  169. font-size: 24rpx;
  170. color: #0090ff;
  171. }
  172. }
  173. .exchange-content-bottom {
  174. padding: 40rpx 50rpx 0 50rpx;
  175. .popup-title {
  176. text-align: left;
  177. margin-bottom: 30rpx;
  178. }
  179. }
  180. }
  181. .popup-btn {
  182. margin-top: 70rpx;
  183. .popup-confirm,
  184. .popup-cancel {
  185. width: 310rpx;
  186. height: 76rpx;
  187. line-height: 76rpx;
  188. border-radius: 38rpx;
  189. font-size: 28rpx;
  190. font-weight: 700;
  191. text-align: center;
  192. }
  193. .popup-confirm {
  194. background: #eb5153;
  195. color: #ffffff;
  196. }
  197. .popup-cancel {
  198. color: #808080;
  199. border: 1px solid #cccccc;
  200. background: #ffffff;
  201. }
  202. }
  203. .cancelQueue {
  204. .exchange-content-top {
  205. background-color: #f8f8f8;
  206. border-bottom: 1rpx solid #e6e6e6 !important;
  207. .cancelQueue-num {
  208. font-size: 40rpx;
  209. font-weight: 700;
  210. text-align: center;
  211. color: #eb5153;
  212. }
  213. .cancelQueue-prompt {
  214. font-size: 28rpx;
  215. font-weight: 400;
  216. color: #1a1a1a;
  217. text-align: center;
  218. margin-top: 20rpx;
  219. }
  220. }
  221. }
  222. </style>