<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>
      <el-button v-if="!isHidePut" :loading="listLoading" icon="el-icon-document" class="xl-form-btn bgc4" @click="pushToUser">推送给关注{{name}}的用户</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: [],
      isHidePut: false,
    }
  },
  computed: {
    name () {
      return this.parentData.$route.query.name || ''
    }
  },
  mounted () {
    this.getDef()
  },
  methods: {
    addHandle () {
      this.parentData.isDtlShow = true
      this.parentData.curObj = {}
    },
    pushToUser () {
      this.$msg(`您确定要推送给关注的用户吗？`, 'confirm', () => {
        this.$api.user.admestatepricepush({
          estate_id: this.parentData.$route.query.id
        }).then(() => {
          this.$msgs('推送成功~')
          this.isHidePut = true
        })
      }, null, true)
    },
    getDef (str) {
      let params = { ...this.$refs.ruleForm.baseForm }
      const query = this.$route.query
      let estateName = query.name || ''
      params.estate_id = query.id ? Number(query.id) : ''
      this.searchData = [
        { label: '选择楼盘', key: 'estate_id', type: 'selectRemote', changeHandle: this.estateChange,
          remoteParams: { skey: 'estate_name', api: `house.admestatelist`, opKey: 'estate_name', opVal: 'id' },
          remoteOptions: [{ keyRO: estateName, valRO: params.estate_id }]
        },
        { label: '签约中介', key: 'company' },
        { label: '签约日期', label2: '开始时间', label3: '结束时间', key: 'startEndTime', type: 'datePicker', rules: 1},
      ]
      this.setDefaultValue(params, 'searchData')
    },
    estateChange (val, options, curItem) {
      this.$router.push(`/house/price?id=${val}&name=${curItem.estate_name}`)
      // this.$router.go(0)
      this.searchHandle()
    },
    searchHandle() {
      const oldform = this.$refs.ruleForm.baseForm
      const newForm = { ...oldform }
      if (newForm.startEndTime) {
        newForm.start_at = newForm.startEndTime[0]
        newForm.end_at = newForm.startEndTime[1]
        delete newForm.startEndTime
      }
      // newForm.estate_id = this.parentData.searchForm.estate_id
      this.$emit('change', newForm)
    }
  }
}
</script>
