<template>
  <search-white-board @search="handleSearch">
    <div slot="base">
      <el-row :gutter="20">
        <el-col class="toolbar-txt txt-right" :span="2">文章类型</el-col>
        <el-col :span="6">
          <el-select v-model="form.carrier" clearable placeholder="请选择" style="width: 100%;">
            <el-option
              v-for="item in carrierOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-col>

        <el-col class="toolbar-txt txt-right" :span="2">时间</el-col>
        <el-col :span="8">
          <el-date-picker
            v-model="form.timeArr"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-col>
      </el-row>
    </div>
  </search-white-board>
</template>

<script>
import CARRIERKEY from '@/const/carrierKey'

import mxField from '@/mixins/field'

export default {
  name: 'TagToolbar',

  mixins: [mxField()],

  data() {
    return {
      form: {
        carrier: null,
        timeArr: []
      },
      apiForm: {
        carrier: 'contentType'
      },
      carrierOptions: CARRIERKEY.CARRIER
    }
  },

  methods: {
    handleSearch() {
      const result = {}
      for (const i in this.form) {
        if (i === 'timeArr') {
          result.startDate = this.form[i] ? this.form.timeArr[0] : null
          result.endDate = this.form[i] ? this.form.timeArr[1] : null
        } else {
          result[this.apiForm[i]] = this.form[i]
        }
      }
      this.$emit('onSearch', result)
    }
  }
}
</script>

<style scoped>
.toolbar-txt {
  font-size: 13px;
  padding: 5px;
  line-height: 1.7;
}
.txt-right {
  text-align: right;
}
</style>
