<template>
  <el-select v-model="value" placeholder="全部">
    <el-option label="全部" :value="''" v-if="showAll"></el-option>
    <el-option v-for="(item, i) in options" :key="i" :label="item[label] || '暫無'" :value="item[optid] || ''"></el-option>
  </el-select>
</template>

<script>
import selectComponentJs from "../select";
import axios from "axios";

const extObj = selectComponentJs();

export default {
  ...extObj,
  async mounted() {
    let res = await axios.post(this.url, {
      pageNum: 1,
      pageSize: 499,
    });
    let coms = Array.isArray(res.data) ? res.data : res.data.list;
    console.log('cschoshcos',coms);

    this.options = coms.map((item) => ({ ...item, id: item.id.toString() }));
    if (this.filter) {
      this.options = this.options.filter((item) => {
        let flag = true;
        for (let i = 0; i < this.filter.length; i++) {
          const ii = this.filter[i];
          flag = item[ii.key] == ii.value;
          if (!flag) return;
          
        }
        return flag;
      });
      // this.value = String(this.options[0][this.optid || 'id']).trim()
    }
    this.$emit("asyncLoad");
    extObj.mounted.call(this);
  },
};
</script>
