<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 { fetchRepairFee } from '@/api/repair/fee'
import Detail from '@/views/repair/fee/modules/Detail'
const DetailListItem = DetailList.Item

export default {
  name: 'DetailRepairReportFee',
  components: {
    DetailList,
    DetailListItem,
    Detail
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      typeMap: {},
      moneyTypeMap: {},
      model: {},
      // 查询参数
      queryParam: {
        filter: this.filter,
        searchType: this.searchType
      },
      // 表头
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          checked: true,
          width: '100px',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '设备编号',
          checked: true,
          width: '100px',
          dataIndex: 'sbNo'
        },
        {
          title: '设备名称',
          checked: true,
          width: '150px',
          dataIndex: 'sbName'
        },
        {
          title: '维修单号',
          checked: true,
          width: '150px',
          dataIndex: 'repairNo'
        },
        {
          title: '费用单号',
          checked: true,
          width: '150px',
          dataIndex: 'no'
        },
        {
          title: '费用金额',
          dataIndex: 'fee',
          checked: true,
          width: '150px',
          customRender: (text, record, index) => {
            return this.BaseTool.Amount.formatter(text)
          }
        },
        {
          title: '费用日期',
          checked: true,
          width: '150px',
          dataIndex: 'feeDate'
        },
        {
          title: '货币单位',
          dataIndex: 'moneyType',
          checked: true,
          width: '150px',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.moneyTypeMap, text)
          }
        },
        {
          title: '费用类别',
          dataIndex: 'type',
          checked: true,
          width: '150px',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.typeMap, text)
          }
        },
        {
          title: '费用原因',
          checked: true,
          width: '150px',
          dataIndex: 'reason'
        },
        {
          title: '费用描述',
          checked: true,
          width: '150px',
          dataIndex: 'descripition'
        },
        {
          title: '备注',
          checked: true,
          width: '150px',
          dataIndex: 'remark'
        },
        {
          title: '创建日期',
          checked: true,
          width: '200px',
          dataIndex: 'createdTime'
        },
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 下拉框map
      sourceMap: {},
      levelMap: {},
      needStopMap: {},
      planFlagMap: {},
      data: []
    }
  },
  created () {
    // 下拉框map
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_FEE_TYPE)
    this.moneyTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.MONEY_TYPE)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.detailList
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    },
    handleView (record) {
      fetchRepairFee({ id: record.id }).then(res => {
        const modal = this.$refs.detailModal
        modal.base(res.data)
      })
    }
  }
}
</script>
