<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="计划名称" prop="planName" v-if="!visibleSelect">
        <el-input

          v-model="queryParams.planName"
          placeholder="请输入计划名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资柜" prop="cabinetId">
        <el-select
          v-model="queryParams.cabinetId"
          placeholder="请选择需要检查的物资柜"
          clearable
          :disabled="visibleSelect"
        >
          <el-option
            v-for="dict in cabinets"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="计划日期">
        <el-date-picker
          style="width: 300px"
          :default-time="['00:00:00', '23:59:59']"
          v-model="createTime"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
          @change="handleClearTime"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="检察员" prop="checkUserName">
        <el-select
          v-model="queryParams.checkUserName"
          placeholder="请选择检察员"
          clearable
        >
          <el-option
            v-for="dict in planPersonOption"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="状态">
          <el-option
            v-for="dict in dict.type.checking_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          v-no-more-click
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button>
        <el-button
          v-no-more-click
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
        >重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-no-more-click
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['iscs:plan:add']"
        >新增
        </el-button>
      </el-col>
      <!--       <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-no-more-click-->
      <!--          type="danger"-->
      <!--          plain-->
      <!--          icon="el-icon-delete"-->
      <!--          size="mini"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--          v-hasPermi="['iscs:plan:remove']"-->
      <!--          >批量删除-->
      <!--        </el-button>-->
      <!--      </el-col>-->

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <!--    自动配置检查计划开始-->
    <el-row :gutter="10" class="mb8">
      <el-form label-width="70px">
        <el-col :span="2" style="margin-top: 8px">
          <el-checkbox style="transform: scale(1.5);" v-model="autoConfig.startStatus" @change="handleClickStatus"
          ></el-checkbox>
          <span style="margin-left: 6%;">启动自动创建</span>
        </el-col>
        <el-col :span="4">
          <el-form-item label="计划频率">
            <el-select
              :disabled="!autoConfig.startStatus"
              v-model="autoConfig.planFrequency"
              placeholder="请选择计划频率"
              clearable
              @change="handleFrequencyChange"
            >
              <el-option
                label="月"
                value="月"
              />
              <el-option
                label="周"
                value="周"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="计划日期">
            <el-select
              :disabled="!autoConfig.startStatus"
              v-model="autoConfig.planDate"
              placeholder="请选择计划日期"
              clearable
              @change="handleClickAuto"
            >
              <el-option
                v-for="option in planDateOptions"
                :key="option.value"
                :label="option.label"
                :value="option.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5.5">
          <el-form-item label="检察员">
            <el-select
              :disabled="!autoConfig.startStatus"
              v-model="autoConfig.checkUserId"
              placeholder="请选择检察员"
              clearable
              @change="handleClickAuto"
            >
              <el-option
                v-for="dict in planPersonOption"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5.5 " style="margin-top: 8px">
          <span>(*自动创建的检查计划，覆盖所有物资柜)</span>
        </el-col>
      </el-form>

    </el-row>
    <!--    自动配置检查计划结束-->
    <el-table
      v-loading="loading"
      :data="PlanList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="计划编号" align="center" prop="planId">
      </el-table-column>
      <el-table-column label="计划名称" align="center" prop="planName">
      </el-table-column>
      <el-table-column label="物资柜" align="center" prop="cabinetName">
        <template slot-scope="scope">
          <el-tooltip :content="scope.row.cabinetName" placement="top">
            <span style="color:#1890ff;cursor: pointer" @click="PlanDetail(scope.row)"
            >{{ getDisplayText(scope.row.cabinetName) }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="计划日期" align="center" prop="planDate">
        <template slot-scope="scope">
          {{ scope.row.planDate }}
        </template>
      </el-table-column>
      <el-table-column label="检察员" align="center" prop="checkUserName">
        <template slot-scope="scope">
          {{ scope.row.checkUserName }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.checking_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column label="检查记录" align="center" prop="status">
        <template slot-scope="scope">
          <el-button type="text" @click="goto(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.status=='1'"
            v-no-more-click
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['iscs:plan:query']"
          >修改
          </el-button>

          <el-button
            v-no-more-click
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['iscs:plan:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
    <!-- 添加或修改班组对话框 -->
    <el-dialog :visible.sync="open" width="500px" append-to-body>
      <div slot="title" class="dialog-title">
        <i></i>
        <span class="title">{{ title }}</span>
      </div>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="计划名称" prop="planName">
          <el-input v-model="form.planName" placeholder="请输入计划名称"/>
        </el-form-item>
        <el-form-item label="所属区域" prop="workstationId">
          <treeselect style="width: 348px" v-model="form.workstationId" :options="workstationOption"
                      :normalizer="normalizer" placeholder="选择所属区域"
          />
        </el-form-item>
        <el-form-item label="物资柜" prop="cabinetIds">
          <el-select
            :disabled="visibleSelect"
            style="width: 348px"
            v-model="form.cabinetIds"
            placeholder="请选择需要检查的物资柜"
            multiple
            clearable
          >
            <el-option
              v-for="dict in cabinets"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="计划日期" prop="planDate">
          <el-date-picker
            style="width: 350px"
            v-model="form.planDate"
            placeholder="请选择日期"
            :picker-options="FormpickerOptions"
            align="right"
          >
          </el-date-picker>
        </el-form-item>


        <el-form-item label="检察员" prop="checkUserId">
          <el-select
            style="width: 348px"
            v-model="form.checkUserId"
            placeholder="请选择检察员"
            clearable
          >
            <el-option
              v-for="dict in planPersonOption"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button v-no-more-click type="primary" @click="submitForm"
        >确 定
        </el-button>
        <el-button v-no-more-click @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--    签名弹窗-->
    <el-dialog :visible.sync="openTable" width="800px" append-to-body>
      <div slot="title" class="dialog-title">
        <i></i>
        <span class="title">巡检物资柜详情</span>
      </div>
      <el-table v-loading="loading" :data="PlanDetailTableList">
        <el-table-column label="计划名称" align="center" prop="planName">
        </el-table-column>
        <el-table-column label="巡检物资柜" align="center" prop="cabinetName">
        </el-table-column>
        <el-table-column label="签名" align="left" prop="signatureImg">
          <template slot-scope="scope">
            <div class="img-box" v-if="scope.row.signatureImg">
              <el-image
                style="width: 50px; height: 50px"
                :preview-teleported="true"
                class="images"
                :hide-on-click-modal=true
                :src="scope.row.signatureImg"
                :zoom-rate="1.2"
                :preview-src-list="[scope.row.signatureImg]"
                :initial-index="1"
                fit="cover"
              >
              </el-image>
              <i class="el-icon-zoom-in" id="eyeicon"></i>
            </div>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="left" prop="">
          <template slot-scope="scope">
            <el-button type="text" @click="PlanDialogDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button v-no-more-click @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
    <!--  签名详情弹窗-->
    <el-dialog :visible.sync="openRecord" width="1500px" append-to-body>
      <div slot="title" class="dialog-title">
        <i></i>
        <span class="title">物资柜检查记录</span>
      </div>
      <el-table v-loading="loading" :data="RecordList">
        <el-table-column label="计划名称" align="center" prop="planName" width="200">
          <template slot-scope="scope">
            {{ scope.row.planName }}
          </template>
        </el-table-column>
        <el-table-column label="物资柜" align="center" prop="cabinetName">
        </el-table-column>
        <el-table-column label="物资编号" align="center" prop="materialsId">
        </el-table-column>
        <el-table-column label="物资名称" align="center" prop="materialsName"/>
        <el-table-column label="物资类型" align="center" prop="materialsTypeName"/>
        <el-table-column
          label="物资图片"
          align="center"
          prop="materialsTypePicture"
        >
          <template slot-scope="scope">
            <img
              v-if="scope.row.materialsTypePicture"
              :src="scope.row.materialsTypePicture"
              alt=""
              style="width: 50px; height: 50px"
            />
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="RFID" align="center" prop="materialsRfid">
        </el-table-column>
        <el-table-column
          label="检查时间"
          align="center"
          prop="createTime"
          width="250"
        >
          <template slot-scope="scope">
            {{ scope.row.createTime }}
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.checks_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="异常原因" align="center" prop="reason">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.exceptions_status" :value="scope.row.reason"/>
          </template>
        </el-table-column>

      </el-table>
      <pagination
        v-show="recordtotal > 0"
        :total="recordtotal"
        :page.sync="recordCurrent"
        :limit.sync="recordSize"
        @pagination="handlePagination"
      />
      <div slot="footer" class="dialog-footer">
        <el-button v-no-more-click @click="cancelDetail">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {
  listPlan,
  addPlan,
  deletePlan,
  updatePlan,
  selectPlanById, getCheckPlanCabinetList, updateAutomaticConfig, selectIsMailNotifyConfigByCode
} from '@/api/mes/material/plan'
import Crontab from '@/components/Crontab/index.vue'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { listMarsDept } from '@/api/system/marsdept'
import { getIsMaterialsCabinets, listMaterials } from '@/api/mes/material/information'
import { listUser } from '@/api/system/user'
import Template from '@/views/print/printtemplate/list.vue'
import { listCheckRecord } from '@/api/mes/material/checkRecord'

export default {
  name: 'Team',
  components: { Template, Treeselect, Crontab },
  props: {
    cabinetId: {
      type: String,
      required: false
    }
  },
  dicts: ['material_status', 'checking_status', 'checks_status', 'exceptions_status'],
  data() {
    return {
      //自动生成编码
      autoGenFlag: false,
      // 自动配置检查计划数据项
      autoConfig: {
        planFrequency: null,
        planDate: null,
        checkUserId: null,
        startStatus: null,
        templateCode: 'CHECK_PLAN'
      },
      optType: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      codes: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      recordtotal: 0,//签名详情渲染
      recordCurrent: 1,//签名列表页面
      recordSize: 10,
      // 班组表格数据
      PlanList: [],
      PlanDetailTableList: [],
      // 检查记录表格数据
      RecordList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openTable: false,//巡检物资柜详情
      openRecord: false,//签名弹框详情再打开
      RecordselectedRow: null,//保证签名详情列表分页切换查询数据还在
      // 查询参数
      createTime: '',
      queryParams: {
        current: 1,
        size: 10,
        checkUserName: '',
        planName: '',
        cabinetId: '',
        startTime: null,
        endTime: null,
        status: ''
      },
      // 表单参数
      form: {
        cabinetIds: ''
      },
      cabinets: [], //物资所属柜
      planPersonOption: [], // 检查人员
      workstationOption: [],//所属岗位
      // 表单校验
      rules: {
        planDate: [
          { required: true, message: '日期不能为空', trigger: 'blur' }
        ],
        planName: [
          { required: true, message: '计划名称不能为空', trigger: 'blur' }
        ],
        checkUserId: [
          { required: true, message: '检察员不能为空', trigger: 'blur' }
        ],
        cabinetIds: [
          { required: true, message: '物资柜不能为空', trigger: 'blur' }
        ]
      },
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      FormpickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        },
        // shortcuts: [
        //   {
        //     text: '最近一周',
        //     onClick(picker) {
        //       const end = new Date()
        //       const start = new Date()
        //       start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
        //       picker.$emit('pick', [start, end])
        //     }
        //   },
        //   {
        //     text: '最近一个月',
        //     onClick(picker) {
        //       const end = new Date()
        //       const start = new Date()
        //       start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
        //       picker.$emit('pick', [start, end])
        //     }
        //   },
        //   {
        //     text: '最近三个月',
        //     onClick(picker) {
        //       const end = new Date()
        //       const start = new Date()
        //       start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
        //       picker.$emit('pick', [start, end])
        //     }
        //   }
        // ]
      },
      visibleSelect: false,//控制查询
      planDateOptions: null
    }
  },
  watch: {
    'form.workstationId': function(newVal, oldVal) {
      if (newVal) {
        console.log(newVal, 'gangwei ')
        const data = {
          current: 1,
          size: -1,
          workstationId: newVal
        }
        getIsMaterialsCabinets(data).then((response) => {
          console.log(response, 'wgahah')
          if (response.data.records) {
            this.form.cabinetIds = response.data.records.map((item) => item.cabinetId)
            console.log(this.form.cabinetIds, 'this.form.cabinetIds')
            this.cabinets = response.data.records.map((item) => ({
              value: item.cabinetId,
              label: item.cabinetName
            }))
          }
        })
      }
    }
  },
  created() {
    this.queryParams.cabinetId = this.cabinetId || null
    if (this.cabinetId) {
      this.visibleSelect = true
    }
    this.getList()
    this.getOtherList()
    this.getAutoConfigInfo()

  },

  methods: {
    handleClickAuto() {
      let StartValue = null
      if (this.autoConfig.startStatus == false) {
        StartValue = 0
      } else {
        StartValue = 1
      }
      const data = {
        planFrequency: this.autoConfig.planFrequency,
        planDate: this.autoConfig.planDate,
        checkUserId: this.autoConfig.checkUserId,
        startStatus: StartValue,
        templateCode: this.autoConfig.templateCode
      }
      updateAutomaticConfig(data).then(res => {
        console.log(res, '自动创建设置成功')
        if (res.data) {
          // this.$message.success('更新成功')
        }
      })
    },
    handleClickStatus(value) {
      console.log(value, 'checkbox数据是否更换')
      let StartValue = null
      if (value == false) {
        StartValue = 0
      } else {
        StartValue = 1
      }
      console.log(this.autoConfig, '拿到的自定义数据')
      const data = {
        planFrequency: this.autoConfig.planFrequency,
        planDate: this.autoConfig.planDate,
        checkUserId: this.autoConfig.checkUserId,
        startStatus: StartValue,
        templateCode: this.autoConfig.templateCode
      }
      updateAutomaticConfig(data).then(res => {
        console.log(res, '自动创建设置成功')
        if (res.data) {
          this.$message.success('更新成功')
        }
      })
    },
    handleFrequencyChange(frequency, isInitial = false) {
      if (frequency === '月') {
        // 生成 1 到 31 的日期，并将个位数格式化为两位数
        this.planDateOptions = Array.from({ length: 31 }, (_, i) => {
          const day = i + 1
          const formattedDay = String(day).padStart(2, '0') // 将个位数格式化为两位数
          return {
            value: formattedDay,
            label: formattedDay
          }
        })
      } else if (frequency === '周') {
        this.planDateOptions = [
          { value: 1, label: '周一' },
          { value: 2, label: '周二' },
          { value: 3, label: '周三' },
          { value: 4, label: '周四' },
          { value: 5, label: '周五' },
          { value: 6, label: '周六' },
          { value: 7, label: '周日' }
        ]
      } else {
        this.planDateOptions = []
      }

      // 如果不是初始化，清空计划日期
      if (!isInitial) {
        this.autoConfig.planDate = null
      }

      // 每次更新都调用接口
      this.handleClickAuto()
    },
//     自动创建计划检查 回显函数
    getAutoConfigInfo() {
      const data = {
        templateCode: 'CHECK_PLAN'
      }
      selectIsMailNotifyConfigByCode(data).then(res => {
        console.log(res, '拿到了自动创建检查计划回显数据')
        this.autoConfig.planDate = res.data.planDate
        this.autoConfig.planFrequency = res.data.planFrequency
        this.autoConfig.checkUserId = res.data.checkUserId

        // 初始化时传入 isInitial 为 true
        this.handleFrequencyChange(res.data.planFrequency, true)

        // 如果频率是周，将 planDate 转换为对应的中文星期
        if (res.data.planFrequency === '周') {
          const weekMap = {
            1: '周一',
            2: '周二',
            3: '周三',
            4: '周四',
            5: '周五',
            6: '周六',
            7: '周日'
          }
          this.autoConfig.planDate = weekMap[res.data.planDate] || res.data.planDate
        }

        if (res.data.startStatus == '0') {
          this.autoConfig.startStatus = false
        } else {
          this.autoConfig.startStatus = true
        }
      })
    },
// 格式化日期查询数据
    formatDate(date) {
      const year = date.getFullYear().toString().padStart(2, '0')
      const month = (date.getMonth() + 1).toString().padStart(2, '0')
      const day = date.getDate().toString().padStart(2, '0')
      const hours = date.getHours().toString().padStart(2, '0')
      const minutes = date.getMinutes().toString().padStart(2, '0')
      const seconds = date.getSeconds().toString().padStart(2, '0')

      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
    },
    /** 查询物资信息列表 */
    getList() {
      this.loading = true
      // 格式化日期并更新 queryParams
      if (Array.isArray(this.createTime) && this.createTime.length === 2) {
        this.queryParams.startTime = this.formatDate(this.createTime[0])
        this.queryParams.endTime = this.formatDate(this.createTime[1])
      }
      listPlan(this.queryParams).then((response) => {
        console.log(response, '获取物资信息allList ')
        this.PlanList = response.data.records
        this.total = response.data.total
        this.machinerytypeList = this.handleTree(
          response.data.records,
          'materialsTypeId',
          'parentId',
          'children'
        )
        this.loading = false
      })

    },

    getOtherList() {
      const data = {
        current: 1,
        size: -1
      }
      getIsMaterialsCabinets(data).then((response) => {
        if (response?.data?.records) {
          this.cabinets = response.data.records.map((item) => ({
            value: item.cabinetId,
            label: item.cabinetName
          }))
        }
      })
      const data1 = {
        pageSize: 999999999,
        pageNum: 1,
        roleId: 12
      }
      listUser(data1).then((res) => {
        this.planPersonOption = res.rows.map((item) => {
          return {
            label: item.nickName,
            value: item.userId
          }
        })
      })
      listMarsDept(data).then(res => {
        const data = res.data.records.filter((item) => {
          return item.parentId == '0'
        })
        this.workstationOption = this.handleTree(data, 'workstationId', 'parentId')
      })
    },
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.workstationId,
        label: node.workstationName,
        children: node.children
      }
    },
    /* 物资柜信息转换展示 */
    getDisplayText(cabinetName) {
      const names = cabinetName.split(',')
      if (names.length == 1) {
        // return `${names.length}个 (${names[0]})`
        return `${names.length}个`
      }
      if (names.length > 1) {
        // return `${names.length}个 (${names[0]}...)`
        return `${names.length}个`
      }
      return names[0]
    },
    // 巡检物资柜 点击事件
    PlanDetail(row) {
      console.log(row, '签名分页')
      this.openTable = true
      const data = {
        planId: row.planId,
        pageSize: 999999999,
        pageNum: 1
      }
      getCheckPlanCabinetList(data).then((response) => {
        console.log(response, '物资柜 签名分页')
        this.PlanDetailTableList = response.data
      })
    },
    // 签名弹窗内部详情查看
    handlePagination() {
      // 确保传递当前选中的 row 参数
      this.PlanDialogDetail(this.RecordselectedRow)
    },
    PlanDialogDetail(row) {
      this.openRecord = true
      this.RecordselectedRow = row || this.RecordselectedRow
      console.log(this.RecordselectedRow, '存储了参数 详情')
      const data = {
        planId: this.RecordselectedRow.planId,
        cabinetId: this.RecordselectedRow.cabinetId,
        current: this.recordCurrent,
        size: this.recordSize
      }
      listCheckRecord(data).then((response) => {
        console.log(response, 'response')
        this.RecordList = response.data.records
        this.recordtotal = response.data.total
        this.loading = false
      })
    },
    goto(row) {
      console.log(row, 'goto检查计划查看')
      if (this.cabinetId) {
        this.$emit('planId', {
          planId: row.planId,
          planName: row.planName
        })
      } else {
        this.$router.push({
          path: '/material/Inspectionrecords',
          query: {
            planId: row.planId,
            planName: row.planName
          }
        })
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.form.workstationId = null
      this.title = '新增检查计划'
      this.optType = 'add'
      if (this.visibleSelect) {
        this.form.cabinetIds = [this.cabinetId]
      }
      this.form.planName = `物资检查计划${this.formatELTime(new Date())}`
    },

    formatELTime(date) {
      if (!date) return ''
      const d = new Date(date)
      let month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear()

      if (month.length < 2) month = '0' + month
      if (day.length < 2) day = '0' + day

      return [year, month, day].join('-')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      selectPlanById(row.planId).then((response) => {
        this.form = response.data
        this.open = true
        this.title = '修改检查计划'
        this.optType = 'edit'
      })
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.planId != null) {
            this.form.planDate = this.formatELTime(this.form.planDate)
            updatePlan(this.form).then((response) => {
              console.log(response, '修改返回')
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            this.form.planDate = this.formatELTime(this.form.planDate)
            addPlan(this.form).then((response) => {
              console.log(response, '新增返回')
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.openTable = false

      this.reset()
    },
    cancelDetail() {
      this.openRecord = false
    },
    // 表单重置
    reset() {
      this.form = {
        planName: '',
        cabinetIds: '',
        workstationId: '',
        checkUserName: ''
      }
      this.resetForm('form')
      this.autoGenFlag = false
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams.startTime = ''
      this.queryParams.endTime = ''
      this.createTime = ''
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.planId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const checkIds = row.planId || this.ids
      this.$modal
        .confirm('是否确认删除所选数据项？')
        .then(function() {
          return deletePlan(checkIds)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {
        })
    },
    //   计划日期清空
    handleClearTime(value) {
      if (value == null) {
        this.queryParams.startTime = null
        this.queryParams.endTime = null
      }
    }

  }
}
</script>
<style lang="scss" src="@/assets/styles/dialog-title.scss" scoped>
</style>
<style lang="scss">
//图片放大
.img-box {
  width: 50px;
  height: 50px;
  position: relative;

  #eyeicon {
    display: none;
  }
}

.img-box:hover {
  background: #000;

  .images {
    opacity: 0.6;
  }

  #eyeicon {
    display: block;
    position: absolute;
    top: 40%;
    left: 40%;
    z-index: 100;
    color: white;
    pointer-events: none
  }
}

.img-box1 {
  width: 90px;
  height: 90px;
  position: relative;

  #eyeicon {
    display: none;
  }
}

.img-box1:hover {
  background: #000;
  position: absolute;
  top: 62%;

  .images {
    opacity: 0.6;
  }

  #eyeicon {
    display: block;
    position: absolute;
    top: 40%;
    left: 40%;
    z-index: 100;
    color: white;
    pointer-events: none
  }
}

.el-input-width {
  width: 380px !important;
}
</style>
