<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <!-- <el-form-item label="库位状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="库位状态 -1:不可用，0:空库位, 1:空货架, 2:货物正常, 3:货物预入库, 4:货物预出库" clearable />
    </el-form-item>
    <el-form-item label="是否为空" prop="isEmpty">
      <el-input v-model="dataForm.isEmpty" placeholder="是否为空，0表示空，1表示有货" clearable />
    </el-form-item>
    <el-form-item label="产品id" prop="productId">
      <el-input v-model="dataForm.productId" placeholder="产品id，关联产品表：mt_product" clearable />
    </el-form-item>
    <el-form-item label="详细规格" prop="specModel">
      <el-input v-model="dataForm.specModel" placeholder="详细规格" clearable />
    </el-form-item> -->
    <el-form-item label="产品编码" prop="productCode">
      <el-input v-model="dataForm.productCode" placeholder="产品编码" disabled />
    </el-form-item>
    <el-form-item label="板材名称" prop="productName">
      <el-input v-model="dataForm.productName" placeholder="板材名称" disabled />
    </el-form-item>
    <el-form-item label="货物数量" prop="quantity">
      <el-input v-model="dataForm.quantity" placeholder="货物数量， 货物总的数量" clearable />
    </el-form-item>
    <!-- <el-form-item label="库位id" prop="warehousPositionId">
      <el-input v-model="dataForm.warehousPositionId" placeholder="库位id，关联表：mt_warehous_rank" clearable />
    </el-form-item> -->
    <el-form-item label="库位名称" prop="warehousPositionName">
      <el-input v-model="dataForm.warehousPositionName" placeholder="库位名称" disabled />
    </el-form-item>
    <!-- <el-form-item label="批次号" prop="dateNum">
      <el-input v-model="dataForm.dateNum" placeholder="批次号" clearable />
    </el-form-item> -->
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注" clearable />
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          status: '',
          isEmpty: '',
          productId: '',
          specModel: '',
          productCode: '',
          productName: '',
          quantity: '',
          warehousPositionId: '',
          warehousPositionName: '',
          dateNum: '',
          remark: ''
        },
        dataRule: {
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || ''
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/work/mtwarehouspositionrelat/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm = data.mtWarehousePositionRelat
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/work/mtwarehouspositionrelat/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'status': this.dataForm.status,
                'isEmpty': this.dataForm.isEmpty,
                'productId': this.dataForm.productId,
                'specModel': this.dataForm.specModel,
                'productCode': this.dataForm.productCode,
                'productName': this.dataForm.productName,
                'quantity': this.dataForm.quantity,
                'warehousPositionId': this.dataForm.warehousPositionId,
                'warehousPositionName': this.dataForm.warehousPositionName,
                'dateNum': this.dataForm.dateNum,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
