<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 v-show='sbInfoAllocate' title="设备调拨" :col="2">
      <detail-list-item term="单号">{{ model.no }}</detail-list-item>
      <detail-list-item term="标题">{{ model.title }}</detail-list-item>
      <detail-list-item term="申请部门">{{ model.currentDeptName }}</detail-list-item>
      <detail-list-item term="目标部门">{{ model.targetDeptName }}</detail-list-item>
      <detail-list-item term="开始时间">{{ model.startTime }}</detail-list-item>
      <detail-list-item term="结束时间">{{ model.endTime }}</detail-list-item>
      <detail-list-item term="备注">{{ model.dataRemark }}</detail-list-item>
    </detail-list>
    <detail-list v-show='sbInfoAllocate' title="设备调拨详情" :col="2" v-for="(item, index) in sbInfos" :key="index">
      <detail-list-item term="设备名称">{{ item.name }}</detail-list-item>
      <detail-list-item term="设备编号">{{ item.no }}</detail-list-item>
      <detail-list-item term="设备类型">{{ item.typeName }}</detail-list-item>
      <detail-list-item term="生成厂商">{{ item.producerName }}</detail-list-item>
    </detail-list>
    <detail-list v-show='sbInfoStop' title="设备停用" :col="2">
      <detail-list-item term="单号">{{ model.no }}</detail-list-item>
      <detail-list-item term="设备名称">{{ model.sbName }}</detail-list-item>
      <detail-list-item term="维修单">{{ model.repairId }}</detail-list-item>
      <detail-list-item term="停用日期">{{ model.stopDate }}</detail-list-item>
      <detail-list-item term="停用原因">{{ model.reason }}</detail-list-item>
      <detail-list-item term="备注">{{ model.dataRemark }}</detail-list-item>
    </detail-list>
    <detail-list v-show='sbInfoScrap' title="设备报废" :col="2">
      <detail-list-item term="单号">{{ model.no }}</detail-list-item>
      <detail-list-item term="设备名称">{{ model.sbName }}</detail-list-item>
      <detail-list-item term="设备编号">{{ model.sbNo }}</detail-list-item>
      <detail-list-item term="报废原因">{{ model.reason }}</detail-list-item>
      <detail-list-item term="备注">{{ model.dataRemark }}</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,
      sbInfoStop: false,
      sbInfoScrap: false,
      visible: false,
      // 下拉框map
      statusMap: {},
      task: {},
      model: {
        'auditName': null,
        'remark': null,
        'status': null,
        'createdUserName': null,
        'createdTime': null,
        'dataRemark': null,
        'startTime': null,
        'endTime': null,
        'currentDeptName': null,
        'targetDeptName': null,
        'title': null,
        'reason': null,
        'stopDate': null,
        'sbName': null,
        'repairId': null,
        'no': null,
        'sbNo': null
      },
      sbInfos: []
    }
  },
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.ACTIVITI_FORM_STATUS)
  },
  methods: {
    base (record, model) {
      this.visible = true
      this.modalTitle = '详情'
      this.task = record
      this.model = record
      this.model.no = model.no
      this.model.auditName = this.DictCache.VALUE.SB_INFO_AUDIT_MODEL_NAME[record.remark]
      if (record.remark === this.DictCache.VALUE.CUSTOM_TEMPLATE_SB_REMARK.SB_ALLOCATE_FORM) {
        this.sbInfoAllocate = true
        this.sbInfos = JSON.parse(model.sbInfos)
      } else if (record.remark === this.DictCache.VALUE.CUSTOM_TEMPLATE_SB_REMARK.SB_SCRAP_FORM) {
        this.sbInfoScrap = true
      } else if (record.remark === this.DictCache.VALUE.CUSTOM_TEMPLATE_SB_REMARK.SB_STOP_FORM) {
        this.sbInfoStop = true
      }
      if (record.targetId === undefined) {
        model.id = record.id // 将targetId赋给model,带入history，用作提交
      } else {
        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>
