<template>
<el-dialog
  width="70%"
  class="more-query"
  title="高级查询"
  :visible="showMore"
  @close="close"
>
  <el-form
    inline
    label-position="top"
    :model="query"
    ref="queryForm"
  >
    <!--公用查询框-->
    <el-form-item label="货主" prop="owner">
      <PublicQuery
        title="货主"
        cfgKey="repWmsCustomer"
        :baseUrl="baseUrl"
        :valueField.sync="query.owner"
        :textField.sync="query.ebcuNameCn"
      ></PublicQuery>
    </el-form-item>
    <el-form-item label="商品" prop="sku">
      <PublicQuery
        title="商品"
        cfgKey="repWmsSku"
        :baseUrl="baseUrl"
        :valueField.sync="query.sku"
        :textField.sync="query.skuName"
      ></PublicQuery>
    </el-form-item>

    <el-form-item label="批次号" prop="lot">
      <el-input v-model="query.lot"></el-input>
    </el-form-item>
    <el-form-item label="交易时间">
      <el-date-picker
        v-model="dateTime"
        type="datetimerange"
        :picker-options="pickerOptions"
        :default-time="['00:00:00', '23:59:59']"
        format="yyyy-MM-dd HH:mm"
        value-format="yyyy-MM-dd HH:mm:ss"
        @change="dateTimeChange"
      ></el-date-picker>
    </el-form-item>
  </el-form>
  <div class="more-query__btn">
    <el-button type="primary" @click="submitForm">查询</el-button>
    <el-button @click="reset">重置</el-button>
  </div>
</el-dialog>
</template>

<script>
import { time } from 'apec-fe-utils'
import * as shortcuts from '@/config/shortcuts'
export default {
  props: ['showMore', 'queryProp'],
  created () {
  },
  mounted () {
    this.setDefaultTime()
  },

  data () {
    return {
      query: { ...this.queryProp }, // 查询条件
      baseUrl: '/rep_web/repweb',
      dateTime: [],
      pickerOptions: {
        shortcuts: { ...shortcuts }
      },
    }
  },
  methods: {
    setDefaultTime () {
      // 设置默认时间
      const startTime = new Date().getTime() - 29 * 24 * 60 * 60 * 1000
      this.dateTime = [ time.formatDate(new Date(startTime)) + ' 00:00:00', time.formatDate(new Date()) + ' 23:59:59' ]
      this.query.tranTimeFrom = this.dateTime[0]
      this.query.tranTimeTo = this.dateTime[1]
    },
    // 关闭弹窗
    close () {
      this.$emit('close')
    },
    // 提交表单
    submitForm () {
      this.$emit('toGetList', this.query)
      this.close()
    },
    // 重置表单
    reset () {
      this.dateTime = []
      this.query.tranTimeFrom = ''
      this.query.tranTimeTo = ''
      this.query.ebcuNameCn = ''
      this.query.skuName = ''
      this.$refs.queryForm.resetFields()
    },
    // 时间变化
    dateTimeChange (val) {
      this.query.tranTimeFrom = val ? val[0] : ''
      this.query.tranTimeTo = val ? val[1] : ''
    }
  },
}
</script>

<style lang="scss" scoped>
</style>
