<template>
  <el-form
    inline
    :model="form"
    ref="form"
    class="form-wrap"
    label-width="150px"
  >

    <div class="dialog-info">
      <el-form-item
        verify
        label="税率"
        prop="taxNum">
        <el-input v-model="form.taxNum"></el-input>
      </el-form-item>
      <el-form-item
        verify
        label="商品编码"
        prop="goodsCode">
        <el-input v-model="form.goodsCode"></el-input>
      </el-form-item>
      <el-form-item
        verify
        label="商品项目名称"
        prop="goodsCodeName">
        <el-input v-model="form.goodsCodeName"></el-input>
      </el-form-item>
    </div>

    <div class="dialog-btn-wrap">
      <el-button
        @click="reset"
        v-if="dialogType==='add'">
        重置
      </el-button>
      <el-button
        @click="handleClose"
        v-if="dialogType==='edit'">
        关闭
      </el-button>
      <el-button
        @click="submit"
        type="primary">
        保存
      </el-button>
    </div>
  </el-form>
</template>

<script>
import { updateInvoiceChannel } from '@/api/invoice'

export default {
  props: {
    currentItem: {
      type: Object,
      default: () => {}
    },
    dialogType: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      visible: false,
      form: {
        id: '',
        taxNum: '',
        goodsCode: '',
        goodsCodeName: ''
      }
    }
  },
  watch: {
    visible (val) {
      this.reset()
      this.form = Object.assign({}, this.currentItem)
    }
  },
  methods: {
    handleClose () {
      this.$parent.handleClose()
    },
    reset () {
      this.$refs.form.resetFields()
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.updateTicket()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    updateTicket () {
      updateInvoiceChannel(this.form).then(res => {
        this.$message.success('保存成功')
        this.reset()
        this.handleClose()
        this.$emit('updateList')
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-alert{
   margin-bottom: 20px;
   p{
      margin: 0;margin: 0;
   }
}

  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
     ::v-deep .el-input{
      width: 90px;
      margin-left: 10px;
      vertical-align: bottom;
    }
  }
</style>
