<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      top="8vh"
      width="40%"
      :visible.sync="dialogVisible"
      center
      @close="handleCancel"
    >
      <div class="el-dialog-div">
      <el-form
        :rules="rules"
        ref="dataForm"
        :model="temp"
        label-position="right"
        label-width="120px"
        style="height: 90%;"
      >

                  <el-form-item label="库存详情id" prop="stockDetailId"  class="is-required">
            <el-input v-model="temp.stockDetailId" placeholder="库存详情id" />
          </el-form-item>

          <el-form-item label="库存单id" prop="stockId"  class="is-required">
            <el-input v-model="temp.stockId" placeholder="库存单id" />
          </el-form-item>

          <el-form-item label="商品" prop="productId"  class="is-required">
            <el-input v-model="temp.productId" placeholder="商品" />
          </el-form-item>

          <el-form-item label="商品名 " prop="productName"  class="is-required">
            <el-input v-model="temp.productName" placeholder="商品名 " />
          </el-form-item>

          <el-form-item label="库存数量" prop="count"  class="is-required">
            <el-input v-model="temp.count" placeholder="库存数量" />
          </el-form-item>

          <el-form-item label="0正常 1审核完毕 2取消" prop="stockStatus"  class="is-required">
            <el-input v-model="temp.stockStatus" placeholder="0正常 1审核完毕 2取消" />
          </el-form-item>

          <el-form-item label="类型 1入库 2出库" prop="stockType"  class="is-required">
            <el-input v-model="temp.stockType" placeholder="类型 1入库 2出库" />
          </el-form-item>

          <el-form-item label="金额" prop="amount"  class="is-required">
            <el-input v-model="temp.amount" placeholder="金额" />
          </el-form-item>

          <el-form-item label="创建时间" prop="createTime"  class="is-required">
            <el-input v-model="temp.createTime" placeholder="创建时间" />
          </el-form-item>


      </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addStockDetail} from "@/api/business/stockDetail/stockDetail";
import {setRequiredFields} from "@/utils";
const requiredFields = []
export default {
  name: "addForm",
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        stockDetailId:'',
        stockId:'',
        productId:'',
        productName:'',
        count:'',
        stockStatus:'',
        stockType:'',
        amount:'',
        createTime:'',
      },
    }
  },
  methods: {
    open() {
      this.dialogVisible = true
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          addStockDetail(this.temp).then(response =>{
            this.handleCancel()
            this.$emit('ok', response.data)
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    handleCancel() {
      //初始化
      this.temp = this.$options.data().temp
      this.dialogVisible = false
      this.$refs['dataForm'].resetFields();
    }
  },
}
</script>

<style scoped>

</style>
