<template>
    <div>
        <div class="mrg-b">
            <el-row>
                <el-col :span="21">
                <el-button v-auth="50400050105" type="primary" @click="handleAdd">新增</el-button>
                <el-button v-auth="50400050106" type="primary" @click="handleDeleteRows">删除</el-button>
                </el-col>
                <el-col :span="3">
                <el-col :span="24" class="mrg-l">
                    <el-button v-auth="50400050102" type="primary" @click="handleMoreSearch">更多</el-button>
                    <el-button v-auth="50400050101" icon="el-icon-refresh" class="query__item" type="primary" @click="handleRefresh" plain circle></el-button>
                    <el-button
                    icon="el-icon-download"
                    v-if="false"
                    type="primary"
                    @click="handleExcel"
                    plain
                    circle
                  ></el-button>
                </el-col>
                </el-col>
            </el-row>
        </div>
        <div class="inputBox">
          <el-form inline :model="query" ref="query" label-position="left">
            <el-form-item label="批次属性编码" prop="lotCode">
              <el-input v-model="query.lotCode" @keyup.enter.native="handleSearch" placeholder="快捷查询(批次属性编码)"></el-input>
            </el-form-item>
            <el-form-item label="批次属性名称" prop="lotName">
              <el-input v-model="query.lotName" @keyup.enter.native="handleSearch" ></el-input>
            </el-form-item>
          <el-form-item
              label="创建时间">
              <el-date-picker
                v-model="date1"
                type="datetimerange"
                format="yyyy-MM-dd HH:mm"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions2"
                @change="getcreateTime">
              </el-date-picker>
            </el-form-item>
            <el-form-item
              label="修改时间">
              <el-date-picker
                v-model="date2"
                type="daterange"
                align="right"
                unlink-panels
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions2"
                @change="getmodifyTime">
              </el-date-picker>
            </el-form-item>
            </el-form>
        </div>
        <more-query
        :moreQueryVisible="moreQueryVisible"
        @close="moreQueryVisible=false"
        @toGetList="getQueryList">
        </more-query>

    </div>
</template>
<script>
import { today, yesterday, week, month, twoMonths, threeMonths } from '@/config/shortcuts'
import MoreQuery from './more-query'
export default {
  components: {
    MoreQuery
  },
  data () {
    return {
      query: {},
      tableList: [],
      total: 0,
      moreQueryVisible: false,
      date1: '',
      date2: '',
      pickerOptions2: {
        shortcuts: [today, yesterday, week, month, twoMonths, threeMonths]
      },
      moreData: {}
    }
  },
  props: {
    selectedIds: String
  },
  methods: {

    // 检查是否选中行
    checkSelections () {
      if (!this.selectedIds) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },

    getcreateTime (val) {
      this.query.createTimeFrom = val[0]
      this.query.createTimeTo = val[1]
      this.handleSearch()
    },
    // 修改时间
    getmodifyTime (val) {
      this.query.modifyTimeFrom = val[0]
      this.query.modifyTimeTo = val[1]
      this.handleSearch()
    },

    // 新增
    handleAdd () {
      this.$emit('handleOpenForm', 'create')
    },

    // 删除
    handleDeleteRows () {
      const url = this.$API.warehouseBasic.libraryBatch.delList
      const param = { jobIds: this.selectedIds }
      if (!this.checkSelections()) return
      this.$confirm(`您已选中${this.selectedIds.split(',').length}条数据,是否删除？`, '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList')
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    handleRefresh () {
      this.date1 = ''
      this.date2 = ''
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, lotCode: `%${this.query.lotCode || ''}%` }
      this.$emit('getList', query)
    },

    // 更多查询数据
    getQueryList (query) {
      this.moreQueryVisible = false
      this.moreData = query
      this.$emit('getList', query)
    },

    // 更多搜索查询
    handleMoreSearch () {
      this.moreQueryVisible = true
    },

    handleExcel () {
      const url = this.$API.warehouseBasic.libraryBatch.getList
      const options = this.moreData
      this.$exportExcel(url, options)
    },
  }
}
</script>
<style lang="scss" scoped>
.inputBox {
      width: 100%;
      border: 1px solid #d1d5db;
      margin-top: 10px;
      margin-bottom: 10px;
      border-radius: 10px;
      padding-bottom: 10px;
      padding-left: 10px;
      .el-form-item {
        margin-bottom: 0px;
        margin-top: 10px;
      }
    }
    .mrg-b{
        margin-bottom: 20px;
    }
    .mrg-l{
        margin-left:10px;
    }
  .query {
    &__operations {
      float: left;
    }
    &__retrieve {
      float: right;
      .el-input {
        max-width: 180px;
      }
    }
    &__item {
      margin-left: 10px;
    }
  }
</style>
