<template>
  <div class="invoice-detail">
    <el-dialog title="发票详情" :visible.sync="showInvoiceDetailDialog" @close="onClose">
      <div>
        <div>
          <span class="bold">流水号：</span>
          <span>{{ invoiceDetailInfo.applyNo }}</span>
        </div>
      </div>
      <div style="margin-top: 20px">
        <div class="bold title">发票信息</div>
        <div class="item">
          <div class="sub-item">
            <span class="bold">发票抬头：</span>
            <span>{{ invoiceDetailInfo.title }}</span>
          </div>
          <div class="sub-item">
            <span class="bold">发票类型：</span>
            <span>{{ invoiceDetailInfo.fapiaoType === 0 ? '普通发票' : '专用发票' }}</span>
          </div>
        </div>
        <div class="item">
          <div class="sub-item">
            <span class="bold">发票抬头类型：</span>
            <span>{{ invoiceDetailInfo.titleType === 0 ? '个人' : '企业' }}</span>
          </div>
          <div class="sub-item">
            <span class="bold">发票金额：</span>
            <span>￥ {{ invoiceDetailInfo.amount }}</span>
          </div>
        </div>
        <div class="item">
          <div class="sub-item" v-if="invoiceDetailInfo.taxNo">
            <span class="bold">企业税号：</span>
            <span>{{ invoiceDetailInfo.taxNo }}</span>
          </div>
          <div class="sub-item" v-if="invoiceDetailInfo.bankName">
            <span class="bold">开户银行：</span>
            <span>{{ invoiceDetailInfo.bankName }}</span>
          </div>
        </div>
        <div class="item">
          <div class="sub-item" v-if="invoiceDetailInfo.bankAccount">
            <span class="bold">银行账号：</span>
            <span>{{ invoiceDetailInfo.bankAccount }}</span>
          </div>
          <div class="sub-item" v-if="invoiceDetailInfo.address">
            <span class="bold">企业地址：</span>
            <span>{{ invoiceDetailInfo.address }}</span>
          </div>
        </div>
        <div class="item">
          <div class="sub-item" v-if="invoiceDetailInfo.phone">
            <span class="bold">企业电话：</span>
            <span>{{ invoiceDetailInfo.phone }}</span>
          </div>
        </div>
      </div>
      <div style="margin-top: 20px">
        <div class="bold title">联系信息</div>
        <div class="item">
          <div class="sub-item">
            <span class="bold">联系邮箱：</span>
            <span>{{ invoiceDetailInfo.email }}</span>
          </div>
        </div>
      </div>
      <div style="margin-top: 20px">
        <div class="item">
          <div class="sub-item">
            <span class="bold">开票状态：</span>
            <span>{{ invoiceDetailInfo.fapiaoStatus === 0 ? '未开票' : '已开票' }}</span>
          </div>
        </div>
      </div>
      <div style="margin-top: 20px" v-if="type === 'edit'">
        <div class="bold">发票号码</div>
        <el-input placeholder="请输入发票号码" style="margin-top: 15px" v-model="invoiceDetailInfo.fapiaoNo" />
      </div>
      <div style="margin-top: 20px" v-else>
        <div class="item">
          <div class="sub-item">
            <span class="bold">发票号码：</span>
            <span>{{ invoiceDetailInfo.fapiaoNo }}</span>
            <div class="sub-item">
          </div>
          </div>
        </div>
      </div>
      <div style="margin-top: 20px" v-if="type === 'edit'">
        <div class="bold">发票备注</div>
        <el-input
          style="margin-top: 15px"
          placeholder="请输入发票备注"
          type="textarea"
          :autosize="{ minRows: 3 }"
          :show-word-limit="true"
          v-model="invoiceDetailInfo.remark"
        />
      </div>
      <div style="margin-top: 20px" v-else>
        <div class="item">
          <div class="sub-item">
            <span class="bold">发票备注：</span>
            <span>{{ invoiceDetailInfo.remark }}</span>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" v-if="type === 'edit'">
        <el-button @click="onClose">取 消</el-button>
        <el-button type="primary" @click="confirmInvoice">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { editInvoiceApi } from '@/api/finance';

export default {
  props: ['showInvoiceDetailDialog', 'invoiceDetailInfo', 'type', 'ids'],

  data() {
    return {
      fapiaoNo: '',
      remark: '',
    };
  },

  methods: {
    onClose() {
      this.$emit('closeInvoiceDetailDialog');
    },

    confirmInvoice() {
      let params = {
        fapiaoNo: this.invoiceDetailInfo.fapiaoNo,
        remark: this.invoiceDetailInfo.remark,
        applyNo: this.invoiceDetailInfo.applyNo,
        
      };

      if (!params.fapiaoNo) {
        this.$message({
          message: '发票号码不能为空',
          type: 'warning',
          showClose: true,
        });

        return;
      }

      editInvoiceApi(params).then(() => {
        this.$message({
          message: '开票成功',
          type: 'success',
          showClose: true,
        });
        this.onClose();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.invoice-detail {
  .bold {
    font-weight: bold;
  }

  .title {
    border-bottom: 1px solid #eeeeee;
    padding-bottom: 10px;
  }

  .item {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;

    .sub-item {
      flex: 1;
    }
  }
}
</style>
