FillItem.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view>
  3. <uni-popup type="bottom" background-color="#fff" ref="fillRef" class="FillPopup" :animation="true">
  4. <view class="popup-content">
  5. <input v-model.trim="result" @close="handleClose" :focus="focus" placeholder="请输入答案" :auto-blur="true" :adjust-position="true" style="position: z-index: 10;"
  6. @blur="onBlur" @confirm="handleConfirm" class="my-textarea" type="text" />
  7. </view>
  8. </uni-popup>
  9. </view>
  10. </template>
  11. <script setup>
  12. import {
  13. nextTick,
  14. ref,
  15. watch
  16. } from "vue";
  17. const fillRef = ref(null);
  18. const result = ref('');
  19. const focus = ref(false);
  20. const emits = defineEmits(['blur']);
  21. const props = defineProps({
  22. value: {
  23. type: String,
  24. default: ''
  25. },
  26. index: {
  27. type: Number,
  28. }
  29. })
  30. watch(() => props.value, (val) => {
  31. result.value = val;
  32. })
  33. function handleClear() {
  34. result.value = '';
  35. }
  36. function handleClose() {
  37. focus.value = false;
  38. }
  39. function showPopup() {
  40. fillRef.value && fillRef.value.open();
  41. nextTick(() => focus.value = true);
  42. }
  43. function handleConfirm() {
  44. fillRef.value && fillRef.value.close();
  45. }
  46. function onBlur() {
  47. emits("blur", {
  48. result: result.value,
  49. index: props.index
  50. });
  51. focus.value = false;
  52. }
  53. uni.$on("swiper-change", () => {
  54. fillRef.value && fillRef.value.close()
  55. })
  56. defineExpose({
  57. showPopup,handleClear
  58. })
  59. </script>
  60. <style lang="scss" scoped>
  61. .popup-content {
  62. padding: 10px;
  63. }
  64. .my-textarea {
  65. height: 36px;
  66. line-height: 36px;
  67. }
  68. </style>