<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="MAC" prop="mac">
        <el-input style="width: 120px" v-model="queryParams.mac" placeholder="请输入mac" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="SN号" prop="sn">
        <el-input style="width: 120px" v-model="queryParams.sn" placeholder="请输入SN号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="硬件版本" prop="hardwareVersion">
        <el-input style="width: 120px" v-model="queryParams.hardwareVersion" placeholder="请输入硬件版本" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="软件版本" prop="version">
        <el-input style="width: 120px" v-model="queryParams.version" placeholder="请输入软件版本" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="在线状态" prop="onlineStatus">
        <el-select v-model="queryParams.onlineStatus" placeholder="请选择在线状态" style="width: 100px;" clearable>
          <el-option v-for="dict in dict.type.as_online_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" style="width: 100px;" clearable>
          <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="锁状态" prop="status">
        <el-select v-model="queryParams.powerStatus" placeholder="请选择锁状态" style="width: 100px;" clearable>
          <el-option v-for="dict in dict.type.et_device_lock_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </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"
          v-hasPermi="['system:device:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:device:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:device:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:device:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange"
      :default-sort="defaultSort" @sort-change="onSortChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column fixed label="MAC-1" prop="mac" width="150" align="center">
        <template slot-scope="d">
          <router-link :to="'/system/deviceDetail/index/' + d.row.deviceId" class="link-type">
            <span>{{ d.row.mac }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="MAC-2" prop="mac2" width="150" align="center">
        <template slot-scope="d">
          <router-link :to="'/system/deviceDetail/index/' + d.row.deviceId" class="link-type">
            <span>{{ d.row.mac2 }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="SN" prop="sn" width="150" align="center">
        <template slot-scope="d">
          <router-link :to="'/system/deviceDetail/index/' + d.row.deviceId" class="link-type">
            <span>{{ d.row.sn }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="图片" width="80" align="center">
        <template slot-scope="d">
          <image-preview v-if="isEmpty(d.row.customPicture)" :src="d.row.picture" :width="50" :height="50" />
          <image-preview v-else :src="d.row.customPicture" :width="50" :height="50" />
        </template>
      </el-table-column>
      <template v-for="column of showColumns">
        <el-table-column
          :key="column.key"
          :label="column.label"
          :prop="column.key"
          :align="column.align"
          :min-width="column.minWidth"
          :sort-orders="orderSorts"
          :sortable="column.sortable"
          :show-overflow-tooltip="column.overflow"
          :width="column.width"
        >
          <template slot-scope="d">
            <template v-if="column.key === 'status'">
              <dict-tag :options="dict.type.as_device_status" :value="d.row[column.key]" />
            </template>
            <template v-else-if="column.key === 'qrText'">
              <el-popover placement="top" width="180" trigger="hover">
                <div class="qr-code-box">
                  <qr-code :text="qrCodeText(d.row)" :width="150" :height="150" />
                  <p>扫描二维码进行设备绑定</p>
                </div>
                <el-button slot="reference" type="text" icon="el-icon-picture">查看</el-button>
              </el-popover>
            </template>
            <template v-else-if="column.key === 'powerStatus'">
              <dict-tag :options="dict.type.et_device_lock_status" :value="d.row[column.key]" />
            </template>
            <template v-else-if="column.key === 'onlineStatus'">
              <el-tag size="small" :type="d.row[column.key] === 1 ? 'success' : 'danger'">
                {{ d.row[column.key] === 1 ? '在线' : '离线' }}
              </el-tag>
            </template>
            <template v-else-if="column.key === 'model'">
              <el-tag size="small">{{ d.row[column.key] }}</el-tag>
            </template>
            <template v-else-if="column.key === 'userName'">
              <el-link
                type="primary"
                @click="handleUserDetail(d.row.userId)"
              >
                <span class="no-wrap">商户：{{ d.row.userName }}</span>
              </el-link>
            </template>
            <template v-else-if="column.key === 'placementStatus'">
              <template v-if="d.row.placementStatus === '2'">
                <span>未投放</span>
              </template>
              <template v-else-if="d.row.placementStatus === '1' && d.row.equ">
                <el-link
                  type="primary"
                  @click="handleEquipmentDetail(d.row.equ.equipmentId)"
                >
                  {{ formatEquipmentInfo(d.row.equ) }}
                </el-link>
              </template>
              <template v-else>-</template>
            </template>
            <template v-else>
              <span class="no-wrap">{{ d.row[column.key] }}</span>
            </template>
          </template>
        </el-table-column>
      </template>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="180"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['system:device:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:device:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:device:remove']"
          >删除</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="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-col :span="8">
          <el-form-item label="MAC" prop="mac">
            <el-input v-model="form.mac" placeholder="请输入设备MAC" :disabled="title == '修改设备'" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="SN" prop="sn">
            <el-input v-model="form.sn" placeholder="请输入SN" :disabled="title == '修改设备' && userName != 'admin'" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="设备型号" prop="modelId">
            <el-select v-model="form.modelId" clearable placeholder="请选择设备型号">
              <el-option v-for="item in modelOptions" :key="item.modelId" :label="item.model"
                :value="item.modelId"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="设备名称" prop="deviceName">
            <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="硬件版本" prop="deviceName" v-if="hardwareVersionOptions.length > 0">
            <el-select v-model="form.hardwareVersionId" clearable placeholder="请选择硬件版本">
              <el-option v-for="item in hardwareVersionOptions" :key="item.id" :label="item.version"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <div v-if="title == '修改设备'">
          <el-col :span="8">
            <el-form-item label="剩余电量" prop="remainingPower">
              <el-input v-model="form.remainingPower" placeholder="请输入剩余电量" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="电压" prop="voltage">
              <el-input v-model="form.voltage" placeholder="请输入剩余电量" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="经度" prop="longitude">
              <el-input v-model="form.longitude" placeholder="请输入经度" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="纬度" prop="latitude">
              <el-input v-model="form.latitude" placeholder="请输入纬度" disabled />
            </el-form-item>
          </el-col>
        </div>
        <el-col :span="24">
          <el-form-item label="硬件版本说明：" label-width="200">
            <span style="color: red;font-weight: 600">
              {{ versionDescription }}
            </span>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 设备详情对话框 -->
    <el-dialog style="font-weight: bold;" title="设备详情" :close-on-click-modal="true" :visible.sync="open2" width="1300px"
      append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="8">
            <el-form-item label="设备mac：">{{ form.mac }}</el-form-item>
            <el-form-item label="设备SN：">{{ form.sn }}</el-form-item>
            <el-form-item label="设备状态：" style="color: #12d2ac;font-weight: 700">{{ form.statusStr }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="分区：" style="color:#4c97e7;font-weight: 700">{{ form.areaName }}</el-form-item>
            <el-form-item label="剩余电量：">{{ form.remainingPower }}%</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="二维码：">
              <template>
                <el-popover placement="top" width="180" trigger="hover">
                  <div class="qr-code-box">
                    <qr-code :text="form.qrText" :width="150" :height="150" />
                  </div>
                  <el-button slot="reference" type="text" icon="el-icon-picture">查看</el-button>
                </el-popover>
              </template>
            </el-form-item>
            <el-form-item label="网络状态：" style="color: #ffcc00;font-weight: 700">{{ form.onlineStatus == 1 ? '在线' : '离线'
              }}</el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <h2 style="font-weight: bold;font-size: 18px;padding: 0;margin: 0">定位更新</h2>
          <el-col :span="6">
            <el-form-item label="经度：">{{ form.longitude }}</el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="纬度：">{{ form.latitude }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="最后更新时间：" label-width="120">{{ form.lastLocationTime }}</el-form-item>
          </el-col>
          <el-col :span="4" v-if="form.gps === '0'">
            <span style="color: red;font-weight: 700">
              当前无gps信号
            </span>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel2">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  listDevice,
  getDevice,
  delDevice,
  addDevice,
  updateDevice,
  handleLock,
  handleUnlocking,
  ring,
  oneClickOnline,
  oneClickOffline,
  reboot,
  oneClickListing,
  oneClickWarehousing,
  seatCushionLock, refreshDevice
} from '@/api/system/device'
import QrCode from '@/components/QrCode/index.vue'
import { parseTime } from '../../../utils/ruoyi';
import { getHardwareVersion, listHardwareVersion } from '@/api/system/hardwareVersion'
import Treeselect from '@riophae/vue-treeselect'
import { $showColumns } from '@/utils/mixins';
import { isEmpty } from '@/utils'
import { getWxIndexUrl } from '@/utils/wx'

// 默认排序字段
const defaultSort = {
  prop: "createTime",
  order: "descending"
}

export default {
  name: "Device",
  mixins: [$showColumns],
  dicts: ['as_online_status', 'as_device_status', 'et_device_lock_status'],
  components: { QrCode },
  props: {
    initLng: {
      type: Number,
      default: 120.356031
    },
    initLat: {
      type: Number,
      default: 26.94088
    },
    storeId: {
      type: Number,
      default: 0
    },
  },
  data() {
    return {
      userName: undefined,
      activeIndex: '1',
      loading: true,
      loading2: true,
      ids: [],
      deptOptions: [],
      key: 0,
      single: true,
      versionDescription: '',
      multiple: true,
      statusOptions: [],
      showSearch: true,
      total: 0,
      defaultSort,
      deviceList: [],
      title: "",
      open: false,
      open2: false,
      modelOptions: [],
      hardwareVersionOptions: [],
      areaOptions: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: defaultSort.prop,
        isAsc: defaultSort.order,
        deviceName: null,
        mac: null,
        sn: null,
        onlineStatus: null,
        status: null,
        version: null,
        hardwareVersion: null,
      },
      columns: [
        { key: 'deviceName', visible: true, label: '设备名称', width: '180', sortable: true, align: 'center' },
        { key: 'model', visible: true, label: '设备型号', width: '150', sortable: true, align: 'center' },
        { key: 'placementStatus', visible: true, label: '投放状态', width: '150', sortable: true, align: 'center' },
        { key: 'version', visible: true, label: '版本', width: '150', sortable: true, align: 'center' },
        { key: 'status', visible: true, label: '状态', width: '120', sortable: true, align: 'center' },
        { key: 'powerStatus', visible: true, label: '开关状态', width: '120', sortable: true, align: 'center' },
        { key: 'onlineStatus', visible: true, label: '网络', width: '120', sortable: true, align: 'center' },
        { key: 'createTime', visible: true, label: '创建时间', width: '180', sortable: true, align: 'center' },
        { key: 'userName', visible: true, label: '所属用户', width: '180', sortable: true, align: 'center' },
      ],
      orderSorts: ['ascending', 'descending', null],
      showPlaceSearchMap: false,
      selected: null,
      form: {},
      rules: {
        sn: [
          { required: true, message: "SN不能为空", trigger: "blur" }
        ],
        mac: [
          { required: true, message: "MAC不能为空", trigger: "blur" }
        ],
      }
    };
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll, true)
  },
  destroyed() {
    window.removeEventListener('scroll', this.handleScroll, true)
  },
  created() {
    if (this.userName === "admin") {
      listHardwareVersion(this.queryParams).then(response => {
        this.hardwareVersionOptions = response.rows;
        this.loading2 = false;
      });
    }
    console.log("当前用户信息：", this.$store.state.user.name)
    const sn = this.$route.params && this.$route.params.sn;
    const vehicleNum = this.$route.params && this.$route.params.vehicleNum;
    console.log("sn------", sn)
    console.log("vehicleNum------", vehicleNum)
    if (sn != null) {
      this.queryParams.sn = sn;
    }
    if (vehicleNum != null) {
      this.queryParams.vehicleNum = vehicleNum;
    }
    this.getDicts("as_device_status").then(response => {
      let options = response.data;
      let mergedObj = { dictValue: '34', dictLabel: '使用中' };
      options = options.filter(option => {
        return option.dictValue !== '3' && option.dictValue !== '4';
      });
      options.splice(4, 0, mergedObj);
      this.statusOptions = options;
    });
    this.userName = this.$store.state.user.name;
    this.getList();
  },
  watch: {
  },
  beforeDestroy() {
  },
  methods: {
    navigateToDetail(type, value) {
      if (type === 'mac') {
        this.$router.push({ path: `/device/mac/${value}` });
      } else if (type === 'sn') {
        this.$router.push({ path: `/device/sn/${value}` });
      }
    },
    onSortChange(column) {
      if (column.order == null) {
        this.queryParams.orderByColumn = defaultSort.prop;
        this.queryParams.isAsc = defaultSort.order;
      } else {
        this.queryParams.orderByColumn = column.prop;
        this.queryParams.isAsc = column.order;
      }
      this.getList();
    },
    handleScroll() {
      let scrollTop = window.scrollY;
      let heightTop = this.$refs['tableSort'].$parent.$parent.$el.offsetTop;
      const headerWrapper = document.querySelector('.el-table__header-wrapper');
      if (scrollTop >= (heightTop + 160)) {
        let top = scrollTop - (heightTop + 160);
        headerWrapper.style.position = 'relative';
        headerWrapper.style.zIndex = '500';
        headerWrapper.style.top = `${top}px`;
      } else if (scrollTop === 0) {
        headerWrapper.style.position = 'relative';
        headerWrapper.style.zIndex = '500';
      } else {
        headerWrapper.style.position = '';
        headerWrapper.style.top = '';
        headerWrapper.style.zIndex = '';
      }
    },
    formatVersion(versionId) {
      if (versionId && this.hardwareVersionOptions.length > 0) {
        const versionItem = this.hardwareVersionOptions.find(item => item.id === versionId);
        if (versionItem) {
          return versionItem.version;
        }
      }
      return "";
    },
    selectHardwareVersion(hardwareVersionId) {
      getHardwareVersion(hardwareVersionId).then(response => {
        this.versionDescription = response.data.instructions;
      });
    },
    closeDialog() {
      this.open2 = false;
    },
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    formatVoltage(row) {
      if (row == undefined || row.voltage == null) {
        return "";
      }
      return row.voltage + 'V';
    },
    qrCodeText(device) {
      let url = `https://testcha.chuangtewl.com?sn=` + device.sn;
      console.log("url------", url)
      return url;
    },
    isEmpty,
    handleBindSn(row) {
      this.form.deviceId = row.deviceId;
      this.showBindSn = true;
    },
    formatPower(row) {
      if (row == undefined || row.remainingPower == null) {
        return "";
      }
      return row.remainingPower + '%';
    },
    oneClickOnline(row) {
      const deviceIds = row.deviceId || this.ids;
      this.$modal.confirm('确认一键解禁？').then(function () {
        return oneClickOnline(deviceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => { });
    },
    oneClickOffline(row) {
      const deviceIds = row.deviceId || this.ids;
      this.$modal.confirm('确认一键禁用？').then(function () {
        return oneClickOffline(deviceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => { });
    },
    oneClickListing(row) {
      const deviceIds = row.deviceId || this.ids;
      this.$modal.confirm('确认一键出仓？').then(function () {
        return oneClickListing(deviceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => { });
    },
    refresh(row) {
      const deviceIds = row.deviceId || this.ids;
      refreshDevice(deviceIds).then(response => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      });
    },
    oneClickWarehousing(row) {
      const deviceIds = row.deviceId || this.ids;
      this.$modal.confirm('确认一键入仓？').then(function () {
        return oneClickWarehousing(deviceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => { });
    },
    onMapGeo(data, lat, lng) {
      console.log("onMapGeo", data)
      let component = data.regeocode.addressComponent;
      this.selected = {
        address: data.regeocode.formattedAddress,
        lng: lat,
        lat: lng,
        province: component.province,
        city: component.city === '' ? '市辖区' : component.city,
        county: component.district,
        name: component.street + component.streetNumber
      }
    },
    onSelectChange(addr) {
      console.log("onSelectChange", addr)
      let data = addr.selected.data;
      this.selected = {
        address: data.pname + (data.cityname === data.pname ? '' : data.cityname) + data.adname + data.address + data.name,
        lng: data.location.lng,
        lat: data.location.lat,
        province: data.pname,
        city: data.cityname === data.pname ? '市辖区' : data.cityname,
        county: data.adname,
        name: data.address + data.name,
      }
    },
    parseTime,
    handleSelect(key, keyPath) {
      this.activeIndex = key;
      console.log(key, keyPath);
    },
    getList() {
      this.loading = true;
      this.queryParams.storeId = this.storeId;
      listDevice(this.queryParams).then(response => {
        this.deviceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel2() {
      this.open2 = false;
    },
    reset() {
      this.form = {
        deviceId: null,
        picture: null,
        deviceName: null,
        mac: null,
        deptId: null,
        modelId: null,
        activationTime: null,
        onlineStatus: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        status: null,
        location: null,
        remainingPower: null,
        qrcode: null,
        longitude: null,
        latitude: null
      };
      this.resetForm("form");
    },
    reset2() {
      console.log(11111)
      this.form.deptId = null;
      this.form.modelId = null;
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.deviceId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备";
    },
    handleView(row) {
      if (row.deviceId) {
        this.$router.push({
          path: `/system/deviceDetail/index/${row.deviceId}`
        });
      }
    },
    handleUpdate(row) {
      this.reset();
      const deviceId = row.deviceId || this.ids
      getDevice(deviceId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备";
      });
    },
    toLog(row) {
      this.$router.push(`/system/commandLog/index/${row.sn}`);
    },
    ring(row) {
      this.reset();
      const deviceId = row.deviceId || this.ids
      getDevice(deviceId).then(response => {
        let form1 = response.data;
        ring(form1).then(response => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        });
      });
    },
    seatCushionLock(row) {
      this.reset();
      const deviceId = row.deviceId || this.ids
      getDevice(deviceId).then(response => {
        let form1 = response.data;
        seatCushionLock(form1).then(response => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        });
      });
    },
    reboot(row) {
      this.reset();
      const deviceId = row.deviceId || this.ids
      getDevice(deviceId).then(response => {
        let form1 = response.data;
        reboot(form1).then(response => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        });
      });
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.deviceId != null) {
            updateDevice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDevice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleDelete(row) {
      const deviceIds = row.deviceId || this.ids;
      this.$modal.confirm('是否确认删除设备编号为"' + deviceIds + '"的数据项？').then(function () {
        return delDevice(deviceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    handleExport() {
      this.download('system/device/export', {
        ...this.queryParams
      }, `device_${new Date().getTime()}.xlsx`)
    },
    handleEquipmentDetail(equipmentId) {
      this.$router.push(`/system/equipment/detail/${equipmentId}`);
    },
    /** 格式化设施信息 */
    formatEquipmentInfo(equipment) {
      if (!equipment) return '-';
      return `${equipment.storeName || ''}-${equipment.name || ''}`;
    },
    /** 查看用户详情按钮操作 */
    handleUserDetail(userId) {
      if (userId) {
        this.$router.push(`/user/detail/${userId}`);
      }
    },
  }
};
</script>
<style lang="scss">
.link-type {
  color: #11A983;
  text-decoration: underline;
}

.link-type:hover {
  color: #11A98330;
  text-decoration: underline;
}
.operation-column {
  .cell {
    white-space: normal !important; /* 允许操作列换行 */
  }
}
/* 添加防止换行的样式 */
.no-wrap {
  white-space: nowrap;
  display: inline-block;
}

.no-wrap-column {
  .cell {
    white-space: nowrap !important;
  }
}

/* 调整表格单元格样式 */
.el-table {
  .cell {
    white-space: nowrap !important;
  }
}
.operation-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;

  .el-button {
    margin: 0;
    padding: 0 5px;
  }
}
.el-select {
  .el-input__inner {
    color: red;
  }
}

.el-input {
  .el-input__inner {
    color: red;
  }
}

.nav-container {
  display: flex;
  justify-content: center;
}

.nav-menu {
  margin: 0;
  padding: 0;
}

.el-dialog__body {
  padding: 10px 20px;
}

.el-dialog:not(.is-fullscreen) {
  margin-top: 1vh !important;
}

.el-dialog__header {
  padding: 10px 20px !important;
}
</style>
