<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <!-- 计划名称 -->
      <el-form-item :label="$t('administration.ProjectName')">
        <el-input
          v-model="queryParams.taskName"
          :placeholder="
            $t('share.PleaseEnter') + ' ' + $t('administration.ProjectName')
          "
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- 区域名称 -->
      <el-form-item :label="$t('administration.RegionName')">
        <el-input
          v-model="queryParams.areaName"
          :placeholder="
            $t('share.PleaseEnter') + ' ' + $t('administration.RegionName')
          "
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- 状态 -->
      <el-form-item :label="$t('share.status')" prop="status">
        <el-select
          v-model="queryParams.isenable"
          :placeholder="$t('share.status')"
          clearable
          style="width: 240px"
        >
          <el-option :label="$t('share.On')" value="0"></el-option>
          <el-option :label="$t('share.Off')" value="1"></el-option>
        </el-select>
      </el-form-item>
      <!-- 计划有效期 -->
      <el-form-item :label="$t('administration.PlanValidityPeriod')">
        <el-date-picker
          v-model="queryParams.cycleStartTime"
          type="date"
          :placeholder="$t('share.StartTime')"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
        -
        <el-date-picker
          v-model="queryParams.cycleEndTime"
          type="date"
          :placeholder="$t('share.EndTime')"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <!-- 创建时间 -->
      <el-form-item :label="$t('share.CreationTime')">
        <el-date-picker
          v-model="queryParams.beginTime"
          type="date"
          :placeholder="$t('share.StartTime')"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
        -
        <el-date-picker
          v-model="queryParams.endTime"
          type="date"
          :placeholder="$t('share.EndTime')"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <!-- 按钮 -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >{{ $t("share.search") }}</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{
          $t("share.reset")
        }}</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!-- 新增 -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >{{ $t("share.new") }}</el-button
        >
      </el-col>
      <!-- 删除 -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDeleteAll"
          >{{ $t("share.delete") }}</el-button
        >
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="dataList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- 计划名称 -->
      <el-table-column
        :label="$t('administration.ProjectName')"
        prop="taskName"
      />
      <!-- 计划有效期开始时间 -->
      <el-table-column
        :label="$t('administration.PlanValidityPeriod') + $t('share.StartTime')"
        prop="cycleStartTime"
        :show-overflow-tooltip="true"
        min-width="100px"
      />
      <!-- 计划有效期结束时间 -->
      <el-table-column
        :label="$t('administration.PlanValidityPeriod') + $t('share.EndTime')"
        prop="cycleEndTime"
        :show-overflow-tooltip="true"
        min-width="100px"
      />
      <!-- 创建时间 -->
      <el-table-column :label="$t('share.CreationTime')" prop="beginTime" />
      <!-- 区域时间 -->
      <el-table-column
        :label="$t('administration.RegionName')"
        prop="areaName"
      />
      <!-- 任务策略 -->
      <el-table-column
        :label="$t('administration.TaskStrategy')"
        prop="roleSort"
      />
      <!-- 执行任务周期 -->
      <el-table-column
        :label="$t('administration.ExecutionTaskCycle')"
        prop="roleSort"
      />
      <!-- 状态 -->
      <el-table-column :label="$t('share.status')" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isenable"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <!-- 操作 -->
      <el-table-column
        :label="$t('share.operate')"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope" v-if="scope.row.roleId !== 1">
          <!-- 立即执行 -->
          <el-button size="mini" type="text" icon="el-icon-edit">{{
            $t("administration.ImmediateExecution")
          }}</el-button>
          <!-- 下发 -->
          <el-button size="mini" type="text" icon="el-icon-edit">{{
            $t("administration.issue")
          }}</el-button>
          <!-- 复制任务 -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCopy(scope.row)"
            >{{ $t("administration.ReplicationTask") }}</el-button
          >
          <!-- 编辑 -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >{{ $t("share.edit") }}</el-button
          >
          <!-- 删除 -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row.taskId)"
            >{{ $t("share.delete") }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
    />
    <el-dialog :title="title" :visible.sync="dialogTableVisible">
      <el-steps :active="active" style="margin-bottom: 20px">
        <el-step :title="$t('administration.SetPlanObject')"></el-step>
        <el-step :title="$t('administration.SelectInspectionObject')"></el-step>
        <el-step :title="$t('administration.PointSetting')"></el-step>
      </el-steps>

      <el-form
        ref="ruleForm"
        :model="dialogForm"
        label-width="110px"
        :rules="rules"
      >
        <div v-if="dialogTableVisibleStep == 0">
          <!-- 名称 -->
          <el-form-item :label="$t('administration.name')" prop="taskName">
            <el-input
              v-model="dialogForm.taskName"
              :placeholder="$t('share.PleaseEnter') + $t('administration.name')"
            ></el-input>
          </el-form-item>
          <!-- 优先级 -->
          <el-form-item :label="$t('administration.priority')" prop="priority">
            <el-select
              v-model="dialogForm.priority"
              :placeholder="$t('administration.priority')"
            >
              <el-option
                :label="$t('administration.priority') + 1"
                value="1"
              ></el-option>
              <el-option
                :label="$t('administration.priority') + 2"
                value="2"
              ></el-option>
              <el-option
                :label="$t('administration.priority') + 3"
                value="3"
              ></el-option>
              <el-option
                :label="$t('administration.priority') + 4"
                value="4"
              ></el-option>
            </el-select>
          </el-form-item>
          <!-- 任务类型 -->
          <el-form-item :label="$t('administration.TaskType')" prop="type">
            <el-select
              v-model="dialogForm.type"
              :placeholder="$t('administration.TaskType')"
            >
              <el-option
                :label="item.patrolTypeName"
                :value="item.patrolTypeId"
                v-for="item in patroltype"
                :key="item.patrolTypeId"
              ></el-option>
            </el-select>
          </el-form-item>
          <!-- 任务执行方式 -->
          <el-form-item
            :label="$t('administration.TaskExecutionMethod')"
            prop="executionMode"
          >
            <el-checkbox-group v-model="dialogForm.executionMode">
              <el-checkbox label="0" name="type">{{
                $t("administration.WalkThrough")
              }}</el-checkbox>
              <!-- <el-checkbox label="现场巡视1" name="type"></el-checkbox> -->
            </el-checkbox-group>
          </el-form-item>
          <!-- 巡检区域 -->
          <el-form-item
            :label="$t('administration.InspectionArea')"
            prop="areaIdS"
          >
            <!-- :default-checked-keys="dialogForm.areaIdS" -->
            <el-tree
              :data="treeData"
              show-checkbox
              node-key="areaId"
              ref="tree"
              highlight-current
              :props="defaultProps"
              @check="setUpHandleCheckChange"
            >
            </el-tree>
          </el-form-item>
          <!-- 执行周期 -->
          <el-form-item :label="$t('administration.executeCycle')">
            <el-radio-group v-model="dialogForm.executionStatus">
              <el-radio :label="1" :value="1">{{
                $t("administration.RegularExecution")
              }}</el-radio>
              <el-radio :label="2" :value="2">{{
                $t("administration.PeriodicExecution")
              }}</el-radio>
              <el-radio :label="4" :value="4">{{
                $t("administration.IntervalExecution")
              }}</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- 执行日期 -->
          <el-form-item
            :label="$t('administration.ExecutionDate')"
            v-if="dialogForm.executionStatus == 1"
            prop="fixedStartTime"
          >
            <el-date-picker
              v-model="dialogForm.fixedStartTime"
              type="datetime"
              :placeholder="$t('administration.ExecutionDate')"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
          <div
            v-if="dialogForm.executionStatus == 2"
            style="margin-bottom: 20px"
          >
            <div class="cycle2">{{ $t("administration.timeSetting") }}</div>
            <!-- 计划有效期 -->
            <el-form-item
              :label="$t('administration.PlanValidityPeriod')"
              prop="PlanValidityPeriod"
            >
              <el-date-picker
                v-model="dialogForm.value1"
                type="datetimerange"
                range-separator="-"
                :start-placeholder="$t('share.StartTime')"
                :end-placeholder="$t('share.EndTime')"
              >
              </el-date-picker>
            </el-form-item>
            <!-- 执行任务周期 -->
            <el-form-item
              :label="$t('administration.ExecutionTaskCycle')"
              prop="ExecutionTaskCycle"
            >
              <el-select
                v-model="dialogForm.region"
                :placeholder="
                  $t('share.PleaseChoose') +
                  $t('administration.ExecutionTaskCycle')
                "
              >
                <el-option
                  :label="$t('administration.SelectByWeek')"
                  value="shanghai"
                ></el-option>
                <el-option
                  :label="$t('administration.MonthlySelection')"
                  value="beijing"
                ></el-option>
              </el-select>
            </el-form-item>
            <!-- 执行日期添加 -->
            <el-form-item
              :label="$t('administration.ExecutionDate')"
              prop="ExecutionDate"
            >
              <el-button type="primary" @click="executionTimeBtn"
                >{{ $t("share.addTo") }}{{ executionTimeButton }}/7</el-button
              >
            </el-form-item>
            <el-table
              :data="executionTimeData"
              style="width: 80%; margin-left: 10%"
            >
              <!-- 日期 -->
              <el-table-column
                :label="$t('administration.date')"
                align="center"
              >
                <template slot-scope="scope">
                  <el-select
                    v-model="scope.row.day"
                    :placeholder="
                      $t('share.PleaseChoose') + $t('administration.date')
                    "
                  >
                    <el-option
                      :label="item.name"
                      :value="item.name"
                      v-for="(item, index) in weekData"
                      :key="item.id"
                      >{{ item.name }}</el-option
                    >
                  </el-select>
                </template>
              </el-table-column>
              <!-- 时间 -->
              <el-table-column
                prop="name"
                :label="$t('administration.time')"
                align="center"
              >
                <template slot-scope="scope">
                  <el-time-picker
                    v-model="scope.row.time"
                    :placeholder="
                      $t('share.PleaseChoose') + $t('administration.time')
                    "
                  >
                  </el-time-picker>
                </template>
              </el-table-column>
              <!-- 操作 -->
              <el-table-column
                prop="address"
                :label="$t('share.delete')"
                align="center"
              >
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    icon="el-icon-delete"
                    @click="executionTimeDelet(scope.row)"
                  />
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div
            v-if="dialogForm.executionStatus == 4"
            style="margin-bottom: 20px"
          >
            <!-- <div class="cycle2">时间设置</div> -->
            <!-- 间隔 -->
            <el-form-item
              :label="$t('administration.interval')"
              prop="interval"
            >
              <el-date-picker
                v-model="dialogForm.value1"
                type="datetimerange"
                range-separator="-"
                :start-placeholder="$t('share.StartTime')"
                :end-placeholder="$t('share.EndTime')"
              >
              </el-date-picker>
            </el-form-item>
            <!-- 执行时间 -->
            <el-form-item
              :label="$t('administration.executionTime')"
              prop="executionTime"
            >
              <el-time-picker
                v-model="dialogForm.value1"
                :placeholder="
                  $t('share.PleaseChoose') + $t('administration.executionTime')
                "
              >
              </el-time-picker>
            </el-form-item>
            <!-- 间隔类型 -->
            <el-form-item
              :label="$t('administration.intervalType')"
              prop="intervalType"
            >
              <el-select
                v-model="dialogForm.region"
                :placeholder="
                  $t('share.PleaseChoose') + $t('administration.intervalType')
                "
              >
                <el-option :label="$t('share.hour')" value="小时"></el-option>
              </el-select>
            </el-form-item>
            <!-- 数量 -->
            <el-form-item
              :label="$t('administration.quantity')"
              prop="quantity"
            >
              <el-input-number
                v-model="dialogForm.num"
                :min="1"
              ></el-input-number>
            </el-form-item>
          </div>
          <el-form-item>
            <el-button @click="resetForm('ruleForm')">{{
              $t("share.cancel")
            }}</el-button>
            <el-button type="primary" @click="submitForm(0)">{{
              $t("administration.nextStep")
            }}</el-button>
          </el-form-item>
        </div>
        <!-- 选择巡检对象 -->
        <div v-if="dialogTableVisibleStep == 1">
          <div class="dialogTableVisibleStep1">
            <div class="dialogTableVisibleStep1-content">
              <div class="leftTotle">{{ $t("administration.region") }}</div>
              <div
                class="dialogTableVisibleStepQurey"
                style="margin-bottom: 10px"
              >
                <el-input :placeholder="$t('share.content')" v-model="input3">
                </el-input>
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  type="primary"
                ></el-button>
              </div>
              <el-tree
                :data="selectTreeData"
                show-checkbox
                node-key="areaId"
                ref="selectTree"
                highlight-current
                :props="defaultProps"
                @check="selectTreeHandleCheckChange"
                :check-strictly="true"
              >
              </el-tree>
            </div>
            <div>
              <el-transfer
                v-model="transferValue"
                :data="transferData"
                :props="{ key: 'deviceId', label: 'deviceName' }"
                :titles="[
                  $t('administration.ToBeAdded'),
                  $t('administration.Added'),
                ]"
              ></el-transfer>
            </div>
          </div>
          <div
            style="
              margin-left: 80%;
              margin-top: 20px;
              display: flex;
              justify-content: flex-end;
            "
          >
            <el-button @click="returnCancel(0)">{{
              $t("administration.PreviousStep")
            }}</el-button>
            <el-button type="primary" @click="submitForm(1)">{{
              $t("administration.nextStep")
            }}</el-button>
          </div>
        </div>
        <!-- 点位设置 -->
        <div v-if="dialogTableVisibleStep == 2">
          <el-tree
            :data="pointSettingsTreeData"
            show-checkbox
            node-key="areaId"
            ref="pointSettingsTree"
            highlight-current
            :props="pointSettingsDefaultProps"
            @check="pointSettingsTreeDataHandleCheckChange"
          >
          </el-tree>
          <el-form-item
            :label="$t('administration.IsItEnabled')"
            prop="isenable"
          >
            <el-radio-group v-model="dialogForm.isenable">
              <el-radio :label="0">{{ $t("share.Yes") }}</el-radio>
              <el-radio :label="1">{{ $t("share.No") }}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button @click="returnCancel(1)">{{
              $t("administration.PreviousStep")
            }}</el-button>
            <el-button type="primary" @click="submitForm(2)">{{
              $t("share.confirm")
            }}</el-button>
          </el-form-item>
        </div>
        <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">下一步</el-button>
      </span> -->
      </el-form>
    </el-dialog>

    <!-- 复制弹框 -->
    <el-dialog
      :title="$t('administration.CopyTask')"
      :visible.sync="copyDialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-time-picker :placeholder="$t('share.PleaseChoose')+$t('administration.time')"> </el-time-picker>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="copyDialogVisible = false"
          >{{ $t('administration.Copy') }}</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getList,
  getChangeStatus,
  postRemove,
  getPatroltypeList,
  getAreaList,
  getProDeviceTreeSelect,
  getTreeProMainDevicePatrolEquSelect,
} from "@/api/administration";
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskName: "",
        cycleStartTime: "",
        cycleEndTime: "",
        areaName: "",
        isenable: "",
        beginTime: "",
        endTime: "",
      },
      total: 0,
      loading: true,
      dataList: [],
      // 选中数组
      ids: [],
      title: "新增",
      dialogTableVisible: false,
      active: 0,
      patroltype: [],
      dialogForm: {
        areaIdS: [],
        executionMode: [],
        executionStatus: 1,
      },
      areaIdS: [],
      treeData: [],
      setUpAreaIds: [],
      selectTreeData: [],
      selectTreeIds: [],
      pointSettingsTreeData: [],
      pointSettingsDefaultProps: {
        children: "children",
        label: "label",
      },
      defaultProps: {
        children: "children",
        label: "areaName",
      },
      rules: {},
      executionTimeButton: 1,
      executionTimeData: [{ day: "", time: "", id: Date.now() }],
      weekData: [
        { name: "周一", id: "0" },
        { name: "周二", id: "1" },
        { name: "周三", id: "2" },
        { name: "周四", id: "3" },
        { name: "周五", id: "4" },
        { name: "周六", id: "5" },
        { name: "周日", id: "6" },
      ],
      dialogTableVisibleStep: 0,
      transferData: [],
      transferValue: [],
      copyDialogVisible: false,
      rules: {
        taskName: [
          {
            required: true,
            message:
              this.$t("share.PleaseEnter") + this.$t("administration.name"),
            trigger: "blur",
          },
        ],
        priority: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.priority"),
            trigger: "blur",
          },
        ],
        type: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.TaskType"),
            trigger: "blur",
          },
        ],
        executionMode: [
          {
            type: "array",
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.TaskExecutionMethod"),
            trigger: "change",
          },
        ],
        areaIdS: [
          {
            type: "array",
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.InspectionArea"),
            trigger: "change",
          },
        ],
        fixedStartTime: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.ExecutionDate"),
            trigger: "change",
          },
        ],
        proDeviceTreeSelect: [],
        isenable: [
          {
            required: true,
            message: this.$t("share.PleaseChoose") + this.$t("share.status"),
            trigger: "change",
          },
        ],
        PlanValidityPeriod: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.PlanValidityPeriod"),
            trigger: "change",
          },
        ],
        ExecutionTaskCycle: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.ExecutionTaskCycle"),
            trigger: "change",
          },
        ],
        ExecutionDate: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.ExecutionDate"),
            trigger: "change",
          },
        ],
        interval: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.interval"),
            trigger: "change",
          },
        ],
        executionTime: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.executionTime"),
            trigger: "change",
          },
        ],
        intervalType: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.intervalType"),
            trigger: "change",
          },
        ],
        quantity: [
          {
            required: true,
            message:
              this.$t("share.PleaseChoose") +
              this.$t("administration.quantity"),
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      getList(this.queryParams).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.loading = false;
          this.dataList = res.rows;
          this.total = res.total;
        }
      });
    },
    // 查询
    handleQuery() {
      this.init();
    },
    // 重置
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.init();
    },
    handleStatusChange(row) {
      let data = {
        taskId: row.taskId,
        isenable: row.isenable,
      };
      getChangeStatus(data).then((res) => {
        if (res.code == 200) {
          this.init();
        }
      });
    },
    // 新增
    handleAdd() {
      this.dialogTableVisible = true;
      getPatroltypeList().then((res) => {
        if (res.code == 200) {
          this.patroltype = res.rows;
        }
      });
      getAreaList().then((res) => {
        if (res.code == 200) {
          let tree = this.dialogTree(res.data);
          this.treeData = tree;
        }
      });
    },
    // 弹框tree扁平转树结构
    dialogTree(list) {
      var map = {},
        node,
        tree = [];
      for (let i = 0; i < list.length; i++) {
        map[list[i].areaId] = list[i];
        list[i].children = [];
      }
      for (let i = 0; i < list.length; i += 1) {
        list[i];
        if (list[i].parentId !== 0) {
          // 不是根节点
          map[list[i].parentId].children.push(list[i]); // 放到父节点的children里
        } else {
          // 是根节点
          tree.push(list[i]); // 根节点计入结果数组
        }
      }
      return tree;
    },
    // 多选删除
    handleDeleteAll() {
      if (this.ids.length <= 0) {
        this.$message({
          message: "请选择要删除的数据",
          type: "warning",
        });
        return;
      } else {
        console.log(this.ids);
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.taskId);
    },
    handleDelete(taskId) {
      postRemove(taskId).then((res) => {
        if (res.code == 200) {
          this.init();
        }
      });
    },
    cancel() {
      this.dialogTableVisible = false;
      this.dialogForm = {};
    },

    // 弹框tree树选择
    handleCheckChange(data) {
      let idArr = [];
      if (idArr.indexOf(data.areaId) > -1) {
        idArr.splice(idArr.indexOf(data.areaId), 1);
      } else {
        idArr.push(data.areaId);
      }
      return idArr;
    },
    // 设置计划对象弹框选择
    setUpHandleCheckChange(data) {
      var parentIds = this.$refs.tree.getHalfCheckedKeys();
      var childsIds = this.$refs.tree.getCheckedKeys();
      let treeIds = parentIds.concat(childsIds);
      this.dialogForm.areaIdS = treeIds;

      return;
      this.dialogForm.areaIdS = this.handleCheckChange(treeIds);
      console.log(this.dialogForm.areaIdS);
    },
    // 弹框选择巡检对象 tree树选择
    selectTreeHandleCheckChange(data) {
      // this.selectTreeIds = this.handleCheckChange(data);
      let res = this.$refs.selectTree.getCheckedNodes();
      let arrDeptId = [];
      res.forEach((item) => {
        arrDeptId.push(item.areaId);
      });
      this.transferData = this.proDeviceTreeSelect.filter((item) =>
        arrDeptId.some((ele) => ele === item.areaId)
      );
    },
    // 点位设置数
    pointSettingsTreeDataHandleCheckChange() {
      let res = this.$refs.pointSettingsTree.getCheckedNodes();
      console.log(res);
    },
    // 弹框下一步
    submitForm(type) {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          console.log(this.dialogForm);
          // this.dialogForm.executionMode = 0;
          if (type == 0) {
            this.active = 1;
            this.dialogTableVisibleStep = 1;
            let areaIdS = JSON.parse(JSON.stringify(this.dialogForm.areaIdS));
            // areaIdS.push(1);
            getAreaList(areaIdS.join(","), 1).then((res) => {
              if (res.code == 200) {
                let tree = this.dialogTree(res.data);
                this.selectTreeData = tree;
              }
            });
            getProDeviceTreeSelect(areaIdS.join(",")).then((res) => {
              if (res.code == 200) {
                this.proDeviceTreeSelect = res.data;
                console.log(this.proDeviceTreeSelect);
              }
            });
          }
          if (type == 1 && this.transferValue) {
            this.active = 2;
            this.dialogTableVisibleStep = 2;
            getTreeProMainDevicePatrolEquSelect(
              this.transferValue.join(",")
            ).then((res) => {
              console.log(res, 11111);
              this.pointSettingsTreeData = res.data;
            });
          }
          if (type == 2) {
            console.log(this.dialogForm);
          }
        }
      });
    },
    // 弹框上一步
    returnCancel(type) {
      this.active = type;
      this.dialogTableVisibleStep = type;
    },
    resetForm(formName) {
      this.dialogForm = {};
      this.$refs[formName].resetFields();
      this.dialogTableVisible = false;
    },
    // 添加任务执行时间输入框
    executionTimeBtn() {
      if (this.executionTimeData.length <= 6) {
        this.executionTimeData.push({ day: "", time: "", id: Date.now() });
      }
    },
    executionTimeDelet(row) {
      if (this.executionTimeData.length > 1) {
        this.executionTimeData = this.executionTimeData.filter(
          (item) => item.id != row.id
        );
        console.log(this.executionTimeData);
      }
    },
    // 复制任务
    handleCopy(row) {
      this.copyDialogVisible = true;
    },
    // 编辑任务
    handleUpdate(row) {
      this.dialogTableVisible = true;
    },
    handleClose() {
      this.copyDialogVisible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.cycle2 {
  padding: 10px;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 20px;
}
.dialogTableVisibleStep1 {
  display: flex;
  justify-content: space-around;
}
.dialogTableVisibleStep1-content {
  width: 30%;
  // height: 200px;
  .leftTotle {
    font-size: 20px;
    margin-bottom: 10px;
  }
  .el-input {
    width: 75%;
  }
}
</style>
