<template>
  <van-popup v-model="popup" round position="bottom">
    <div class="popup">
      <div class="popup-header flex">
        <div>{{ title || $t('common.l38') }}</div>
        <img class="close" @click="cancel" src="/img/home/nav/close.png" alt="极度证券">
      </div>
      <div class="search-box">
        <div class="input-box flex">
          <img class="search" src="/img/deposit/search.png" alt="极度证券">
          <el-input v-model="value" :placeholder="$t('common.l23')"></el-input>
        </div>
      </div>
      <div class="list">
        <div class="item flex" :class="{active: val.area_code == item.area_code}" v-for="item in list1" :key="item.id" @click="sslectItem(item)">
          <div class="description">{{ item.name }}</div>
          <div>+{{ item.area_code }}</div>
        </div>
        <!-- 未找到相关结果 -->
        <NoData :title="$t('common.l37')" v-if="list1.length == 0 && list.length !== 0" />
      </div>
    </div>
  </van-popup>
</template>
<script>
import { getCountryList } from '@/api/app'
export default {
  props: {
    val: {
      default() {
        return {}
      }
    },
    title: {
      default: ''
    }
  },
  data () {
    return {
      list: [],
      popup: false,
      value: ''
    }
  },
  computed: {
    list1() {
      return this.list.filter(item => ((item.description).toLowerCase().indexOf(this.value.trim().toLowerCase()) !== -1 || (item.area_code).toLowerCase().indexOf(this.value.trim().toLowerCase()) !== -1 || (item.name).toLowerCase().indexOf(this.value.trim().toLowerCase()) !== -1))
    }
  },
  created () {
    this.getCountryList()
  },
  methods: {
    reset() {
      this.popup = true
      this.value = ''
    },
    getCountryList() {
      getCountryList().then(res => {
        this.list = res.list || []
        this.$emit('list', this.list)
      }).catch(() => {})
    },
    sslectItem(item) {
      this.popup = false
      this.$emit('back', item)
    },
    cancel() {
      this.popup = false
    }
  }
}
</script>
<style lang="less" scoped>
.popup {
  padding: 27px 16px 0;
}
.popup-header {
  position: relative;
  font-size: 16px;
  font-weight: 500;
  justify-content: space-between;
  padding-bottom: 10px;
  .close {
    width: 15px;
  }
}
.list {
  height: 70vh;
  overflow-y: auto;
  padding-bottom: 20px;
  .item {
    justify-content: space-between;
    padding: 10px 0;
    font-size: 15px;
    &.active {
      color: var(--color-);
    }
  }
  .description {
    flex: 1;
    min-width: 10%;
    padding-right: 6px;
  }
}
.search-box {
  padding: 12px 0 16px;
}
.input-box {
  background: #FFFFFF;
  box-shadow: 0px 2px 10px 0px rgba(212,212,212,0.5);
  border-radius: 18px;
  padding-left: 14px;
  padding-right: 30px;
  flex: 1;
  min-width: 10%;
  max-width: 100%;
  .search {
    width: 18px;
  }
  .el-input {
    flex: 1;
    min-width: 10%;
    max-width: 100%;
  }
}
::v-deep {
  .input-box {
    .el-input__inner {
      border: none;
      height: 34px;
      line-height: 34px;
      padding-left: 4px;
    }
  }
}
</style>