<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-input
          v-model="query.code"
          clearable
          size="small"
          placeholder="输入巡检点编号"
          style="width: 160px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.name"
          clearable
          size="small"
          placeholder="输入巡检点名称"
          style="width: 160px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-cascader
          v-model="query.departmentId"
          :options="departmentOptions"
          :props="{ checkStrictly: true, emitPath: false }"
          filterable
          clearable
          size="small"
          placeholder="请选择责任部门"
          style="width: 160px"
          class="filter-item"
        />
        <el-select
          v-model="query.areaId"
          filterable
          clearable
          size="small"
          placeholder="请输入所属区域"
          class="filter-item"
          style="width: 160px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in areaOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <!-- <el-select
          v-model="query.checkPointType"
          filterable
          clearable
          size="small"
          placeholder="请输入巡检点类型"
          class="filter-item"
          style="width: 160px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.CheckPointType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select> -->
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
    </div>
    <!-- 选择责任部门 -->
    <select-department title="选择部门" ref='selectDept' width="40%" @getData="selectDept"/>
    <!-- 选择巡检标签 -->
    <select-patrol-label title="选择巡检标签" v-model='form' ref="selectPatrolLabel" dataType="patrolLabel" @getData="selectPatrolLabel"></select-patrol-label>
    <!-- 选择所属区域 -->
    <select-area title="选择区域" ref="selectArea" width="30%" @getData="selectArea" />
    <!-- 选择巡检对象 -->
    <select-patrol-object title="选择巡检对象" v-model='form' ref="selectPatrolObject" dataType="patrolObject" @getData="selectPatrolObject" checkFlag="2"></select-patrol-object>
    <!-- 地图标识 -->
    <el-dialog
      title="地图"
      :visible.sync="showDialog"
      width="950px"
    >
      <relative-map
        ref="showDialog"
        v-model="mapData"
        :buildFloor="buildFloor"
        :drawShow=false
        drawMode="Polygon"
        width="40%"
      />
      <div slot="footer" class="dialog-footer-batchMap">
        <el-button @click=" showDialog = false">关闭</el-button>
      </div>
    </el-dialog>
    <!--表单组件-->    
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="crud.cancelCU"
      :visible="crud.status.cu > 0"
      :title="crud.status.title"
      width="1150px"
    >
      <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="巡检点名称" prop="name">
              <el-input v-model="form.name" />
            </el-form-item>
            <el-form-item label="巡检标签" prop="labelName">
              <el-input v-model="form.labelName" :disabled="true" style="width:146px"/>
              <el-button type="primary" @click="openSelectPatrolLabel">选择</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="巡检点编码" prop="code">
              <el-input v-model="form.code" />
            </el-form-item>
            <!-- <el-form-item label="巡检点类型" prop="type">
              <el-select
                  v-model="form.type"
                  clearable
                  size="small"
                  placeholder=""
                  class="filter-item"
                  style="width: 200px"
                >
                  <el-option
                    v-for="item of typeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
            </el-form-item> -->
            <el-form-item label="所属位置" prop="points">
              <el-button type="primary" @click="openshowDialog()">查看</el-button>
            </el-form-item>
          </el-col>  
          <el-col :span="8">
            <el-form-item label="责任单位" prop="departmentName">
              <el-input v-model="form.departmentName" :disabled="true" style="width:146px"/>
              <el-button type="primary" @click="openSelectDept">选择</el-button>
            </el-form-item>
            <el-form-item label="所属区域" prop="areaName">
              <el-input v-model="form.areaName" :disabled="true" style="width:146px"/>
              <el-button type="primary" @click="openSelectArea">选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
            <el-form-item label="校验方式" prop="checkInMethod">
                <el-checkbox-group v-model="form.checkInMethod">
                  <el-checkbox 
                    v-for="(item,index) of optionsObj.CheckInMethod" 
                    :key="index"  
                    :label="+item.value"
                  >{{item.label}}</el-checkbox>
                </el-checkbox-group>
            </el-form-item>
            <el-form-item label="一键完成" prop="oneKeyFinish">
              <el-switch
                v-model="form.oneKeyFinish"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="启用"
                inactive-text="禁用"
                :active-value="true"
                :inactive-value="false"
              >
              </el-switch>
            </el-form-item>
        </el-row>
        <el-row>
          <el-button type="primary" @click="openSelectPatrolObject">选择巡检对象</el-button>
          <el-button>批量导入巡检项目</el-button>
          <el-button>导出巡检项目</el-button>
        </el-row>  
        <el-row>
          <el-table
            :data="form.objects"
            :default-sort="{ prop:'id' }"
            row-key="key"
            border
            style="width: 100%; margin-top: 20px">
            <el-table-column
              prop="name"
              label="名称"
              width="120px"
              align="center">
            </el-table-column>
            <el-table-column
              prop="code"
              label="编号"
              align="center">
            </el-table-column>
            <!-- <el-table-column
              label="检查项目">
              <template slot-scope="scope">
                <el-table
                  :data="scope.row.items"
                  :default-sort="{ prop:'id' }"
                  :show-header=false
                  row-key="key"
                  border
                  style="width: 100%; margin-top: 20px">
                  <el-table-column label="检查项目">
                    <el-input type="textarea" v-for="(item,index) in scope.row.items" :key="index" v-model="item.content"/>
                  </el-table-column>
                </el-table>
              </template>
            </el-table-column> -->
            <el-table-column
              label="检查项目">
              <template slot-scope="scope">
                <el-input type="textarea" v-for="(item,index) in scope.row.items" :key="index" v-model="item.content" style="margin-bottom:2px;"/>
              </template>
            </el-table-column>
            <el-table-column
              label="检查标准">
              <template slot-scope="scope">
                <el-input type="textarea" v-for="(item,index) in scope.row.items" :key="index" v-model="item.standard" style="margin-bottom:2px;"/>
              </template>
            </el-table-column>
            <el-table-column
              label="数据类型">
              <template slot-scope="scope" style="margin-top:10px">
                <el-select
                  v-for="(item,index) in scope.row.items" 
                  :key="index" 
                  v-model="item.dataType"
                  clearable
                  size="small"
                  placeholder=""
                  class="filter-item"
                  style="width: 80px;margin:6px 0 14px 0;"
                >
                  <el-option
                    v-for="item of optionsObj.ItemDataType"
                    :key="item.value"
                    :label="item.label"
                    :value="+item.value"
                  />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              label="正常值"
              width="400px">
              <template slot-scope="scope">
                  <el-row v-for="(item,index) in scope.row.items" :key="index" style="margin:10px 0 10px 0;height:40px;">
                    <template v-if="item.dataType =='2'" >
                    <el-col :span="6">
                      <el-form-item label-width="0px">
                        <el-select
                          v-for="(item,index) in item.items" 
                          :key="index"
                          v-model="item.statusOption"
                          clearable
                          size="small"
                          placeholder=""
                          class="filter-item"
                          style="width: 80px">
                          <el-option
                            v-for="item of stateDataTypeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    </template>
                    <template v-if="item.dataType =='1'" >
                      <el-col :span="4">
                        <el-form-item label-width="0px">
                          <!-- <el-select
                            v-model="item.unit"
                            clearable
                            size="small"
                            placeholder=""
                            class="filter-item"
                            style="width: 80px"
                          >
                            <el-option
                              v-for="item of unitList"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            />
                          </el-select> -->
                          <el-input v-model="item.unit" placeholder="单位" size="small" class="filter-item" style="width: 60px" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="20">
                      <template class="judgementConditions">
                        <el-row v-for="(it,i) in item.numberJudgment[0].judgementConditions" :key="i">
                          <el-col :span="6">
                            <el-form-item label-width="4px">
                              <el-select
                                v-model="it.logicalOperator"
                                clearable
                                size="small"
                                placeholder="逻辑符号"
                                class="filter-item"
                                style="width: 80px"
                              >
                                <el-option
                                  v-for="item of optionsObj.LogicalOperator"
                                  :key="item.value"
                                  :label="item.label"
                                  :value="+item.value"
                                />
                              </el-select>
                            </el-form-item>
                          </el-col>
                          <el-col :span="6">
                            <el-form-item label-width="4px">
                              <el-select
                                v-model="it.comparisonOperator"
                                clearable
                                size="small"
                                placeholder="运算符号"
                                class="filter-item"
                                style="width: 80px"
                              >
                                <el-option
                                  v-for="item of optionsObj.ComparisonOperator"
                                  :key="item.value"
                                  :label="item.label"
                                  :value="+item.value"
                                />
                              </el-select>
                            </el-form-item>
                          </el-col>
                          <el-col :span="5">
                            <el-form-item  label-width="12px">
                              <el-input v-model="it.comparisonValue" size="small" class="filter-item" style="width: 60px" />
                            </el-form-item>
                          </el-col>
                          <el-col :span="6">
                            <el-form-item  label-width="12px">
                              <el-button type="primary" size="mini"  icon="el-icon-minus" @click="handleDeleteJud(i,index,scope.row)" circle></el-button>
                              <el-button type="primary" size="mini" icon="el-icon-plus" @click="handleAddJud(i,index, scope.row)"  circle></el-button>
                            </el-form-item>
                          </el-col>
                        </el-row>
                      </template>
                      </el-col>
                    </template>
                  </el-row>
              </template>
            </el-table-column>
            <el-table-column
              label="强制拍照" width="60px">
              <template slot-scope="scope">
                <el-checkbox v-for="(item,index) in scope.row.items" :key="index" v-model="item.forcePhotograph" style="margin:10px 0 10px 0;width:100px"></el-checkbox>
              </template>
            </el-table-column>
            <el-table-column width="60px">
              <template slot-scope="scope">
                <el-row v-for="(item,index) in scope.row.items" :key="index">
                  <el-button type="primary" size="mini"  icon="el-icon-minus" @click="handleDelete(index,item,scope.row)" circle style="margin:10px 0 10px 0"></el-button>
                </el-row>
              </template>
            </el-table-column>
            <el-table-column
              prop="amount6"
              label="操作"
              width="90px">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" icon="el-icon-plus" @click="handleAdd(scope.$index, scope.row)"  circle></el-button>
                <el-button type="danger" size="mini" icon="el-icon-delete-solid" @click="handleDeleteObj(scope.$index, scope.row)" circle></el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">取消</el-button>
        <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU"
          >确认</el-button>
      </div>
    </el-dialog>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      style="width: 100%"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column
        v-for="item in checkPointTableOptions"
        :key="item.prop"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        :align="item.align"
        :fixed="item.fixed"
        :sortable="item.sortable"
      ></el-table-column>
      <!--   编辑与删除   -->
      <el-table-column
        v-if="checkPer(['admin', 'checkPoint:edit', 'checkPoint:del'])"
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <udOperation :data="scope.row" :permission="permission" />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import permission from '@/directive/permission'
import crudCheckPoint from '@/api/patrolManage/checkPoint'
import { getOptions } from '@/api/patrolManage/options'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import { crudOperation, rrOperation, udOperation, pagination } from '@crud'
import crudComps from '@crud'
import DateRangePicker from '@/components/DateRangePicker'
import RelativeMap from "@/components/RelativeMap";
import SelectView from "@/views/common/selectView";
import SelectArea from "@/views/common/selectArea";
import SelectDepartment from "@/views/common/selectDepartment";
import SelectPatrolLabel from "@/views/common/selectPatrolLabel";
import SelectPatrolObject from "@/views/common/selectPatrolObject";
import { checkPointTableOptions } from '../tableConfig'
import { getToken } from '@/utils/auth'
import { initData } from '@/api/data'

const defaultForm = {
  //主要参数
  id: '',
  code: 123,
  name: '321',
  type:'',
  areaId: 0,
  areaName: '123',

  departmentId: 0,
  departmentName: '123',

  labelId: 123,
  labelName: 'string',
  label:{
    id:123,
    code: "string",
    name: "string",
    description: "string",
    buildId: "204209",
    buildName: "string",
    floorNo: 0,
    floorStr: "string",
    extent: {
      buildId: "string",
      floor: [
        0
      ],
      points: [
        {'x': 119436,'y': 36865},
        {'x': 119436,'y': 60265},
        {'x': 16436,'y': 60265},
        {'x': 119436,'y': 36865}
      ],
    },
    nfcCode: "string",
    rfidCode: "string",
    qrCode: "string",
    barCode: "string"
  },

  checkInMethod: [2,3],
  checkInMethodStr: [],
  oneKeyFinish: true,
  //关联对象与项目
  objects:[
    {
      objectId:'1',
      name: '王小虎',
      code:'',
      type:0,
      typeStr:'',
      buildId: '',
      floorNo: 0,
      areaId: 0,
      areaName: '',
      items:[
        {
          id: 0,
          token: "string",
          baseCreateTime: "2022-07-19T02:37:26.672Z",
          baseCreatorId: 0,
          checkpointId: 0,
          objectId: 0,
          content: "234",
          standard: "3.2",
          dataType: 3,
          unit: "string",
          numberJudgment: [
            {
              judgementConditions: [
                {
                  logicalOperator: 1,
                  comparisonOperator: 1,
                  comparisonValue: 0
                }
              ]
            }
          ],
          statusOptionId: 0,
          statusOption: [
            "string"
          ],
          forcePhotograph: true,
          tag: "string",
          symbol: '',
          lowerLimit: '',
          upperLimit:'',
        }, 
        {
          id: 4,
          token: "string",
          baseCreateTime: "2022-07-19T02:37:26.672Z",
          baseCreatorId: 0,
          checkpointId: 0,
          objectId: 0,
          content: "234",
          standard: "3.2",
          dataType: 1,
          unit: "string",
          numberJudgment: [
            {
              judgementConditions: [
                {
                  logicalOperator: 1,
                  comparisonOperator: 1,
                  comparisonValue: 0
                }
              ]
            }
          ],
          statusOptionId: 0,
          statusOption: [
            "string"
          ],
          forcePhotograph: true,
          tag: "string",
          symbol: '',
          unit: '', lowerLimit: '',upperLimit:'',
        }, 
      ],
    },
    {
      objectId:'4',
      name: '王小虎',
      code:'',
      type:0,
      typeStr:'',
      buildId: '',
      floorNo: 0,
      areaId: 0,
      areaName: '',
      items:[
        {
          id: 0,
          token: "string",
          baseCreateTime: "2022-07-19T02:37:26.672Z",
          baseCreatorId: 0,
          checkpointId: 0,
          objectId: 0,
          content: "21231234",
          standard: "3.2",
          dataType: 2,
          unit: "string",
          numberJudgment: [
            {
              judgementConditions: [
                {
                  logicalOperator: 1,
                  comparisonOperator: 1,
                  comparisonValue: 0
                }
              ]
            }
          ],
          statusOptionId: 0,
          statusOption: [
            "string"
          ],
          forcePhotograph: true,
          tag: "string",
          symbol: '',
          unit: '', lowerLimit: '',upperLimit:'',
        }, 
      ],
    },
  ],
}

export default {
  name: 'checkPoint',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker,RelativeMap,SelectView,SelectPatrolLabel,SelectPatrolObject,SelectDepartment,SelectArea },
  cruds() {
    return CRUD({
      title: '巡检点',
      url: 'patrol/checkPoint/getList',
      listOrder: [],
      crudMethod: { ...crudCheckPoint },
      optShow: { add: true, edit: true, del: true, reset: true, import: true },
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    },
    VUE_APP_BASE_API() {
      return process.env.VUE_APP_BASE_API
    },
  },
  data() {
    return {
      mapData: [],
      buildFloor: {},
      checkPointTableOptions,
      viewLoading: false,
      permission: {
        add: ['admin', 'checkPoint : add'],
        edit: ['admin', 'checkPoint : edit'],
        del: ['admin', 'checkPoint : del'],
      },
      rules: {
        name: [{ required: true, message: '请输入巡检点名称', trigger: 'blur' }],
        code: [{ required: true, message: '请输入巡检点编码', trigger: 'blur' }],
        areaName: [{ required: true, message: '请选择所属区域', trigger: 'blur' }],
        labelName: [{ required: true, message: '请选择巡检标签', trigger: 'blur' }],
        checkInMethod: [{ required: true, message: '请选择校验方式', trigger: 'blur' }],
      },
      optionsObj: {
        Build:[],
        CheckInMethod:[],
        ComparisonOperator:[],//比较运算符
        LogicalOperator:[],//逻辑运算符
        ItemDataType:[],//巡检项目数据类型
      },
      areaOptions:[],
      departmentOptions:[],
      token: getToken() ?? '',
      stateDataTypeList:[
        {label:"正常",value:"1"},
        {label:"异常(1)",value:"2"},
        {label:"异常(2)",value:"3"},
      ],
      unitList:[
        {label:"pH值",value:"1"},
        {label:"液位(mm)",value:"2"},
        {label:"压力(KPa)",value:"3"},
        {label:"气体(ppm)",value:"4"},
        {label:"浓度(%LEL)",value:"5"},
        {label:"液位(%)",value:"6"},
      ],
      symbolList:[
        {label:"><",value:"1"},
        {label:"≥≤",value:"2"},
        {label:">",value:"3"},
        {label:"<",value:"4"},
        {label:"≥",value:"5"},
        {label:"≤",value:"6"},
      ],
      showDialog:false
    }
  },
  created() {
    this.getOptions()
    this.getAreaOptions()
    this.getDeptOptions()
  },
  methods: {
    // // 提交前的验证
    [CRUD.HOOK.afterValidateCU]() {
    },
    [CRUD.HOOK.beforeToAdd]() {
    },
    [CRUD.HOOK.beforeToEdit]() {
     
    },
    // //名称验证
    // async nameValidator(val){
    //   console.log(val);
    //   try {
    //     const res = await initData('patrol/checkPoint/nameValidator', {
    //       data:val,
    //     })
    //     console.log(res);
    //     if(!res.data){
    //       this.$message({
    //       showClose: true,
    //       message: '该名称已存在',
    //       type: 'error'
    //     });
    //     }
    //   } catch (error) {
    //     console.log(error);
    //   }
    // },
    // //编码验证
    // async codeValidator(val){
    //   console.log(val);
    //   try {
    //     const res = await initData('patrol/checkPoint/codeValidator', {
    //       data:val,
    //     })
    //     console.log(res);
    //     if(!res.data){
    //       this.$message({
    //       showClose: true,
    //       message: '该编码已存在',
    //       type: 'error'
    //     });
    //     }
    //   } catch (error) {
    //     console.log(error);
    //   }
    // },
    getOptions() {
      Object.keys(this.optionsObj).forEach(async (key) => {
        try {
          let res = await getOptions(key)
          if (res.code === 20000) this.optionsObj[key] = res.data.content
        } catch (error) {
          console.log(error)
        }
      })
    },
    async getAreaOptions(){
      try {
          let res = await initData('positioning/area/getListJson',{"buildId": this.optionsObj.Build.BuildId})
          if (res.code === 20000) res.data.content.forEach((a)=>{
            this.areaOptions.push({
              'label':a.areaName,'value':a.id
            })
          })
          console.log(res);
          console.log(this.areaOptions);
        } catch (error) {
          console.log(error)
        }
    },
    async getDeptOptions(){
      try {
          let res = await initData('system/options/getDepartmentOptions')
          if (res.code === 20000) this.departmentOptions = res.data.content
          console.log(res);
        } catch (error) {
          console.log(error)
        }
    },
    //合并表格
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
     // 判断哪一列 如果需要处理多了 使用 || 进行处理即可
      if (columnIndex === 0) {
        const _row = this.flitterData(this.form.checkItem).one[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    /**合并表格的第一列，处理表格数据 */
    flitterData(arr) {
      let spanOneArr = [];
      let concatOne = 0;
      arr.forEach((item, index) => {
        console.log(item, index);
        if (index === 0) {
          spanOneArr.push(1);
        } else {
        //注意这里的data是表格绑定的字段，根据自己的需求来改
          if (item.data === arr[index - 1].data) {
            //第一列需合并相同内容的判断条件
            spanOneArr[concatOne] += 1;
            spanOneArr.push(0);
          } else {
            spanOneArr.push(1);
            concatOne = index;
          }
        }
      });
      return {
        one: spanOneArr,
      };
    },
    handleDeleteJud(i,index,row) {
      console.log(row);
      if (row && 
          row.items && 
          row.items[index].numberJudgment && 
          row.items[index].numberJudgment[0].judgementConditions && 
          row.items[index].numberJudgment[0].judgementConditions.length > 1
      ) {
        row.items[index].numberJudgment[0].judgementConditions.splice(i,1)
      }else{
        this.$message({
          showClose: true,
          message: '不能再减少运算式',
          type: 'warning'
        })
      }
    },
    handleAddJud(i,index,row){
      console.log(row)
      row.items[index].numberJudgment[0].judgementConditions.splice(row.items.length,0,{
        logicalOperator:1,
        comparisonOperator:1,
        comparisonValue:0
      })
    },
    handleDelete(index,item,row) {
      row.items.splice(index,1)
    },
    handleAdd(index,row){
      console.log(row)
      console.log(index)
      row.items.splice(row.items.length,0,{
        objectId:row.objectId,
        objectName:row.objectName,
        numberJudgment:[
          {
            judgementConditions: [{
              logicalOperator:1,
              comparisonOperator:1,
              comparisonValue:0
            }]
          }
        ]
      })
    },
    // handleAdd(index,row){
    //   console.log(row)
    //   console.log(index)
    //   this.form.checkItem.splice(index+1,0,{
    //     objectId:row.objectId,
    //     objectName:row.objectName
    //   })
    // },
    // handleDelete(index, row) {
    //   this.form.checkItem.splice(index, 1)
    // },
    handleDeleteObj(index, row){
      this.form.objects.splice(index, 1)
    },
    openSelectDept(){
      if (this.$refs.selectDept) {
        this.$refs.selectDept.openOrClose = true
      }
    },
    openSelectPatrolLabel(){
      this.$refs.selectPatrolLabel.openOrClose = true
    },
    openSelectPatrolObject(){
      this.$refs.selectPatrolObject.openOrClose = true
    },
    openSelectArea(){
      this.$refs.selectArea.openOrClose = true
    },
    openshowDialog(){
      this.showDialog = true
      this.mapData = [
        {
          buildId: this.form.label.buildId,
          floorNo: this.form.label.floorNo,
          geometries: [
            {
              type: 'Polygon',
              points: this.form.label.extent.points,
            },
          ],
        },
      ]
    },
    selectDept(list){
      console.log(list)
      this.form.departmentId = list[0].id
      this.form.departmentName= list[0].departmentName
    },
    selectArea(list){
      // console.log(list)
      this.form.areaId = list[0].id
      this.form.areaName = list[0].areaName
    },
    selectPatrolLabel(list){
      // console.log(list)
      this.form.labelId = list[0].id
      this.form.labelName = list[0].name
      this.form.label= list[0]
    },
    //巡检对象选择
    selectPatrolObject(list){
      console.log(list)
      if (list) {
        for (let i = 0; i < list.length; i++) {
          const item = list[i];
          if (!this.inObjectsList(item,this.form.objects)) {
            this.form.objects.push({
              objectId: item.id,
              code: item.code,
              name: item.name,
              type: item.type,
              typeStr: item.typeStr,
              buildId: item.buildId,
              buildName: item.buildName,
              floorNo: item.floorNo,
              floorStr: item.floorStr,
              areaId: item.areaId,
              areaName: item.areaName,
              items: [{
                numberJudgment:[
                  {
                    judgementConditions: [
                      {
                      logicalOperator:1,
                      comparisonOperator:1,
                      comparisonValue:0
                    }
                    ]
                  }
                ]
              }]
            }) 
          }
        }
      }
    },
    inObjectsList(item,list){
      for (let i = 0; i < list.length; i++) {
        const e = list[i];
        if(item && e && item.id == e.objectId){
          return true
        }
      }
      return false
    },
    onCloseDialog(){
      this.showDialog = false
    }
  },
}
</script>

<style lang="scss" scoped>
</style>
