<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 ref="detailModal"/>
  </a-modal>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import { fetchRepairApplicationForm } from '@/api/repair/application-form'
import Detail from '@/views/repair/application-form/modules/Detail'
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: '设备编号',
          checked: true,
          width: '100px',
          dataIndex: 'sbNo'
        },
        {
          title: '设备名称',
          checked: true,
          width: '150px',
          dataIndex: 'sbId',
          customRender: (text, record, index) => {
            return record.sbName
          }
        },
        {
          title: '报修人',
          checked: true,
          width: '120px',
          dataIndex: 'actualUser'
        },
        {
          title: '维修人',
          checked: true,
          width: '120px',
          dataIndex: 'repairUserName'
        },
        /*  {
            title: '报修来源',
            checked: true,
            width: '100px',
            dataIndex: 'source',
            customRender: (text, record, index) => {
              return this.BaseTool.Object.getField(this.sourceMap, text)
            }
          }, */
        {
          title: '工单类型',
          checked: true,
          width: '150px',
          dataIndex: 'category',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.planFlagMap, text)
          }
        },
        {
          title: '报修时间',
          checked: true,
          width: '200px',
          dataIndex: 'applyTime'
        },
        /* {
          title: '紧急等级',
          checked: true,
          width: '200px',
          dataIndex: 'level',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.levelMap, text)
          }
        },
        {
          title: '计划性维修',
          checked: true,
          dataIndex: 'needStop',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.needStopMap, text)
          }
        }, */
        {
          title: '创建日期',
          width: '200px',
          dataIndex: 'createdTime'
        },
        {
          title: '接收超时',
          checked: true,
          width: '100px',
          dataIndex: 'receiveOvertime',
          customRender: (text, record, index) => {
            if (text) {
              return '是'
            } else {
              return '否'
            }
          }
        },
        {
          title: '维修超时',
          checked: true,
          width: '100px',
          dataIndex: 'repairOvertime',
          customRender: (text, record, index) => {
            if (text) {
              return '是'
            } else {
              return '否'
            }
          }
        },
        {
          title: '报修状态',
          checked: true,
          width: '100px',
          dataIndex: 'status',
          fixed: 'right',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '操作',
          checked: true,
          fixed: 'right',
          key: 'action',
          width: '100px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 下拉框map
      sourceMap: {},
      levelMap: {},
      needStopMap: {},
      planFlagMap: {},
      data: []
    }
  },
  created () {
    // 下拉框map
    this.sourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_SOURCE)
    this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_LEVEL)
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_STATUS)
    this.needStopMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
    this.planFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_CATEGORY)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.detailList
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    },
    handleView (record) {
      fetchRepairApplicationForm({ id: record.id }).then(res => {
        const modal = this.$refs.detailModal
        modal.base(res.data)
      })
    }
  }
}
</script>
