<template>
  <a-card :bordered="false" v-show="visible" class="card" title="审核">
    <a-row :gutter="48" slot="extra">
      <a-col :md="48" :sm="48">
        <span class="table-page-search-submitButtons" style="float: right">
          <a-button type="primary" @click="save()" :disabled="disabled">提交</a-button>
          <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="3">
      <detail-list-item term="名称">{{ model.name }}</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="明细控制总价">{{ BaseTool.Amount.formatter(model.planListControlMoney) + BaseTool.Number.divForDollar(model.planListControlMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="资金预算">{{ BaseTool.Amount.formatter(model.planMoney) + BaseTool.Number.divForDollar(model.planMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="增补金额">{{ BaseTool.Amount.formatter(model.addMoney) + BaseTool.Number.divForDollar(model.addMoney, model.dollarExchangeRate, 2) }}</detail-list-item>
      <detail-list-item term="增补数量">{{ BaseTool.Amount.formatter(model.addQuantity) }}</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-demand-plan-add-list ref="planList" :viewFlag="true" @ok="loadOk"></purchase-demand-plan-add-list>
    <title-divider title="审核信息" width="90px"></title-divider>
    <a-row class="form-row" :gutter="16">
      <a-col :lg="12" :md="12" :sm="24">

        <a-radio-group v-model="auditFlag">
          <a-radio :value="1">同意</a-radio>
          <a-radio :value="0">不同意</a-radio>
        </a-radio-group>
      </a-col>
    </a-row>
    <a-row class="form-row" :gutter="16">
      <a-col :lg="12" :md="12" :sm="24">
        <a-form-item
          label="审核描述"
        >
          <a-textarea
            v-model="refuseReason"/>
        </a-form-item>
      </a-col>
    </a-row>

  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import { audit, fetchPurchaseDemandPlanAdd } from '@/api/purchase/purchase-demand-plan-add'
import PurchaseDemandPlanAddList from '../PurchaseDemandPlanAddList'
const DetailListItem = DetailList.Item

export default {
  name: 'PurchaseDemandPlanAddAudit',
  components: {
    DetailList,
    DetailListItem,
    PurchaseDemandPlanAddList
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      auditFlag: 1,
      refuseReason: '同意',
      visible: false,
      disabled: false,
      taskId: '',
      // 下拉框map
      typeMap: {},
      moneyTypeMap: {},
      reportTypeMap: {},
      periodTypeMap: {},
      model: {
        'name': null,
        'companyId': null,
        'companyName': null,
        'projectId': null,
        'projectName': null,
        'type': null,
        'addMoney': null,
        'projectMoneyType': null,
        'addQuantity': null,
        'planMoney': null,
        'dollarExchangeRate': null,
        'planListControlMoney': null,
        'usedMoney': null,
        'progress': null,
        'quantity': null,
        'boughtQuantity': null,
        'arrivedQuantity': null,
        'notArriveQuantity': null,
        'status': null,
        'remark': null,
        'delFlag': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateUserName': null,
        'updateTime': null
      }
    }
  },
  created () {
    // 下拉框map
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_TYPE)
    this.moneyTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.MONEY_TYPE)
  },
  props: {

  },
  methods: {
    base (record) {
      this.disabled = true
      this.taskId = record.taskId
      const modal = this.$refs.planList
      modal.base(null, record.targetId)
      this.model = {}
      fetchPurchaseDemandPlanAdd({ id: record.targetId }).then(res => {
        this.model = res.data
        this.visible = true
        let dollarExchangeRate = 1
        if (this.model.projectMoneyType === this.DictCache.VALUE.MONEY_TYPE.RMB) {
          dollarExchangeRate = this.$store.getters.rmbRate
        }
        this.model.dollarExchangeRate = dollarExchangeRate
      })
    },
    loadOk () {
      this.disabled = false
    },
    save () {
      audit({ id: this.model.id, refuseReason: this.refuseReason, auditFlag: this.auditFlag, taskId: this.taskId })
        .then(() => {
          this.$message.info('操作成功')
          this.handleCancel()
        }).catch(() => {
          this.confirmLoading = false
        })
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.$emit('ok', {})
    }

  }
}
</script>
<style scoped>
  .image {
    width: calc(20% - 10px);
    cursor: pointer;
    margin: 5px;
    display: inline-block;
  }
</style>
