<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.billNo }}</detail-list-item>
      <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="需求计划名称">{{ model.demandPlanName }}</detail-list-item>
      <detail-list-item term="呈报">{{ BaseTool.Object.getField(reportTypeMap,model.reportType) }}</detail-list-item>
      <detail-list-item term="需求日期">{{ model.demandDate }}</detail-list-item>
      <!--      <detail-list-item term="事项">{{ model.item }}</detail-list-item>-->
      <!--      <detail-list-item term="设备物资综述">{{ model.summary }}</detail-list-item>-->
      <!--      <detail-list-item term="特殊情况">{{ model.specialDescription }}</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.quantity) }}</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-plan-list ref="planList" :viewFlag="true" @loadOk="loadOk"></purchase-plan-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, fetchPurchasePlan } from '@/api/purchase/purchase-plan'
import PurchasePlanList from '../PurchasePlanListView'
const DetailListItem = DetailList.Item

export default {
  name: 'PurchasePlanAudit',
  components: {
    DetailList,
    DetailListItem,
    PurchasePlanList
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      auditFlag: 1,
      disabled: true,
      refuseReason: '同意',
      visible: false,
      taskId: '',
      // 下拉框map
      typeMap: {},
      reportTypeMap: {},
      periodTypeMap: {},
      moneyTypeMap: {},
      model: {
        'billNo': null,
        'demandPlanId': null,
        'demandPlanName': null,
        'companyId': null,
        'companyName': null,
        'projectId': null,
        'projectName': null,
        'projectMoneyType': null,
        'dollarExchangeRate': null,
        'type': null,
        'planDate': null,
        'reportType': null,
        'demandDate': null,
        'item': null,
        'year': null,
        'periodValue': null,
        'periodType': null,
        'summary': null,
        'specialDescription': null,
        'money': null,
        'planMoney': null,
        'usedMoney': null,
        'progress': null,
        'quantity': null,
        'boughtQuantity': null,
        'arrivedQuantity': null,
        'notArriveQuantity': null,
        'totalWeight': null,
        'totalVolume': null,
        'refuseReason': null,
        'applyTime': null,
        'auditTime': 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.reportTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPORT_RANK)
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_PERIOD_TYPE)
    this.moneyTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.MONEY_TYPE)
    // this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_PLAN_STATUS)
  },
  props: {

  },
  methods: {
    base (record) {
      this.disabled = true
      this.taskId = record.taskId
      const modal = this.$refs.planList
      modal.base(record.targetId)
      this.model = {}
      fetchPurchasePlan({ 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>
