<template>
  <div id="">
    <a-select
      v-model:value="value"
      placeholder="请选择"
      size="small"
      :filter-option="false"
      @search="filterMethod"
      @change="chooseChange">
      <a-select-option v-for="item in searchDataList" :key="item.adCode" :value="item.adCode">{{ item.adName }}
      </a-select-option>
    </a-select>
  </div>
</template>

<script>
import request from '../utils/gw_ajax_request.js';
export default {
  props: ['nodeList'],
  components: {},
  data() {
    return {
      value: '',
      searchDataList: [],
    };
  },
  computed: {
    userId: () =>
      localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096',
  },
  mounted() {
    this.getAreaList();
  },
  methods: {
    getAreaList() {
      var str = '';
      const codes = [];
      for (var i = 0; i < this.nodeList.length; i++) {
        codes.push(this.nodeList[i].code);
      }
      str = codes.join(',');
      request
        .get('/dc/att/adXBase/getTargetAdByNodeId', {
          params: { persGuid: this.userId, nodeIds: str },
        })
        .then((res) => {
          const data = res.data;
          this.searchDataList = data;
        });
    },
    chooseChange: function (p) {
      console.log(p);
      this.searchDataList.forEach((element) => {
        if (element.adCode == p) {
          console.log(element);
          this.$emit('selectDuChaAreaNode', {
            adCode: element.adCode,
            adName: element.adName,
          });
        }
      });
    },
    filterMethod: function (text) {
      console.log(text);
      this.value = text;
      const filterResult = [];
      this.searchDataList.forEach((element) => {
        if (element.adName.indexOf(text) >= 0) {
          filterResult.push(element);
        }
      });
      this.searchDataList = filterResult;
    },
  },
};
</script>

<style lang="less" scoped>

</style>
