<template>
  <div>
    <el-form ref="form" :model="form" label-width="130px">
      <headerTitle title="基本信息"></headerTitle>
      <el-row :gutter="12">
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item
              label="发票类型"
              prop="type"
              style="margin-bottom: 22px">
              <el-select v-model="form.type" disabled style="width: 100%">
                <el-option label="开票" :value="1"></el-option>
                <el-option label="收票" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="金额"
              prop="amount"
              style="margin-bottom: 22px">
              <el-input-number disabled v-model="form.amount" :precision="2" :controls="false" style="width: 100%"
                               :min="0"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="12">
          <el-form-item
            label="申请部门"
            prop="applyDeptId"
            style="margin-bottom: 22px">
            <el-input v-model="form.applyDeptName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="申请人"
            prop="applyUserId"
            style="margin-bottom: 22px"
          >
            <el-input v-model="form.applyUserName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item
            label="预计开票日期"
            style="margin-bottom: 22px">
            <el-date-picker
              style="width: 100%"
              v-model="form.expectInvoiceDate"
              type="date"
              disabled
              value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="taskDefinitionKey=='financeApprove'">
          <el-form-item
            label="会计科目"
            prop="accountingSubjectId"
            style="margin-bottom: 22px">
            <el-input v-model="form.accountingSubjectName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="12">
        <el-col :span="12" v-if="taskDefinitionKey=='financeApprove'">
          <el-form-item prop="files" label="发票附件">
            <div v-if="form.files && form.files?.length">
              <el-link
                v-for="link in form.files"
                :key="link.id"
                type="primary"
                :underline="false"
                @click="downloadFile(link)"
              >
                {{ link.name }}
              </el-link
              >
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <headerTitle title="开票信息"></headerTitle>
      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item
            label="公司名称"
            prop="companyName"
            style="margin-bottom: 22px">
            <el-input disabled v-model="form.companyName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="统一社会信用代码"
            prop="companyUsc"
            style="margin-bottom: 22px">
            <el-input disabled v-model="form.companyUsc"></el-input>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item
            label="开户银行"
            prop="companyBankBranchNo"
            style="margin-bottom: 22px">
            <el-input disabled v-model="form.companyBankBranchNo"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="银行账户"
            prop="companyBankAccount"
            style="margin-bottom: 22px">
            <el-input disabled v-model="form.companyBankAccount"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item
            label="电话号码"
            prop="companyTel"
            style="margin-bottom: 22px">
            <el-input disabled v-model="form.companyTel"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="单位地址"
            prop="companyAddress"
            style="margin-bottom: 22px">
            <el-input disabled v-model="form.companyAddress"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <headerTitle title="收票信息"></headerTitle>


      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item
            label="收票人"
            prop="receiverName"
            style="margin-bottom: 22px"
          >
            <el-input disabled v-model="form.receiverName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="收票人地址"
            prop="receiverAddress"
            style="margin-bottom: 22px"
          >
            <el-input disabled v-model="form.receiverAddress"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item
            label="联系方式"
            prop="receiverTel"
            style="margin-bottom: 22px"
          >
            <el-input disabled v-model="form.receiverTel"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <headerTitle title="关联信息"></headerTitle>
    <table-info v-if="dialogType!='add'&&form.detailList.length" dialogType="view" :form="form"
                ref="table"></table-info>
  </div>
</template>

<script>
import {getFile} from '@/api/system/file';
import dictMixins from '@/mixins/dictMixins';
import fileUpload from "@/components/upload/fileUpload.vue";

import personSelect from "@/components/CommomSelect/person-select.vue";
import tableInfo from "./tableInfo.vue";
import {invoiceApplyInfoAPI} from "@/api/bpm/components/financialManage/invoiceManage";


export default {
  mixins: [dictMixins],
  components: {
    tableInfo,
    personSelect,
    fileUpload
  },
  data() {
    return {
      dialogType: '',
      form: {
        files: []
      },
    };
  },
  props:{
    businessId: {
      default: ''
    },
    taskDefinitionKey: {
      default: ''
    },
  },
  async created() {
    await this.getInfo(this.businessId)
  },
  methods: {
    //获取详情
    async getInfo(id) {
      this.form = await invoiceApplyInfoAPI(id)
    },
    downloadFile(file) {
      getFile({objectName: file.storePath}, file.name);
    },
    cancel() {
      this.$emit('update:detailDialogFlag', false)
    }
  }
};
</script>

<style scoped lang="scss">
.ele-dialog-form {
  .el-form-item {
    margin-bottom: 10px;
  }
}

.headbox {
  display: flex;
  justify-content: flex-start;
  align-items: center;

  .amount {
    font-size: 14px;
    font-weight: bold;
    margin-right: 20px;
  }
}
</style>
