<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-select
          v-model="queryParams.robotId"
          filterable
          clearable
          size="small"
          placeholder="机器人"
          class="filter-item"
          style="width: 160px"
        >
          <el-option
            v-for="item in robotList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select
          v-model="queryParams.mapId"
          filterable
          clearable
          size="small"
          placeholder="地图"
          class="filter-item"
          style="width: 160px"
        >
          <el-option
            v-for="item in sceneList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-cascader
          :options="areaTree"
          clearable
          :props="{ multiple: true }"
          size="small"
          placeholder="区域ID"
          class="filter-item"
          style="width: 160px;"
          collapse-tags
        />
        <el-select
          v-model="queryParams.recognizeIdList"
          clearable
          multiple
          collapse-tags
          size="small"
          placeholder="识别类型"
          class="filter-item"
          style="width: 280px"
        >
          <el-option
            v-for="item in recognizeTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-input
          v-model="queryParams.positionList"
          clearable
          multiple
          size="small"
          placeholder="输入点位名称"
          style="width: 160px"
          class="filter-item"
        />
        <el-input
          v-model="queryParams.taskIdLike"
          clearable
          size="small"
          placeholder="输入任务编号"
          style="width: 160px"
          class="filter-item"
        />
        <el-input
          v-model="queryParams.taskTitleLike"
          clearable
          size="small"
          placeholder="输入任务名称"
          style="width: 160px"
          class="filter-item"
        />

        <el-select
          v-model="queryParams.defectGradeList"
          clearable
          multiple
          collapse-tags
          size="small"
          placeholder="缺陷等级"
          class="filter-item"
          style="width: 160px"
        >
          <el-option
            v-for="item in defectGradeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>

        <el-input
          v-model="queryParams.indicatorNameLike"
          clearable
          size="small"
          placeholder="输入指标名称"
          style="width: 160px"
          class="filter-item"
        />
        <date-range-picker
          type="datetimerange"
          v-model="timeRange"
          class="date-item"
          style="width: 400px !important"
          @change="setTime"
        />
        <span>
          <el-button
            class="filter-item"
            size="mini"
            type="success"
            icon="el-icon-search"
            @click="searchPatrolRecord()"
            >搜索</el-button
          >
        </span>
        <!-- <rrOperation /> -->
      </div>
      <crudOperation :permission="permission" />
    </div>
    <!-- 表单组件 -->
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="crud.cancelCU"
      :visible.sync="crudCU"
      title="巡检记录"
      width="900px"
    >
      <el-row :gutter="40">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
          <el-col :span="12">
            <el-form-item label="机器人名称" prop="robot">
              <el-input v-model="form.robot" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="任务名称" prop="task">
              <el-input v-model="form.task" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="场景名称" prop="scene">
              <el-input v-model="form.scene" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="地图名称" prop="map">
              <el-input v-model="form.map" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="区域名称" prop="area">
              <el-input v-model="form.area" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="导航点编号" prop="naviSequence">
              <el-input v-model="form.naviSequence" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="巡检点ID" prop="positionId">
              <el-input v-model="form.positionId" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="指标类目名称" prop="categoryName">
              <el-input v-model="form.categoryName" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="指标名称" prop="indicatorName">
              <el-input v-model="form.indicatorName" size="small" cvlass="filter-item" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="识别类型编码" prop="recognizeCode">
              <el-input v-model="form.recognizeCode" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="识别类型名称" prop="recognizeName">
              <el-input v-model="form.recognizeName" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="单位" prop="unit">
              <el-input v-model="form.unit" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="序号" prop="index">
              <el-input v-model="form.index" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="巡检时间" prop="patrolTime">
              <el-input v-model="form.patrolTime" size="small" class="filter-item" disabled />
            </el-form-item>
            <!-- <el-form-item label="识别状态" prop="recognizeState">
              <el-switch
                disabled
                v-model="form.recognizeState"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="true"
                :inactive-value="false"
              >
              </el-switch>
            </el-form-item> -->
            <el-form-item label="识别状态" prop="recognizeState">
              <el-input v-model="form.recognizeState" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="识别阈值ID" prop="thresholdId">
              <el-input v-model="form.thresholdId" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="缺陷等级" prop="defectGrade">
              <el-input v-model="form.defectGrade" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="检测值" prop="value">
              <el-input v-model="form.value" size="small" class="filter-item" disabled />
            </el-form-item>
            <!-- <el-form-item label="检测值明细" prop="detail">
              <el-input v-model="form.detail" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="矫正时间" prop="adjustTime">
              <el-input v-model="form.adjustTime" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="识别时间" prop="recognizeTime">
              <el-input v-model="form.recognizeTime" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="修正后等级" prop="modifiedGrade">
              <el-input v-model="form.modifiedGrade" size="small" class="filter-item" disabled />
            </el-form-item> -->
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="缺陷追溯" prop="defectReview">
              <el-input v-model="form.defectReview" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="缺陷审核备注" prop="reviewMemo">
              <el-input v-model="form.reviewMemo" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="缺陷处理状态" prop="reviewState">
              <el-input v-model="form.reviewState" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="缺陷确认时间" prop="confirmTime">
              <el-input v-model="form.confirmTime" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="缺陷确认人" prop="reviewer">
              <el-input v-model="form.reviewer" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="缺陷解决时间" prop="solveTime">
              <el-input v-model="form.solveTime" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="缺陷解决人" prop="solver">
              <el-input v-model="form.solver" size="small" class="filter-item" disabled />
            </el-form-item>
            <el-form-item label="警戒线" prop="guardLine">
              <el-input v-model="form.guardLine" size="small" class="filter-item" disabled />
            </el-form-item>
          </el-col> -->
        </el-form>
      </el-row>
      <!-- <el-row :gutter="40">
        <div style="margin-left: 22px; color: #000; font-weight: bold">
          <div>算法资源列表:</div>
          <el-table :data="resourceList" style="width: 98%" :height="'100%'">
            <el-table-column prop="index" label="序号" align="center" />
            <el-table-column prop="tye" label="资源类型" align="center" />
            <el-table-column prop="originUrl" label="原始资源路径" align="center" />
            <el-table-column prop="processedUrl" label="已处理资源路径" />
          </el-table>
        </div>
      </el-row> -->

    </el-dialog>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="patrolRecordList.list"
      style="width: 100%"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column
        v-for="item in patrolRecordTableOptions"
        :key="item.prop"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        :align="item.align"
        :fixed="item.fixed"
        :sortable="item.sortable"
      >
      </el-table-column>
      <!--   编辑与删除   -->
      <el-table-column
        v-if="
          checkPer(['admin', 'robotSLG:patrolRecord:list:edit', 'robotSLG:patrolRecord:list:del'])
        "
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <udOperation :data="scope.row" :permission="permission" />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100, 200, 500]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="+patrolRecordList.totalCount"
      style="margin-top:4px;"
    >
    </el-pagination>
  </div>
</template>

<script>
import permission from '@/directive/permission'
import crudVisualIntercom from '@/api/visualIntercom/config'
import { getOptions } from '@/api/visualIntercom/public'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import { crudOperation, rrOperation, udOperation, pagination } from '@crud'
import crudComps from '@crud'
import DateRangePicker from '@/components/DateRangePicker'
import { patrolRecordTableOptions } from '../tableConfig'
import { initData } from '@/api/data'
import {
  getRobotList,
  getRecognizeList,
  getAreaTree,
  getNaviList,
  getPositionList,
  getSenceList,
  getTaskList,
  getRobotToken,
  getPatrolRecordList,
} from '@/api/robotSLG/public'

const defaultForm = {
  id: '', //主键ID
  orgId: '', //组织ID
  robotId: '', //机器人ID
  robot: '', //机器人名称
  taskId: '', //任务ID
  task: '', //任务名称
  sceneId: '', //场景ID
  scene: '', //场景名称
  mapId: '', //地图ID
  map: '', //地图名称
  areaId: '', //区域ID
  area: '', //区域名称
  naviId: '', //导航点ID
  naviSequence: '', //导航点编号
  positionId: '', //巡检点ID
  indicatorId: '', //指标ID
  indicatorName: '', //指标名称
  categoryId: '', //指标类目ID
  categoryName: '', //指标类目名称
  recognizeId: '', //识别类型ID
  recognizeCode: '', //识别类型编码
  recognizeName: '', //识别类型名称
  unit: '', //单位
  index: '', //序号
  patrolTime: '', //巡检时间
  recognizeState: '', //识别状态
  thresholdId: '', //识别阈值ID
  defectGrade: '', //缺陷等级
  value: '', //检测值
  detail: '', //检测值明细
  adjustTime: '', //矫正时间
  recognizeTime: '', //识别时间
  modifiedGrade: '', //修正后等级
  defectReview: '', //缺陷追溯
  reviewMemo: '', //缺陷审核备注
  reviewState: '', //缺陷处理状态
  confirmTime: '', //缺陷确认时间
  reviewerId: '', //缺陷确认人ID
  reviewer: '', //缺陷确认人名
  solveTime: '', //缺陷解决时间
  solverId: '', //缺陷解决人ID
  solver: '', //缺陷解决人名
  guardLine: '', //警戒线
  resourceList: [
    //算法资源列表
    {
      index: '', //序号
      type: '', //资源类型
      originUrl: '', //原始资源路径
      processedUrl: '', //已处理资源路径
    },
  ],
  createTime: '', //创建时间
}

export default {
  name: 'PatrolRecord',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker },
  cruds() {
    return CRUD({
      title: '巡检记录',
      url: 'explosive-api/patrol-record/list',
      query: { pageIndex: 1, pageSize: 10 },
      listOrder: [],
      crudMethod: { ...crudVisualIntercom },
      optShow: {
        add: false,
        edit: true,
        del: false,
        reset: false,
        import: false,
        export: false,
      },
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    },
    VUE_APP_BASE_API() {
      return process.env.VUE_APP_BASE_API
    },
    VUE_APP_BASE_WS() {
      return 'ws://' + window.location.host + process.env.VUE_APP_BASE_API
    },
  },
  data() {
    return {
      patrolRecordTableOptions,
      permission: {
        add: ['admin', 'robotSLG:patrolRecord:list:add'],
        edit: ['admin', 'robotSLG:patrolRecord:list:edit'],
        del: ['admin', 'robotSLG:patrolRecord:list:del'],
      },
      rules: {
        // code: [{ required: true, message: '请选输入编号', trigger: 'blur' }],
      },
      optionsObj: {
        Camera: [],
        Build: [],
        FloorNo: [],
        VisualIntercomType: [],
      },
      //分页
      pageIndex: 1,
      pageSize: 10,
      timeRange: [],
      //搜索条件
      queryParams: {
        token: this.robotToken,
        idList: null, //记录ID列表
        taskIdList: null, //任务ID列表
        taskIdLike: '', //任务ID模糊查询
        taskTitleLike: '', //任务标题（模糊查询）
        robotId: '', //机器人ID
        mapId: '', //地图ID
        areaList: null, //区域ID列表
        positionList: null, //点位ID列表
        defectGradeList: null, //缺陷等级
        recognizeIdList: null, //识别类型列表
        indicatorNameLike: '', //指标名称模糊查询
        minPatrolTime: '', //最小巡检时间
        maxPatrolTime: '', //最大巡检时间
        pageIndex: this.pageIndex, //页号
        pageSize: this.pageSize, //每页记录数
      },
      //机器人登录token
      robotToken: null,
      robotList: [
        {
          id: '', //主键ID
          modelId: '', //模型ID
          number: '', //设备编号
          category: '', //设备类型
          issueDate: '', //发售时间
          sequence: '', //出厂号
          title: '', //名称
          profile: '', //头像
          desc: '', //描述
          func: '', //功能说明
          battery: '', //剩余电量
          deviceStatus: '', //设备状态
          taskMode: '', //机器人任务执行模式
          createTime: '', //创建时间
        },
      ],
      recognizeTypeList: [
        {
          id: '', //主键ID
          name: '', //识别类型名称
          code: '', //编号
          desc: '', //描述信息
          createTime: '', //创建时间
        },
      ],
      areaTree: {
        id: '', //主键ID
        parentId: '', //父节点ID
        parent: '', //父节点名称
        path: '', //区域树路径
        level: '', //层级
        sort: '', //排序比重值
        name: '', //区域名称
        memo: '', //备注
        editor: '', //编辑人
        createTime: '', //创建时间
        subList: '', //下级区域节点
        naviList: '', //下辖导航点
      },
      navPointList: [
        {
          id: '', //主键ID
          robotId: '', //机器人ID
          robot: '', //机器人名称
          mapId: '', //地图ID
          map: '', //地图名称
          areaId: '', //区域ID
          area: '', //区域名称
          alias: '', //导航点别名
          naviType: '', //导航点类型
          sequence: '', //导航点编号
          coordinateX: '', //横坐标
          coordinateY: '', //纵坐标
          yaw: '', //航向角
          longitude: '', //经度
          latitude: '', //维度
          distance: '', //与原点距离
          chargingDeviceId: '', //充电设备ID
          positionCount: '', //巡检点个数
          positionList: '', //巡检点列表
          createTime: '', //创建时间
        },
      ],
      patrolPostionList: [
        {
          id: '', //主键ID
          robotId: '', //机器人ID
          mapId: '', //地图ID
          areaId: '', //区域ID
          area: '', //区域名称
          naviId: '', //导航点ID
          naviSequence: '', //导航点别名
          indicatorId: '', //指标ID
          indicatorName: '', //指标名称
          categoryId: '', //指标类目ID
          categoryName: '', //指标类目名称
          recognizeId: '', //识别类型ID
          recognizeName: '', //识别类型名称
          recognizeCode: '', //识别类型编码
          regionSequence: '', //区域编号
          panRotateAngleLocationH: '', //云台水平算法定位转动角度
          panRotateAngleLocationV: '', //云台垂直算法定位转动角度
          panRotateAngleRecognizeH: '', //云台水平算法识别转动角度
          panRotateAngleRecognizeV: '', //云台垂直算法识别转动角度
          visibleCameraLocationZoom: '', //可见光相机算法定位变焦
          visibleCameraLocationFocus: '', //可见光相机算法定位聚焦
          visibleCameraRecognizeZoom: '', //可见光相机算法识别变焦
          visibleCameraRecognizeFocus: '', //可见光相机算法识别聚焦
          infraredCameraRadiation: '', //红外相机辐射
          infraredCameraZoom: '', //红外相机变焦
          infraredCameraFocus: '', //红外相机聚焦
          infraredDistance: '', //红外线距离
          needFillLight: '', //是否开启补光灯
          hasObstacle: '', //是否有障碍
          recordVoiceSecond: '', //录音时间
          cycleTaskPicturePtzStepDegree: '', //循环拍照的步长
          cycleRangeDegree: '', //环测范围
          cycleIsClockwise: '', //环测旋转方向
          cyclePtzSpeed: '', //环测转动速度
          sceneList: '', //已设置阈值场景列表
          resourceList: [
            {
              id: '', //主键ID
              mapId: '', //地图ID
              naviId: '', //导航点ID
              positionId: '', //巡检点ID
              index: '', //序号
              type: '', //资源类型
              url: '', //资源路径
              createTime: '', //创建时间
            },
          ], //算法资源列表
          createTime: '', //创建时间
        },
      ],
      sceneList: [
        {
          id: '', //主键ID
          title: '', //场景名称
          desc: '', //描述
          editor: '', //编辑人
          createTime: '', //创建时间
        },
      ],
      taskList: [
        {
          //任务
          id: '', //主键ID
          periodicTaskId: '', //任务模板ID
          orgId: '', //组织ID
          robotId: '', //机器人Id
          robot: '', //机器人名称
          mapId: '', //地图ID
          map: '', //地图名称
          sceneId: '', //巡检场景ID
          scene: '', //场景名称
          title: '', //任务名称
          type: '', //任务类型
          taskFrom: '', //任务下发来源
          priority: '', //任务优先级
          exitOnPrior: '', //遇更高优先级任务提前终止
          finalJob: '', //任务完成后指令
          scheduleTime: '', //计划开始时间
          beginTime: '', //任务开始时间
          endTime: '', //任务结束时间
          state: '', //任务状态
          progress: '', //运行进度
          totalNumber: '', //须检测总数
          finishedNumber: '', //已检测总数
          defectNumber: '', //缺陷总数
          unrecognizeNumber: '', //未识别总数
          areaList: '', //关联区域列表
          positionList: '', //检测点列表
          nextPosition: '', //当前任务下一个检测点位
          editor: '', //编辑人
          createTime: '', //创建时间
        },
      ],
      patrolRecordList: [
        {
          id: '', //主键ID
          orgId: '', //组织ID
          robotId: '', //机器人ID
          robot: '', //机器人名称
          taskId: '', //任务ID
          task: '', //任务名称
          sceneId: '', //场景ID
          scene: '', //场景名称
          mapId: '', //地图ID
          map: '', //地图名称
          areaId: '', //区域ID
          area: '', //区域名称
          naviId: '', //导航点ID
          naviSequence: '', //导航点编号
          positionId: '', //巡检点ID
          indicatorId: '', //指标ID
          indicatorName: '', //指标名称
          categoryId: '', //指标类目ID
          categoryName: '', //指标类目名称
          recognizeId: '', //识别类型ID
          recognizeCode: '', //识别类型编码
          recognizeName: '', //识别类型名称
          unit: '', //单位
          index: '', //序号
          patrolTime: '', //巡检时间
          recognizeState: '', //识别状态
          thresholdId: '', //识别阈值ID
          defectGrade: '', //缺陷等级
          value: '', //检测值
          detail: '', //检测值明细
          adjustTime: '', //矫正时间
          recognizeTime: '', //识别时间
          modifiedGrade: '', //修正后等级
          defectReview: '', //缺陷追溯
          reviewMemo: '', //缺陷审核备注
          reviewState: '', //缺陷处理状态
          confirmTime: '', //缺陷确认时间
          reviewerId: '', //缺陷确认人ID
          reviewer: '', //缺陷确认人名
          solveTime: '', //缺陷解决时间
          solverId: '', //缺陷解决人ID
          solver: '', //缺陷解决人名
          guardLine: '', //警戒线
          resourceList: [
            {
              index: '', //序号
              type: '', //资源类型
              originUrl: '', //原始资源路径
              processedUrl: '', //已处理资源路径
            },
          ], //算法资源列表
          createTime: '', //创建时间
        },
      ],
      RobotRealtimeInfoList: [
        {
          id: '', //主键ID
          orgId: '', //组织ID
          robotId: '', //机器人ID
          robot: '', //机器人名称
          taskId: '', //任务ID
          task: '', //任务名称
          sceneId: '', //场景ID
          scene: '', //场景名称
          mapId: '', //地图ID
          map: '', //地图名称
          areaId: '', //区域ID
          area: '', //区域名称
          naviId: '', //导航点ID
          naviSequence: '', //导航点编号
          positionId: '', //巡检点ID
          indicatorId: '', //指标ID
          indicatorName: '', //指标名称
          categoryId: '', //指标类目ID
          categoryName: '', //指标类目名称
          recognizeId: '', //识别类型ID
          recognizeCode: '', //识别类型编码
          recognizeName: '', //识别类型名称
          unit: '', //单位
          index: '', //序号
          patrolTime: '', //巡检时间
          recognizeState: '', //识别状态
          thresholdId: '', //识别阈值ID
          defectGrade: '', //缺陷等级
          value: '', //检测值
          detail: '', //检测值明细
          adjustTime: '', //矫正时间
          recognizeTime: '', //识别时间
          modifiedGrade: '', //修正后等级
          defectReview: '', //缺陷追溯
          reviewMemo: '', //缺陷审核备注
          reviewState: '', //缺陷处理状态
          confirmTime: '', //缺陷确认时间
          reviewerId: '', //缺陷确认人ID
          reviewer: '', //缺陷确认人名
          solveTime: '', //缺陷解决时间
          solverId: '', //缺陷解决人ID
          solver: '', //缺陷解决人名
          guardLine: '', //警戒线
          resourceList: [
            {
              id: '', //主键ID
              orgId: '', //组织ID
              robotId: '', //机器人ID
              robot: '', //机器人名称
              mapId: '', //地图ID
              health: '', //机器人本体是否正常
              reportTime: '', //上报时间
              leftWheelSpeed: '', //左轮速度
              rightWheelSpeed: '', //右轮速度
              speed: '', //实时速度
              angularSpeed: '', //实时角速度
              cpuUsed: '', //CPU使用率
              memUsed: '', //内存使用率
              diskUsed: '', //磁盘使用率
              batteryRatio: '', //剩余电量比率
              batteryVolt: '', //当前电池电压
              batteryCurrent: '', //当前电池电流
              temperature: '', //舱内温度
              humidity: '', //舱内湿度
              mileage: '', //当前行驶里程
              rotation: '', //当前旋转角度
              direction: '', //当前行驶方向
              distance: '', //距原点距离
              laserDistance: '', //激光距离
              panRotateAngleH: '', //云台水平转动角度
              panRotateAngleV: '', //云台垂直转动角度
              visibleFocus: '', //可见光相机焦距
              visibleZoom: '', //可见光相机变焦
              infraredFocus: '', //红外相机焦距
              coordinateX: '', //横坐标
              coordinateY: '', //纵坐标
              yaw: '', //航向角
              longitude: '', //经度
              latitude: '', //维度
              controlSysState: '', //控制系统状态
              chargeSysState: '', //充电系统状态
              visibleCameraState: '', //可见光相机状态
              infraredCameraState: '', //红外相机状态
              panState: '', //云台状态
              bridgeState: '', //网桥状态
              laserObstacleState: '', //激光避障器状态
              mmwObstacleState: '', //毫米波避障器状态
              backObstacleState: '', //后置避障器状态
              pitObstacleState: '', //测坑避障器状态
              wiperState: '', //雨刷状态
              lightState: '', //补光灯状态
              recordState: '', //录音状态
              intercomState: '', //对讲机状态
              eStopState: '', //急停按钮状态
              runState: '', //机器人运行状态
              taskMode: '', //机器人任务执行模式
              createTime: '', //创建时间
            },
          ], //算法资源列表
          createTime: '', //创建时间
        },
      ],
      defectGradeList: [
        {
          value: 0,
          label: '正常',
        },
        {
          value: 1,
          label: '轻微',
        },
        {
          value: 2,
          label: '预警',
        },
        {
          value: 3,
          label: '严重',
        },
        {
          value: 4,
          label: '危及',
        },
        {
          value: -1,
          label: '未识别',
        },
      ],
      resourceList: [],
    }
  },
  created() {
    this.getOptions()
    // console.log(`${ROBOT}`)
    this.init().then((data) => {
      setTimeout(() => {
        this.getAreaOption()
        this.getRobotOption()
        this.getSenceOption()
        this.getRecognizeOption()
        this.getPositionOption()
        this.getTaskListOption()
        this.getPatrolRecordListOption()
      }, 500)
    })
  },
  methods: {
    getOptions() {
      Object.keys(this.optionsObj).forEach(async (key) => {
        if (key == 'FloorNo') return
        try {
          let res = await getOptions(key)
          if (res.code === 20000) this.optionsObj[key] = res.data.content
        } catch (error) {
          console.log(error)
        }
      })
    },
    async init() {
      try {
        let res = await getRobotToken(ROBOT)
        // console.log(res)
        if (res.code === 1) {
          this.robotToken = res.data
        }
      } catch (error) {}
    },
    async getAreaOption() {
      try {
        let res = await getAreaTree({ token: this.robotToken, id: '' })
        if (res.code === 1) {
          this.areaTree = {
            value: res.data.id,
            label: res.data.name,
            children: res.data.subList.map((a) => {
              return {
                value: a.id,
                label: a.name,
              }
            }),
          }
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
    async getRobotOption() {
      try {
        let res = await getRobotList({ token: this.robotToken, pageIndex: 1, pageSize: 100 })
        if (res.code === 1) {
          this.robotList = res.data.list.map((a) => {
            return {
              label: a.title,
              value: a.id,
            }
          })
          // console.log(this.robotList)
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
    async getSenceOption() {
      try {
        let res = await getSenceList({ token: this.robotToken, pageIndex: 1, pageSize: 100 })
        if (res.code === 1) {
          this.sceneList = res.data.map((a) => {
            return {
              label: a.title,
              value: a.id,
            }
          })
          // console.log(this.sceneList)
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
    async getPositionOption() {
      try {
        let res = await getPositionList({ token: this.robotToken, pageIndex: 1, pageSize: 100 })
        if (res.code === 1) {
          this.positionList = res.data.map((a) => {
            return {
              label: a.naviSequence,
              value: a.id,
            }
          })
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
    //
    async getRecognizeOption() {
      try {
        let res = await getRecognizeList({ token: this.robotToken, pageIndex: 1, pageSize: 100 })
        if (res.code === 1) {
          this.recognizeTypeList = res.data.map((a) => {
            return {
              label: a.name,
              value: a.id,
            }
          })
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
    //获取任务
    async getTaskListOption() {
      try {
        let res = await getTaskList({
          token: this.robotToken,
          pageIndex: 1,
          pageSize: 100,
        })
        if (res.code === 1) {
          this.taskList = res.data.list.map((a) => {
            return {
              label: a.name,
              value: a.id,
            }
          })
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
    //获取巡检记录
    async getPatrolRecordListOption() {
      try {
        let res = await getPatrolRecordList({
          token: this.robotToken,
          pageIndex: this.pageIndex,
          pageSize: this.pageSize,
        })
        if (res.code === 1) {
          this.patrolRecordList = res.data
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
    async getDictDOptions() {
      try {
        let res = await initData('system/dataDictDetail/getTypeListJson', {
          dictType: '151',
        })
        if (res.code === 20000) {
          this.defectGradeList = res.data.content
        }
      } catch (error) {
        console.log(error)
      }
    },
    //分页调整单页条数
    handleSizeChange(val) {
      this.pageSize = val
      this.searchPatrolRecord()
      // console.log(`每页 ${val} 条`)
    },
    //分页调整页码
    handleCurrentChange(val) {
      this.pageIndex = val
      this.searchPatrolRecord()
      // console.log(`当前页: ${val}`)
    },
    setTime() {
      console.log(this.timeRange)
      if (this.timeRange && this.timeRange.length > 1) {
        this.queryParams.minPatrolTime = this.timeRange[0]
        this.queryParams.maxPatrolTime = this.timeRange[1]
      }
    },
    //条件搜索巡检记录
    async searchPatrolRecord() {
      ;(this.queryParams.token = this.robotToken),
        (this.queryParams.pageIndex = this.pageIndex),
        (this.queryParams.pageSize = this.pageSize),
        console.log(this.queryParams)
      try {
        let res = await getPatrolRecordList({
          token: this.robotToken,
          pageIndex: this.pageIndex,
          pageSize: this.pageSize,
          idList: this.queryParams.idList ? this.queryParams.idList : null, //记录ID列表
          taskIdList: this.queryParams.taskIdList ? this.queryParams.taskIdList : null, //任务ID列表
          taskIdLike: this.queryParams.taskIdLike ? this.queryParams.taskIdLike : null, //任务ID模糊查询
          taskTitleLike: this.queryParams.taskTitleLike ? this.queryParams.taskTitleLike : null, //任务标题（模糊查询）
          robotId: this.queryParams.robotId ? this.queryParams.robotId : null, //机器人ID
          mapId: this.queryParams.mapId ? this.queryParams.mapId : null, //地图ID
          areaList: this.queryParams.areaList ? this.queryParams.areaList : null, //区域ID列表
          positionList: this.queryParams.positionList ? this.queryParams.positionList : null, //点位ID列表
          defectGradeList: this.queryParams.defectGradeList
            ? this.queryParams.defectGradeList
            : null, //缺陷等级
          recognizeIdList: this.queryParams.recognizeIdList
            ? this.queryParams.recognizeIdList
            : null, //识别类型列表
          indicatorNameLike: this.queryParams.indicatorNameLike
            ? this.queryParams.indicatorNameLike
            : null, //指标名称模糊查询
          minPatrolTime: this.queryParams.minPatrolTime ? this.queryParams.minPatrolTime : null, //最小巡检时间
          maxPatrolTime: this.queryParams.maxPatrolTime ? this.queryParams.maxPatrolTime : null, //最大巡检时间
        })
        if (res.code === 1) {
          this.patrolRecordList = res.data
        } else {
          this.getRobotToken()
        }
      } catch (error) {}
    },
  },
}
</script>

<style></style>
