<template>
<el-row class="query">
  <div class="query__operations">
    <el-button type="primary" @click="toAdd">新增</el-button>
    <el-button type="primary" @click="e => operate(e, 'delete')" needconfirm>删除</el-button>
    <el-button type="primary" @click="e => operate(e, 'audit')" needconfirm>审核</el-button>
    <el-button type="primary" @click="e => operate(e, 'cancelAudit')" needconfirm>取消审核</el-button>
    <el-button type="primary" @click="e => operate(e, 'execute')">执行业务</el-button>
  </div>
  <div class="query__retrieve">
    <span class="el-form-item__label">业务类型</span>
    <el-select clearable v-model="query.businessType" @change="toGetList(query)">
      <template v-for="item in $keys.inventory.insideBusiness.businessType">
        <el-option
          :key="item.id"
          :value="item.key"
          :label="item.name"
        ></el-option>
      </template>
    </el-select>
    <el-input
      class="query__item"
      v-model="query.businessNo"
      placeholder="快捷查询（业务单号）"
      @keyup.enter.native="toGetList(query)"
    ></el-input>
    <!--<el-button v-auth="50300050102" class="query__item" type="primary" @click="moreQuery">更多</el-button>-->
    <el-button v-auth="50300050101" icon="el-icon-refresh" class="query__item" type="primary" @click="refresh" plain circle></el-button>
    <el-button v-auth="50100030101" icon="el-icon-download" v-if="false" type="primary" @click="handleExcel" plain circle></el-button>
    <!--<MoreQuery-->
      <!--:queryProp="query"-->
      <!--:showMore="showMore"-->
      <!--@close="showMore = false"-->
      <!--@toGetList="toGetList"-->
    <!--&gt;</MoreQuery>-->
  </div>
</el-row>
</template>

<script>
// import MoreQuery from './MoreQuery'
export default {
  // components: { MoreQuery },
  props: ['selectedIds'],
  created () {
  },
  mounted () {
  },

  data () {
    return {
      query: {}, // 查询条件
      showMore: false, // 显示更多查询
      moreData: {}
    }
  },
  methods: {
    // 检查是否有勾选
    checkSelections () {
      if (!this.selectedIds) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },
    // 新增
    toAdd () {
      this.$router.push({
        name: 'insideBusinessCreator',
        params: {
          mode: 'create',
        }
      })
    },
    // 对移动单进行操作, 更多按钮也在这里
    operateConfirm (type) {
      if (this.checkSelections()) {
        const url = this.$API.inventory.insideBusiness[type]
        const param = {
          businessNos: this.selectedIds
        }
        this.$https.post(url, param)
          .then(data => {
            console.log('操作成功', data)
            this.toGetList()
          })
      }
    },
    // 查询
    toGetList (query) {
      this.moreData = query
      this.$emit('getList', query)
    },
    // 刷新
    refresh () {
      this.query.businessNo = undefined
      this.query.businessType = undefined
      this.$emit('getList')
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    handleExcel () {
      const url = this.$API.inventory.insideBusiness.getList
      const options = this.moreData
      this.$exportExcel(url, options)
    },
  },
}
</script>

<style lang="scss" scoped>
  .query {
    &__operations {
      float: left;
    }
    &__retrieve {
      float: right;
      .el-input {
        max-width: 180px;
      }
    }
    &__item {
      margin-left: 10px;
    }
  }
</style>
