<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="55%"
    height="300px"
    append-to-body
  >
    <div class="table">
      <el-form :model="ruleForm" ref="ruleForm" :rules="rules" label-width="120px" class="demo-ruleForm" >
        <el-row :gutter="28">
          <el-col :span="9" v-if="branchType===0">
            <el-form-item label="购买方入账凭证号" prop="voucherCode">
              <el-input v-model="ruleForm.voucherCode"   style="width: 200px">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="9" :push="2" v-if="branchType===1">
            <el-form-item label="销售方入账凭证号" prop="ynVoucherCode">
              <el-input v-model="ruleForm.ynVoucherCode"   style="width: 200px">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div style="display:flex;justify-content: center">
          <el-button type="primary" @click="submitForm('ruleForm')" >保存</el-button>
        </div>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
import {invoiceCodeSave, invoiceSave, invoiceSaveE} from '@/api/utils'
const rules={
  ynVoucherCode: [
    { required: true, message: '请输入销售方入账凭证号', trigger: 'blur' },
  ],
  voucherCode: [
    { required: true, message: '请输入购买方入账凭证号', trigger: 'blur' }
  ],
}
export default {
  data() {
    return {
      title: "凭证生成",
      deptList:[],
      dialogVisible: false,
      loading: false,
      pageNo:1,
      list:[],
      rules,
      pageSize:10,
      total:0,
      ruleForm: {
        ynVoucherCode: '',
        voucherCode:'',
        ids: [],
      },
      branchType:'',
    };
  },
  created() {
  },
  methods: {
    handle(list,branchType){
      this.dialogVisible=true
      this.ruleForm={
          ynVoucherCode: '',
          voucherCode:'',
          ids: [],
      }
      this.branchType=branchType
      this.ruleForm.ids=list
      this.$refs['ruleForm'].resetFields();
    },
     submitForm(formName){
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let res = await  invoiceCodeSave(this.ruleForm)
          if (res.code==200){
            this.$message.success('提交成功')
            this.dialogVisible=false
            this.$emit('handelData')
          }else {
            this.$message.error('提交失败')
          }
        } else {
          return false;
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.demo-ruleForm{
  position: relative;
}
.el-form-item__content {
  margin-left: 0px;
}
</style>
