<template>
  <a-modal
    :title="modalTitle"
    :width="850"
    :visible="visible"
    :confirmLoading="confirmLoading"
    class="ant-modal2"
    @cancel="handleCancel"
  >
    <detail-list title="" :col="2">
      <detail-list-item term="编码">{{ model.no }}</detail-list-item>
      <detail-list-item term="计划名称">{{ model.name }}</detail-list-item>
      <detail-list-item term="负责人方式">{{ BaseTool.Object.getField(checkUserTypeMap,model.checkUserType) }}</detail-list-item>
      <detail-list-item term="负责人">{{ model.checkUserName }}</detail-list-item>

      <detail-list-item term="检查类型">{{ BaseTool.Object.getField(typeMap,model.type) }}</detail-list-item>
      <detail-list-item term="有效时间">{{ model.validTime }}{{ BaseTool.Object.getField(validTimeTypeMap,model.validTimeType) }}</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.lastGeneratedTime }}</detail-list-item>
      <detail-list-item term="是否启用"><badge :status="DictCache.COLOR.YES_NO[model.enable]" :text="enableMap[model.enable]"></badge></detail-list-item>
      <detail-list-item term="创建人">{{ model.createdUserName }}</detail-list-item>
      <detail-list-item term="更新时间">{{ model.updateTime }}</detail-list-item>
    </detail-list>
    <detail-list title="" :col="1">
      <detail-list-item term="备注">{{ model.remark }}</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="record">
            <template>
              <a @click="handleViewProject(record)">查看</a>
            </template>
          </span>
        </a-table>
      </a-tab-pane>
    </a-tabs>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
    </template>
    <detail ref="detailModal"/>
  </a-modal>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item
import Detail from '../../checkproject/modules/Detail'
import { getCheckProjectPage, deleteCheckProjects, fetchCheckProject, exportCheckProject } from '@/api/check/checkproject'

export default {
  name: 'CheckPlanDetail',
  components: {
    DetailList,
    DetailListItem,
    Detail
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      typeMap: {},

      checkUserTypeMap: {},
      periodTypeMap: {},
      validTimeTypeMap: {},
      enableMap: {},
      model: {
        'no': null,
        'name': null,
        'checkUserId': null,
        'checkUserName': null,
        'period': null,
        'type': null,
        'periodType': null,
        'validTime': null,
        'validTimeType': null,
        'startTime': null,
        'endTime': null,
        'lastGeneratedTime': null,
        'enable': null,
        'remark': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateUserName': null,
        'updateTime': null
      },
      rowSelection: {
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = selectedRowKeys
          this.selectedRows = selectedRows
        }
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return index + 1
          }
        },
        {
          title: '项目名称',
          dataIndex: 'name'
        },
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      data: [],
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  created () {
    // 下拉框map
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_TYPE)
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.checkUserTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_USER_TYPE)
    this.validTimeTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.enableMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.projectList
    },
    handleViewProject (record) {
      fetchCheckProject({ id: record.id }).then(res => {
        const modal = this.$refs.detailModal
        modal.base(res.data)
      })
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    }

  }
}
</script>
