<template>
  <ele-modal
    custom-class="ele-dialog-form long-dialog-form"
    :centered="true"
    :visible.sync="detailDialogFlag"
    :title="title"
    :close-on-click-modal="false"
    width="60%"
    :before-close="cancel"
  >
    <div class="switch_left">
      <ul>
        <li
          v-for="item in tabOptions"
          :key="item.key"
          :class="{ active: activeComp == item.key }"
          @click="activeComp = item.key"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
    <div v-if="activeComp === 'main'">
      <el-form ref="form" :model="form" class="el-form-box" label-width="120px">
        <headerTitle title="基本信息"></headerTitle>
        <el-row :gutter="12">
          <el-row :gutter="12">
            <el-col :span="12">
              <el-form-item
                label="发票类型"
                prop="type"
                >
                <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"
                >
                <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"
              >
              <el-input v-model="form.applyDeptName" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="申请人"
              prop="applyUserId"

            >
              <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="预计开票日期"
              >
              <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">
            <el-form-item
              label="会计科目"
              prop="accountingSubjectId"
              >
              <el-input v-model="form.accountingSubjectName" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="12">
          <el-col :span="12">
            <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">
              <el-input disabled v-model="form.companyName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="统一社会信用代码"
              class="form_item_label"
              prop="companyUsc">
              <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"
              >
              <el-input disabled v-model="form.companyBankBranchNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="银行账户"
              prop="companyBankAccount"
              >
              <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="companyAddress"
              >
              <el-input disabled v-model="form.companyAddress"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="电话号码"
              prop="companyTel"
              >
              <el-input disabled v-model="form.companyTel"></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"

            >
              <el-input disabled v-model="form.receiverName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="收票人地址"
              prop="receiverAddress"

            >
              <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"

            >
              <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>
    <bpmDetail v-if="activeComp === 'bpm' && form.processInstanceId" :id="form.processInstanceId"></bpmDetail>
    <div slot="footer" class="footer">
      <el-button @click="cancel">返回</el-button>
    </div>
  </ele-modal>
</template>

<script>
import {getFile} from '@/api/system/file';
import dictMixins from '@/mixins/dictMixins';
import bpmDetail from '@/views/bpm/processInstance/detail.vue';
import fileUpload from "@/components/upload/fileUpload.vue";
import {getFeeApplyInfoAPI} from "@/api/financialManage/fee-manage/fee-application";
import feeRelatedInfoTable from "@/views/financialManage/components/feeRelatedInfoTable.vue";
import personSelect from "@/components/CommomSelect/person-select.vue";
import tableInfo from "@/views/financialManage/invoiceManage/components/tableInfo.vue";
import {invoiceApplyInfoAPI} from "@/api/financialManage/invoiceManage";

export default {
  mixins: [dictMixins],
  props: ['detailDialogFlag'],
  components: {
    tableInfo, personSelect,
    feeRelatedInfoTable,
    fileUpload,
    bpmDetail
  },
  data() {
    return {
      activeComp: 'main',
      tabOptions: [
        {key: 'main', name: '申请详情'},
        {key: 'bpm', name: '流程详情'}
      ],
      title: '详情',
      dialogType: '',
      form: {
        files:[]
      },
    };
  },
  methods: {
    //初始化
    async init(row = {}, type) {
      this.title = '详情'
      this.dialogType = type
      await this.getInfo(row.id)
    },
    //获取详情
    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">


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

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