<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-document" class="xl-form-btn bgc2" @click="toExportExcel">导出</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 {
  name: 'custIndex',
  mixins: [],
  props: {
    listLoading: Boolean
  },
  inject: ['parentData'],
  data() {
    return {
      searchData: [
        { label: '房屋类型', key: 'house_type', type: 'select', options: this.$dictData.trade_house_type},
        { label: '成交店员', key: 'deal_clerk' },
        { label: '成交楼盘', key: 'deal_item' },
        { label: '成交类型', key: 'deal_type', type: 'select', options: this.$dictData.trade_deal_type},
        { label: '审核状态', key: 'check_state', type: 'select', options: this.$dictData.check_state},
        { label: '成交单状态', key: 'trade_state', type: 'select', options: this.$dictData.trade_state},
        { label: '时间', label2: '开始成交日期', label3: '结束成交日期', key: 'startEndTime', type: 'datePicker'},
        { label: '客户姓名', key: 'customer_name' },
        { label: '客户电话', key: 'customer_phone' },
        { label: '报备渠道', key: 'report_dept' },
      ]
    }
  },
  methods: {
    addHandle () {
      this.parentData.isDtlShow = true
      this.parentData.curObj = {}
    },
    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
      this.$emit('change', newForm)
    },
    toExportExcel () {
      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
      } else {
        this.$msgw('请选择导出的时间范围')
        return
      }
      const token = window.sessionStorage.getItem('fp_token')
      window.open(`https://api.fangpiaovip.com/adm/trade/export?token=${encodeURIComponent(token)}&start_at=${newForm.start_at}&end_at=${newForm.end_at}&house_type=${newForm.house_type}&deal_clerk=${newForm.deal_clerk}&deal_item=${newForm.deal_item}&deal_type=${newForm.deal_type}&trade_state=${newForm.trade_state}`)
    }
  }
}
</script>
