<template>
  <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">
    <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" type="default" @click="handleCancel()">返回</a-button>
        </span>
      </a-col>
    </a-row>
    <detail-list title="" :col="2">
      <detail-list-item term="类型">{{ model.auditName }}</detail-list-item>
      <detail-list-item term="状态">{{ BaseTool.Object.getField(this.statusMap,model.status) }}</detail-list-item>
      <detail-list-item term="申请人">{{ model.createdUserName }}</detail-list-item>
      <detail-list-item term="申请日期">{{ model.createdTime }}</detail-list-item>
    </detail-list>
    <detail-list title="申请详情" :col="2" v-for="(item, index) in recordData" :key="index">
      <detail-list-item :term="item.label">{{ item.no }}</detail-list-item>
      <detail-list-item term="设备Id"><a @click="sbIdhandleDetail">{{ model.sbId }}</a></detail-list-item>
      <detail-list-item term="设备编号">{{ model.sbNo }}</detail-list-item>
      <detail-list-item term="设备名称">{{ model.sbName }}</detail-list-item>
      <detail-list-item term="报废原因">{{ model.reason }}</detail-list-item>
      <detail-list-item term="备注">{{ model.remark }}</detail-list-item>
      <detail-list-item term="状态">{{ BaseTool.Object.getField(this.statusMap,model.status) }}</detail-list-item>
      <detail-list-item term="申请人">{{ model.applyUserId }}</detail-list-item>
      <detail-list-item term="创建日期">{{ model.createdTime }}</detail-list-item>
      <detail-list-item term="更新日期">{{ model.updateTime }}</detail-list-item>
    </detail-list>
    <detail-list v-show='sbInfoAllocate' title="申请详情附件" :col="2">
      <detail-list-item term="单号">{{ model.no }}</detail-list-item>
      <detail-list-item term="设备Id"><a @click="sbIdhandleDetail">{{ model.sbId }}</a></detail-list-item>
      <detail-list-item term="设备编号">{{ model.sbNo }}</detail-list-item>
      <detail-list-item term="设备名称">{{ model.sbName }}</detail-list-item>
      <detail-list-item term="报废原因">{{ model.reason }}</detail-list-item>
      <detail-list-item term="备注">{{ model.remark }}</detail-list-item>
      <detail-list-item term="状态">{{ BaseTool.Object.getField(this.statusMap,model.status) }}</detail-list-item>
      <detail-list-item term="申请人">{{ model.applyUserId }}</detail-list-item>
      <detail-list-item term="创建日期">{{ model.createdTime }}</detail-list-item>
      <detail-list-item term="更新日期">{{ model.updateTime }}</detail-list-item>
    </detail-list>
    <history ref="history" :audit="audit" @ok="handleCancel"></history>
  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import History from '@/views/activiti/History'
const DetailListItem = DetailList.Item

export default {
  name: 'SbScrapFormDetail',
  components: {
    DetailList,
    DetailListItem,
    History
  },
  props: {
    audit: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      sbInfoAllocate: false,
      visible: false,
      // 下拉框map
      statusMap: {},
      task: {},
      model: {
        'auditName': null,
        'remark': null,
        'status': null,
        'createdUserName': null,
        'createdTime': null
      },
      recordData: {}
    }
  },
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.ACTIVITI_FORM_STATUS)
  },
  methods: {
    base (record, model) {
      console.log(record)
      console.log(model)
      this.visible = true
      this.modalTitle = '详情'
      this.task = record
      this.model = record
      this.model.auditName = this.DictCache.VALUE.SB_INFO_AUDIT_MODEL_NAME[record.remark]
      this.recordData = model
      model.id = record.targetId // 将targetId赋给model,带入history，用作提交
      const modal = this.$refs.history
      model.auditModelKey = record.remark
      modal.base(model, this.task.taskId)
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.$emit('ok')
    },
    sbIdhandleDetail () {
      const text = this.$router.resolve({
        name: 'SbInfo',
        query: { id: this.model.sbId }
      })
      // 打开一个新的页面
      window.open(text.href, '_blank')
    }
  }
}
</script>
