<template>
    <div>
        <div class="mrg-b">
            <el-row>
                <el-col :span="21">
                <el-button v-auth="50400020111" type="primary" @click="handleAdd">新增</el-button>
                <el-button v-auth="50400020108" type="primary" @click="handleDeleteRows">删除</el-button>
                </el-col>
                <el-col :span="3">
                <el-col :span="24" class="mrg-l">
                    <el-button v-auth="50400020102" type="primary" @click="handleMoreSearch">更多</el-button>
                    <el-button v-auth="50400020101" 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="zoneCode">
              <el-input v-model="query.zoneCode" @keyup.enter.native="handleSearch" placeholder="快捷查询(库区编码)"></el-input>
            </el-form-item>
            <el-form-item label="库区名称" prop="zoneName">
              <el-input v-model="query.zoneName" @keyup.enter.native="handleSearch" ></el-input>
            </el-form-item>
            <el-form-item
              label="库区类型"
              prop="type">
              <el-select multiple v-model="type"  @change="handleStatus">
                <el-option label="平面仓库区" value="1"></el-option>
                <el-option label="货架仓库区" value="2"></el-option>
                <el-option label="高架仓库区" value="3"></el-option>
                <el-option label="重力式货架库区" value="4"></el-option>
                <el-option label="堆垛机货架库区" value="5"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="所属区域"
              prop="areaCode">
              <PublicQuery
              title="所属区域"
              baseUrl="/bd_web/bdweb"
              cfgKey="bdWmsArea"
              :valueField.sync="query.areaCode" @change="handleSearch">
              </PublicQuery>
            </el-form-item>
          </el-form>
        </div>
        <more-query
        :moreQueryVisible="moreQueryVisible"
        @close="moreQueryVisible=false"
        @toGetList="getQueryList">
        </more-query>
    </div>
</template>
<script>
import MoreQuery from './more-query'
export default {
  components: {
    MoreQuery
  },
  data () {
    return {
      query: {},
      moreQueryVisible: false,
      type: [],
      moreData: {}
    }
  },
  props: {
    selectedIds: String
  },
  methods: {

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

    handleStatus (val) {
      this.query.type = val.join(',')
      this.handleSearch()
    },

    handleRefresh () {
      this.type = []
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, zoneCode: `%${this.query.zoneCode || ''}%` }
      this.$emit('getList', query)
    },

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

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

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

    // 保存成功
    saveOK () {
      this.$emit('getList')
    },

    // 删除
    handleDeleteRows () {
      const url = this.$API.warehouseBasic.libraryArea.delList
      const removeCodes = this.selectedIds.split(',')
      const param = { removeCodes: JSON.stringify(removeCodes) }

      if (!this.checkSelections()) return
      this.$confirm(`您已选中${removeCodes.length}条数据,是否删除？`, '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList')
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleExcel () {
      const url = this.$API.warehouseBasic.libraryArea.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>
