<template>
  <div>
    <div v-show="visible">
      <a-row :gutter="40">
        <a-col :span="6">
          <div class="gutter-box gutter-color center">
            <div style=" overflow: auto;height: 300px;">
              <a-steps :current="repairStatus.length-1" direction="vertical" >
                <a-step v-for="item in repairStatus" :key="item.id" :title="DictCache.COLOR.REPAIR_STATUS[item.status]" :description="item.createdTime" />
              </a-steps>
            </div>
          </div>
        </a-col>
        <a-col :span="18" class="gutter-box">
          <a-row :gutter="[20,20]">
            <a-col :span="6">
              <div class="gutter-btn gutter-color" :class="{'act':current===0}" @click="current=0">
                <my-icon type="icon-weixiu1" />
                <div style="font-size:25px">报修数据</div>
              </div>
            </a-col>
            <a-col :span="6" >
              <div class="gutter-btn gutter-color" :class="{'act':current===1}" @click="current=1">
                <my-icon type="icon-weixiubaoxiu" />
                <div style="font-size:25px; ">维修数据</div>
              </div>
            </a-col>
            <a-col :span="6">
              <div class="gutter-btn gutter-color" :class="{'act':current===7}" @click="current=7">
                <my-icon type="icon-weixiu" />
                <div style="font-size:25px; ">维修方案</div>
              </div>
            </a-col>
            <a-col :span="6">
              <div class="gutter-btn gutter-color" @click="current=3" :class="{'act':current===3}">
                <img v-if="current==3" src="@/assets/icons/jilu.png" width="50px"/>
                <my-icon v-else class="act" type="icon-xinzengyugengxinhuopindangan" />
                <div style="font-size:25px;">维修记录</div>
              </div>
            </a-col>
            <a-col :span="6">
              <div class="gutter-btn gutter-color" @click="current=4" :class="{'act':current===4}">
                <img v-if="current==4" src="@/assets/icons/beijian.png" width="50px"/>
                <my-icon v-else class="act" type="icon-shouhoubeijianjijingpinjianjiageshenqingbiao-06" />
                <div style="font-size:25px; ">备件清单</div>
              </div>
            </a-col>
            <a-col :span="6" >
              <div class="gutter-btn gutter-color" :class="{'act':current===5}" @click="current=5">
                <my-icon type="icon-qitafeiyong" />
                <div style="font-size:25px;">费用清单</div>
              </div>
            </a-col>
            <a-col :span="6">
              <div class="gutter-btn gutter-color" :class="{'act':current===6}" @click="current=6">
                <my-icon type="icon-zhengzaiweixiudegongdan" />
                <div style="font-size:25px; ">维修报告</div>
              </div>
            </a-col>

            <a-col :span="6">
              <div class="gutter-btn gutter-color" @click="current=2" :class="{'act':current===2}">
                <img v-if="current==2" src="@/assets/icons/shenhe.png" width="50px"/>
                <my-icon v-else class="act" type="icon-fapiaoshenhe" />
                <div style="font-size:25px; ">审核详情</div>
              </div>
            </a-col>
          </a-row>
        </a-col>
      </a-row>
      <div>
        <div class="main gutter-color" v-show="current == 0">
          <div class="title">报修数据</div>
          <div>
            <a-descriptions :column="3" bordered>
              <a-descriptions-item label="报修单号">{{ model.no }}</a-descriptions-item>
              <a-descriptions-item label="设备编号">{{ model.sbNo }}</a-descriptions-item>
              <a-descriptions-item label="设备名称">{{ model.sbName }}</a-descriptions-item>
              <a-descriptions-item label="机电仪位号">{{ model.parentSbNo }}</a-descriptions-item>
              <a-descriptions-item label="父位号">{{ model.selfParentNo }}</a-descriptions-item>
              <a-descriptions-item label="报修车间">{{ model.sbPositionName }}</a-descriptions-item>
              <a-descriptions-item label="车间具体位置">{{ model.sbCph }}</a-descriptions-item>
              <a-descriptions-item label="工单类别">{{ BaseTool.Object.getField(planFlagMap,model.category) }}</a-descriptions-item>
              <a-descriptions-item label="报修状态"><badge :text="BaseTool.Object.getField(statusMap,model.status)" :status="DictCache.COLOR.REPAIR_APPLICATION_FORM_STATUS[model.status]"/></a-descriptions-item>
              <a-descriptions-item label="报修时间">{{ model.applyTime }}</a-descriptions-item>
              <a-descriptions-item label="报修人">{{ model.actualUser }}</a-descriptions-item>
              <a-descriptions-item label="要求时间">{{ model.limitHours }}小时</a-descriptions-item>
              <a-descriptions-item label="送修部门">{{ model.name }}</a-descriptions-item>
              <a-descriptions-item label="维修工程师" >{{ model.checkUserName }}</a-descriptions-item>
              <a-descriptions-item label="故障描述" :span="3"> <span v-html="model.content "></span> </a-descriptions-item>
              <a-descriptions-item label="报修图片" :span="3">
                <div v-if="model.applicationFileList != null && model.applicationFileList.length > 0">
                  <viewer :images="model.applicationFileList" @inited="inited" ref="viewer" :index="1" >
                    <img
                      v-for="item in model.applicationFileList"
                      :src="item.url"
                      :key="item.id"
                      class="image"
                      width="200px"
                      style="margin:10px;">
                  </viewer></div>
                <div v-if="model.applicationFileList == null || model.applicationFileList.length === 0"> 暂无</div>
              </a-descriptions-item>
            </a-descriptions>
          </div>
        </div>
        <div class="main gutter-color" v-show="current == 1">
          <div class="title">维修数据</div>
          <div>
            <a-descriptions :column="2" bordered>
              <a-descriptions-item label="维修开始时间">{{ model.repairStartTime }}</a-descriptions-item>
              <a-descriptions-item label="维修结束时间">{{ model.repairEndTime }}</a-descriptions-item>
              <a-descriptions-item label="维修耗时">{{ model.repairMinutes }}小时</a-descriptions-item>
              <a-descriptions-item label="当前维修人">{{ model.repairUserName }}</a-descriptions-item>
            </a-descriptions>
          </div>
        </div>
        <div class="main gutter-color" v-show="current == 2">
          <div class="title">审核记录</div>
          <a-table
            :data-source="dataVerifyRecord"
            :columns="columnsVerifyRecord"
            tableLayout="auto"
            rowKey="id">
            <span slot="action" slot-scope="record">
              <template>
                <a @click="handleVerifyRecord(record)">审核详情</a>
              </template>
            </span>
          </a-table>
        </div>
        <div class="main gutter-color" v-show="current == 3">
          <div class="title">维修记录</div>
          <a-table
            :data-source="dataRecord"
            :columns="columnsRecord"
            tableLayout="auto"
            rowKey="id">
            <span slot="action" slot-scope="record">
              <template>
                <a @click="handleViewRecord(record)">维修详情</a>
                <operation-button @click="handleEditRecord(record)" >编辑</operation-button>
              </template>
            </span>
          </a-table>
        </div>
        <div class="main gutter-color" v-show="current == 4">
          <div class="title">备件清单</div>
          <div style="margin:20px;margin-left: 33%;" class="table-operator" v-if="$auth('repair-application-forms-finish')">
            <a-button type="primary" @click="updateLongYanSpare(1)">
              <a-icon type="plus"/>
              更换关联备件
            </a-button>
            <a-divider type="vertical" />
            <a-button type="primary" @click="updateLongYanSpare(0)">
              <a-icon type="plus"/>
              更换常用备件
            </a-button>
            <!--            <a-divider type="vertical" />
            <a-button type="primary" @click="handleAddSpare()">
              <a-icon type="plus"/>
              添加专用备件
            </a-button>-->
          </div>
          <a-table
            :data-source="dataSpare"
            :columns="columnsSpare"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            tableLayout="auto"
            rowKey="id">
            <span slot="actionSpare" slot-scope="record">
              <template>
                <a v-if="$auth('repair-application-forms-finish') && record.isSpecial === 0" @click="handleEditSpare(record)">修改</a>
                <a-divider type="vertical" />
                <a-popconfirm v-if="$auth('repair-application-forms-finish')" title="是否要删除该条数据？" @confirm="batchDeleteSpare(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </template>
            </span>
          </a-table>
        </div>
        <div class="main gutter-color" v-show="current == 5">
          <div class="title">费用清单</div>
          <div style="margin:20px;margin-left:45%;" class="table-operator" v-if="$auth('repair-application-forms-finish')">
            <a-button type="primary" @click="handleAddFee">
              <a-icon type="plus"/>
              费用单
            </a-button>
          </div>
          <a-table
            :data-source="dataFee"
            :columns="columnsFee"
            tableLayout="auto"
            rowKey="id">
            <span slot="action" slot-scope="record">
              <template>
                <a @click="handleViewFee(record)">查看</a>
                <operation-button
                  @click="handleEditFee(record)" >修改</operation-button>
                <operation-button
                  title="确认删除该笔费用？"
                  @confirm="batchDeleteFee(record.id)" >删除</operation-button>
              </template>
            </span>
          </a-table>
        </div>
        <div class="main gutter-color" v-show="current == 6">
          <div class="title">维修报告</div>
          <div style="margin:20px;margin-left:45%;" class="table-operator" v-if="$auth('repair-application-forms-finish') && ((dataReason === null) || (dataReason.length===0))">
            <a-button type="primary" @click="handleAddReason">
              <a-icon type="plus"/>
              维修报告
            </a-button>
          </div>
          <a-table
            :data-source="dataReason"
            :columns="columnsReason"
            :scroll="{x: 1, y: BaseTool.Constant.scrollY }"
            rowKey="id">
            <span slot="action" slot-scope="record">
              <template>
                <a @click="handleViewReason(record)">查看</a>
                <operation-button
                  @click="handleEditReason(record)" >修改</operation-button>
                <!--                <operation-button
                  v-if="$auth('repair-application-forms-finish') && ( DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.PROCESSING === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.REBACK === model.status)"
                  @click="handleCopyReason(record)" >复制</operation-button>-->
                <operation-button
                  :type="2"
                  title="确认删除该记录？"
                  @confirm="batchDeleteReason(record.id)" >删除</operation-button>
              </template>
            </span>
          </a-table>
        </div>
        <div class="main gutter-color" v-show="current == 7">
          <div class="title">维修方案</div>
          <div style="margin:20px;margin-left:45%;" class="table-operator" >
            <a-button v-if="$auth('repair-repairs-add')" type="primary" @click="handleAddRepairResolve">
              <a-icon type="plus"/>
              添加方案
            </a-button>
            <a-button style="margin-left:30px;" v-if="$auth('repair-repairs-add')" type="primary" @click="handleAddRepairResolves">
              <a-icon type="read" />
              方案库
            </a-button>
          </div>
          <a-table
            :data-source="dataRepairResolve"
            :columns="columnsRepairResolve"
            tableLayout="auto"
            rowKey="id">
            <span slot="action" slot-scope="record">
              <template>
                <a @click="handleViewRepairResolve(record)">方案详情</a>
                <operation-button
                  @click="handleEditRepairResolve(record)" >修改</operation-button>
              </template>
            </span>
          </a-table>
        </div>
      </div>
      <div class="btn">
        <a-popconfirm v-if="DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.NOT_ALLOCATED === model.status " title="是否要接单？" @confirm="receiveRepair">
          <a-button style="margin-left: 8px" type="default">接单</a-button>
        </a-popconfirm>
        <a-button v-if="$auth('repair-application-forms-dispatch') && (DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.RECEIVED === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.REBACK === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.MM_DISPATCH === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.DISPATCH_REPAIR === model.status)" style="margin-left: 16px" type="default" @click="handleAssign">派单</a-button>
        <a-button v-if="(DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.PROCESSING === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.REPAIR_FAIL === model.status)" style="margin-left: 16px" type="default" @click="reportRepair">维修上报</a-button>
        <a-button v-if="(DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.REPAIR_FAIL === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.MM_REPAIR_FAIL === model.status)" style="margin-left: 16px" type="default" @click="handleReportRepair">处理维修上报</a-button>
        <a-button v-if="$auth('repair-application-forms-finish') && (DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.WAIT_SUBMIT === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.REPAIR_FAIL === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.MM_REPAIR_FAIL === model.status)" style="margin-left: 8px" type="default" @click="handleTransfer()">转派</a-button>
        <a-button v-if="$auth('repair-application-forms-examine') && DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.PROCESSING === model.status" style="margin-left: 8px" type="default" @click="handleFinish()">完成维修</a-button>
        <a-button v-if="DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.PROCESSING === model.status" style="margin-left: 8px" type="default" @click="handleViewTicket()">维修票证</a-button>
        <a-popconfirm v-if="$auth('repair-application-forms-finish') && (DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.WAIT_SUBMIT === model.status)" title="是否要结单？" @confirm="handleExamine">
          <a-button style="margin-left: 8px" type="default">结单</a-button>
        </a-popconfirm>
        <a-popconfirm v-if="$auth('repair-application-forms-approve') && DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.NOT_ACCEPTANCE === model.status" title="是否要接受？" @confirm="handleApprove">
          <a-button :loading="confirmLoading" style="margin-left: 8px" type="default">接受</a-button>
        </a-popconfirm>
        <a-popconfirm v-if="$auth('repair-application-forms-reback') && DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.NOT_ACCEPTANCE === model.status" title="是否要拒绝？" @confirm="handleReturn">
          <a-button style="margin-left: 8px" type="error">拒绝</a-button>
        </a-popconfirm>
        <a-button style="margin-left: 8px" type="primary" @click="handleCancel">返回</a-button>
      </div>
    </div>
    <check-form ref="checkForm" @ok="handleOk" />
    <base-out-form ref="outForm" @ok="handleCancel" />
    <finish-form ref="finishForm" @ok="handleRepairRecordOk" />
    <dispatch-form ref="dispatchForm" @ok="handleCancel" />
    <assign-form ref="assignForm" @ok="handleCancel" />
    <spare-pick-base-form ref="baseModal" @ok="handleOk"/>
    <base-form-for-repair ref="baseFormForRepair" @ok="handleOk" />
    <spare-store-select-modal ref="spareStoreSelectModal" @selected="handleSpareStoreSelected"/>
    <fee-base-form ref="feeForm" @ok="handleOk" />
    <fee-detail ref="feeDetail" @ok="handleOk" />
    <reason-base-form ref="reasonForm" @ok="handleOk" />
    <reason-detail ref="reasonDetail" @ok="handleOk" />
    <detail-sb-bom ref="detailSbBomModal" @ok="handleOk"/>
    <detail-sb-check ref="detailSbCheckModal" @ok="handleOk"/>
    <base-form ref="baseRepairProjectModal" @ok="handleOk"/>
    <detail ref="detailRepairProjectModal"/>
    <edit-form ref="editForm" @ok="handleOk" />
    <resolve-base-form ref="resolveBaseForm" @ok="handleResolveOk"/>
    <resolve-detail ref="resolveDetail" @ok="handleResolveOk"/>
    <detail-repair-record ref="detailRepairRecord" @ok="handleRepairRecordOk"/>
    <transfer-form ref="transferForm" @ok="handleOk"/>
    <detail-check-new ref="detailCheckNew" @ok="handleVerifyRecordOk"/>
    <repair-record-form ref="repairRecordForm" @ok="handleRepairRecordOk" />
    <report-up-form ref="reportUpForm" @ok="handleOk" @okk="handleCancel" />
    <ticket-form ref="ticketForm" @ok="handleOk" />
    <longYanSelectSpareForm ref="longYanSelectSpareForm" @ok="handleOk"/>
    <scheme-library ref="schemeLibrary" @ok="handleOk"/>
  </div>
</template>

<script>
// import { stringify } from 'qs'
import DetailList from '@/components/tools/DetailList'
import { fetchRepairApplicationForm, approve, receive, receiveRepair } from '@/api/repair/application-form'
import CheckForm from './CheckForm'
import BaseOutForm from './BaseOutForm'
import FinishForm from './FinishForm'
import EditForm from './EditForm'
import DispatchForm from './DispatchForm'
import AssignForm from './AssignForm'
import SchemeLibrary from './SchemeLibrary'
import SparePickBaseForm from '../../../store/sparepickform/modules/BaseForm'
import SparePartUsedSelectTable from '@/views/sqarepartmanage/sparepartused/modules/SparePartUsedSelectTable'
import SparePickFormSelectTable from '@/views/store/sparepickform/modules/SparePickFormSelectTable'
import RepairProjectSelectModal from '@/views/repair/repairproject/modules/RepairProjectSelectModal'
import { queryRepairProject, fetchRepairProject, deleteRepairProjects } from '@/api/repair/repairproject'
import SparePartInfoSelectModal from '@/views/sqarepartmanage/sparepartinfo/modules/SparePartInfoSelectModal'
import BaseFormForRepair from '@/views/sqarepartmanage/sparepartused/modules/BaseFormForRepair'
import { selectSparePartUsedListBySbId, addSparePartUsedBatch, deleteSparePartUseds, updateSpare, selectLongYanListByRepairId } from '@/api/sqarepartmanage/sparepartused'
import SpareStoreSelectModal from '@/views/store/sparestore/modules/SpareStoreSelectModal'
import BaseTool from '@/utils/tool'
import FeeBaseForm from '@/views/repair/fee/modules/BaseForm'
import FeeDetail from '@/views/repair/fee/modules/Detail'
import { deleteRepairFees, fetchRepairFee, queryRepairFee } from '@/api/repair/fee'
import { getSelfRole } from '@/api/upms/role'
import ReasonBaseForm from '@/views/repair/repair-reason/modules/BaseForm'
import ReasonDetail from '@/views/repair/repair-reason/modules/Detail'
import { deleteRepairReasons, fetchRepairReason, queryRepairReason } from '@/api/repair/repair-reason'
import { queryRepairRecord, fetchCustomDataForRepairRecord, fetchRepairTicketRecord } from '@/api/customize/fieldTemplateData'
import DetailSbBom from '@/views/sb/modelbom/modules/DetailSbBom'
import DetailSbCheck from '@/views/check/checkstandard/modules/DetailSbCheck'
import { fetchSbInfo } from '@/api/sb/info'
import { getRepairSchemePage, fetchRepairScheme } from '@/api/repair/repair'
import BaseForm from '@/views/repair/repairproject/modules/BaseForm'
import Detail from '@/views/repair/repairproject/modules/Detail'
import ResolveBaseForm from '@/views/repair/repair/modules/BaseForm'
import ResolveDetail from '@/views/repair/repair/modules/Detail'
import DetailRepairRecord from './DetailRepairRecord'
import TransferForm from './TransferForm'
import DetailCheckNew from './DetailCheckNew'
import RepairRecordForm from './RepairRecordForm'
import ReportUpForm from './ReportUpForm'
import TicketForm from './TicketForm'
import LongYanSelectSpareForm from './LongYanSelectSpareForm'
const DetailListItem = DetailList.Item

export default {
  name: 'RepairApplicationFormDetail',
  components: {
    CheckForm,
    SchemeLibrary,
    EditForm,
    DetailList,
    DetailSbCheck,
    DetailSbBom,
    ReasonBaseForm,
    ReasonDetail,
    DetailListItem,
    FinishForm,
    BaseOutForm,
    DispatchForm,
    FeeDetail,
    AssignForm,
    FeeBaseForm,
    SparePickBaseForm,
    SparePartUsedSelectTable,
    SparePickFormSelectTable,
    RepairProjectSelectModal,
    SparePartInfoSelectModal,
    BaseFormForRepair,
    SpareStoreSelectModal,
    BaseForm,
    Detail,
    ResolveBaseForm,
    ResolveDetail,
    DetailRepairRecord,
    TransferForm,
    DetailCheckNew,
    RepairRecordForm,
    ReportUpForm,
    TicketForm,
    LongYanSelectSpareForm
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      current: 0,
      modalTitle: null,
      needStopMap: {},
      planFlagMap: {},
      dispatchList: [],
      visible: false,
      showSbFlag: false,
      sbInfo: {},
      // 下拉框map
      sourceMap: {},
      typeMap: {},
      repairStatus: [],
      levelMap: {},
      descripitionMap: {},
      selectedRowKeys: [],
      statusMap: {},
      repairProjectMap: {},
      repairTechnologyMap: {},
      activeKey: 'a',
      data: [],
      dataSpare: [],
      dataFee: [],
      dataReason: [],
      dataRepairResolve: [],
      dataRecord: [],
      dataVerifyRecord: [],
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '维修内容',
          dataIndex: 'name'
        },
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      columnsSpare: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '备件名称',
          dataIndex: 'spareName'
        },
        {
          title: '备件编码',
          dataIndex: 'spareId'
        },
        {
          title: '规格型号',
          dataIndex: 'ggxh'
        },
        {
          title: '更换数量',
          dataIndex: 'num'
        },
        {
          title: '更换日期',
          dataIndex: 'startDate'
        },
        /* {
          title: '下次更换日期',
          dataIndex: 'startDate'
        }, */
        {
          title: '更换备注',
          dataIndex: 'remark'
        },
        {
          title: '是否关联设备',
          dataIndex: 'isSpecial',
          checked: true,
          customRender: (text, record, index) => {
            if (text === 1) {
              return '是'
            } else {
              return '否'
            }
          }
        }
        /*
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'actionSpare' }
        } */
      ],
      columnsFee: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '费用金额',
          dataIndex: 'fee',
          customRender: (text, record, index) => {
            return this.BaseTool.Amount.formatter(text)
          }
        },
        {
          title: '费用类别',
          dataIndex: 'type',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.typeMap, text)
          }
        },
        {
          title: '费用原因',
          dataIndex: 'reason'
        },
        {
          title: '费用描述',
          dataIndex: 'descripition'
        },
        {
          title: '备注',
          dataIndex: 'remark'
        },
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      columnsVerifyRecord: [
        {
          title: '序号',
          dataIndex: 'index',
          width: '70px',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '审核人',
          dataIndex: 'createdUserName',
          width: '100px'
        },
        {
          title: '审核时间',
          dataIndex: 'createdTime',
          width: '150px'
        },
        {
          title: '审核类别',
          dataIndex: 'type',
          ellipsis: true,
          width: '100px',
          customRender: (text, record, index) => {
            if (text === 1) {
              return '维修审核'
            } else if (text === 2) {
              return '报修审核'
            }
          }
        },
        {
          title: '审核状态',
          dataIndex: 'status',
          ellipsis: true,
          width: '100px',
          customRender: (text, record, index) => {
            if (text === 1) {
              return '审核通过'
            } else if (text === 2) {
              return '审核拒绝'
            }
          }
        },
        {
          title: '审核意见',
          dataIndex: 'dataRemark',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      columnsRecord: [
        {
          title: '序号',
          dataIndex: 'index',
          width: '70px',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '维修人',
          dataIndex: 'createdUserName',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '维修时间',
          dataIndex: 'createdTime',
          width: '150px'
        },
        {
          title: '结束时间',
          dataIndex: 'updateTime',
          width: '150px'
        },
        {
          title: '维修时长',
          dataIndex: 'repairHours',
          ellipsis: true,
          width: '100px'
        },
        /* {
          title: '维修建议',
          dataIndex: 'opinion',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '维修描述',
          dataIndex: 'dataRemark',
          ellipsis: true,
          width: '150px'
        }, */
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      columnsRepairResolve: [
        {
          title: '序号',
          dataIndex: 'index',
          width: '70px',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '维修建议',
          dataIndex: 'opinion',
          width: '200px'
        },
        {
          title: '方案提供者',
          dataIndex: 'createdUserName',
          width: '120px'
        },
        {
          title: '方案提供时间',
          dataIndex: 'createdTime',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      columnsReason: [
        {
          title: '序号',
          dataIndex: 'index',
          width: '70px',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '分析时间',
          dataIndex: 'analyzeTime',
          width: '150px'
        },
        {
          title: '故障现象',
          dataIndex: 'problemDesc',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '检查处理过程',
          dataIndex: 'checkProcess',
          ellipsis: true,
          width: '150px'
        },
        {
          title: '改进措施类别',
          dataIndex: 'type',
          ellipsis: true,
          width: '150px',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.typeReasonMap, text)
          }
        },
        {
          title: '改进内容',
          dataIndex: 'changeRepairPlanContent',
          ellipsis: true,
          width: '250px'
        },
        {
          title: '操作',
          key: 'action',
          width: '200px',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      typeReasonMap: {},
      model: {
        'id': null,
        'sbId': null,
        'partId': null,
        'repairUserId': null,
        'needStop': null,
        'category': null,
        'no': null,
        'source': null,
        'applyTime': null,
        'level': null,
        'content': null,
        'status': null,
        'remark': null,
        'updateTime': null,
        'createdUserId': null,
        'updateUserId': null,
        'createdUserName': null,
        'sbName': null,
        'partName': null,
        'limitHours': null,
        'limitDate': null,
        'updateUserName': null,
        'repairFormVO': null,
        'repairCheckVO': null,
        'checkUserName': null,
        'remarkTwo': null,
        'repairMinutes': null,
        'repairDeptId': null,
        'userId': null,
        'sbCph': null,
        'actualUser': null,
        'dispatchUserId': null,
        'parentSbNo': null,
        'sbPositionName': null,
        'selfParentNo': null
      }
    }
  },
  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.statusRepairMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_FORM_STATUS)
    this.statusCheckMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_CHECK_STATUS)
    this.needStopMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
    this.repairProjectMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_PROJECT_TYPE)
    this.repairTechnologyMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_TECHNOLOGY_TYPE)
    this.descripitionMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIRE_ACTION)
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_FEE_TYPE)
    this.typeReasonMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_REASON_TYPE)
    this.planFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_CATEGORY)
  },
  methods: {
    base (record) {
      this.visible = true
      this.showSbFlag = false
      this.modalTitle = '详情'
      this.model = record
      this.activeKey = 'a'
      const sbId = record.sbId
      if (sbId) {
        fetchSbInfo({ id: sbId }).then(res => {
          this.sbInfo = res.data
          this.showSbFlag = true
        })
      }
      if (record.repairMinutes === null) {
        this.model.repairMinutes = '?'
      }
      this.init()
    },
    init () {
      queryRepairProject({ repairId: this.model.id }).then(res => {
        this.data = res.data
      })
      selectLongYanListByRepairId({ id: this.model.id }).then(res => {
        this.dataSpare = res.data
      })
      queryRepairFee({ repairId: this.model.id }).then(res => {
        this.dataFee = res.data
      })
      queryRepairReason({ repairId: this.model.id }).then(res => {
        this.dataReason = res.data
      })
      queryRepairRecord({ objId: this.model.id, remark: 'repair_record' }).then(res => {
        this.dataRecord = res.data.rows
      })
      queryRepairRecord({ objId: this.model.id, pageSize: 20, remark: 'repair_status_record' }).then(res => {
        this.repairStatus = res.data.rows
      })
      queryRepairRecord({ objId: this.model.id, remark: 'repair_verify_record' }).then(res => {
        this.dataVerifyRecord = res.data.rows
      })
      getRepairSchemePage({ repairId: this.model.id }).then(res => {
        this.dataRepairResolve = res.data.rows
      })
    },
    handleViewBom (record) {
      this.visible = false
      const modal = this.$refs.detailSbBomModal
      modal.base(this.sbInfo)
    },
    handleViewCheck (record) {
      this.visible = false
      const modal = this.$refs.detailSbCheckModal
      modal.base(this.sbInfo)
    },
    handleCancel () {
      this.visible = false
      this.current = 0
      this.confirmLoading = false
      this.$emit('ok')
    },
    handleOkUp (num) {
      if (num === 1) {
        this.handleOk()
      } else {
        this.handleCancel()
      }
    },
    handleAddSpare () {
      const id = this.model.sbId
      const routeUrl = this.$router.resolve({ path: '/spare/used/record', query: { id: id } })
      window.open(routeUrl.href, '_blank')
    },
    receive () {
      this.model.status = this.DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.PROCESSING
      receive(this.model).then(() => {
      })
    },
    batchDeleteFee (id) {
      let ids = []
      if (this.BaseTool.String.isBlank(id)) {
        const length = this.selectedRows.length
        if (length === 0) {
          this.$message.info('请选择要删除的记录')
          return
        }
        ids = this.selectedRows.map(item => item.id)
      } else {
        ids = [id]
      }
      deleteRepairFees(ids).then(res => {
        this.$message.info('删除成功')
        this.handleOk()
      })
    },
    handleOut () {
      const modal = this.$refs.outForm
      modal.base(null, this.model)
    },
    handleTransfer () {
      getSelfRole().then(res => {
        const modal = this.$refs.transferForm
        modal.base(this.model, res.data)
      })
    },
    handleAddFee () {
      const modal = this.$refs.feeForm
      modal.base(null, this.model)
    },
    handleEditFee (record) {
      fetchRepairFee({ id: record.id }).then(res => {
        const modal = this.$refs.feeForm
        const data = res.data
        data.repairNo = this.model.no
        modal.base(data, this.model)
      })
    },
    handleViewFee (record) {
      fetchRepairFee({ id: record.id }).then(res => {
        const modal = this.$refs.feeDetail
        modal.base(res.data)
      })
    },
    handleAddRepairResolve () {
      const modal = this.$refs.resolveBaseForm
      modal.base({ repairId: this.model.id, repairNo: this.model.no, errorContent: this.model.content, sbId: this.model.sbId })
    },
    handleAddRepairResolves () {
      const modal = this.$refs.schemeLibrary
      modal.base(this.model)
    },
    handleViewRepairResolve (record) {
      this.visible = false
      fetchRepairScheme({ id: record.id }).then(res => {
        const modal = this.$refs.resolveDetail
        modal.base(res.data)
      })
    },
    handleEditRepairResolve (record) {
      fetchRepairScheme({ id: record.id }).then(res => {
        const modal = this.$refs.resolveBaseForm
        const data = res.data
        modal.base(data)
      })
    },
    handleViewRecord (record) {
      this.visible = false
      fetchCustomDataForRepairRecord({ id: record.id }).then(res => {
        const modal = this.$refs.detailRepairRecord
        modal.base(res.data)
      })
    },
    handleViewTicket () {
      this.visible = false
      fetchRepairTicketRecord({ id: this.model.id }).then(res => {
        const modal = this.$refs.ticketForm
        modal.base(res.data)
      })
    },
    handleVerifyRecord (record) {
      this.visible = false
      fetchCustomDataForRepairRecord({ id: record.id }).then(res => {
        const modal = this.$refs.detailCheckNew
        modal.base(res.data)
      })
    },
    batchDeleteReason (id) {
      let ids = []
      if (this.BaseTool.String.isBlank(id)) {
        const length = this.selectedRows.length
        if (length === 0) {
          this.$message.info('请选择要删除的记录')
          return
        }
        ids = this.selectedRows.map(item => item.id)
      } else {
        ids = [id]
      }
      deleteRepairReasons(ids).then(res => {
        this.$message.info('删除成功')
        this.handleOk()
        this.$refs.table.clearSelected()
      })
    },
    handleAddReason () {
      const modal = this.$refs.reasonForm
      this.visible = false
      modal.base(null, this.model)
    },
    handleEditReason (record) {
      fetchRepairReason({ id: record.id }).then(res => {
        const modal = this.$refs.reasonForm
        this.visible = false
        modal.base(res.data, this.model)
      })
    },
    handleCopyReason (record) {
      fetchRepairReason({ id: record.id }).then(res => {
        const modal = this.$refs.reasonForm
        this.visible = false
        res.data.id = null
        modal.base(res.data, this.model)
      })
    },
    handleViewReason (record) {
      fetchRepairReason({ id: record.id }).then(res => {
        const modal = this.$refs.reasonDetail
        modal.base(res.data)
      })
    },
    handleApprove () {
      approve(this.model).then(() => {
        this.$message.info('操作成功')
        this.handleOk()
      })
    },
    receiveRepair () {
      const params = {}
      params.id = this.model.id
      params.repairDeptId = this.model.repairDeptId
      params.applyTime = this.model.applyTime
      params.userId = this.model.userId
      params.no = this.model.no
      receiveRepair(params).then(() => {
        this.$message.info('接单成功')
        this.handleOk()
      })
    },
    reportRepair () {
      const params = {}
      params.id = this.model.id
      params.repairDeptId = this.model.repairDeptId
      params.applyTime = this.model.applyTime
      params.userId = this.model.userId
      params.no = this.model.no
      params.sbId = this.model.sbId
      params.sbCph = this.model.sbCph
      params.actualUser = this.model.actualUser
      params.content = this.model.content
      params.repairUserId = this.model.repairUserId
      params.remark = this.model.remark
      params.reportHandleType = 2 // 维修上报
      getSelfRole().then(res => {
        const modal = this.$refs.reportUpForm
        params.roleType = res.data
        modal.base(params)
      })
    },
    handleReportRepair () {
      const params = {}
      params.id = this.model.id
      params.repairDeptId = this.model.repairDeptId
      params.applyTime = this.model.applyTime
      params.userId = this.model.userId
      params.no = this.model.no
      params.sbId = this.model.sbId
      params.sbCph = this.model.sbCph
      params.actualUser = this.model.actualUser
      params.content = this.model.content
      params.repairUserId = this.model.repairUserId
      params.remark = this.model.remarkTwo
      params.reportHandleType = 1 // 处理维修上报
      getSelfRole().then(res => {
        const modal = this.$refs.reportUpForm
        params.roleType = res.data
        modal.base(params)
      })
    },
    handleEditRecord (record) {
      this.visible = false
      fetchCustomDataForRepairRecord({ id: record.id }).then(res => {
        const modal = this.$refs.repairRecordForm
        modal.base(res.data)
      })
    },
    handleReturn () {
      const modal = this.$refs.checkForm
      modal.base(this.model, 1)
    },
    handleOk () {
      this.loading = true
      fetchRepairApplicationForm({ id: this.model.id }).then(res => {
        this.loading = false
        this.model = res.data
        this.visible = true
      })
      this.init()
    },
    handleResolveOk () {
      this.loading = true
      this.visible = true
      getRepairSchemePage({ repairId: this.model.id }).then(res => {
        this.loading = false
        this.dataRepairResolve = res.data.rows
      })
    },
    handleRepairRecordOk () {
      this.loading = true
      this.visible = true
      queryRepairRecord({ objId: this.model.id, remark: 'repair_record' }).then(res => {
        this.loading = false
        this.dataRecord = res.data.rows
      })
      fetchRepairApplicationForm({ id: this.model.id }).then(res => {
        this.model = res.data
      })
    },
    handleVerifyRecordOk () {
      this.loading = true
      this.visible = true
      queryRepairRecord({ objId: this.model.id, remark: 'repair_verify_record' }).then(res => {
        this.loading = false
        this.dataVerifyRecord = res.data.rows
      })
    },
    handleFinish () {
      const modal = this.$refs.finishForm
      modal.base(this.model)
    },
    handleExamine () {
      const modal = this.$refs.checkForm
      modal.base(this.model, 2)
    },
    handleDispatch () {
      const modal = this.$refs.dispatchForm
      modal.base(this.model)
    },
    handleAssign () {
      getSelfRole().then(res => {
        const roleType = res.data // 获取当前用户的角色
        if (roleType === 4) {
          const modal = this.$refs.reportUpForm
          const params = {}
          params.id = this.model.id
          params.repairDeptId = this.model.repairDeptId
          params.applyTime = this.model.applyTime
          params.userId = this.model.userId
          params.no = this.model.no
          params.sbId = this.model.sbId
          params.sbCph = this.model.sbCph
          params.actualUser = this.model.actualUser
          params.content = this.model.content
          params.repairUserId = this.model.repairUserId
          params.remark = this.model.remarkTwo
          params.reportHandleType = 1 // 处理维修上报
          params.roleType = 4
          modal.base(params)
        } else {
          const modal = this.$refs.assignForm
          modal.base(this.model)
        }
      })
    },
    handleSparePick () {
      const modal = this.$refs.baseModal
      modal.base(null, { repairId: this.model.id, repairNo: this.model.no, reason: '维修领用' })
    },
    changeTab (activeKey) {
      this.activeKey = activeKey
      if (this.activeKey === 'a' && this.BaseTool.Object.isNotBlank(this.$refs.sparePartUsedSelectTable)) {
        const modal = this.$refs.sparePartUsedSelectTable
        modal.handleOk()
        return
      }
      if (this.activeKey === 'b' && this.BaseTool.Object.isNotBlank(this.$refs.sparePickFormSelectTable)) {
        const modal = this.$refs.sparePickFormSelectTable
        modal.handleOk()
      }
    },
    handleView (record) {
      fetchRepairProject({ id: record.id }).then(res => {
        const modal = this.$refs.detailRepairProjectModal
        modal.base(res.data)
      })
    },
    handleEdit (record) {
      const modal = this.$refs.editForm
      modal.base(this.model)
    },
    handleRepairProjectAdd () {
      this.$refs.baseRepairProjectModal.base({ repairId: this.model.id })
    },
    batchDelete (id) {
      let ids = []
      if (this.BaseTool.String.isBlank(id)) {
        if (length === 0) {
          this.$message.info('请选择要删除的记录')
          return
        }
        ids = this.selectedRows.map(item => item.id)
      } else {
        ids = [id]
      }
      deleteRepairProjects(ids).then(res => {
        this.$message.info('删除成功')
        this.handleOk()
      })
    },
    handleSpareSelect () {
      this.$refs.spareSelectModal.base({}, { yt: 1 })
    },
    updateLongYanSpare (num) {
      this.$refs.longYanSelectSpareForm.base({ isSpecial: num }, this.model)
    },
    /* handleSpareLongYanSelect (num) {
      this.$refs.spareLongYanSelectModal.base({ isSpecial: num }, { isSpecial: num })
    },
    handleSpareLongYanSelected (record, keys, rows) {
      const data = []
      for (let i = 0; i < rows.length; i++) {
        data.push({ sparePeriod: rows[i].sparePeriod, isSpecial: record.isSpecial, sbId: this.model.sbId, spareId: rows[i].id, repairId: this.model.id, num: 1, spareName: rows[i].spareName, ggxh: rows[i].ggxh })
      }
      addLongYanSparePartUsedBatch(data)
        .then((response) => {
          this.$message.info('更换成功')
          this.handleOk()
        }).catch(() => {
          this.confirmLoading = false
        })
    }, */
    handleSpareSelected (record, keys, rows) {
      const data = []
      for (let i = 0; i < rows.length; i++) {
        data.push({ sbId: this.model.sbId, spareId: rows[i].id, repairId: this.model.id, num: 1, price: rows[i].initialValue, totalPrice: rows[i].initialValue })
      }
      addSparePartUsedBatch(data)
        .then((response) => {
          this.$message.info('添加成功')
          this.handleOk()
        }).catch(() => {
          this.confirmLoading = false
        })
    },
    batchDeleteSpare (id) {
      let ids = []
      if (this.BaseTool.String.isBlank(id)) {
        if (length === 0) {
          this.$message.info('请选择要删除的记录')
          return
        }
        ids = this.selectedRows.map(item => item.id)
      } else {
        ids = [id]
      }
      deleteSparePartUseds(ids).then(res => {
        this.$message.info('删除成功')
        this.handleOk()
      })
    },
    handleEditSpare (record) {
      const modal = this.$refs.baseFormForRepair
      modal.base(record)
    },
    updateSpare (record) {
      updateSpare(record).then(res => {
        this.$message.info('更换成功')
        selectSparePartUsedListBySbId({ id: this.model.sbId }).then(res => {
          this.dataSpare = res.data
        })
      })
    },
    handleSpareStoreSelect (isSpecial) {
      this.$refs.spareStoreSelectModal.base({}, { repairFlag: 1, storeId: this.storeId, isSpecial: isSpecial, sbId: this.model.sbId })
    },
    handleSpareStoreSelected (record, keys, rows) {
      const data = []
      for (let i = 0; i < rows.length; i++) {
        data.push({ isSpecial: record.isSpecial, sbId: this.model.sbId, spareId: rows[i].spareId, repairNo: this.model.no, repairId: this.model.id, num: 1, price: rows[i].price, totalPrice: rows[i].price, startDate: BaseTool.Date.formatter(new Date(), BaseTool.Date.PICKER_NORM_DATE_PATTERN) })
      }
      if (record.isSpecial === 1) {
        updateSpare(data)
          .then((response) => {
            this.$message.info('更换成功')
            this.handleOk()
          }).catch(() => {
            this.confirmLoading = false
          })
      } else {
        addSparePartUsedBatch(data)
          .then((response) => {
            this.$message.info('更换成功')
            this.handleOk()
          }).catch(() => {
            this.confirmLoading = false
          })
      }
    },
    onSelectChange (selectedRowKeys) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      this.selectedRowKeys = selectedRowKeys
    },
    inited (viewer) {
      this.$viewer = viewer
    }
  }
}
</script>

<style lang="less" scoped>
.gutter-box{
  height: 350px;
}
.gutter-color{
  background: #fff;
  border: 1px solid #DDDDDD;
}

.gutter-btn{
  height: 165px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 50px;
  color:#333;
  &:hover{
    cursor: pointer;
  }
}
.act{
  color:#3462FD;
}
.main{
 margin-top:30px;
}
.title{
 font-size: 28px;
 font-family: PingFang SC;
 font-weight: 500;
 color: #3462FD;
 padding:10px 42px;
 border-bottom: 1px solid #DDDDDD;
}
.btn{
   position: fixed;
   bottom: 50px;
   width: 100%;
    display: flex;
    justify-content: center;
}
.center{
 display: flex;
 justify-content: center;
 align-items: center;
}
::-webkit-scrollbar { width: 0; height: 0; color: transparent; }
</style>
