<template>
  <div>
    <el-form
      :model="form"
      :rules="rules"
      ref="form"
    >
      <el-form-item
        label="备查货号"
        prop="supplyChannel"
        label-width="100px"
      >
        <el-input
          v-model="form.supplyChannel"
          placeholder="请输入备查货号"
        />
      </el-form-item>
      <el-form-item
        label="内部库存"
        prop="stockCount"
        label-width="100px"
      >
        <el-input
          v-model="form.stockCount"
          type="number"
          placeholder="请输入内部库存"
        />
      </el-form-item>
      <el-form-item
        label="税务库存"
        prop="taxStockCount"
        label-width="100px"
      >
        <el-input
          v-model="form.taxStockCount"
          type="number"
          placeholder="请输入税务库存"
        />
      </el-form-item>
      <el-form-item
        label="商品采购价1"
        prop="discountPrice"
        label-width="100px"
      >
        <el-input
          v-model="form.discountPrice"
          type="number"
          placeholder="请输入商品采购价1"
        />
      </el-form-item>
      <el-form-item
        label="商品采购价2"
        prop="agreeCostPrice"
        label-width="100px"
      >
        <el-input
          v-model="form.agreeCostPrice"
          type="number"
          placeholder="请输入商品采购价2"
        />
      </el-form-item>
    </el-form>
    <span
      slot="footer"
      class="dialog-footer"
    >
      <el-button
        @click="$listeners.close"
      >取消</el-button>
      <el-button
        type="primary"
        @click="submit"
      >确认</el-button>
    </span>
  </div>
</template>
<script>
import { createGoodsProcurements } from '@/api/businessManager'
export default {
  props: ['goodsId'],
  data() {
    return {
      form: {
        supplyChannel: '',
        stockCount: '',
        taxStockCount: '',
        discountPrice: '',
        agreeCostPrice: '',
      },
      rules: {
        supplyChannel: [{ required: true, message: '请输入备查货号', trigger: 'blur' }],
        stockCount: [{ required: true, message: '请输入内部库存', trigger: 'blur' }],
        taxStockCount: [{ required: true, message: '请输入税务库存', trigger: 'blur' }],
        discountPrice: [{ required: true, message: '请输入商品采购价1', trigger: 'blur' }],
        agreeCostPrice: [{ required: false, message: '请输入商品采购价2', trigger: 'blur' }],
      },
    }
  },
  methods: {
    async submit() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          try {
            await this.$confirm('是否确认提交', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            })
            await createGoodsProcurements({
              goodsId: this.goodsId,
              ...this.form,
            })
            this.$message.success('添加成功')
              this.$listeners.submited()
              this.$listeners.close()
          } catch (error) {}
        }
      })
    }
  },
}
</script>
<style lang="less" scoped>
  .dialog-footer{
    text-align: right;
    display: block;
  }
</style>
