<template>
  <a-modal
    :title="modalTitle"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <title-divider title="明细列表" width="90px"></title-divider>
    <a-table
      bordered
      :data-source="data"
      :columns="columns"
      :scroll="{x: 1000, y: BaseTool.Constant.scrollY}"
      tableLayout="auto"
      rowKey="id"
    >
      <span slot="action" slot-scope="record">
        <template>
          <a @click="handleView(record)">查看</a>
        </template>
      </span>
      <span slot="status" slot-scope="text">
        <badge
          :text="BaseTool.Object.getField(statusMap,text)"
          :status="DictCache.COLOR.REPAIR_APPLICATION_FORM_STATUS[text]" />
      </span>
    </a-table>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
    </template>
    <detail :check-type="2" ref="detailModal"/>
  </a-modal>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import Detail from '@/views/check/checkjob/modules/Detail'
import { fetchCheckJob } from '@/api/check/checkjob'

const DetailListItem = DetailList.Item

export default {
  name: 'DetailRepairReport',
  components: {
    DetailList,
    DetailListItem,
    Detail
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      typeMap: {},
      statusMap: {},
      model: {},
      // 查询参数
      queryParam: {
        filter: this.filter,
        searchType: this.searchType
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          checked: true,
          width: '70px',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '设备新号',
          dataIndex: 'sbNo',
          checked: true,
          width: '150px'
        },
        {
          title: '设备名称',
          dataIndex: 'sbName',
          checked: true,
          width: '200px'
        },
        {
          title: '设备部位',
          dataIndex: 'partName',
          checked: true,
          width: '150px'
        },
        {
          title: '维护等级',
          dataIndex: 'standardLevel',
          width: '100px',
          checked: true,
          customRender: (text, record, index) => {
            return this.BaseTool.Table.getMapText(this.standardLevelMap, text)
          }
        },
        {
          title: '任务要求',
          dataIndex: 'requirement',
          checked: true,
          width: '200px'
        },
        {
          title: '计划周期',
          dataIndex: 'period',
          checked: true,
          width: '150px',
          customRender: (text, record, index) => {
            return text + this.BaseTool.Table.getMapText(this.periodTypeMap, record.periodType)
          }
        },
        /*        {
          title: '计划名称',
          dataIndex: 'planName',
          checked: true
        }, */
        {
          title: '负责人',
          dataIndex: 'checkUserName',
          checked: true,
          width: '150px'
        },

        // {
        // title: '负责部件',
        // dataIndex: 'partName',
        // checked: true
        // },
        /*  {
          title: '截至日期',
          dataIndex: 'endTime',
          checked: true,
          width: '200px'
        }, */
        {
          title: '标准工时',
          dataIndex: 'standardHours',
          checked: true,
          width: '200px'
        },
        {
          title: '实际工时',
          dataIndex: 'realHours',
          checked: true,
          width: '200px'
        },
        {
          title: '实际结束时间',
          dataIndex: 'actualEndTime',
          checked: true,
          width: '200px'
        },
        {
          title: '执行日期',
          dataIndex: 'startTime',
          checked: true,
          width: '200px'
        },
        {
          title: '实际执行日期',
          dataIndex: 'actualStartTime',
          checked: true,
          width: '200px',
          customRender: (text, record, index) => {
            return (text == null ? '暂无' : this.BaseTool.Date.formatter(text, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN))
          }
        },
        {
          title: '任务状态',
          dataIndex: 'status',
          width: '100px',
          checked: true,
          fixed: 'right',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '操作',
          key: 'action',
          width: '100px',
          fixed: 'right',
          align: 'center',
          scopedSlots: { customRender: 'action' },
          checked: true
        }
      ],
      // 下拉框map
      levelMap: {},
      standardLevelMap: {},
      sbStatusMap: {},
      periodTypeMap: {},
      data: []
    }
  },
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_JOB_STATUS)
    this.sbStatusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_LEVEL)
    this.standardLevelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_LEVEL)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.detailList
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    },
    handleView (record) {
      fetchCheckJob({ id: record.id }).then(res => {
        const modal = this.$refs.detailModal
        modal.base(res.data)
      })
    }
  }
}
</script>
