<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="status" slot-scope="text">
        <badge
          :text="BaseTool.Object.getField(statusMap,text)"
          :status="DictCache.COLOR.SPARE_PART_USED_STATUS[text]" />
      </span>

      <span slot="usedSource" slot-scope="text">
        <badge
          :text="BaseTool.Object.getField(usedSourceMap,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>
  </a-modal>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item

export default {
  name: 'DetailSparePartUsedReport',
  components: {
    DetailList,
    DetailListItem
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      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: 'spareName',
          checked: true,
          width: '150px'
        },
        {
          title: '设备名称',
          dataIndex: 'sbName',
          checked: true,
          width: '200px'
        },
        {
          title: '设备部位',
          dataIndex: 'partName',
          checked: true,
          width: '150px'
        },
        {
          title: '投用日期',
          dataIndex: 'startDate',
          checked: true,
          width: '150px'
        },
        {
          title: '预计报废日期',
          dataIndex: 'changeDate',
          checked: true,
          width: '150px'
        },
        {
          title: '更换数量',
          dataIndex: 'num',
          checked: true,
          width: '120px'
        },
        {
          title: '备件价值(元)',
          dataIndex: 'price',
          checked: true,
          width: '150px'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          checked: true,
          width: '150px'
        },
        {
          title: '当前状态',
          dataIndex: 'status',
          width: '100px',
          checked: true,
          fixed: 'right',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '更换场景',
          dataIndex: 'usedSource',
          checked: true,
          width: '200px',
          fixed: 'right',
          scopedSlots: { customRender: 'usedSource' }
        }
      ],
      // 下拉框map
      usedSourceMap: {},
      statusMap: {},
      data: []
    }
  },
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_USED_STATUS)
    this.usedSourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_USED_SOURCE)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.detailList
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    }
  }
}
</script>
