<template>
  <!-- 发票登记详情-->
  <a-modal class="add-custom custom-detail" title="发票登记详情" v-model:visible="visible" centered :maskClosable="false" @cancel="cancel" width="890px">
    <template #footer>
      <a-button key="submit" type="primary" :loading="loading" @click="submit">关闭 </a-button>
    </template>
    <a-form class="inlineForm">
      <fieldset class="formFieldSet">
        <legend>合同基本信息</legend>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="合同编号">
              <span class="white">{{ getContractTypeName(selectedRow.contracttype) + '/' + formatValue(selectedRow.contractno) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="点价类型">
              <span class="white">{{ getPriceTypeName(selectedRow.pricetype) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="销售方" v-if="selectedRow.contracttype === 1">
              <span class="white">{{ formatValue(selectedRow.sellusername) }}</span>
            </a-form-item>
            <a-form-item label="采购方" v-else>
              <span class="white">{{ formatValue(selectedRow.buyusername) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="现货品种">
              <span class="white">{{ formatValue(selectedRow.deliverygoodsname) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
      </fieldset>
      <fieldset class="formFieldSet">
        <legend>待审核登记信息</legend>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="类型">
              <span class="white">{{ invoiceStatusName(selectedRow.contracttype) }}</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="发票金额">
              <span class="white">{{ formatValue(selectedRow.invoiceamount) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="发票附件">
              <span class="blue" v-if="selectedRow.attachurl" @click="previewImg(selectedRow.attachurl)">查看</span>
              <span class="white" v-else>--</span>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="登记时间">
              <span class="white">{{ formatValue(selectedRow.applytime) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="登记人">
              <span class="white">{{ formatValue(selectedRow.applyname) }}</span>
            </a-form-item>
          </a-col>
        </a-row>
      </fieldset>
    </a-form>
  </a-modal>
  <a-modal :visible="previewVisible" :footer="null" @cancel="cancelImg">
    <img alt="预览附件" style="width: 100%" :src="previewImage" />
  </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { getStatusName } from '@/common/constants/enumsName';
import { formatValue } from '@/common/methods';
import { QryBussinessFpRsp } from '@/services/go/ermcp/finance-review/interface';
import { invoiceStatusName } from '@/views/manage/finance-review/setup';
import { getContractTypeName, getPriceTypeName } from '@/common/constants/enumsName';
import { handlePreviewImg } from '@/common/setup/upload';
import { _closeModal } from '@/common/setup/modal/modal';

export default defineComponent({
  name: 'finance_review_invoice_detail',
  emits: ['cancel', 'update'],
  components: {},
  props: {
    selectedRow: {
      type: Object as PropType<QryBussinessFpRsp>,
      default: {},
    },
  },
  setup(props, context) {
    const { visible, cancel } = _closeModal(context);
    const loading = ref<boolean>(false);
    const maskClosableFlag = ref<boolean>(false);
    // 预览附件
    const { previewVisible, previewImage, cancelImg, previewImg } = handlePreviewImg();
    function submit() {
      cancel(true);
    }

    return {
      visible,
      cancel,
      submit,
      loading,
      formatValue,
      getStatusName,
      maskClosableFlag,
      invoiceStatusName,
      getPriceTypeName,
      getContractTypeName,
      previewVisible,
      previewImage,
      cancelImg,
      previewImg,
    };
  },
});
</script>

<style lang="less">
.finance_review_invoice_detail {
    .ant-form.inlineForm {
        margin-top: 20px;
    }
}
</style>;
