searchBox.vue 2.5 KB
<template>
  <!-- 搜索框 -->
  <view class="boxs">
    <view class="searchInput flexJ" @click="jump">
      <u-search @search="doSearchs" @custom="doSearchs" :disabled="disabled" placeholder="请输入" v-model="inputText" bgColor="#fff" searchIconColor="#fda9a3" :actionStyle="actionStyle"></u-search>
      <!-- <view class="left flexA">
        <image src="/static/indexIc/indexSearchIc.png" mode=""></image>
        <input :disabled="disabled" confirm-type="search" v-model="inputText" @confirm="doSearchs" @input="input" type="text" placeholder="请输入" placeholder-class="ples" />
      </view>
      <view class="right flexA" @click="doSearchs(0)">
        <view class="line"></view>
        <text>搜索</text>
      </view> -->
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted, defineEmits } from 'vue'
const props = defineProps({
  disabled: {
    type: Boolean,
    default: true
  },
  keyWord: {
    type: String,
    default: ''
  }
})
let inputText = ref('') //输入框文字
const actionStyle = ref({
  fontSize: '28rpx',
  fontWeight: 700,
  color: '#fb753c'
})
onMounted(() => {
  inputText.value = props.keyWord
  // console.log('首艘',props.disabled)
})
const emit = defineEmits(['doSearchs', 'input'])
// 回车事件
const doSearchs = e => {
  emit('doSearchs', inputText.value)
  // if (e == 0) {
  //   if (inputText.value.trim() == '') return
  //   emit('doSearchs', inputText.value)
  // } else {
  //   emit('doSearchs', e.detail.value)
  // }
}
// 输入框为空
const input = e => {
  if (e.detail.value == '') {
    emit('input', e.detail.value)
  }
}
// // 点击搜索按钮
// const search = ()=> {
// 	console.log('搜索为你做')
// }
const jump = () => {
  props.disabled ? uni.navigateTo({ url: '/pages/index/search' }) : ''
}
</script>

<style lang="scss">
.boxs {
  width: 100%;
  padding: 18rpx 24rpx;
  box-sizing: border-box;

  .searchInput {
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    border-radius: 38rpx;

    .left {
      image {
        margin-right: 8rpx;
        width: 32rpx;
        height: 32rpx;
      }

      input {
        width: 500rpx !important;
      }

      .ples {
        color: #00000042;
        font-size: 26rpx;
      }
    }

    .right {
      .line {
        height: 30rpx;
        width: 1rpx;
        background-color: #fc6a3d;
        margin-right: 14rpx;
      }

      text {
        font-size: 28rpx;
        font-weight: 700;
        color: #fb753c;
      }
    }
  }
}
</style>