src/sfc/InputSearch.vue
@@ -13,10 +13,8 @@
  1代表需要默认值 ,0代表不需要默认值
 -->
<script>
import exceptionApi from '@/api/exceptionApi.js';
import exceptionApi from '@/api/exceptionApi.js'
export default {
  props: {
    // 0代表不需要默认值,1代表需要默认值
@@ -61,9 +59,10 @@
  },
  watch:{
    beginTime(val,oldVal){
      if(this.isNeedRealTimeAdvice =='1' && oldVal != ''){
        exceptionApi.getExceptionName(this.exceptionType,this.beginTime,this.endTime).then( res=>{
        exceptionApi
          .getExceptionName(this.exceptionType, this.beginTime, this.endTime)
          .then((res) => {
          this.siteNames = []
          const sites = res.data.data
          sites.filter((item) => {
@@ -74,7 +73,9 @@
    },
    exceptionType(){
      if(this.isNeedRealTimeAdvice =='1' ){
        exceptionApi.getExceptionName(this.exceptionType,this.beginTime,this.endTime).then( res=>{
        exceptionApi
          .getExceptionName(this.exceptionType, this.beginTime, this.endTime)
          .then((res) => {
          this.siteNames = []
          const sites = res.data.data
          sites.filter((item) => {
@@ -108,24 +109,32 @@
    }
  },
  methods: {
    obscureMatch(a, b) {
      const pattern = new RegExp(a, 'i')
      // 'i' 表示不区分大小写
      return pattern.test(b)
    },
    querySearch(queryString, cb) {
      const results = queryString
        ? this.siteNames.filter(this.createFilter(queryString))
        : this.siteNames
      cb(results)
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          // toLowerCase() 方法用于把字符串转换为小写。
          restaurant.toLowerCase().indexOf(queryString.toLowerCase()) === 0
          this.obscureMatch(queryString,restaurant)
        )
      }
    },
    // 初始化加载所有的站点名字
    loadAll() {
      if(this.isNeedRealTimeAdvice == '1'){
        exceptionApi.getExceptionName(this.exceptionType,this.beginTime,this.endTime).then( res=>{
        exceptionApi
          .getExceptionName(this.exceptionType, this.beginTime, this.endTime)
          .then((res) => {
          this.siteNames = []
          const sites = res.data.data
          sites.filter((item) => {
@@ -136,7 +145,6 @@
          this.siteNamesAndMnCode.push(temp)
          })
        })
    }else if(this.isNeedRealTimeAdvice == '0'){
      exceptionApi.getSitesNum().then((response) => {
        const sites = response.data.data
@@ -153,7 +161,7 @@
    },
    // 根据选中的站点查询设备编号
    onSiteNameSelected(siteName) { 
      const selectedSite = this.siteNamesAndMnCode.find((site) => site.name == siteName);
      const selectedSite = this.siteNamesAndMnCode.find((site) => site.name == siteName)
  if (selectedSite) { 
    this.$emit('submitMncode',selectedSite.mnCode)
  }else{
@@ -209,5 +217,4 @@
.el-autocomplete {
  width: 200px;
}
</style>