<template>
<div>
<el-row class="query">
  <div class="query__operations">
    <!--##二期: 导入-->
    <el-button v-auth="50300050124" type="primary" @click="toImport">导入</el-button>
    <el-button v-auth="50300050105" type="primary" @click="toAdd">新增</el-button>
    <el-button v-auth="50300050106" type="primary" @click="e => operate(e, 'delete')" needconfirm>删除</el-button>
    <el-button v-auth="50300050107" type="primary" @click="e => operate(e, 'auditMvOrder')" needconfirm>审核</el-button>
    <el-button v-auth="50300050108" type="primary" @click="e => operate(e, 'performMove')">执行移动</el-button>
    <el-dropdown v-auth="50300050114" class="query__item" @command="toPrint">
      <el-button type="primary">
        打印<i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item v-auth="50300050115" command="18010070115">打印移动单</el-dropdown-item>
        <el-dropdown-item v-auth="50300050121" command="18010070116">Print Moving List</el-dropdown-item>
        <el-dropdown-item v-auth="50300050116" command="18010070117">打印移动上架单</el-dropdown-item>
        <el-dropdown-item v-auth="50300050122" command="18010070118">Print Moving Up List</el-dropdown-item>
        <el-dropdown-item v-auth="50300050117" command="18010070119">打印移动下架单</el-dropdown-item>
        <el-dropdown-item v-auth="50300050123" command="18010070120">Print Moving Down List</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <el-dropdown v-auth="50300050109" class="query__item">
      <el-button type="primary">
        更多<i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item v-auth="50300050110" command="cancelAudit" needconfirm @click.native="operate">取消审核</el-dropdown-item>
        <el-dropdown-item v-auth="50300050111" command="cancelMove" needconfirm @click.native="operate">取消移动</el-dropdown-item>
        <el-dropdown-item v-auth="50300050112" command="closeMvOrder" needconfirm @click.native="operate">关闭订单</el-dropdown-item>
        <el-dropdown-item v-auth="50300050113" command="cancelMvOrder" needconfirm @click.native="operate">取消订单</el-dropdown-item>
        <!--todo: 附件管理-->
        <!--<el-dropdown-item v-auth="50300030101" command="cancelMvDoc">附件管理</el-dropdown-item>-->
      </el-dropdown-menu>
    </el-dropdown>
  </div>
  <div class="query__retrieve">
    <!-- <el-input
      v-model="query.quickCondition"
      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="handelGetList(query)" 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="状态"
        prop="status">
        <el-select multiple v-model="status" @change="val => handleStatus(val)">
          <el-option
            v-for="item in $keys.inventory.mvOrder.status"
            :key="item.id"
            :label="item.name"
            :value="item.key"
          ></el-option>
        </el-select>
      </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-item label="商品" prop="skuName">
          <PublicQuery
            title="商品"
            cfgKey="invWmsSku"
            baseUrl="/inv_web/invweb"
            :valueField.sync="formData.skuCode"
            :textField.sync="formData.skuName"
            @change="handelOwner">
          </PublicQuery>
      </el-form-item>
    </el-form>
  </div>
</div>
</template>

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

  data () {
    return {
      formData: {},
      status: [],
      query: {}, // 查询条件
      showMore: false, // 显示更多查询
      moreData: {}
    }
  },
  methods: {
    handelGetList () {
      this.$refs.formData.resetFields()
      this.status = []
      this.$emit('getList')
    },
    handelOwner () {
      this.$emit('getList', this.formData)
    },
    handleStatus (val) {
      this.formData.status = val.join(',')
      this.$emit('getList', this.formData)
    },
    // 检查是否有勾选
    checkSelections () {
      if (!this.selectedIds) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },
    // 新增
    toAdd () {
      this.$router.push({
        name: 'mvOrderCreator',
        params: {
          mode: 'create',
        }
      })
    },
    // todo: 导入
    toImport () {
      this.$importExcel('/inv_web/invweb', 'InventoryMoveOrderImport')
    },
    // 对移动单进行操作, 更多按钮也在这里
    operateConfirm (type) {
      if (this.checkSelections()) {
        const url = this.$API.inventory.mvOrder[type]
        const param = {
          mvNos: this.selectedIds
        }
        this.$https.post(url, param)
          .then(data => {
            console.log('操作成功', data)
            this.toGetList()
          })
      }
    },
    // 打印
    toPrint (command, vmNode) {
      if (this.checkSelections()) {
        const param = {
          title: vmNode.$el.innerHTML,
          qs: `_functionCode=${command}&mvNo=${this.selectedIds.split(',').join(';')}`
        }
        this.$print(param)
      }
    },
    // 查询
    toGetList (query) {
      this.moreData = query
      this.$emit('getList', query)
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
    handleExcel () {
      const url = this.$API.inventory.mvOrder.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>
