<template>
<div>
  <el-row class="query">
    <div class="query__operations">
      <el-button v-auth="50300060105" type="primary" @click="e => operate(e, 'invTaskMovement')">执行移动</el-button>
      <el-button v-auth="50300060106" type="primary" @click="e => operate(e, 'invCancelTaskMovement')" needconfirm>取消移动</el-button>
    </div>
    <div class="query__retrieve">
      <!-- <el-input
        v-model="query.quickCondition"
        placeholder="快捷查询（任务ID）"
        @keyup.enter.native="toGetList(query)"
      ></el-input> -->
      <el-button v-auth="50300060102" class="query__item" type="primary" @click="moreQuery">更多</el-button>
      <el-button v-auth="50300060101" icon="el-icon-refresh" class="query__item" type="primary" @click="handelGetList" 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"
      ></MoreQuery>
    </div>
  </el-row>
  <div class="inputBox">
    <el-form inline :model="formData" ref="formData" label-position="left">
      <el-form-item label="移动单号" prop="mvNo">
        <el-input
          v-model="formData.mvNo"
          placeholder="快捷查询（移动单号）"
          @keyup.enter.native="toGetList(formData)"
        ></el-input>
      </el-form-item>
      <el-form-item label="移动任务ID" prop="mvId">
        <el-input
          v-model="formData.mvId"
          placeholder="移动任务ID"
          @keyup.enter.native="toGetList(formData)"
        ></el-input>
      </el-form-item>
      <el-form-item label="批次号" prop="lotNum">
        <el-input
          v-model="formData.lotNum"
          placeholder="批次号"
          @keyup.enter.native="toGetList(formData)"
        ></el-input>
      </el-form-item>
      <el-form-item label="货主" prop="ownerCode">
          <PublicQuery
            title="货主"
            cfgKey="invWmsCustomer"
            baseUrl="/inv_web/invweb"
            :valueField.sync="formData.ownerCode"
            @change="handelOwner">
          </PublicQuery>
      </el-form-item>
    </el-form>
  </div>
</div>
</template>

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

  data () {
    return {
      formData: {},
      query: {}, // 查询条件
      showMore: false, // 显示更多查询
      moreData: {}
    }
  },
  methods: {
    handelGetList () {
      this.$refs.formData.resetFields()
      this.$emit('getList')
    },
    handelOwner () {
      this.$emit('getList', this.formData)
    },
    // 检查是否有勾选
    checkSelections () {
      if (!this.selection.length) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },
    // todo: 新增按钮
    toAdd () {
      if (this.checkSelections()) {

      }
    },
    // todo: 导入
    toImport () {},
    // 删除, 已与operate合并, 要加确认弹窗再说
    toDelete () {
      if (this.checkSelections()) {

      }
    },
    // 对移动任务进行操作, 更多按钮也在这里
    operateConfirm (type) {
      if (this.checkSelections()) {
        const url = this.$API.inventory.mvTask[type]
        const param = {
          wmTaskMvEntityQueryItemBean: JSON.stringify(this.selection)
        }
        this.$https.post(url, param)
          .then(data => {
            this.toGetList()
          })
      }
    },
    // 查询
    toGetList (query) {
      this.moreData = query
      this.$emit('getList', query)
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    handleExcel () {
      const url = this.$API.inventory.mvTask.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;
      }
  }
  .query {
    &__operations {
      float: left;
    }
    &__retrieve {
      float: right;
      .el-input {
        max-width: 180px;
      }
    }
    &__item {
      margin-left: 10px;
    }
  }
</style>
