<template>
  <a-modal
    :title="modalTitle"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    class="ant-modal2"
    @cancel="handleCancel"
  >
    <detail-list title="" :col="2">
      <detail-list-item term="设备名称">{{ model.sbName }}</detail-list-item>
      <detail-list-item term="设备编号">{{ model.sbNo }}</detail-list-item>
      <detail-list-item term="仓库名称">{{ model.storeName }}</detail-list-item>
      <detail-list-item term="申请人">{{ model.userName }}</detail-list-item>
      <detail-list-item term="申请油量">{{ BaseTool.Amount.formatter(model.applyOil) }}升</detail-list-item>
      <detail-list-item term="审批人">{{ model.auditType===DictCache.VALUE.SB_OIL_AUDIT_TYPE.USER?model.auditUserName:'系统' }}</detail-list-item>
      <detail-list-item term="燃油类型">{{ model.spareName }}</detail-list-item>
      <detail-list-item v-show="false" term="工程项目">{{ model.projectQuantityName }}</detail-list-item>
      <detail-list-item term="用途">{{ model.reason }}</detail-list-item>
      <detail-list-item term="审批状态">{{ auditTypeMap[model.auditType] }}</detail-list-item>
      <detail-list-item term="仓库管理员">{{ model.storeUserName }}</detail-list-item>
      <detail-list-item term="实际加油量">{{ BaseTool.Amount.formatter(model.realOil) }}升</detail-list-item>
      <detail-list-item term="状态"><badge :status="DictCache.COLOR.SB_OIL_STATUS[model.status]" :text="statusMap[model.status]"></badge></detail-list-item>
    </detail-list>
    <detail-list :col="1">
      <detail-list-item term="申请说明">{{ model.applyRemark }}&nbsp;&nbsp;</detail-list-item>
      <detail-list-item term="审批说明">{{ model.remark }}&nbsp;&nbsp;</detail-list-item>
      <detail-list-item term="加油说明">{{ model.handleRemark }}&nbsp;&nbsp;</detail-list-item>
    </detail-list>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="save()">确认</a-button>
    </template>
  </a-modal>
</template>

<script>
import { updateConfirmSbOil } from '@/api/sb/oil'
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item

export default {
  name: 'BaseSbOil',
  components: {
    DetailList,
    DetailListItem
  },
  data () {
    return {
      confirmLoading: false,
      modalTitle: null,
      visible: false,
      model: {},
      // 下拉框map
      statusMap: {},
      auditTypeMap: {}
    }
  },
  props: {},
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_OIL_STATUS)
    this.auditTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_OIL_AUDIT_TYPE)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '确认'
      this.model = record
    },
    save () {
      updateConfirmSbOil({ id: this.model.id })
        .then(() => {
          this.handleCancel({ id: this.model.id })
        }).catch(() => {
          this.confirmLoading = false
        })
    },
    handleCancel (values) {
      this.visible = false
      this.confirmLoading = false
      if (this.BaseTool.Object.isNotBlank(values)) {
        this.$emit('ok', values)
      }
    }

  }
}
</script>
