<template>
<!-- 巡检任务 -->
  <basic-container>
    <avue-crud
      ref="crud"
      :data="data"
      id="avue-id"
      :option="option"
      :page.sync="listPage"
      :row-key="getRowKeys"
      :table-loading="loading"
      @row-del="rowDel"
      @row-save="rowSave"
      @search-reset="reset"
      @row-update="rowUpdate"
      @refresh-change="refresh"
      @search-change="searchChangeScope"
      @selection-change="selectionChange"
      @size-change="sizeChange"
      @current-change="currentChange"
    >
      <template slot="menuLeft">
        <el-form
          ref="searchForm"
          :model="searchForm"
          label-width="120px"
          style="border: 0px solid red; margin-bottom: 8px"
        >
          <el-row>
            <el-col :span="2.5">
              <el-select
                v-model="searchForm.taskStatus"
                class="search-select"
                placeholder="请选择任务状态"
              >
                <el-option label="待检" :value="0"></el-option>
                <el-option label="检中" :value="1"></el-option>
                <el-option label="结束" :value="2"></el-option>
                <el-option label="取消" :value="3"></el-option>
              </el-select>
            </el-col>
            <el-col :span="2.5">
              <el-select
                v-model="searchForm.groupId"
                class="search-select"
                placeholder="请选择巡检班组"
              >
                <el-option v-for="item in groupList" :key="item.id"  :label="item.fullName" :value="item.id"></el-option>
              </el-select>
            </el-col>
            <el-col :span="2.5">
              <el-input
                class="search-input"
                v-model="searchForm.taskCode"
                placeholder="请输入任务单据"
              ></el-input>
            </el-col>
            <el-col :span="2.5">
              <el-input
                class="search-input"
                v-model="searchForm.planName"
                placeholder="请输入巡检名称"
              ></el-input>
            </el-col>
            <el-col style="margin-left: 18px" :span="3.5">
              <el-button class="search" @click="searchHandle(0)"
                >查询</el-button
              >
              <el-button class="reset" @click="searchHandle(1)">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </template>
      <template slot-scope="{ type }" slot="menuForm">
        <el-button
          class="buttonOne"
          size="small"
          @click="$refs.crud.closeDialog()"
          >取 消</el-button
        >
        <el-button
          v-if="type == 'add'"
          class="buttonOne"
          size="small"
          @click="$refs.crud.rowSave()"
          >确 定</el-button
        >
        <el-button
          v-if="type == 'edit'"
          class="buttonOne"
          size="small"
          @click="$refs.crud.rowUpdate()"
          >修 改</el-button
        >
      </template>
      <!-- <template slot="menuRight">
        <el-button class="search" style="width: 120px" @click="handleAdd"
          >新建</el-button
        >
      </template> -->
      <template slot-scope="{ row }" slot="taskStatus">
        <span v-if="row.taskStatus == 0" style="color: #e56926">待检</span>
        <span v-if="row.taskStatus == 1" style="color: #1e62f6">检中</span>
        <span v-if="row.taskStatus == 2" style="color: #34c447">结束</span>
        <span v-if="row.taskStatus == 3" style="color: #999999">取消</span>
      </template>
      <template slot-scope="{ row }" slot="type">
        <span v-if="row.type === 1">类型1</span>
        <span v-if="row.type === 2">类型2</span>
      </template>
      <template slot-scope="{ row }" slot="device">
        <span>{{row.device | deviceName}}</span>
      </template>
      <template slot-scope="{ row, index }" slot="menu">
        <el-button @click="handleView(row, index)" class="look">查看</el-button>
        <el-button v-show="row.taskStatus == 0 || row.taskStatus == 1" @click="handleEdit(row, index)" class="look">编辑</el-button>
        <el-button v-show="row.taskStatus == 0" @click="handleDelete(row, index)" class="look">删除</el-button>
        <el-button v-show="row.taskStatus == 1"  @click="handleFinish(row, index)" class="look">完成</el-button>
        <el-button v-show="row.taskStatus == 0 || row.taskStatus == 1"  @click="handleCancel(row, index)" class="look">取消</el-button>
      </template>
    </avue-crud>
    <!-- 新增/编辑巡检任务 弹窗 -->
    <el-dialog
      :before-close="handleClose"
      :cell-style="tableCellStyle"
      :visible.sync="showAddDialog"
      :title="title"
      width="70%"
      :append-to-body="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      custom-class="planAdd_form"
    >
      <div style="height: 550px; overflow-y: auto; overflow-x: hidden">
        <el-form :model="addForm" :rules="addRules" ref="addForm">
          <div class="add_all">
            <h1
              style="
                font-size: 16px;
                font-weight: 500;
                color: rgba(0, 0, 0, 0.85);
                line-height: 20px;
              "
            >
              <span
                style="
                  border-left: 4px solid blue;
                  margin-top: -20px;
                  height: 15px;
                  display: inline-block;
                  transform: translateY(2px);
                "
              >
              </span
              >&ensp;<b>基本信息</b>
            </h1>
          </div>
          <el-row :gutter="20">
            <el-col :span="6" style="width: 31%; margin-left: 1%">
              <el-form-item label="巡检名称" prop="planName">
                <el-input
                  style="width: 98%"
                  v-model="addForm.planName"
                  placeholder="请输入巡检名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6" style="width: 31%; margin-left: 1%">
              <el-form-item label="计划单据" prop="taskCode">
                <el-input
                  style="width: 98%"
                  v-model="addForm.taskCode"
                  placeholder="请输入计划单据"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6" style="width: 31%; margin-left: 1%">
              <el-form-item label="巡检班组" prop="groupName">
                <el-input
                  style="width: 98%"
                  v-model="addForm.groupName"
                  placeholder="巡检班组"
                  disabled
                ></el-input>
              </el-form-item>
              <!-- <el-form-item label="巡检班组" prop="groupId">
                <el-select
                  v-model="addForm.groupId"
                  placeholder="请选择巡检班组"
                  style="width: 98%"
                >
                  <el-option v-for="item in groupList" :key="item.id"  :label="item.fullName" :value="item.id"></el-option>
                </el-select>
              </el-form-item> -->
            </el-col>
          </el-row>
          <el-row :gutter="20">
             <el-col :span="6" style="width: 31%; margin-left: 1%">
              <el-form-item label="实际开始" prop="actStartTime">
                <el-date-picker
                  v-model="addForm.actStartTime"
                  type="date"
                  placeholder="请选择实际开始"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  style="width: 98%"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6" style="width: 31%; margin-left: 1%">
              <el-form-item label="实际完成" prop="actFinishTime">
                <el-date-picker
                  v-model="addForm.actFinishTime"
                  type="date"
                  placeholder="请选择实际完成"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  style="width: 98%"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6" style="width: 31%; margin-left: 1%">
              <el-form-item label="完成用时(时)" prop="actTotalCost">
                <el-input-number style="width: 98%" controls-position="right" v-model="addForm.actTotalCost" :min="0" :precision="1" :step="1"></el-input-number>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col style="width: 90%; margin-left: 1%">
              <el-form-item label="任务反馈" prop="content">
                <el-input
                  style="width: 100%"
                  type="textarea"
                  v-model="addForm.content"
                  placeholder="请输入任务反馈"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col style="width: 90%; margin-left: 1%">
              <el-form-item label="备注" prop="notes">
                <el-input
                  style="width: 100%"
                  type="textarea"
                  v-model="addForm.notes"
                  placeholder="请输入备注"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="add_all">
            <h1
                style="
                font-size: 16px;
                font-weight: 500;
                color: rgba(0, 0, 0, 0.85);
                line-height: 20px;
                "
            >
                <span
                style="
                    border-left: 4px solid blue;
                    margin-top: -20px;
                    height: 15px;
                    display: inline-block;
                    transform: translateY(2px);
                "
                >
                </span
                >&ensp;<b>巡检计划</b>
            </h1>
            </div>
            <el-row :gutter="20">
                <!-- <el-col :span="6" style="width: 31%; margin-left: 1%">
                    <el-form-item label="预计用时(时)" prop="planCompletionTime">
                        <el-input-number style="width: 98%" controls-position="right" v-model="addForm.planCompletionTime" :min="0" :precision="1" :step="1"></el-input-number>
                    </el-form-item>
                </el-col> -->
                <el-col :span="6" style="width: 31%; margin-left: 1%">
                    <el-form-item label="巡检顺序" prop="planInspectionMethod">
                        <el-select
                        v-model="addForm.planInspectionMethod"
                        placeholder="请选择巡检顺序"
                        style="width: 98%"
                        >
                          <el-option label="顺序" :value="1"></el-option>
                          <el-option label="随机" :value="2"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                 <el-col :span="6" style="width: 31%; margin-left: 1%">
                    <el-form-item label="应开始时间" prop="planStartTime">
                        <el-date-picker
                        v-model="addForm.planStartTime"
                        type="date"
                        placeholder="请选择应开始时间"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        style="width: 98%"
                        >
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col style="width: 90%; margin-left: 1%">
                    <el-form-item label="巡检备注" prop="planNotes">
                        <el-input
                        style="width: 100%"
                        type="textarea"
                        v-model="addForm.planNotes"
                        placeholder="请输入巡检备注"
                        ></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div class="add_all">
          <h1
            style="
              font-size: 16px;
              font-weight: 500;
              color: rgba(0, 0, 0, 0.85);
              line-height: 20px;
            "
          >
            <span
              style="
                border-left: 4px solid blue;
                margin-top: -20px;
                height: 15px;
                display: inline-block;
                transform: translateY(2px);
              "
            >
            </span
            >&ensp;<b>巡检点</b>
          </h1>
        </div>
         <el-row :gutter="20">
          <el-table
            :data="addForm.orderList"
            :key="index"
            border
            style="
              margin-bottom: 30px;
              width: 92%;
              margin-left: 4%;
              border-radius: 4px;
            "
            header-cell-style="background-color:#fafafa;font-size:12px;color:black"
          >
            <el-table-column
              prop="pointStatus"
              label="巡检状态"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
              <div v-if="scope.row.pointStatus == 0">待检</div>
              <div v-if="scope.row.pointStatus == 1">正常</div>
              <div v-if="scope.row.pointStatus == 2">异常</div>
              <div v-if="scope.row.pointStatus == 3">不巡检</div>
            </template>
            </el-table-column>
            <!-- <el-table-column
              prop="people"
              label="操作人"
              show-overflow-tooltip
            ></el-table-column> -->
            <el-table-column
              prop="content"
              label="巡检结果"
              show-overflow-tooltip
            ></el-table-column>
            <!-- <el-table-column
              prop="time"
              label="操作时间"
              show-overflow-tooltip
            ></el-table-column> -->
            <el-table-column
              prop="pointCode"
              label="巡检编码"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="pointName"
              label="巡检点"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="pointContent"
              label="巡检内容"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="pointPos"
              label="位置"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="pointNotes"
              label="巡检点备注"
              show-overflow-tooltip
            ></el-table-column>
            <!-- <el-table-column
              prop="itemCount"
              label="检查项数"
              show-overflow-tooltip
            ></el-table-column> -->
            <el-table-column
              fixed="right"
              align="left"
              header-align="left"
              label="操作"
              width="200px"
            >
              <template slot-scope="scope">
                <el-button
                  class="look"
                  size="mini"
                  @click="handleExecute(scope.row)"
                  >执行</el-button
                >
                <el-button
                  class="look"
                  size="mini"
                  @click="handleViewCheck(scope.row)"
                  >检查项</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showAddDialog = false">取 消</el-button>
        <el-button @click="handleSubmit()">提 交</el-button>
      </span>
    </el-dialog>
     <!-- 查看巡检任务详情 弹窗 -->
    <el-dialog
      :before-close="handleClose"
      :cell-style="tableCellStyle"
      :visible.sync="showTaskDialog"
      title="查看巡检任务"
      width="70%"
      :append-to-body="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div style="height: 550px; overflow-y: auto; overflow-x: hidden">
        <div class="add_all">
          <h1
            style="
              font-size: 16px;
              font-weight: 500;
              color: rgba(0, 0, 0, 0.85);
              line-height: 20px;
            "
          >
            <span
              style="
                border-left: 4px solid blue;
                margin-top: -20px;
                height: 15px;
                display: inline-block;
                transform: translateY(2px);
              "
            >
            </span
            >&ensp;<b>基本信息</b>
          </h1>
        </div>
        <el-descriptions :column="3" border direction="vertical">
            <el-descriptions-item span="1" label="巡检名称">{{taskForm.planName}}</el-descriptions-item>
            <el-descriptions-item span="1" label="计划单据">{{taskForm.taskCode}}</el-descriptions-item>
            <el-descriptions-item span="1" label="巡检班组">
                {{taskForm.groupName}}
            </el-descriptions-item>
            <el-descriptions-item span="1" label="实际开始">{{taskForm.actStartTime}}</el-descriptions-item>
            <el-descriptions-item span="1" label="实际完成">{{taskForm.actFinishTime}}</el-descriptions-item>
            <el-descriptions-item span="2" label="完成用时(时)">{{taskForm.actTotalCost}}</el-descriptions-item>
            <el-descriptions-item span="3" label="任务反馈">{{taskForm.content}}</el-descriptions-item>
            <el-descriptions-item span="3" label="备注">{{taskForm.notes}}</el-descriptions-item>
        </el-descriptions>
        <div class="add_all">
          <h1
            style="
              font-size: 16px;
              font-weight: 500;
              color: rgba(0, 0, 0, 0.85);
              line-height: 20px;
            "
          >
            <span
              style="
                border-left: 4px solid blue;
                margin-top: -20px;
                height: 15px;
                display: inline-block;
                transform: translateY(2px);
              "
            >
            </span
            >&ensp;<b>巡检计划</b>
          </h1>
        </div>
        <el-descriptions :column="3" border direction="vertical">
            <el-descriptions-item span="1" label="巡检顺序">{{taskForm.planInspectionMethod == 1 ? '顺序' : taskForm.planInspectionMethod == 2 ? '随机' : ''}}</el-descriptions-item>
            <el-descriptions-item span="1" label="应开始时间">{{taskForm.planStartTime}}</el-descriptions-item>
            <el-descriptions-item span="3" label="巡检备注">{{taskForm.planNotes}}</el-descriptions-item>
        </el-descriptions>
        <div class="add_all">
          <h1
            style="
              font-size: 16px;
              font-weight: 500;
              color: rgba(0, 0, 0, 0.85);
              line-height: 20px;
            "
          >
            <span
              style="
                border-left: 4px solid blue;
                margin-top: -20px;
                height: 15px;
                display: inline-block;
                transform: translateY(2px);
              "
            >
            </span
            >&ensp;<b>巡检点</b>
          </h1>
        </div>
        <el-row :gutter="20">
          <el-table
            :data="taskForm.orderList"
            :key="index"
            border
            style="
              margin-bottom: 30px;
              width: 92%;
              margin-left: 4%;
              border-radius: 4px;
            "
            header-cell-style="background-color:#fafafa;font-size:12px;color:black"
          >
            <el-table-column
              prop="pointStatus"
              label="巡检状态"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
              <div v-if="scope.row.pointStatus == 0">待检</div>
              <div v-if="scope.row.pointStatus == 1">正常</div>
              <div v-if="scope.row.pointStatus == 2">异常</div>
              <div v-if="scope.row.pointStatus == 3">不巡检</div>
            </template>
            </el-table-column>
            <!-- <el-table-column
              prop="people"
              label="操作人"
              show-overflow-tooltip
            ></el-table-column> -->
            <el-table-column
              prop="content"
              label="巡检结果"
              show-overflow-tooltip
            ></el-table-column>
            <!-- <el-table-column
              prop="time"
              label="操作时间"
              show-overflow-tooltip
            ></el-table-column> -->
            <el-table-column
              prop="pointCode"
              label="巡检编码"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="pointName"
              label="巡检点"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="pointContent"
              label="巡检内容"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="pointPos"
              label="位置"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="pointNotes"
              label="巡检点备注"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              fixed="right"
              align="left"
              header-align="left"
              label="操作"
              width="100px"
            >
              <template slot-scope="scope">
                <el-button
                  class="look"
                  size="mini"
                  @click="handleViewCheck(scope.row)"
                  >检查项</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </div>
    </el-dialog>
     <!-- 查看巡检检查项 弹窗 -->
     <el-dialog
      :before-close="handleClose"
      :cell-style="tableCellStyle"
      :visible.sync="showCheckProDialog"
      height="160vh"
      max-height="480"
      title="查看检查项"
      width="60%"
      :append-to-body="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div style="height: 550px; overflow-y: auto; overflow-x: hidden">
        <!-- 查询区-->
        <!--<el-form
          ref="proForm"
          :model="proForm"
          label-width="120px"
          style="border: 0px solid red; margin-bottom: 8px"
        >
          <el-row>
            <el-col :span="2.5">
              <el-input
                class="search-input"
                v-model="proForm.code"
                placeholder="请输入检查项编码"
                clearable
              ></el-input>
            </el-col>
            <el-col :span="2.5">
              <el-input
                class="search-input"
                clearable
                v-model="proForm.name"
                placeholder="请输入检查项"
              ></el-input>
            </el-col>
            <el-col style="margin-left: 18px" :span="3.5">
              <el-button class="search" @click="searchCheck()">查询</el-button>
            </el-col>
          </el-row>
        </el-form> -->
        <!-- 表格区 -->
        <el-table
          ref="maintainTable"
          :data="checkTableData"
          :row-style="{ height: '66px' }"
          :header-cell-style="{
            background: '#f6f8fa',
            color: '#999999',
            fontWeight: '400',
            height: '66px',
          }"
          :row-key="getRowKey"
          tooltip-effect="dark"
          style="width: 100%; color: #333333"
          v-loading="loading"
        >
          <el-table-column fixed type="selection" :reserve-selection="true" width="50"></el-table-column>
          <el-table-column
            align="left"
            prop="name"
            label="检查项"
            show-overflow-tooltip
          />
          <el-table-column
            align="left"
            prop="code"
            label="检查项编码"
            show-overflow-tooltip
          />
          <!-- applyStatus:0-暂存 1-提交 2-审批通过 3-审批驳回 4-完成 -->
          <el-table-column align="left" prop="checkDesc" width="120" label="检查项描述">
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <!-- <el-row
          :gutter="20"
          id="avue-id"
          style="margin-top: 40px; margin-bottom: 20px"
        >
          <el-col :span="12" :offset="8"
            ><div class="grid-content bg-purple">
              <div class="block">
                <el-pagination
                  :current-page="checkPage[0].current"
                  :page-sizes="[10, 20, 30, 50, 100]"
                  :page-size="10"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="this.checkTotal"
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                />
              </div>
            </div>
          </el-col>
        </el-row> -->
      </div>
    </el-dialog>
    <!-- 巡检点执行 弹窗 -->
    <el-dialog
      :before-close="handleClose"
      :cell-style="tableCellStyle"
      :visible.sync="showExecuteDialog"
      title="巡检点巡检"
      width="50%"
      :append-to-body="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      custom-class="planAdd_form"
    >
        <div style="height: 550px; overflow-y: auto; overflow-x: hidden">
            <el-form :model="executeForm" :rules="addRules" ref="executeForm">
                <el-row :gutter="20">
                    <el-col :span="6" style="width: 31%; margin-left: 1%">
                        <el-form-item label="巡检状态" prop="pointStatus">
                            <el-select
                            v-model="executeForm.pointStatus"
                            placeholder="请选择巡检状态"
                            style="width: 98%"
                            >
                                <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col style="width: 90%; margin-left: 1%">
                        <el-form-item label="巡检结果" prop="content">
                            <el-input
                            style="width: 100%"
                            type="textarea"
                            v-model="executeForm.content"
                            placeholder="请输入巡检结果"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col style="width: 90%; margin-left: 1%">
                        <el-form-item label="图片" prop="images">
                            <el-upload
                              :headers="headers"
                              action="/api/blade-lims/inspectionTaskPoint/uploadFile"
                              :on-success="handleSuccess"
                              :on-remove="handleRemove"
                              :limit="1"
                              :file-list="fileList"
                              list-type="picture-card">
                              <i class="el-icon-plus"></i>
                            </el-upload>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="showExecuteDialog = false">取 消</el-button>
            <el-button @click="handleSubmitExec">提 交</el-button>
        </span>
    </el-dialog>
  </basic-container>
</template>

<script>
import {getTaskList,saveInsTask,getInsTaskDetail,submitExecute,completeInsTask,deleteInsTask,cancelInsTask} from "@/api/inspection/insTask"
import {getPointDetail} from "@/api/inspection/setting/point"
import {getCheckList} from "@/api/inspection/setting/check"
import {getGroup} from "@/api/inspection/plan"
import { getToken } from "@/util/auth";
let that;
export default {
  data() {
    return {
      showAddDialog: false,
      showTaskDialog:false,
      showExecuteDialog:false,
      showCheckProDialog:false,
      proForm:{},
      addForm: {
        orderList: [],
      },
      currentId:'',
       // 图片
      headers: {
        "Blade-Auth": "",
      }, //认证
      imgList:[],
      fileList:[],
      searchForm: {
        name: null,
        status: null,
        type: null,
        code: null,
      },
      executeForm:{},
      option: {
        searchMenuSpan: 8,
        selection: true,
        index: true,
        delBtn: false,
        editBtn: false,
        labelSuffix: " ", //控制标题后缀
        labelWidth: 120,
        gutter: 20, //设置input的大小
        expandLevel: 3,
        headerAlign: "left",
        menuWidth: 450,
        align: "left",
        menuPosition: "left",
        tree: true,
        menuBtn: false,
        submitBtn: true,
        emptyBtn: false,
        addBtn: false,
        searchBtn: false,
        columnBtn: false,
        refreshBtn: false,
        tip: false,
        border: false,
        saveBtn: false,
        cancelBtn: false,
        dialogWidth: 920,
        updateBtn: false,
        labelPosition: "top",
        dialogCustomClass: "custom",
        indexLabel: "序号",
        column: [
          {
            label: "任务单据",
            prop: "taskCode",
            overHidden: true,
            align: "left",
            width:"200"
          },
          {
            label: "巡检名称",
            prop: "planName",
            overHidden: true,
            align: "left",
            width:"200"
          },
          {
            label: "任务状态",
            prop: "taskStatus",
            slot: true,
            align: "left",
            width:"200",
            overHidden: true,
          },
          {
            label: "巡检点数(总数)",
            prop: "pointCount",
            overHidden: true,
            align: "left",
            width:"200"
          },
          {
            label: "巡检点数(待检)",
            prop: "unPointCount",
            overHidden: true,
            align: "left",
            width:"200"
          },
          {
            label: "巡检点数(正常)",
            overHidden: true,
            prop: "pointNormalCount",
            align: "left",
            width:"120"
          },
          {
            label: "巡检点数(异常)",
            overHidden: true,
            prop: "pointAbnormalCount",
            align: "left",
          },
        ],
      },
      data: [],
      checkPage:[
        {
          size: 10,
          current: 1,
          total: 2,
        },
      ],
      checkTotal:0,
      listPage:{
        current: 1, //当前第几页
        total: 0, //总页数
        size: 10, //每一页加载多少数据
      },
      loading:false,
      addRules:{
        planName:[{required:true,message:'请输入巡检名称',trigger:'blur'}],
        groupId:[{required:true,message:'请选择保养班组',trigger:'blur'}],
      },
      groupList:[],
      title:'',
      statusList:[
        {label:'待检',value:0},
        {label:'正常',value:1},
        {label:'异常',value:2},
        {label:'不巡检',value:3},
      ],
      taskForm:{},
      checkTableData:[]
    };
  },
  beforeCreate() {
    that = this
  },
  created() {
    this.headers["Blade-Auth"] = getToken();
    getGroup().then(res =>{
      this.groupList = res.data.data
    })
    this.onLoad();
  },
  filters: {
    groupName:(data) => {
       for (const i in that.groupList) {
        const element = that.groupList[i];
        if (data == element.id) {
          return element.fullName;
        }
      }
    }
  },
  methods: {
    getRowKey(row) {
      return row.id;
    },
    // 查询 0搜索 1重置
    searchHandle(val) {
      if (val == 0) {
        this.onLoad();
      } else {
        this.searchForm = {
          status: null,
          name: null,
          code: null,
          type: null,
        };
        this.onLoad();
      }
    },
    // 图片上传成功
    handleSuccess(response,file,fileList){
      this.imgList.push(response.data)
      this.fileList.push({url:response.data})
    },
    // 删除图片
    handleRemove(file, fileList){
      if(file.status == "success"){
        this.imgList = this.imgList.filter(item => item != file.url)
        this.fileList = this.imgList.filter(item => item.url != file.url)
      }
    },
    // 按照条数查询检查项
    handleSizeChange(val){
       this.checkPage[0].size = val
       this.searchCheck()
    },
    // 分页查询保养项目
    handleCurrentChange(val){
      this.checkPage[0].current = val;
       this.searchCheck()
    },
    // 查询数据
    onLoad() {
      this.loading = true
      getTaskList({current:this.listPage.current,size:this.listPage.size,...this.searchForm}).then(res =>{
        this.data = res.data.data.records
        this.listPage.total = res.data.data.total
        this.loading = false
      })
    },
    // 查看
    handleView(row, index) {
        getInsTaskDetail(row.id).then(res =>{
          console.log('res =====>',res)
          this.taskForm = res.data.data
          this.taskForm.orderList = res.data.data.taskPointList
          this.showTaskDialog = true
        })
    },
    // 编辑巡检任务保存
    handleSubmit() {
      this.$refs['addForm'].validate((valid) => {
        if(valid){
          console.log("row ========>", this.addForm);
              saveInsTask(this.addForm).then(res =>{
                if(res.data.code == 200){
                  this.$message.success('修改成功')
                  this.showAddDialog = false
                  this.listPage.current = 1
                  this.onLoad()
                }
              })
         
        }
      })
    },
    // 巡检任务列表分页
    currentChange(currentPage) {
      this.listPage.current = currentPage;
      this.onLoad();
    },
    // 巡检任务列表条数
    sizeChange(pageSize) {
      this.listPage.size = pageSize;
      this.onLoad();
    },
    // 打开巡检任务编辑弹窗
    handleEdit(row, index) {
      this.currentId = row.id
      getInsTaskDetail(row.id).then(res =>{
        console.log('res =====>',res)
        this.addForm = res.data.data
        this.addForm.orderList = res.data.data.taskPointList
        this.addForm.planInspectionMethod = Number(this.addForm.planInspectionMethod)
        this.showAddDialog = true
      })
    },
    // 执行
    handleExecute(row,index){
      console.log('执行=======>',row)
      this.executeForm = {
        id:row.id,
        taskId:row.taskId,
        pointStatus:Number(row.pointStatus),
        content:row.content,
        imageId:null
      }
      this.showExecuteDialog = true
    },
    // 执行提交
    handleSubmitExec(){
      this.executeForm.imageId = this.imgList.length != 0 ? this.imgList[0] : null
      console.log('row =======>',this.executeForm)
      submitExecute(this.executeForm).then(res =>{
        if(res.data.code == 200){
          getInsTaskDetail(this.currentId).then(res =>{
            this.addForm = res.data.data
            this.addForm.orderList = res.data.data.taskPointList
            this.addForm.planInspectionMethod = Number(this.addForm.planInspectionMethod)
            this.showExecuteDialog = false
            this.onLoad()
            this.$message.success('执行成功')
          })
        }
      })
    },
    // 查看检查项
    handleViewCheck(row){
      getPointDetail(row.pointId).then(res =>{
        console.log('检查项===>',res)
        this.checkTableData = res.data.data.checkItemList
        this.showCheckProDialog = true
      })
    },
    // 查询检查项
    searchCheck(){
      console.log('pro ====>',this.proForm)
      getCheckList({current:this.checkPage[0].current,size:this.checkPage[0].size,...this.proForm}).then(res =>{
        console.log('pros ====>',res)
        this.checkTableData = res.data.data.records
        this.checkTotal = res.data.data.total
      })
    },
    // 删除巡检任务
    handleDelete(row,index){
      this.$confirm("确定删除此巡检任务吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteInsTask(row.id).then(res =>{
          if(res.data.code == 200){
            this.$message.success('删除成功')
            this.onLoad()
          }
        })
      })
    },
    // 完成巡检任务
    handleFinish(row){
      this.$confirm("确定完成此巡检任务吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        completeInsTask(row.id).then(res =>{
          if(res.data.code == 200){
            this.$message.success('任务完成')
            this.onLoad()
          }
        })
      })
    },

    // 取消巡检任务
    handleCancel(row){
      this.$confirm("确定取消此巡检任务吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        cancelInsTask(row.id).then(res =>{
          if(res.data.code == 200){
            this.$message.success('取消成功')
            this.onLoad()
          }
        })
      })
    }
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-table td.el-table__cell,
.el-table th.el-table__cell.is-leaf {
  border-bottom: 1px solid #f0f3f7;
}
::v-deep .el-table .el-table__cell.is-center {
  text-align: left;
}
::v-deep .avue-crud .el-table th {
  color: #999999;
  font-weight: 400;
  background: #f6f8fa;
  height: 66px;
}
::v-deep .avue-crud .el-table td {
  height: 66px;
  color: #333333;
}
::v-deep .el-table .el-table__cell.is-center {
  text-align: left;
}
::v-deep .el-table__row .el-button--default,
.el-table__row .el-button--text {
  background-color: #fff !important;
}
// 按钮样式
::v-deep .el-table__row .el-button--default,
.el-table__row .el-button--text {
  background-color: #fff !important;
  width: 70px;
  height: 36px;
  border-radius: 0;
  padding: 10px;
  border-color: #e4e7ec;
  color: #333333;
}
// /deep/ .avue-crud__pagination {
//   height: 30px;
//   padding-top: 30px;
//   padding-bottom: 30px;
// }
.search-input {
  width: 255px;
  height: 46px;
  margin-left: 10px;
  /deep/ .el-input__inner {
    width: 255px;
    height: 46px;
  }
}
.search {
  color: #fff;
  background-color: #1e60f5;
  border-color: #1e60f5;
  height: 46px;
  width: 100px;
  border-radius: 0px;
  // margin-left:18px!important;
  margin-right: 0 !important;
}
// 重置按钮
.reset {
  color: #999999;
  background-color: #fff;
  border-color: #e4e7ec;
  height: 46px;
  width: 100px;
  margin-left: 18px !important;
  border-radius: 0px;
}
.search-picker {
  width: 240px;
  height: 46px;
  border-radius: 0;
  margin-left: 10px;
}
.search-select {
  width: 240px !important;
  height: 46px;
  border-radius: 0;
  margin-left: 10px;
  /deep/ .el-input__inner {
    width: 240px;
    height: 46px;
  }
}
.search_select {
  width: 150px !important;
  height: 46px;
  border-radius: 0;
  margin-left: 10px;
  /deep/ .el-input__inner {
    width: 150px;
    height: 46px;
  }
}
// 新增取消确定
.buttonOne {
  color: #999999;
  background-color: #fff;
  border-color: #e4e7ec;
  height: 46px;
  width: 100px;
  border-radius: 0px;
  margin-left: 20px;
}
.buttonOne:hover {
  color: #fff;
  background-color: #1e60f5;
  border-color: #1e60f5;
  height: 46px;
  width: 100px;
  border-radius: 0px;
  margin-left: 20px;
}
// 分页
::v-deep .el-pagination .el-select .el-input .el-input__inner {
  height: 20px;
}

 
</style>
<style lang="scss">
     /*选择日期，年份的隐藏 */
  .picker-dateNoneYear {
    .el-date-picker__header {
      span:nth-child(3) { /*第三个标签是span的标签，把它隐藏*/
        display: none;
      }
      button:nth-child(1) {
        display: none;
      }
      button:nth-child(5) {
        display: none;  
      }
    }
  }
</style>
