<!-- 搜索表单 -->
<template>
  <el-form
    label-width="100px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="工号:">
          <el-input clearable v-model="where.agentId" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="录音流水号:">
          <el-input clearable v-model="where.voiceId" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="客户联系方式:">
          <el-input
            clearable
            v-model="where.customerPhoneNo"
            placeholder="请输入"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="结束类型:">
          <el-select
            clearable
            v-model="where.finishType"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in finishTypeList"
              :key="index"
              :label="item"
              :value="index"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="呼叫类型:">
          <el-select
            clearable
            v-model="where.callType"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in callTypeList"
              :key="index"
              :label="item"
              :value="index"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="挂断类型:">
          <el-select
            clearable
            v-model="where.hangupType"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in hangupTypeList"
              :key="index"
              :label="item"
              :value="index"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 12, md: 12 } : { span: 6 }">
        <el-form-item label="通话开始时间:">
          <el-date-picker
            unlink-panels
            v-model="where.startTime"
            range-separator="-"
            type="daterange"
            end-placeholder="结束日期"
            start-placeholder="开始日期"
            value-format="yyyy-MM-dd"
            class="ele-fluid"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 12, md: 12 } : { span: 6 }">
        <el-form-item label="通话结束时间:">
          <el-date-picker
            unlink-panels
            v-model="where.endTime"
            range-separator="-"
            type="daterange"
            end-placeholder="结束日期"
            start-placeholder="开始日期"
            value-format="yyyy-MM-dd"
            class="ele-fluid"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="业务订单号:">
          <el-input clearable v-model="where.orderId" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <div class="ele-form-actions">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
          >
            查询
          </el-button>
          <el-button @click="reset">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
  import { logSearch } from '@/api/call';
  export default {
    data() {
      // 默认表单数据
      const defaultWhere = {
        orderId: '',
        agentId: '',
        voiceId: '',
        customerPhoneNo: '',
        finishType: '',
        callType: '',
        hangupType: '',
        startTime: '',
        endTime: ''
      };
      return {
        // 表单数据
        where: { ...defaultWhere },
        finishTypeList: [],
        callTypeList: [],
        hangupTypeList: []
      };
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    mounted() {
      this.initSearch();
    },
    methods: {
      initSearch() {
        logSearch()
          .then((data) => {
            this.finishTypeList = data.finishTypeList;
            this.callTypeList = data.callTypeList;
            this.hangupTypeList = data.hangupTypeList;
          })
          .catch((e) => {
            this.$message.error(e.message);
          });
      },
      /* 搜索 */
      search() {
        this.$emit('search', this.where);
      },
      /*  重置 */
      reset() {
        this.where = { ...this.defaultWhere };
        this.search();
      }
    }
  };
</script>
