<template>
  <a-modal
    :title="modalTitle"
    :width="850"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <detail-list title="" :col="2">
      <detail-list-item term="编码">{{ model.no }}</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.sbType }}</detail-list-item>
      <detail-list-item term="部件编号">{{ model.partNo }}</detail-list-item>
      <detail-list-item term="部件名称">{{ model.partName }}</detail-list-item>
      <detail-list-item term="项目名称">{{ model.name }}</detail-list-item>
      <detail-list-item term="创建人">{{ model.createdUserName }}</detail-list-item>
      <detail-list-item term="更新人">{{ model.updateUserName }}</detail-list-item>
      <detail-list-item term="创建时间">{{ model.createdTime }}</detail-list-item>
      <detail-list-item term="更新时间">{{ model.updateTime }}</detail-list-item>
    </detail-list>
    <a-tabs type="card" default-active-key="1">
      <a-tab-pane key="1" tab="检查标准">
        <a-table
          bordered
          :data-source="data"
          :columns="columns"
          tableLayout="auto"
          rowKey="id">
          <span slot="action" slot-scope="record1">
            <template>
              <a @click="handleView(record1)">查看</a>
            </template>
          </span>
        </a-table>
      </a-tab-pane>
    </a-tabs>
    <detail ref="detailModal"/>

    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
    </template>
  </a-modal>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import Detail from '../../checkstandard/modules/Detail'
import { getCheckStandardPage, fetchCheckStandard } from '@/api/check/checkstandard'

const DetailListItem = DetailList.Item

export default {
  name: 'CheckProjectDetail',
  components: {
    Detail,
    DetailList,
    DetailListItem
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      periodTypeMap: {},
      actionTypeMap: {},
      visible: false,
      // 下拉框map
      model: {
        'no': null,
        'sbId': null,
        'partId': null,
        'standardId': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateUserName': null,
        'updateTime': null
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return index + 1
          }
        },
        {
          title: '名称',
          dataIndex: 'name'
        },
        {
          title: '周期',
          dataIndex: 'periodType',
          customRender: (text, record, index) => {
            return record.period + this.BaseTool.Table.getMapText(this.periodTypeMap, text)
          }
        },
        {
          title: '检查类型',
          dataIndex: 'actionType',
          customRender: (text, record, index) => {
            return this.BaseTool.Table.getMapText(this.actionTypeMap, text)
          }
        },
        // {
        // title: '要求',
        // dataIndex: 'requirement'
        // },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      data: []
    }
  },
  created () {
    // 下拉框map
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.actionTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_ACTION_TYPE)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.standardList
    },
    handleView (record) {
      fetchCheckStandard({ id: record.id }).then(res => {
        const modal = this.$refs.detailModal
        modal.base(res.data)
      })
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    }

  }
}
</script>
