<template>
  <base-form slot="content" ref="ruleForm" :data="searchData">
    <div slot="footer">
      <el-button :loading="listLoading" icon="el-icon-search" class="xl-form-btn bgc1" @click="searchHandle">查询</el-button>
      <el-button :loading="listLoading" icon="el-icon-plus" class="xl-form-btn bgc2" @click="addHandle">添加</el-button>
      <!-- <el-button :loading="listLoading" icon="el-icon-document" class="xl-form-btn bgc2" @click="toExportExcel">导出{{ this.$route.meta.title }}信息</el-button> -->
    </div>
  </base-form>
</template>
<script>
export default {
  props: {
    listLoading: Boolean
  },
  inject: ['parentData'],
  mixins,
  data() {
    return {
      searchData: []
    }
  },
  mounted () {
    this.getDef()
  },
  methods: {
    addHandle () {
      this.parentData.isDtlShow = true
      this.parentData.curObj = {}
    },
    subwayLineChange (val) {
      this.getDef('change')
    },
    getDef (str) {
      let params = { ...this.$refs.ruleForm.baseForm }
      let subwayNameDD = this.$dictData.metro_type || []
      if (params.metro_line) {
        subwayNameDD = []
        if (str === 'change') params.metro_type = ''
        const subwayNameAll = this.$dictData.metro_type || []
        subwayNameAll.map(item => {
          if (item.option1.indexOf(params.metro_line) > -1) {
            subwayNameDD.push(item)
          }
        })
        this.searchData = [
          { label: '所属区域', key: 'area_type', type: 'select', options: this.$dictData.area_type},
          { label: '楼盘名称', key: 'estate_name' },
          { label: '是否新房', key: 'is_new', type: 'select', options: this.$dictData.sys_yesno},
          { label: '楼盘状态', key: 'estate_tag', type: 'select', options: this.$dictData.estate_tag},
          { label: '就读学校', key: 'school_id', type: 'selectRemote',
            remoteParams: { skey: 'school_name', api: `school.admschoollist`, opKey: 'school_name', opVal: 'id' }
          },
          { label: '地铁线路', key: 'metro_line', type: 'select', options: this.$dictData.metro_line, changeHandle: this.subwayLineChange},
          { label: '地铁站名', key: 'metro_type', type: 'select', class: 'c-3', options: subwayNameDD},
          // { label: '周边医院', key: 'hospital_type', type: 'select', class: 'c-3', options: this.$dictData.hospital_type },
          // { label: '周边商圈', key: 'high_street', type: 'select', class: 'c-3', options: this.$dictData.high_street },
          // { label: '周边公园', key: 'park_type', type: 'select', class: 'c-3', options: this.$dictData.park_type },
        ]
      } else {
        this.searchData = [
          { label: '所属区域', key: 'area_type', type: 'select', options: this.$dictData.area_type},
          { label: '楼盘名称', key: 'estate_name' },
          { label: '是否新房', key: 'is_new', type: 'select', options: this.$dictData.sys_yesno},
          { label: '楼盘状态', key: 'estate_tag', type: 'select', options: this.$dictData.estate_tag},
          { label: '就读学校', key: 'school_id', type: 'selectRemote',
            remoteParams: { skey: 'school_name', api: `school.admschoollist`, opKey: 'school_name', opVal: 'id' }
          },
          { label: '地铁线路', key: 'metro_line', type: 'select', options: this.$dictData.metro_line, changeHandle: this.subwayLineChange},
          // { label: '周边医院', key: 'hospital_type', type: 'select', class: 'c-3', options: this.$dictData.hospital_type },
          // { label: '周边商圈', key: 'high_street', type: 'select', class: 'c-3', options: this.$dictData.high_street },
          // { label: '周边公园', key: 'park_type', type: 'select', class: 'c-3', options: this.$dictData.park_type },
        ]
      }
      this.setDefaultValue(params, 'searchData')
    },
    searchHandle() {
      const oldform = this.$refs.ruleForm.baseForm
      const newForm = { ...oldform }
      this.$emit('change', newForm)
    }
  }
}
</script>
