<!--
 * @Author: liuzl 461480418@qq.com
 * @Date: 2023-01-09 15:34:20
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-01-10 10:03:40
 * @Description: file content
 * @FilePath: \订单全流程管理系统\src\views\contract\components\Invoicing.vue
-->
<template>
  <el-dialog :title="title" :visible.sync="editVisible" width="500px" @close="handleClose">
    <el-form ref="editForm" :model="editForm" :rules="editRules">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="发票号码" prop="invoiceCode">
            <el-input v-model="editForm.invoiceCode" placeholder="请输入发票号码" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="实际开票日期" prop="actualInvoiceDate">
            <el-date-picker
              v-model="editForm.actualInvoiceDate"
              placeholder="选择实际开票日期"
              style="width: 100%"
              type="date"
              value-format="yyyy-MM-dd" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="物流单号" prop="courierCode">
            <el-input v-model="editForm.courierCode" clearable placeholder="请输入物流单号" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer">
      <el-button type="primary" @click="invoiceSave">保存</el-button>
      <el-button @click="editVisible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import to from 'await-to-js'
  import invoiceApi from '@/api/contract/invoice'
  export default {
    props: {
      details: {
        type: Object,
        default: () => {},
      },
    },
    data() {
      return {
        title: '新建发票',
        editVisible: false,
        editForm: {
          id: 0,
          approStatus: '20',
          actualInvoiceDate: '', //实际开票日期
          invoiceCode: '', //发票号码
          courierCode: '', //快递单号
        },
        editRules: {
          invoiceCode: [{ required: true, trigger: 'blur', message: '请输入发票号码' }],
          actualInvoiceDate: [{ required: true, trigger: 'change', message: '请选择实际开票日期' }],
          courierCode: [{ required: true, trigger: 'blur', message: '请输入快递单号' }],
        },
      }
    },
    mounted() {},
    methods: {
      async init(id) {
        this.title = '发票审核'
        this.editForm.id = id
        this.editVisible = true
      },
      // 审核通过
      async invoiceSave() {
        let params = { ...this.editForm }
        const [valid] = await to(this.$refs.editForm.validate())
        if (valid == false) return
        const [err, res] = await to(invoiceApi.updateInvoice(params))
        if (err) return
        if (res.code == 200) this.$message.success(res.msg)
        else return
        this.editVisible = false
        this.$emit('invoiceSave')
      },
      handleClose() {
        this.editForm = {
          id: 0,
          approStatus: '20',
          actualInvoiceDate: '', //实际开票日期
          invoiceCode: '', //发票号码
          courierCode: '', //快递单号
        }
        this.$refs.editForm.resetFields()
      },
    },
  }
</script>

<style lang="scss" scoped>
  .mb10 {
    margin-bottom: 10px;
  }
  .proj-col {
    text-align: right;
  }
</style>
