<template>
  <a-modal
    centered
    class="expenseManagementDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="详情"
    v-model="isShow"
    @cancle="isShow=false"
    :width="600">
    <!-- 详情 -->
    <div>
      <a-descriptions :column="1" size="default">
        <a-descriptions-item label="费用单号">{{ detailsData&&detailsData.accountExpensesSn || '--' }}</a-descriptions-item>
        <a-descriptions-item label="费用类型">
          <div v-if="detailsData&&(detailsData.expensesTypeName1 || detailsData.expensesTypeName2 || detailsData.expensesTypeName3)">
            {{ detailsData&&detailsData.expensesTypeName1 ? detailsData.expensesTypeName1 : '' }}
            <span v-if="(detailsData&&detailsData.expensesTypeName1) && (detailsData&&detailsData.expensesTypeName2)"> > </span>
            {{ detailsData&&detailsData.expensesTypeName2 ? detailsData.expensesTypeName2 : '' }}
            <span v-if="(detailsData&&detailsData.expensesTypeName2) && (detailsData&&detailsData.expensesTypeName3)"> > </span>
            {{ detailsData&&detailsData.expensesTypeName3 ? detailsData.expensesTypeName3 : '' }}
          </div>
          <span v-else>--</span>
        </a-descriptions-item>
        <a-descriptions-item label="费用金额">￥{{ detailsData&&detailsData.settleAmount || '--' }}</a-descriptions-item>
        <a-descriptions-item label="单据状态">{{ detailsData&&detailsData.stateDictValue || '--' }}</a-descriptions-item>
        <a-descriptions-item label="备注">{{ detailsData&&detailsData.remark || '--' }}</a-descriptions-item>
      </a-descriptions>
      <div class="btn-cont"><a-button id="expenseManagementDetail-modal-back" @click="isShow = false">返回列表</a-button></div>
    </div>
  </a-modal>
</template>

<script>
import { findExpenseDetail } from '@/api/settleExpense'
export default {
  name: 'ExpenseManagementDetailModal',
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemId: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      detailsData: null
    }
  },
  methods: {
    //  获取详情
    getDetail () {
      findExpenseDetail({ id: this.itemId }).then(res => {
        if (res.status == 200) {
          this.detailsData = res.data
        } else {
          this.detailsData = null
        }
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.detailsData = null
      }
    },
    itemId (newValue, oldValue) {
      if (this.isShow && newValue) {
        this.getDetail()
      }
    }
  }
}
</script>

<style lang="less">
  .expenseManagementDetail-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
