<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">查询：{{name}}</el-button>
      <el-button :loading="listLoading" icon="el-icon-plus" class="xl-form-btn bgc2" @click="addHandle">添加</el-button>
    </div>
  </base-form>
</template>
<script>
export default {
  props: {
    listLoading: Boolean
  },
  inject: ['parentData'],
  mixins,
  data() {
    return {
      searchData: [],
      isHidePut: false,
    }
  },
  computed: {
    name () {
      return this.parentData.$route.query.name || ''
    }
  },
  mounted () {
    this.getDef()
  },
  methods: {
    addHandle () {
      this.parentData.isDtlShow = true
      this.parentData.curObj = {}
    },
    getDef (str) {
      let params = { ...this.$refs.ruleForm.baseForm }
      const query = this.$route.query
      let estateName = query.name || ''
      params.estate_lib_id = query.id ? Number(query.id) : ''
      this.searchData = [
        { label: '选择楼盘', key: 'estate_lib_id', type: 'selectRemote', changeHandle: this.estateChange,
          remoteParams: { skey: 'estate_name', api: `house.admestateliblist`, opKey: 'estate_name', opVal: 'id' },
          remoteOptions: [{ keyRO: estateName, valRO: params.estate_lib_id }]
        },
        // { label: '选择用户', key: 'user_id', type: 'selectRemote',
        //   remoteParams: { skey: 'nickname', api: `user.admuserlist?auth_state=1`, opKey: 'nickname', opVal: 'id' },
        // },
      ]
      this.setDefaultValue(params, 'searchData')
    },
    estateChange (val, options, curItem) {
      this.$router.push(`/house/brokerage?id=${val}&name=${curItem.estate_name}`)
      // this.$router.go(0)
      this.searchHandle()
    },
    searchHandle() {
      const oldform = this.$refs.ruleForm.baseForm
      const newForm = { ...oldform }
      this.$emit('change', newForm)
    }
  }
}
</script>
