<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-input
          v-model="query.name"
          clearable
          size="small"
          placeholder="输入姓名"
          style="width: 150px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="query.sex"
          filterable
          clearable
          size="small"
          placeholder="请选择性别"
          class="filter-item"
          style="width: 150px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.Sex"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select
          v-model="query.type"
          filterable
          clearable
          size="small"
          placeholder="请选择人员类型"
          class="filter-item"
          style="width: 150px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.PersonType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-cascader
          v-model="query.department"
          :options="optionsObj.Department"
          :props="{ checkStrictly: true, emitPath: false }"
          filterable
          clearable
          size="small"
          placeholder="请选择部门"
          style="width: 150px"
          class="filter-item"
        />
        <el-select
          v-model="query.position"
          filterable
          clearable
          size="small"
          placeholder="请选择职位"
          class="filter-item"
          style="width: 150px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.Position"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-input
          v-model="query.labelStr"
          clearable
          size="small"
          placeholder="输入标签MAC或名称"
          style="width: 170px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="query.oneKeyAlarm"
          clearable
          size="small"
          placeholder="请选择一键报警"
          class="filter-item"
          style="width: 150px"
          @change="crud.toQuery"
        >
          <el-option label="开启" :value="true" />
          <el-option label="关闭" :value="false" />
        </el-select>
        <el-select
          v-model="query.positioningOnline"
          clearable
          size="small"
          placeholder="请选择定位状态"
          class="filter-item"
          style="width: 150px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in 2"
            :key="item"
            :label="item == '1' ? '在线' : '离线'"
            :value="item == '1' ? true : false"
          />
        </el-select>
        <el-select
          v-model="query.commOnline"
          clearable
          size="small"
          placeholder="请选择通讯状态"
          class="filter-item"
          style="width: 150px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in 2"
            :key="item"
            :label="item == '1' ? '在线' : '离线'"
            :value="item == '1' ? true : false"
          />
        </el-select>
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
    </div>
    <!-- 用户设置 -->
    <el-dialog class="handle-record" width="400px" title="用户设置" :visible.sync="userInfoVisable">
      <el-form size="small" label-width="70px">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="userForm.userName" :disabled="userForm.userName == 'admin'" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="userForm.password" />
        </el-form-item>
        <el-form-item label="状态">
          <el-switch
            v-model="userForm.userStatus"
            active-color="#409EFF"
            inactive-color="#E8E8E8"
            :active-value="1"
            :inactive-value="0"
            :disabled="userForm.userName == 'admin'"
          />
        </el-form-item>
        <el-form-item label="类别">
          <el-radio-group v-model="userForm.isSystem" :disabled="userForm.userName == 'admin'">
            <el-radio :label="1">系统用户</el-radio>
            <el-radio :label="0">普通用户</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="userForm.isSystem == 0" label="角色" prop="roles">
          <el-select v-model="userForm.roleIds" style="width: 290px" multiple placeholder="请选择">
            <el-option v-for="item in optionsObj.Role" :key="item.name" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" v-model="userForm.remark" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="crud.status.cu === 2" type="primary" @click="submitUserInfo"
          >保 存</el-button
        >
        <el-button @click="userInfoVisable = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 报警设置 -->
    <el-dialog
      class="handle-record"
      width="700px"
      title="报警设置"
      :visible.sync="alarmInfoVisable"
    >
      <el-form size="small" label-width="70px">
        <el-row>
          <el-col
            :span="3"
            style="
              font-size: 14px;
              color: #606266;
              font-weight: 600;
              text-align: center;
              padding-top: 6px;
            "
          >
            区域报警
          </el-col>
          <el-col :span="21">
            <div v-for="item in personAreaAlarmConfigList" :key="item.areaId">
              <el-row>
                <el-col
                  :span="3"
                  style="
                    font-size: 14px;
                    color: #606266;
                    font-weight: 600;
                    text-align: center;
                    padding-top: 8px;
                  "
                >
                  <span>{{ item.areaName + '：' }}</span>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="进入报警" prop="crossInAlarm" label-width="80px">
                    <el-switch
                      v-model="item.crossInAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="离开报警" prop="crossOutAlarm" label-width="80px">
                    <el-switch
                      v-model="item.crossOutAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="滞留报警" prop="overstayAlarm" label-width="80px">
                    <el-switch
                      v-model="item.overstayAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="静止报警" prop="actionlessAlarm" label-width="80px">
                    <el-switch
                      v-model="item.actionlessAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col
            :span="3"
            style="
              font-size: 14px;
              color: #606266;
              font-weight: 600;
              text-align: center;
              padding-top: 6px;
            "
          >
            围栏报警
          </el-col>
          <el-col :span="21">
            <div v-for="item in personRailAlarmConfigList" :key="item.railId">
              <el-row>
                <el-col
                  :span="3"
                  style="
                    font-size: 14px;
                    color: #606266;
                    font-weight: 600;
                    text-align: center;
                    padding-top: 8px;
                  "
                >
                  <span>{{ item.railName + '：' }}</span>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="进入报警" prop="crossInAlarm" label-width="80px">
                    <el-switch
                      v-model="item.crossInAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="离开报警" prop="crossOutAlarm" label-width="80px">
                    <el-switch
                      v-model="item.crossOutAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="滞留报警" prop="overstayAlarm" label-width="80px">
                    <el-switch
                      v-model="item.overstayAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="静止报警" prop="actionlessAlarm" label-width="80px">
                    <el-switch
                      v-model="item.actionlessAlarm"
                      active-color="#409EFF"
                      inactive-color="#F56C6C"
                      :active-value="true"
                      :inactive-value="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="crud.status.cu === 2" type="primary" @click="submitAlarmInfo"
          >保 存</el-button
        >
        <el-button @click="alarmInfoVisable = false">关 闭</el-button>
      </span>
    </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="900px"
    >
      <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="工号" prop="workNo">
              <el-input v-model="form.workNo" />
            </el-form-item>
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" />
            </el-form-item>
            <el-form-item label="性别" prop="sex">
              <el-select
                v-model="form.sex"
                filterable
                clearable
                size="small"
                placeholder="请选择性别"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionsObj.Sex"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="标签MAC" prop="labelId">
              <el-select
                v-model="form.labelId"
                filterable
                clearable
                size="small"
                placeholder="请选择标签"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionsLabel"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="入职时间" prop="entryTime">
              <el-date-picker
                v-model="form.entryTime"
                type="date"
                placeholder="请选择日期"
                size="small"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="民族" prop="ethnicity">
              <el-select
                v-model="form.ethnicity"
                filterable
                size="small"
                placeholder="请选择"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionEthnicity"
                  :key="item.dictKey"
                  :label="item.dictValue"
                  :value="item.dictKey"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="证件类型" prop="idType">
              <el-select
                v-model="form.idType"
                filterable
                size="small"
                placeholder="请选择"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionIdType"
                  :key="item.dictKey"
                  :label="item.dictValue"
                  :value="item.dictKey"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="人员类型" prop="type">
              <el-select
                v-model="form.type"
                filterable
                size="small"
                placeholder="请选择类型"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionsObj.PersonType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="部门" prop="department">
              <el-cascader
                v-model="form.department"
                :options="optionsObj.Department"
                :props="{ checkStrictly: true, emitPath: false }"
                filterable
                size="small"
                placeholder="请选择部门"
                style="width: 100%"
                class="filter-item"
              />
            </el-form-item>
            <el-form-item label="职位" prop="position">
              <el-select
                v-model="form.position"
                filterable
                size="small"
                placeholder="请选择职位"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionsObj.Position"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="生日" prop="birthday">
              <el-date-picker
                v-model="form.birthday"
                type="date"
                placeholder="请选择日期"
                size="small"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="年龄" prop="age">
              <el-input v-model="form.age" />
            </el-form-item>
            <el-form-item label="政治面貌" prop="politicalStatus">
              <el-select
                v-model="form.politicalStatus"
                filterable
                clearable
                size="small"
                placeholder="请选择"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionPoliticalStatus"
                  :key="item.dictKey"
                  :label="item.dictValue"
                  :value="item.dictKey"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="证件号码" prop="idNumber">
              <el-input v-model="form.idNumber" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="" prop="" label-width="60px">
              <upload-picture
                v-model="form.photoPath"
                :maxSize="5 * 1024 * 1024"
                previewWidth="170px"
                previewHeight="195px"
              />
            </el-form-item>
            <el-form-item label="一键报警" prop="oneKeyAlarm">
              <el-switch
                v-model="form.oneKeyAlarm"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="true"
                :inactive-value="false"
              >
              </el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="telephone">
              <el-input v-model="form.telephone" />
            </el-form-item>
            <el-form-item label="健康状况" prop="healthCondition">
              <el-select
                v-model="form.healthCondition"
                filterable
                size="small"
                placeholder="请选择"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionHealthCondition"
                  :key="item.dictKey"
                  :label="item.dictValue"
                  :value="item.dictKey"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="户籍所在地" prop="registeredPermanent">
              <el-input v-model="form.registeredPermanent" />
            </el-form-item>
            <el-form-item label="参加工作时间" prop="startWorkTime">
              <el-date-picker
                v-model="form.startWorkTime"
                type="date"
                placeholder="请选择日期"
                size="small"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="办公电话" prop="officePhone">
              <el-input v-model="form.officePhone" />
            </el-form-item>
            <el-form-item label="学历" prop="education">
              <el-select
                v-model="form.education"
                filterable
                size="small"
                placeholder="请选择"
                class="filter-item"
                style="width: 100%"
              >
                <el-option
                  v-for="item in optionEducation"
                  :key="item.dictKey"
                  :label="item.dictValue"
                  :value="item.dictKey"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="通讯地址" prop="contactAddress">
              <el-input v-model="form.contactAddress" />
            </el-form-item>
            <el-form-item label="职称技能等级" prop="jobTitle">
              <el-input v-model="form.jobTitle" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="电子邮箱" prop="email">
              <el-input v-model="form.email" />
            </el-form-item>
            <el-form-item label="专业" prop="speciality">
              <el-input v-model="form.speciality" />
            </el-form-item>
            <el-form-item label="邮编" prop="zipCode">
              <el-input v-model="form.zipCode" />
            </el-form-item>
            <el-form-item label="职务" prop="duty">
              <el-input v-model="form.duty" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="工作职责" prop="dutyOfWork">
              <el-input type="textarea" :rows="3" v-model="form.dutyOfWork" />
            </el-form-item>
            <el-form-item label="工作经历" prop="workExperience">
              <el-input type="textarea" :rows="3" v-model="form.workExperience" />
            </el-form-item>
          </el-col>
        </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 personTableOptions"
        :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', 'person:edit', 'person:del'])"
        label="操作"
        width="400px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <div style="display: flex">
            <el-button
              v-permission="['admin', 'person:edit']"
              type="primary"
              size="mini"
              @click="setUserInfo(scope.row)"
              style="margin-right: 0px"
              >设置用户</el-button
            >
            <el-button
              v-permission="['admin', 'person:edit']"
              type="warning"
              size="mini"
              v-if="true"
              :disabled="scope.row.userName == 'admin' || !scope.row.isLogin"
              @click="delUserInfo(scope.row)"
              style="margin-right: 10px"
              >删除用户</el-button
            >
            <el-button
              v-permission="['admin', 'person:edit']"
              type="danger"
              size="mini"
              @click="setAlarmInfo(scope.row)"
              style="margin-right: 10px"
              >报警设置</el-button
            >
            <udOperation
              :data="scope.row"
              :permission="permission"
              :disabledDle="scope.row.userName == 'admin'"
            />
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import permission from '@/directive/permission'
import crudPerson from '@/api/system/person'
import { getOptions } from '@/api/system/public'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import { crudOperation, rrOperation, udOperation, pagination } from '@crud'
import crudComps from '@crud'
import DateRangePicker from '@/components/DateRangePicker'
import { personTableOptions } from '../tableConfig'
import { initData } from '@/api/data'
import UploadPicture from '@/components/UploadPicture'

const defaultForm = {
  id: null,
  name: '',
  workNo: '',
  type: null,
  typeName: '',
  iconPath: '',
  department: null,
  departmentName: '',
  position: null,
  positionName: '',
  sex: '',
  sexName: '',
  labelId: null,
  labelMAC: '',
  photoPath: '', //照片链接
  oneKeyAlarm: true,
  oneKeyAlarmStr: '',
  entryTime: '',
  birthday: '',
  age: null,
  politicalStatus: '',
  politicalStatusStr: '',
  ethnicity: '',
  ethnicityStr: '',
  idType: '',
  idTypeStr: '',
  idNumber: '',
  telephone: '',
  officePhone: '',
  email: '',
  healthCondition: '',
  healthConditionStr: '',
  education: '',
  educationStr: '',
  speciality: '',
  registeredPermanent: '',
  contactAddress: '',
  zipCode: '',
  startWorkTime: '',
  jobTitle: '',
  duty: '',
  dutyOfWork: '',
  workExperience: '',
  positioningOnline: true,
  positioningOnlineStr: '',
  commOnline: true,
  commOnlineStr: '',
  userName: '',
  isSystem: 0,
  userStatus: 0,
  isOnline: 0,
  userRemark: '',
  isLogin: true,
  isLoginStr: '',
  personAlarmConfigList: [], //报警配置
  locationData: {},
  onOneKeyAlarm: true,
  onCrossInAlarm: true,
  onCrossOutAlarm: true,
  onOverstayAlarm: true,
  onRailAlarm: [],
  onactionlessAlarm: true,
  userName: '',
  isSystem: 0,
  userStatus: 1,
  userRemark: '',
  roleIds:[]
}

export default {
  name: 'Person',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker, UploadPicture },
  cruds() {
    return CRUD({
      title: '人员信息',
      url: 'system/person/getPageListJson',
      listOrder: [],
      crudMethod: { ...crudPerson },
      optShow: { add: true, edit: true, del: true, reset: true, import: true, export: true },
      params: {
        typeBelong: 1,
      },
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    },
    VUE_APP_BASE_API() {
      return process.env.VUE_APP_BASE_API
    },
  },
  data() {
    return {
      personTableOptions,
      viewLoading: false,
      userInfoVisable: false,
      alarmInfoVisable: false,
      permission: {
        add: ['admin', 'person : add'],
        edit: ['admin', 'person : edit'],
        del: ['admin', 'person : del'],
      },
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        //sex: [{ required: true, message: '请选择性别', trigger: 'blur' }],
        type: [{ required: true, message: '请选择人员类型', trigger: 'blur' }],
        department: [{ required: true, message: '请选择部门', trigger: 'blur' }],
        position: [{ required: true, message: '请选择职位', trigger: 'blur' }],
      },
      personRailAlarmConfigList: [],
      personAreaAlarmConfigList: [],
      optionsObj: {
        Sex: [],
        PersonType: [],
        Department: [],
        Position: [],
        Role:[]
      },
      optionPoliticalStatus: [],
      optionEducation: [],
      optionEthnicity: [],
      optionHealthCondition: [],
      optionIdType: [],
      optionsLabel: [],
      popUserDel: false,
      userForm: {
        personId: '',
        userName: '',
        password: '',
        userStatus: 1,
        isSystem: 0,
        remark: '',
        roleIds:[]
      },
      alarmForm: {
        personAlarmConfigList: [], //报警配置
      },
    }
  },
  created() {
    this.getOptions()
    this.getRailData()
    this.getAreaData()
    this.getDictDOptions('154')
    this.getDictDOptions('153')
    this.getDictDOptions('152')
    this.getDictDOptions('151')
    this.getDictDOptions('150')
  },
  methods: {
    // 提交前的验证
    [CRUD.HOOK.afterValidateCU]() {},
    [CRUD.HOOK.beforeToAdd]() {
      console.log(this.form.id)
      this.getLabelOptions(this.form.id)
      this.getRailData()
      this.getAreaData()
    },
    [CRUD.HOOK.beforeToEdit]() {
      // console.log(this.form)
      this.getLabelOptions(this.form.id)
    },
    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 getDictDOptions(type) {
      try {
        let res = await initData('system/dataDictDetail/getTypeListJson', {
          dictType: type,
        })
        if (res.code === 20000) {
          if (type == '154') {
            this.optionPoliticalStatus = res.data.content
          }
          if (type == '153') {
            this.optionEducation = res.data.content
          }
          if (type == '152') {
            this.optionHealthCondition = res.data.content
          }
          if (type == '151') {
            this.optionIdType = res.data.content
          }
          if (type == '150') {
            this.optionEthnicity = res.data.content
          }
        }
      } catch (error) {
        console.log(error)
      }
    },
    async getLabelOptions(id) {
      try {
        let res = await getOptions('Label', { id: id })
        if (res.code === 20000) this.optionsLabel = res.data.content
      } catch (error) {
        console.log(error)
      }
    },
    //获取弹窗内的围栏信息
    async getRailData() {
      try {
        const res = await initData('positioning/rail/getPageListJson', {
          PageIndex: 0,
          PageSize: 0,
        })
        const data = res.data.content
        this.personRailAlarmConfigList = data.map((item) => {
          return {
            railId: item.id,
            railName: item.railName,
            crossInAlarm: false,
            crossOutAlarm: false,
            overstayAlarm: false,
            actionlessAlarm: false,
          }
        })
      } catch (error) {
        console.log(error)
      }
    },
    //获取弹窗内的区域信息
    async getAreaData() {
      try {
        const res = await initData('positioning/area/getPageListJson', {
          PageIndex: 0,
          PageSize: 0,
        })
        const data = res.data.content
        this.personAreaAlarmConfigList = data.map((item) => {
          return {
            areaId: item.id,
            areaName: item.areaName,
            crossInAlarm: false,
            crossOutAlarm: false,
            overstayAlarm: false,
            actionlessAlarm: false,
          }
        })
      } catch (error) {
        console.log(error)
      }
    },
    setUserInfo(row) {
      this.userInfoVisable = true
      if (row.isLogin) {
        this.userForm = {
          personId: row.id,
          userName: row.userName,
          password: '',
          userStatus: row.userStatus,
          isSystem: row.isSystem,
          remark: row.userRemark,
          roleIds:row.roleIds,
        }
      } else {
        this.userForm = {
          personId: row.id,
          userName: '',
          password: '',
          userStatus: 1,
          isSystem: 0,
          remark: '',
          roleIds:[],
        }
      }
    },
    delUserInfo(row) {
      this.$confirm(`确认删除【${row.name}】的用户?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          crudPerson
            .delUser({ id: row.id })
            .then((res) => {
              this.crud.refresh()
            })
            .catch((err) => {
              console.err(err)
            })
        })
        .catch(() => {})
    },
    submitUserInfo() {
      console.log(this.userForm)
      if (this.userForm.isSystem ===0 && this.userForm.roleIds.length === 0) {
        this.$message({
          message: '角色不能为空',
          type: 'warning',
        })
        return false
      }
      crudPerson
        .setUser(this.userForm)
        .then((res) => {
          this.crud.refresh()
        })
        .catch((err) => {
          console.err(err)
        })
      this.userInfoVisable = false
    },
    setAlarmInfo(row) {
      this.alarmInfoVisable = true
      this.alarmForm = row
      // console.log(row)
      if (row.personAlarmConfigList.length) {
        this.personRailAlarmConfigList.forEach((item) => {
          item.crossInAlarm = false
          item.crossOutAlarm = false
          item.overstayAlarm = false
          item.actionlessAlarm = false
          let config = row.personAlarmConfigList.find((formItem) => formItem.railId == item.railId)
          if (config) {
            const { crossInAlarm, crossOutAlarm, overstayAlarm, actionlessAlarm } = config
            item.crossInAlarm = crossInAlarm
            item.crossOutAlarm = crossOutAlarm
            item.overstayAlarm = overstayAlarm
            item.actionlessAlarm = actionlessAlarm
          }
        })
        this.personAreaAlarmConfigList.forEach((item) => {
          item.crossInAlarm = false
          item.crossOutAlarm = false
          item.overstayAlarm = false
          item.actionlessAlarm = false
          let config = row.personAlarmConfigList.find((formItem) => formItem.areaId == item.areaId)
          if (config) {
            const { crossInAlarm, crossOutAlarm, overstayAlarm, actionlessAlarm } = config
            item.crossInAlarm = crossInAlarm
            item.crossOutAlarm = crossOutAlarm
            item.overstayAlarm = overstayAlarm
            item.actionlessAlarm = actionlessAlarm
          }
        })
      } else {
        //this.getRailData()
        //this.getAreaData()
        this.personRailAlarmConfigList.forEach((item) => {
          item.crossInAlarm = false
          item.crossOutAlarm = false
          item.overstayAlarm = false
          item.actionlessAlarm = false
        })
        this.personAreaAlarmConfigList.forEach((item) => {
          item.crossInAlarm = false
          item.crossOutAlarm = false
          item.overstayAlarm = false
          item.actionlessAlarm = false
        })
      }
    },
    submitAlarmInfo() {
      if (this.personRailAlarmConfigList && this.personAreaAlarmConfigList) {
        this.alarmForm.personAlarmConfigList = []
        this.alarmForm.personAlarmConfigList.push.apply(
          this.alarmForm.personAlarmConfigList,
          this.personRailAlarmConfigList
        )
        this.alarmForm.personAlarmConfigList.push.apply(
          this.alarmForm.personAlarmConfigList,
          this.personAreaAlarmConfigList
        )
      }
      console.log(this.alarmForm.personAlarmConfigList)
      crudPerson
        .edit(this.alarmForm)
        .then((res) => {
          this.crud.refresh()
        })
        .catch((err) => {
          console.err(err)
        })
      this.alarmInfoVisable = false
    },
  },
}
</script>

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