<template>
  <Page name="search">
    <template #content>
      <template v-for="(item, index) in list">
        <zui-cell :key="index" @click="onSelect(item, index)">
          <template #title>{{ item.valueName }}</template>
        </zui-cell>
      </template>
    </template>
  </Page>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
  data() {
    return {
      list: [],
      excludes: [],
      title: '字典',
      dict: '',
    };
  },
  onLoad(option) {
    if (option.title) this.title = option.title;
    if (option.dict) this.dict = option.dict;
    if (option.excludes) this.excludes = option.excludes.split(',');
    uni.setNavigationBarTitle({ title: option.title });
    this.initData();
  },
  computed: {
    ...mapGetters(['dictList']),
  },
  methods: {
    initData() {
      const matchDictList = this.dictList(this.dict) || [];
      this.list = matchDictList.filter(i => i.valueCode && i.valueName && !this.excludes.includes(i.valueCode));
      // this.list = [{ valueCode: '', valueName: '不限' }, ...need];
    },
    onSelect(item) {
      uni.$emit('select-dict', item.valueName == '不限' && !item.valueCode ? { valueCode: '', valueName: '' } : item);
      uni.navigateBack();
    },
  },
};
</script>
