<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.rsCode" :value="item.rsCode">{{ item.rsName }}
      </a-select-option>
    </a-select>
  </div>
</template>

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

<style lang="less" scoped>

</style>
