<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.name }}</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.checkUserName }}</a-descriptions-item>
              <a-descriptions-item label="故障描述" :span="3">{{ model.content }}</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="3" 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>
<!--                               <operation-button
                                  title="确认该条维修记录？"
                                  @confirm="deleteRecord(record.id)" >删除</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="handleSpareStoreSelect(1)">
              <a-icon type="plus"/>
              更换专用备件
            </a-button>
            <a-divider type="vertical" />
            <a-button type="primary" @click="handleSpareStoreSelect(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 type="primary" @click="handleAddRepairResolve">
              <a-icon type="plus"/>
              添加方案
            </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>
                <!--                <operation-button
                  title="确认该条维修记录？"
                  @confirm="deleteRepairResolve(record.id)" >删除</operation-button>-->
              </template>
            </span>
          </a-table>
        </div>
      </div>
      <div class="btn">
        <a-button v-if="$auth('repair-application-forms-dispatch') && (DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.NOT_ALLOCATED === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.PROCESSING === model.status || DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.REBACK === model.status)" style="margin-left: 16px" type="default" @click="handleAssign">派工</a-button>
        <a-button v-if="$auth('repair-application-forms-transfer-apply') && (DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.PROCESSING === 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-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' />
  </div>
</template>

<script>
// import { stringify } from 'qs'
import DetailList from '@/components/tools/DetailList'
import { fetchRepairApplicationForm, approve, receive } 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 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, selectSparePartUsedListByRepairId } 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 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 } 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'
const DetailListItem = DetailList.Item

export default {
  name: 'RepairApplicationFormDetail',
  components: {
    CheckForm,
    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
  },
  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: 'spareId',
          customRender: (text, record, index) => {
            return record.spareName
          }
        },
        {
          title: '数量',
          dataIndex: 'num'
        },
        {
          title: '价格',
          dataIndex: 'price'
        },
        {
          title: '总价',
          dataIndex: 'totalPrice'
        },
        {
          title: '更换日期',
          dataIndex: 'startDate'
        },
        {
          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
      }
    }
  },
  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
      console.log(111)
      console.log(record)
      this.activeKey = 'a'
      const sbId = record.sbId
      if (sbId) {
        fetchSbInfo({ id: sbId }).then(res => {
          this.sbInfo = res.data
          this.showSbFlag = true
        })
      }

      this.init()
    },
    init () {
      queryRepairProject({ repairId: this.model.id }).then(res => {
        this.data = res.data
      })
      selectSparePartUsedListByRepairId({ 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')
    },
    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 () {
      const modal = this.$refs.transferForm
      modal.base(this.model)
    },
    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 })
    },
    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)
      })
    },
    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()
      })
    },
    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 () {
      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 })
    },
    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, 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>
