<template>
  <div>
    <el-dialog title="上架任务"  :visible.sync="goodsFormVisible" :before-close="close" width="66%">
      <el-form inline ref="goodsForm" label-position="top" :model="formData" :rules="rules">
        <el-form-item >
          <span class="form-item"><em>任务ID：</em> {{formData.paId}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>行号：</em> {{formData.lineNo}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>状态：</em> {{formData.status}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>单据：</em> {{formData.orderNo}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>货主：</em> {{formData.ownerName}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>商品：</em> {{formData.skuCode}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>商品名称：</em> {{formData.skuName}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>上架规则：</em> {{formData.paRuleName}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>批次号：</em> {{formData.lotNum}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>源库位：</em> {{formData.fmLoc}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>源跟踪号：</em> {{formData.fmId}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>推荐库位：</em> {{formData.suggestLoc}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>包装规格：</em> {{formData.packDesc}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>包装单位：</em> {{formData.uomDesc}}</span>
        </el-form-item>
        <el-form-item >
          <span class="form-item"><em>上架库位指定规则：</em> {{formData.reserveCode}}</span>
        </el-form-item>
        <el-form-item label="上架库位" prop="toLoc">
          <PublicQuery
            title="上架库位"
            single
            baseUrl="/inb_web/inbweb"
            cfgKey="inbWmsLoc"
            :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="qtyPaUom">
          <el-input v-model="formData.qtyPaUom" disabled></el-input>
        </el-form-item>
        <el-form-item label="上架数EA" prop="qtyPaEa">
          <el-input v-model="formData.qtyPaEa"></el-input>
        </el-form-item>
        <el-form-item label="上架重量" prop="paWeight">
          <el-input v-model="formData.paWeight"></el-input>
        </el-form-item>
        <el-form-item label="商品重量" prop="skuWeight">
          <el-input v-model="formData.skuWeight" disabled></el-input>
        </el-form-item>
        <el-form-item label="上架人" prop="paOp">
          <PublicQuery
            title="上架人"
            single
            baseUrl="/inb_web/inbweb"
            cfgKey="inbWmsOperator"
            :valueField.sync="formData.paOp"></PublicQuery>
        </el-form-item>
        <el-form-item label="上架时间">
          <el-date-picker
            v-model="formData.paTime"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="formData.remark"></el-input>
        </el-form-item>
      </el-form>
      <div class="mrg-t">
          <el-button v-auth="50100020205" type="primary" @click="handleConfirm">上架确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { time } from 'apec-fe-utils'

export default {

  data () {
    var checkVal = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('上架重量必填'))
      } else if (value <= 0) {
        callback(new Error('上架重量必须大于0'))
      } else {
        callback()
      }
    }
    return {
      formData: {},
      rules: {
        toLoc: [
          { required: true, message: '上架库位必填', trigger: 'change' }
        ],
        toId: [
          { required: true, message: '上架跟踪号必填', trigger: 'change' }
        ],
        qtyPaUom: [
          { required: true, message: '上架数必填', trigger: 'change' }
        ],
        qtyPaEa: [
          { required: true, message: '上架数EA必填', trigger: 'change' }
        ],
        paWeight: [
          { required: true, validator: checkVal, trigger: 'change' }
        ],

      }
    }
  },
  props: {
    goodsFormVisible: Boolean,
    currentRow: Object,
  },

  methods: {
    close () {
      this.$emit('close')
      this.$refs.goodsForm.resetFields()
    },

    // 保存
    handleConfirm () {
      this.$refs.goodsForm.validate((valid) => {
        if (valid) {
          const url = this.$API.stockIn.Putaway.comfirmTaskPa
          const param = { taskPaBeans: JSON.stringify([this.formData]) }
          this.$https.post(url, param).then(res => {
            this.$emit('editOk')
          })
        }
      })
    },

  },

  watch: {
    currentRow: {
      handler (item) {
        this.formData = { ...item }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
  .mrg-t{
    margin-top: 20px
  }
  .form-item {
  display: inline-block;
  margin-left: 10px;
  em{
    font-style: normal;
    color: #9c9d9e
  }
}
</style>
