<template>
  <!-- <el-dialog
    title="查看"
    width="70%"
    :close-on-click-modal="false"
    :visible.sync="visible"> -->
  <div>
    <div class="my-title">查看</div>
    <div style="margin-left: 20px;margin-right: 20px">
      <e-desc title="基本信息" column="3">
        <e-desc-item label="采购发票编码">{{dataForm.code}}</e-desc-item>
        <e-desc-item label="发票类型">{{typeFormat(dataForm)}}</e-desc-item>
        <e-desc-item label="发票类别代码">{{dataForm.typeCode}}</e-desc-item>
        <e-desc-item label="发票号">{{dataForm.invoiceNumber}}</e-desc-item>
        <e-desc-item label="开票电话">{{dataForm.phone}}</e-desc-item>
        <e-desc-item label="发票金额">{{dataForm.invoiceAmount}}</e-desc-item>
        <e-desc-item label="币种">{{currencyFormat(dataForm)}}</e-desc-item>
        <e-desc-item label="供应商">{{dataForm.supplierName}}</e-desc-item>
        <e-desc-item label="收付款金额">{{dataForm.receivedPaidAmount}}</e-desc-item>
        <e-desc-item label="备注说明" span="3">{{dataForm.notes}}</e-desc-item>
      </e-desc>
      <e-desc title="附件">
        <upload-component :display="true" :display-title="false" :accept="'*'" :file-obj-list="fileList"/>
      </e-desc>
      <e-desc title="客户信息" column="3">
        <e-desc-item label="发票抬头">{{dataForm.invoiceTitle}}</e-desc-item>
        <e-desc-item label="企业税号">{{dataForm.taxNumber}}</e-desc-item>
        <e-desc-item label="开户银行">{{dataForm.bank}}</e-desc-item>
        <e-desc-item label="银行账号">{{dataForm.account}}</e-desc-item>
        <e-desc-item label="电话">{{dataForm.contactTel}}</e-desc-item>
        <e-desc-item label="传真">{{dataForm.fax}}</e-desc-item>
      </e-desc>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="onChose">返回</el-button>
    </span>
  </div>
  <!-- </el-dialog> -->
</template>

<script>
  // import { getSupplierNameList, getSupplierDetail } from '@/api/sale'
  import { getPurchaseInvoiceDetail } from '@/api/finance'
  import EDesc from '../common/e-desc'
  import EDescItem from '../common/e-desc-item'
  import uploadComponent from '../common/upload-component'
  export default {
    name: 'purchase-invoice-detail',
    components: {
      EDesc,
      EDescItem,
      uploadComponent
    },
    data () {
      return {
        isFlow: false,
        visible: false,
        id: 0,
        dataForm: {},
        cusRCommProductVOS: [],
        fileList: [],
        typeState: [ // 发票类型映射关系
          {
            code: '1',
            value: '增值税专用发票'
          },
          {
            code: '2',
            value: '增值税普通发票'
          },
          {
            code: '3',
            value: '形式发票'
          }
        ],
        currencyType: [ // 币种映射关系
          {
            code: '1',
            value: '人民币'
          }
        ]
      }
    },
    methods: {
      onChose () {
        this.$emit('onChose')
      },
      // 转换类别
      typeFormat (row) {
        for (let i = 0; i < this.typeState.length; i++) {
          if (this.typeState[i].code === String(row.type)) {
            return this.typeState[i].value
          }
        }
      },
      // 转换币种
      // 转换属性“级别”
      currencyFormat (row) {
        for (let i = 0; i < this.currencyType.length; i++) {
          if (this.currencyType[i].code === String(row.currency)) {
            return this.currencyType[i].value
          }
        }
      },
      async init (id) {
        this.visible = true
        this.id = id || 0
        // await getSupplierNameList().then(({data}) => {
        //   if (data && data.code === '200') {
        //     this.optionsCus = data.data
        //   }
        // })
        if (!id) return
        await getPurchaseInvoiceDetail(this.id).then(({data}) => {
          if (data && data.code === '200') {
            this.dataForm = data.data
            // 文件列表
            this.fileList = []
            if (data.data.attachList) {
              data.data.attachList.forEach((item) => {
                this.fileList.push({
                  name: item.fileName,
                  url: item.url,
                  id: item.url
                })
              })
            }
          }
        })
      }
    }
  }
</script>

<style scoped>
.my-line{
  border-bottom: 1px solid #c0c4cc;
  margin-bottom: 10px;
}
.title{
  padding: 10px 0 ;
}
</style>
