<template>
  <div class="app-container">
    <el-table
      height="740"
      v-loading="loading"
      :data="isolationList"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="隔离点编号" align="center" prop="id" width="100" />
      <el-table-column label="隔离点名称" align="center" prop="pointName"/>
      <el-table-column
        label="隔离点图标"
        align="center"
        prop="pointIcon"
        width="100"
      >
        <template #default="scope">
          <img
            v-if="scope.row.pointIcon"
            :src="scope.row.pointIcon"
            alt=""
            style="width: 50px; height: 50px"
          />
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="开关状态" align="center" prop="switchStatus">
        <template #default="scope">
          <el-switch
            style="pointer-events: none;"
            v-if="scope.row.switchStatus!==null"
            v-model="scope.row.switchStatus"
            active-value="1"
            inactive-value="0"
            active-color="#13ce66"
            inactive-color="grey"
          />
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="隔离点NFC" align="center" prop="pointNfc" />
      <el-table-column label="岗位" align="center" prop="workstationName" />
      <el-table-column label="设备/工艺" align="center" prop="machineryName" />
      <el-table-column label="锁定站" align="center" prop="lotoName" />
      <el-table-column label="隔离点序列号" align="center" prop="pointSerialNumber" />
      <el-table-column label="作用" align="center" prop="remark" />
      <el-table-column
        label="隔离点图片"
        align="center"
        prop="pointPicture"
        width="100"
      >
        <template #default="scope">
          <img
            v-if="scope.row.pointPicture"
            :src="scope.row.pointPicture"
            alt=""
            style="width: 50px; height: 50px"
          />
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="能量源" align="center" prop="powerType">
        <template #default="scope">
          <dict-tag
            :type="DICT_TYPE.POWER_TYPE"
            :value="scope.row.powerType"
          />
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, watch } from 'vue'
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
import * as SpmApi from '@/api/dv/spm/index'

const props = defineProps({
  id: {
    type: String,
    required: true
  }
})
// 数据定义
const loading = ref(true)
const total = ref(0)
const isolationList = ref([])
const ids = ref([])
const multiple = ref(true)
const deptOptions = ref([])
const showSearch = ref(true)
const autoGenFlag = ref(false)


// 查询参数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  pointCode: '',
  pointName: '',
  delFlag: '',
  pointType: '',
  powerType: '',
  startTime: '',
  endTime: '',
  lotoId: null
})

// 表单参数
const form = reactive({})



// 监听 id 变化
watch(() => props.id, (newVal) => {
  console.log('id changed:', newVal)
  queryParams.lotoId = newVal
  getList()
})

// 方法定义
const getList = async () => {
  loading.value = true
  try {

    queryParams.lotoId = props.id

    const response = await SpmApi.getIsIsolationPointPage(queryParams)
    isolationList.value = response.list
    total.value = response.total

  } finally {
    loading.value = false
  }
}




// 生命周期钩子
onMounted(() => {
  getList()
})




</script>

<style lang="scss" scoped>
.el-input-width {
  width: 380px !important;
}

.image-grid {
  display: flex;
  flex-wrap: wrap;
}

.image-item {
  margin: 5px;
  height: 55px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.3s;
  position: relative;

  &.selected {
    height: 55px;
    border-color: rgb(2, 86, 255);
    border-width: 2px;
  }
}
</style>
