123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <template>
- <div class="input-action-sheet-wrapper" v-if="visible" :style="{position: position}">
- <div class="input-action-sheet-content">
- <div class="title">
- {{title}}
- </div>
- <div class="input-wrapper">
- <input class="input"
- v-model="inputVal"
- placeholder="0"
- autofocus
- @input="onValueInput"
- @blur="onValueBlur">
- </div>
- <div class="desc">
- {{desc}}
- </div>
- <div class="btn-wrapper">
- <div class="btn cancel" @click="cancel">
- {{cancelText}}
- </div>
- <div class="btn confirm" @click="confirm">
- {{confirmText}}
- </div>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, defineProps, defineEmits, watch } from "vue";
- let inputVal = ref('');
- const props = defineProps({
- visible: {
- type: Boolean,
- default: false
- },
- position: {
- type: String,
- default: 'fixed'
- },
- title: {
- type: String,
- default: '',
- },
- cancelText: {
- type: String,
- default: 'Cancel',
- },
- confirmText: {
- type: String,
- default: 'Continue',
- },
- desc: {
- type: String,
- defautl: ''
- }
- });
- watch(() => props.visible, (newVal) => {
- if(!newVal) {
- inputVal.value = ''
- }
- })
- const emits = defineEmits(["cancel", "confirm", "onInput"]);
- const onValueInput = () => {
- let val = inputValHandler();
- emits("onInput", { inputVal: val });
- return val;
- }
- const onValueBlur = () => {
- return inputValHandler();
- }
- const inputValHandler = () => {
- let val = inputVal.value;
- val = val.replace(/^\D*(\d*(?:\.\d{0,18})?).*$/g, '$1');
- if(val == '00') {
- val = '0'
- }
- if(val.indexOf('.') > -1){ //校验 例:00.12 => 0.12
- let arr = val.split('.');
- if(arr[0].startsWith('0')) {
- let num = +arr[0];
- val = num + '.' + arr[1];
- }
- }
- inputVal.value = val;
- return val;
- }
- const cancel = () => {
- emits("cancel", { });
- }
- const confirm = () => {
- if(inputVal.value > 0) {
- emits("confirm", { inputVal: inputVal.value });
- }
- }
- </script>
- <style scoped lang="scss">
- .input-action-sheet-wrapper {
- width: 100%;
- height: 100%;
- background-color: rgba(0, 0, 0, 0.5);
- position: fixed;
- top: 0;
- left: 0;
- .input-action-sheet-content {
- width: 335px;
- min-height: 186px;
- background: #fff;
- border-radius: 20px;
- padding: 20px 15px;
- box-sizing: border-box;
- position: absolute;
- left: 50%;
- top: 50%;
- z-index: 1000;
- transform: translate(-50%, -50%);
- .title {
- font-weight: 600;
- font-size: 16px;
- }
-
- .input-wrapper {
- width: 100%;
- border: 1px solid #DFDFDF;
- border-radius: 5px;
- box-sizing: border-box;
- height: 42px;
- margin: 17px 0 10px 0;
- .input {
- width: 100%;
- height: 100%;
- outline: none;
- border: none;
- padding: 0 10px;
- box-sizing: border-box;
- border-radius: 5px;
- font-weight: 600;
- font-size: 16px;
- }
- .input::placeholder {
- color: #B3B3B3;
- }
- }
-
- .desc {
- font-weight: 500;
- font-size: 13px;
- color: #888888;
- min-height: 40px;
- }
- .btn-wrapper {
- display: flex;
- justify-content: space-between;
- margin-top: 20px;
- .btn {
- width: 150px;
- height: 47px;
- display: flex;
- align-items: center;
- justify-content: center;
- font-weight: 500;
- font-size: 16px;
- box-sizing: border-box;
- border-radius: 1000px;
- cursor: pointer;
- }
- .cancel {
- border: 1px solid #CFCFCF;
- }
- .confirm {
- color: #fff;
- background: #1D9BF0;
- }
- }
- }
- }
- </style>
|