<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属企业" prop="enterpriseId">
        <el-select v-model="queryParams.enterpriseId" placeholder="请选择企业" clearable size="small">
          <el-option
            v-for="item in enterprises"
            :key="item.enterpriseId"
            :label="item.enterpriseName"
            :value="item.enterpriseId"/>
        </el-select>
      </el-form-item>
      <el-form-item label="场所/设施名称" prop="venueFacility">
        <el-input
          v-model="queryParams.venueFacility"
          placeholder="请输入场所/设施名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场所分类" prop="venueType">
        <el-select v-model="queryParams.venueType" placeholder="请选择场所分类" clearable size="small">
          <el-option label="密闭空间" value="1" />
          <el-option label="人员密集场所" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="警示标识" prop="warningSign">
        <el-select v-model="queryParams.warningSign" placeholder="请选择警示标识" clearable size="small">
          <el-option label="已设置" value="1" />
          <el-option label="未设置" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="最近检查日期" prop="lastDate">
        <el-date-picker clearable size="small"
                        v-model="queryParams.lastDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择最近检查日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="spaceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="企业名称" align="center" prop="enterpriseName" />
      <el-table-column label="统一社会信用代码" align="center" prop="socialCreditCode" />
      <el-table-column label="场所/设施名称" align="center" prop="venueFacility" />
      <el-table-column label="场所分类" align="center" prop="venueType" >
        <template slot-scope="scope">
          <span v-if="scope.row.venueType == '1'">密闭空间</span>
          <span v-if="scope.row.venueType == '2'">人员密集场所</span>
        </template>
      </el-table-column>
      <el-table-column label="面积/容积(平方米或立方米)" align="center" prop="area" />
      <el-table-column label="警示标识" align="center" prop="warningSign" >
        <template slot-scope="scope">
          <span v-if="scope.row.warningSign == '1'">已设置</span>
          <span v-if="scope.row.warningSign == '2'">未设置</span>
        </template>
      </el-table-column>
      <el-table-column label="最近检查日期" align="center" prop="lastDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--选择关联设备弹出框-->
    <el-dialog title="选择关联设备" :visible.sync="dialogTableVisible" width="1100px" formLabelWidth="160px">
      <template>
        <el-form :model="dateQueryParams" ref="queryForm" :inline="true" v-show="showSearch">
          <el-form-item label="设备名称" prop="deviceName">
            <el-input
              v-model="dateQueryParams.deviceName"
              placeholder="请输入设备名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="设备型号" prop="deviceCode">
            <el-input
              v-model="dateQueryParams.deviceModel"
              placeholder="请输入设备型号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="物联网编号" prop="deviceAddr">
            <el-input
              v-model="dateQueryParams.iotNo"
              placeholder="请输入物联网编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryData">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQueryDate">重置</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="dialogFormVisible = true"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="deleteListDetailInfo"
            >删除</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getDataList"></right-toolbar>
        </el-row>
        <el-table v-loading="loadings" ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" max-height="250" @selection-change="tableDataSelectionChange">
          <el-table-column type="selection" width="55" align="center"></el-table-column>
          <el-table-column label="设备名称" align="center" prop="deviceName" />
          <el-table-column label="设备型号" align="center" prop="deviceModel" />
          <el-table-column label="设备类型" align="center" prop="deviceType" />
          <el-table-column label="探测介质" align="center" prop="detectionMedium" />
          <el-table-column label="物联网编号" align="center" prop="iotNo" />
          <el-table-column label="备注" align="center" prop="remarksn" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="deleteDetailInfo(scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="insertListDetailInfo">提 交</el-button>
          <el-button @click="dialogTableVisible=false">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!--添加关联设备弹出框-->
    <el-dialog title="添加关联设备" :visible.sync="dialogFormVisible">
      <el-form ref="formDetailInfo" :model="formDetailInfo" :rules="formDetailInfoRules" label-width="95px" style="height: 230px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="设备名称" prop="deviceName">
              <el-input v-model="formDetailInfo.deviceName" placeholder="请输入设备名称" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="设备型号" prop="deviceModel">
              <el-input v-model="formDetailInfo.deviceModel" placeholder="请输入设备型号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="设备类型" prop="deviceType">
              <el-select v-model="formDetailInfo.deviceType" placeholder="请选择设备类型">
                <el-option label="压力表" value="1" />
                <el-option label="流量计" value="2" />
                <el-option label="探测器" value="3" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="物联网编号" prop="iotNo">
              <el-input v-model="formDetailInfo.iotNo" placeholder="请输入物联网编号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
            <el-form-item label="探测介质" prop="detectionMedium">
              <el-input v-model="formDetailInfo.detectionMedium" placeholder="请输入探测介质" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
            <el-form-item label="备注" prop="remarksn">
              <el-input v-model="formDetailInfo.remarksn" type="textarea" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addDetailInfo">提 交</el-button>
        <el-button @click="dialogFormVisible=false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改密闭空间和人员密集场所对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="所属企业" prop="enterpriseId">
              <el-select v-model="form.enterpriseId" placeholder="请选择所属单位名称" style="width: 100%" @change="qiyechang" >
                <el-option
                  v-for="item in enterprises"
                  :key="item.enterpriseId"
                  :label="item.enterpriseName"
                  :value="item.enterpriseId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="统一社会信用代码" prop="socialCreditCode">
              <el-input v-model="form.socialCreditCode" placeholder="请输入统一社会信用代码" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="场所设施" prop="venueFacility">
              <el-input v-model="form.venueFacility" placeholder="请输入场所/设施名称" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="场所分类" prop="venueType">
              <el-select v-model="form.venueType" placeholder="请选择场所分类">
                <el-option label="密闭空间" value="1" />
                <el-option label="人员密集场所" value="2" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="具体位置" prop="specificLocation">
              <el-input v-model="form.specificLocation" placeholder="请输入具体位置" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="面积/容积" prop="area">
              <el-input v-model="form.area" placeholder="请输入面积/容积(平方米或立方米)" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="21">
            <el-form-item label="经纬度坐标" prop="longitude">
              <el-col :span="9">
                <el-input v-model="form.longitude" placeholder="请输入经度" />
              </el-col>
              <el-col :span="9" style="margin-left: 15px">
                <el-input v-model="form.latitude" placeholder="请输入纬度"/>
              </el-col>
              <el-col :span="3" style="margin-left: 33px">
                <el-button type="primary" plain @click="MapdialogFun">选择经纬度</el-button>
              </el-col>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="危险因素" prop="riskFactors">
              <el-input v-model="form.riskFactors" placeholder="请输入主要危险因素" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="频次" prop="workFrequency">
              <el-input v-model="form.workFrequency" placeholder="请输入作业/人员频次" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="警示标识" prop="warningSign">
              <el-select v-model="form.warningSign" placeholder="请选择警示标识">
                <el-option label="已设置" value="1" />
                <el-option label="未设置" value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="应急器材" prop="emergencyEquipment">
              <el-input v-model="form.emergencyEquipment" placeholder="请输入主要应急器材" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="负责人" prop="siteSupervisor">
              <el-input v-model="form.siteSupervisor" placeholder="请输入现场负责人" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="电话" prop="supervisorPhone">
              <el-input v-model="form.supervisorPhone" placeholder="请输入负责人电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="最近检查日期" prop="lastDate">
              <el-date-picker clearable size="small"
                              v-model="form.lastDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择最近检查日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="tableTitle">
        <img :src="relationImg" style="width: 24px; height: 25px;position: relative; left: -339px; top: -12px;"/>
        <span class="midText">关联设备</span>
      </div>
      <el-table v-loading="loadings" ref="multipleTable" :data="DetailInfoList" tooltip-effect="dark" style="width: 100%" max-height="250" @selection-change="tableDataSelectionChange">
        <el-table-column label="设备名称" align="center" prop="deviceName" />
        <el-table-column label="设备型号" align="center" prop="deviceModel" />
        <el-table-column label="设备类型" align="center" prop="deviceType" />
        <el-table-column label="物联网编号" align="center" prop="iotNo" />
        <el-table-column label="备注" align="center" prop="remarksn" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="deleteDataListilInfo(scope.row,scope.$index)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="selectDataListInfo">选择关联设备</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <GetPos
      :dialogVisible.sync="dialogTableVisibles"
      device=""
      :devicePos="devicePos"
      @close="dialogcancelFun"
      @getPath="getPath"
    />
  </div>
</template>

<script>
import { listSpace, getSpace, delSpace, addSpace, updateSpace, exportSpace, getDdeviceDetailInfo, addDetailInfos, deleteDetailInfo, deleteeListDetailInfo, selectDetailInfoList, deleteDeviceDetailInfo, updateDetailInfoLists } from "@/api/risk/space";
import {enterpriseLists} from "@/api/regulation/info";
import GetPos from '@/components/GetPos';

export default {
  name: "Space",
  components: {
    GetPos
  },
  data() {
    return {
      relationImg: require('@/assets/project/relation.png'),
      /**--------------地图使用数据---------------*/
      dialogTableVisibles: false,
      devicePos: [],
      /**--------------地图使用数据---------------*/
      // 遮罩层
      loading: true,
      // 下级数据的遮罩层
      loadings: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 下级关联设备条数
      detailTotal: 0,
      // 密闭空间和人员密集场所表格数据
      spaceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      enterprises: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseId: null,
        enterpriseName: null,
        socialCreditCode: null,
        venueFacility: null,
        venueType: null,
        warningSign: null,
        lastDate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        enterpriseId: [
          { required: true, message: "所属企业不能为空", trigger: "blur" }
        ],
        venueFacility: [
          { required: true, message: "场所/设施名称不能为空", trigger: "blur" }
        ],
        venueType: [
          { required: true, message: "场所分类不能为空", trigger: "blur" }
        ],
      },
      // 关联设备相关数据
      dialogTableVisible: false,
      dialogFormVisible: false,
      tableData: [],
      DetailInfoListId: [],
      DetailInfoList: [],
      multipleSelection: [],
      datalist: [],
      dateQueryParams: {
        deviceName: null,
        deviceModel: null,
        iotNo: null,
      },
      formDetailInfo: {
        relationDeviceDetailId: '',
        deviceName: '',
        deviceModel: '',
        deviceType: '',
        iotNo: '',
        detectionMedium: '',
        remarksn: ''
      },
      formDetailInfoRules: {
        deviceName: [
          { required: true, message: "请输入设备名称", trigger: "blur" },
          { min: 0, max: 20, message: "长度 20 位", trigger: "blur" },
        ],
        deviceModel: [
          { required: true, message: "请输入设备型号", trigger: "blur" },
          { min: 0, max: 20, message: "长度 20 位", trigger: "blur" },
        ],
        deviceType: [
          { required: true, message: "请选择设备类型", trigger: "blur" },
        ],
        iotNo: [
          { required: true, message: "请输入联网编号", trigger: "blur" },
          { min: 0, max: 20, message: "长度 20 位", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getEnterpriseLists();
  },
  methods: {
    qiyechang(value){
      let obj = {};
      obj = this.enterprises.find((item)=>{
        return item.enterpriseId === value;
      });
      this.form.enterpriseName = obj.enterpriseName;
      this.form.enterpriseId = value;
    },
    getEnterpriseLists(){
      const param = {};
      enterpriseLists(param).then(response => {
        if (response.rows.length>1){
          this.enterprises = response.rows;
        }else {
          this.form.enterpriseId=response.rows[0].enterpriseId
          this.enterprises = response.rows;
        }
      });
    },
    /** 查询密闭空间和人员密集场所列表 */
    getList() {
      this.loading = true;
      listSpace(this.queryParams).then(response => {
        this.spaceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /**查询下级数据列表方法*/
    getDataList(){
      this.loadings = true;
      getDdeviceDetailInfo(this.dateQueryParams).then(response => {
        this.tableData = response.rows;
        this.detailTotal = response.total;
        this.loadings = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        enterpriseId: null,
        enterpriseName: null,
        socialCreditCode: null,
        venueFacility: null,
        venueType: null,
        specificLocation: null,
        area: null,
        riskFactors: null,
        workFrequency: null,
        warningSign: null,
        emergencyEquipment: null,
        siteSupervisor: null,
        supervisorPhone: null,
        lastDate: null,
        createTime: null,
        longitude: null,
        latitude: null,
        relationDeviceType: '3',
      };
      this.resetForm("form");
      this.DetailInfoList = [];
      this.datalist = [];
      this.DetailInfoListId = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 下级数据搜索*/
    handleQueryData(){
      this.getDataList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 下级数据重置按钮操作  搜索框重置*/
    resetQueryDate(){
      this.dateQueryParams = {
        deviceName: null,
        deviceModel: null,
        iotNo: null,
      }
      this.getDataList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    //关联数据多选框选中数据
    tableDataSelectionChange(selection){
      this.ids = selection.map(item => item.relationDeviceDetailId)
      this.datalist = selection.map(item => item)
      //按钮 非选中禁用
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.loadings = true;
      //查询下级设备数据
      getDdeviceDetailInfo(this.dateQueryParams).then(response => {
        this.tableData = response.rows;
        this.detailTotal = response.total;
        this.loadings = false;
      });
      this.open = true;
      this.title = "添加密闭空间和人员密集场所";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      var tConfinedSpaceInfo = {
        id: id,
        relationDeviceType: '3'
      }
      //查询关联设备信息数据
      selectDetailInfoList(JSON.stringify(tConfinedSpaceInfo)).then(response => {
        this.DetailInfoList = response.rows;
        this.loadings = false;
      });

      getSpace(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改密闭空间和人员密集场所";
        this.devicePos = [response.data.longitude, response.data.latitude];
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSpace(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
            if (this.datalist != null && this.datalist.length > 0) {
              this.form.relationDeviceType = '3';
              var tConfinedSpaceParam = {
                tConfinedSpace: this.form,
                tDeviceInfoS: this.datalist
              }
              //重新绑定修改后的关联设备
              updateDetailInfoLists(JSON.stringify(tConfinedSpaceParam)).then(response => {
                this.open = false;
                this.getList();
              });
            }
          } else {
            if (valid) {
              const deviceIds = this.ids;
              this.form.relationDeviceType = '3';
              var tConfinedSpaceParam = {
                tConfinedSpace: this.form,
                tDeviceInfoS: this.datalist
              }
              addSpace(JSON.stringify(tConfinedSpaceParam)).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            } else {
              console.log('error submit!!');
              return false;
            }
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除密闭空间和人员密集场所编号为"' + ids + '"的数据项？', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delSpace(ids);
      }).then(() => {
        this.getList();
      this.msgSuccess("删除成功");
    }).catch(() => {});
    },
    /**关联设备添加方法*/
    addDetailInfo(){
      this.$refs["formDetailInfo"].validate(valid => {
        if (valid) {
          addDetailInfos(this.formDetailInfo).then(response => {
            this.dialogFormVisible = false;
            this.formDetailInfo = {
              deviceName: null,
              deviceModel: null,
              deviceType: null,
              iotNo: null,
              remarksn: null
            };
            this.getDataList();
            this.msgSuccess("新增成功");
          });
        }
      });
    },
    /**关联设备单条删除方法*/
    deleteDetailInfo(row){
      const deviceIds = row.relationDeviceDetailId;
      this.$confirm('是否确认删除设备信息编号为"' + deviceIds + '"的数据项？', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return deleteDetailInfo(deviceIds);
      }).then(() => {
        this.getDataList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /**关联设备已经选中数据删除方法*/
    deleteDataListilInfo(row,index){
      const deviceIds = row.relationDeviceDetailId;
      if (this.form.id != null) {
        deleteDeviceDetailInfo(deviceIds).then(response => {
          this.msgSuccess("删除成功");
          this.DetailInfoList.splice(index,1);
        });
      } else {
        this.DetailInfoList.splice(index,1);
        this.msgSuccess("删除成功");
      }
    },
    /**批量删除关联设备方法*/
    deleteListDetailInfo(row){
      const deviceIds = this.ids;
      this.$confirm('是否确认删除设备信息编号为"' + deviceIds + '"的数据项？', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return deleteeListDetailInfo(deviceIds);
      }).then(() => {
        this.getDataList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /**添加关联设备与空间绑定的数据*/
    insertListDetailInfo(row){
      const deviceIds = this.ids;
      const li = this.datalist;
      if (this.form.id != null) {
        this.DetailInfoList = this.DetailInfoList.concat(this.datalist)
        this.DetailInfoListId.push(deviceIds);
        this.dialogTableVisible = false
        this.msgSuccess("添加成功");
      } else {
        this.DetailInfoListId.splice(row);
        this.DetailInfoList = this.datalist;
        this.DetailInfoListId.push(deviceIds);
        this.dialogTableVisible = false
        this.msgSuccess("添加成功");
      }
    },
    /**选择关联设备查询方法*/
    selectDataListInfo(){
      this.loadings = true;
      getDdeviceDetailInfo(this.dateQueryParams).then(response => {
        this.tableData = response.rows;
        this.detailTotal = response.total;
        this.loadings = false;
        this.dialogTableVisible = true
      });
    },
    /**
     * 经纬度坐标方法
     */
    MapdialogFun() {
      this.dialogTableVisibles = true;
    },
    /**
     * 地图关闭方法
     */
    dialogcancelFun() {
      this.dialogTableVisibles = false;
    },
    /**
     * 经纬度 选择
     * @param res
     */
    getPath(res){
      this.form.longitude = res[0];
      this.form.latitude = res[1];
    }
  }
};
</script>
