<template>
  <section class="th-sms--search">
    <div class="search-wrap">
      <th-form
        v-bind="form"
        :options="{
          msgType: smsTypeOptions,
          sheetType: smsSheetTypeOptions,
          sendObjectType: smsSendObjOptions,
          smsType: smsDeviceOptions
        }"
      />
      <div class="buttons-wrap">
        <el-button :loading="loading" type="primary" size="mini" @click="handleSearch">搜索</el-button>
        <el-button type="primary" size="mini" @click="handleExport">导出</el-button>
      </div>
    </div>
  </section>
</template>

<script>
import ThForm from '../../form/src/form'
import baseForm from '../../../src/mixins/baseForm'
import moment from 'moment'

export default {
  components: {
    ThForm
  },
  mixins: [baseForm],
  props: {
    smsDeviceOptions: {
      type: Array,
      default: () => []
    },
    smsTypeOptions: {
      type: Array,
      default: () => []
    },
    smsSheetTypeOptions: {
      type: Array,
      default: () => []
    },
    smsSendObjOptions: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      isShow: false,
      loading: false,
      form: {
        labelWidth: '90px',
        data: {
          sendTime: moment().subtract(3, 'months').format('YYYY-MM-DD'),
          endSendTime: moment().format('YYYY-MM-DD'),
          sheetType: '',
          sendObjectType: '',
          businessCode: '',
          smsContent: '',
          phoneNumber: '',
          msgType: '',
          smsType: '',
          isSendSuccess: ''
        },
        items: [
          {
            label: '发送时间',
            prop: 'sendTime',
            component: 'date',
            props: {
              type: 'date',
              clearable: true,
              valueFormat: 'yyyy-MM-dd'
            }
          },
          {
            label: '至',
            prop: 'endSendTime',
            component: 'date',
            props: {
              type: 'date',
              clearable: true,
              valueFormat: 'yyyy-MM-dd'
            }
          },
          {
            label: '短信内容',
            prop: 'smsContent',
            component: 'input',
            props: {
              maxlength: 200,
              clearable: true,
              placeholder: '请输入'
            }
          },
          {
            label: '手机号',
            prop: 'phoneNumber',
            component: 'input',
            props: {
              maxlength: 200,
              clearable: true,
              placeholder: '请输入'
            }
          },
          {
            label: '工单类型',
            prop: 'sheetType',
            component: 'select',
            props: {
              clearable: true
            }
          },
          {
            label: '短信类型',
            prop: 'msgType',
            component: 'select',
            props: {
              clearable: true
            }
          },
          {
            label: '发送设备',
            prop: 'smsType',
            component: 'select',
            props: {
              clearable: true
            }
          },
          {
            label: '发送对象类型',
            prop: 'sendObjectType',
            component: 'select',
            props: {
              clearable: true
            }
          },
          {
            label: '业务编码',
            prop: 'businessCode',
            component: 'input',
            props: {
              maxlength: 200,
              placeholder: '请输入',
              clearable: true
            }
          },
          {
            label: '是否发送成功',
            prop: 'isSendSuccess',
            component: 'select',
            options: [
              {
                value: true,
                label: '是'
              },
              {
                value: false,
                label: '否'
              }
            ],
            props: {
              clearable: true
            }
          }
        ],
        buttons: [],
        props: {
          inline: true
        }
      }
    }
  },
  methods: {
    // 点击查询按钮
    handleSearch() {
      this.$emit('onSearch')
    },
    // 点击导出按钮
    handleExport() {
      this.$emit('onExport')
    },
    // 初始化参数
    initData(row) {
      this.form.data.sheetType = row.sheetType
      this.form.data.businessCode = row.sheetNo
    }
  }
}
</script>
