<template>
  <a-card :bordered="false" :title="modalTitle" v-show="visible">
    <a-row :gutter="48" slot="extra">
      <a-col :md="48" :sm="48">
        <span class="table-page-search-submitButtons" style="float: right">
          <a-button style="margin-left: 8px" @click="handleCancel()">返回</a-button>
        </span>
      </a-col>
    </a-row>
    <title-divider title="基本信息" width="90px"></title-divider>
    <detail-list title="" :col="2">
      <detail-list-item term="单号">{{ model.billNo }}</detail-list-item>
      <detail-list-item term="公司名称">{{ model.companyName }}</detail-list-item>
      <detail-list-item term="项目名称">{{ model.projectName }}</detail-list-item>
      <detail-list-item term="项目记账主币">{{ BaseTool.Object.getField(moneyTypeMap,model.projectMoneyType) }}</detail-list-item>
      <detail-list-item term="类型">{{ BaseTool.Object.getField(typeMap,model.type) }}</detail-list-item>
      <detail-list-item term="需求日期">{{ model.demandDate }}</detail-list-item>
      <detail-list-item term="采购员名称">{{ model.purchaserName }}</detail-list-item>
      <detail-list-item term="预计总金额">{{ BaseTool.Amount.formatter(model.originMoney)+ BaseTool.Number.divForDollar(model.originMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="实际总金额(按记账主币)">{{ BaseTool.Amount.formatter(model.accountMoney) + BaseTool.Number.divForDollar(model.accountMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="实际总金额(按询价主币)">{{ BaseTool.Amount.formatter(model.money) }} {{ moneyTypeMap[model.moneyType] }}</detail-list-item>
      <detail-list-item term="总费用（含运费等）(按询价主币)">{{ BaseTool.Amount.formatter(model.totalMoney) }} {{ moneyTypeMap[model.moneyType] }}</detail-list-item>
      <detail-list-item term="总费用（含运费等）(按记账主币)">{{ BaseTool.Amount.formatter(model.accountTotalMoney)+ BaseTool.Number.divForDollar(model.accountTotalMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="数量">{{ BaseTool.Amount.formatter(model.quantity) }}</detail-list-item>
      <detail-list-item term="已付金额(按记账主币)">{{ BaseTool.Amount.formatter(model.accountPaidMoney)+ BaseTool.Number.divForDollar(model.accountPaidMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="已报销金额(按记账主币)">{{ BaseTool.Amount.formatter(model.accountReimbursedMoney)+ BaseTool.Number.divForDollar(model.accountReimbursedMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="已购数量">{{ BaseTool.Amount.formatter(model.boughtQuantity) }}</detail-list-item>
      <detail-list-item term="已到数量">{{ BaseTool.Amount.formatter(model.arrivedQuantity) }}</detail-list-item>
      <detail-list-item term="已发数量">{{ BaseTool.Amount.formatter(model.dispatchedQuantity) }}</detail-list-item>
      <detail-list-item term="临时存放位置">{{ BaseTool.Object.getField(tempStoreMap,model.tempStore) }}</detail-list-item>
      <detail-list-item term="总重">{{ BaseTool.Amount.formatter(model.totalWeight) }}</detail-list-item>
      <detail-list-item term="总体积">{{ BaseTool.Amount.formatter(model.totalVolume) }}</detail-list-item>
      <detail-list-item term="供货周期">{{ model.supplyPeriod }}天</detail-list-item>
      <detail-list-item term="货款支付方式">{{ BaseTool.Object.getField(payTypeMap,model.payType) }}</detail-list-item>
      <detail-list-item term="发票类别">{{ BaseTool.Object.getField(invoiceTypeMap,model.invoiceType) }}</detail-list-item>
      <detail-list-item term="入库仓库" v-if="!model.dispatchFlag">{{ model.warehouseName }}</detail-list-item>
      <detail-list-item term="入库原因" v-if="!model.dispatchFlag">{{ BaseTool.Object.getField(enterReasonMap,model.enterReason) }}</detail-list-item>
      <detail-list-item term="状态"><badge :status="DictCache.COLOR.PURCHASE_ORDER_STATUS[model.status]" :text="statusMap[model.status]"></badge></detail-list-item>
      <detail-list-item term="备注">{{ model.remark }}</detail-list-item>
      <detail-list-item term="更新人名称">{{ model.updateUserName }}</detail-list-item>
      <detail-list-item term="更新时间">{{ model.updateTime }}</detail-list-item>
    </detail-list>
    <title-divider title="申请明细" width="90px"></title-divider>
    <purchase-order-list ref="orderList" :viewFlag="true"/>
  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import PurchaseOrderList from '@/views/purchase/purchase-order/PurchaseOrderList'
const DetailListItem = DetailList.Item

export default {
  name: 'PurchaseOrderDetail',
  components: {
    DetailList,
    PurchaseOrderList,
    DetailListItem
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      typeMap: {},
      statusMap: {},
      moneyTypeMap: {},
      enterReasonMap: {},
      payTypeMap: {},
      invoiceTypeMap: {},
      tempStoreMap: {},
      model: {
        'billNo': null,
        'purchaseApplyId': null,
        'purchasePlanId': null,
        'demandPlanId': null,
        'dispatchFlag': null,
        'companyId': null,
        'companyName': null,
        'tempStore': null,
        'projectId': null,
        'projectName': null,
        'projectMoneyType': null,
        'dollarExchangeRate': null,
        'type': null,
        'demandDate': null,
        'purchaserId': null,
        'accountMoney': null,
        'moneyType': null,
        'accountTotalMoney': null,
        'totalMoney': null,
        'purchaserName': null,
        'originMoney': null,
        'money': null,
        'paidMoney': null,
        'reimbursedMoney': null,
        'accountPaidMoney': null,
        'accountReimbursedMoney': null,
        'quantity': null,
        'boughtQuantity': null,
        'arrivedQuantity': null,
        'dispatchedQuantity': null,
        'warehouseId': null,
        'warehouseName': null,
        'enterReason': null,
        'totalWeight': null,
        'totalVolume': null,
        'supplyPeriod': null,
        'payType': null,
        'invoiceType': null,
        'status': null,
        'remark': null,
        'delFlag': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateUserName': null,
        'updateTime': null
      }
    }
  },
  created () {
    // 下拉框map
    // 下拉框map
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_APPLY_TYPE)
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_ORDER_STATUS)
    this.payTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_PAY_TYPE)
    this.invoiceTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_INVOICE_TYPE)
    this.enterReasonMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.IN_STORE_FORM_TYPE)
    this.moneyTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.MONEY_TYPE)
    this.tempStoreMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_STORE_PLACE)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '采购单详情'
      this.model = record
      const modal = this.$refs.orderList
      modal.base(record)
      let dollarExchangeRate = 1
      if (record.projectMoneyType === this.DictCache.VALUE.MONEY_TYPE.RMB) {
        dollarExchangeRate = this.$store.getters.rmbRate
      }
      this.model.dollarExchangeRate = dollarExchangeRate
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.$emit('ok', {})
    }

  }
}
</script>
