<template>
  <seek-page
    :seekList="seekList"
    @search="handleSearch"
    @reset="handleReset"
    :formLength="3"
  />
</template>

<script>
  import { getByCode } from '@/api/system/dictionary-data';
  import { businessStatus, sourceStatus } from '@/utils/dict/warehouse';

  export default {
    props: ['networkCounts'],
    data() {
      return {
        assetLevel: [],
        businessStatus,
        sourceStatus: Object.keys(sourceStatus).map((key) => {
          return {
            value: key,
            label: sourceStatus[key]
          };
        }),
        consumption: false
      };
    },
    computed: {
      seekList() {
        return [
          {
            label: '编码',
            value: 'code',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '名称',
            value: 'name',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '使用单位',
            value: 'postId',
            type: 'DeptSelect',
            placeholder: '请选择'
          },
          {
            label: '固资编码',
            value: 'fixCode',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '型号',
            value: 'module',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '编号',
            value: 'codeNumber',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '网络状态',
            value: 'networkStatus',
            type: 'DictSelection',
            dictName: '网络状态',
            placeholder: '请选择'
          },
          {
            label: '生命周期',
            value: 'lifeCycle',
            type: 'select',
            placeholder: '请选择',
            selectList: this.sourceStatus
          },
          {
            label: '有效期结束',
            value: 'endTime',
            type: 'date',
            valueFormat: 'yyyy-MM',
            dateType: 'month',
            placeholder: '选择有效期结束时间'
          },
          {
            label: '状态',
            value: 'status',
            type: 'select',
            placeholder: '请选择',
            selectList: this.businessStatus.map((item) => ({
              value: item.code,
              label: item.label
            }))
          },
          {
            label: '级别',
            value: 'level',
            type: 'select',
            placeholder: '请选择',
            selectList: this.assetLevel
          }
        ];
      }
    },
    created() {
      this.getAssetLevelOptions();
    },
    methods: {
      // 获取资产级别下拉
      async getAssetLevelOptions() {
        let { data } = await getByCode('asset_level');
        this.assetLevel =
          data.length > 0
            ? data.map((item) => {
                return {
                  label: Object.keys(item)[0],
                  value: item[Object.keys(item)[0]]
                };
              })
            : [];
      },

      /* 搜索 */
      handleSearch(where) {
        this.$emit('search', where);
      },

      /* 重置 */
      handleReset() {
        this.$emit('reset');
      }
    }
  };
</script>
