<template>
<el-dialog
  class="creator"
  title="执行移动到"
  :visible="show"
  @close="close"
>
  <el-form
    inline
    label-position="top"
    :model="formData"
    ref="form"
    :rules="rules"
  >
    <el-form-item label="目标库位" prop="toLoc">
      <PublicQuery
        single
        title="目标库位"
        cfgKey="invWmsLoc"
        :baseUrl="baseUrl"
        :valueField.sync="formData.toLoc"
      ></PublicQuery>
    </el-form-item>
    <el-form-item label="目标跟踪号" prop="toId">
      <el-input v-model="formData.toId"></el-input>
    </el-form-item>
    <el-form-item label="移动操作人" prop="moveOp">
      <PublicQuery
        single
        title="移动操作人"
        cfgKey="invWmsOperator"
        :baseUrl="baseUrl"
        :valueField.sync="formData.moveOp"
      ></PublicQuery>
    </el-form-item>
    <el-form-item label="移动时间" prop="mvTime">
      <el-date-picker
        type="datetime"
        value-format="yyyy-MM-dd HH:mm:ss"
        v-model="formData.mvTime"
      ></el-date-picker>
    </el-form-item>
  </el-form>
  <div slot="footer">
    <el-button v-auth="50300050303" type="primary" @click="confirm">确认</el-button>
    <el-button v-auth="50300050304" type="primary" @click="reset">重置</el-button>
  </div>
</el-dialog>
</template>

<script>
export default {
  name: 'MoveTo',
  props: ['show', 'selectedRows'],
  watch: {},
  created () {
  },
  mounted () {
  },

  data () {
    return {
      formData: {}, // 提交对象
      rules: {
        toLoc: [{ required: true, message: '必填', trigger: 'change' }],
      }, // 校验规则
      baseUrl: '/inv_web/invweb', // 弹框基础url
    }
  },
  methods: {
    // 重置
    reset () {
      this.$refs.form.resetFields()
    },
    // 关闭
    close () {
      this.$emit('close')
    },
    // 确认按钮
    confirm () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const url = this.$API.inventory.mvOrder.moveToConfirm
          const param = {
            mvTaskRows: JSON.stringify(this.selectedRows),
            taskInfo: JSON.stringify(this.formData)
          }
          this.$https.post(url, param)
            .then(() => {
              this.$emit('createDone')
              this.close()
              this.reset()
            })
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
  .el-collapse-item {
    margin-bottom: 20px;
  }
  .detail-item {
    display: inline-table;
    width: 25%;
    font-size: 14px;
    padding: 7px;
  }
</style>
