<template>
  <a-card v-show="visible" :bordered="false" class="card" :title="modalTitle">
    <div>
      <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.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.createdTime }}</detail-list-item>
        <detail-list-item term="更新日期">{{ model.updateTime }}</detail-list-item>
      </detail-list>
    </div>
    <history ref="history" :audit="false" :ok="handleCancel"></history>
  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import History from '@/views/activiti/History'
import { fetchSbScrapForm } from '@/api/sb/scraps'
const DetailListItem = DetailList.Item

export default {
  name: 'SbScrapFormDetail',
  components: {
    DetailList,
    DetailListItem,
    History
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      statusMap: {},
      model: {
        'id': null,
        'no': null,
        'sbId': null,
        'sbNo': null,
        'sbName': null,
        'reason': null,
        'remark': null,
        'status': null,
        'processInstanceId': null,
        'applyUserId': null,
        'applyUserName': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateUserName': null,
        'updateTime': null
      }
    }
  },
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.ACTIVITI_FORM_STATUS)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      fetchSbScrapForm({ id: record.id }).then(res => {
        this.model = res.data
        const modal = this.$refs.history
        modal.base(res.data, null)
      })
    },
    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>
