<template>
  <!-- 变量列表 -->
  <el-dialog
    v-model="listDialog"
    :title="DialogArray.monitorDeviceName + '的变量列表'"
    width="70rem"
    @close="close"
    @open="open"
  >
    <div class="dialogOne" style="overflow: hidden">
      <el-radio-group
        v-model="listTabPosition"
        @change="listTabsChange(listTabPosition)"
        style="margin-bottom: 15px; display: flex"
      >
        <el-radio-button label="model">模拟量</el-radio-button>
        <el-radio-button label="state">状态量</el-radio-button>
        <el-radio-button label="parameter">参数量</el-radio-button>
        <!-- <div style="margin-left: 10px">
          <el-button icon="el-icon-plus" type="success">新增</el-button>
        </div> -->
      </el-radio-group>

      <el-input
        placeholder="搜索变量或编码"
        v-model="listInputText"
        style="width: 15rem; margin-bottom: 15px"
      >
        <template #suffix>
          <i class="el-icon-search el-input__icon"></i>
        </template>
      </el-input>

      <el-table
        :data="
          listNumberData.filter(
            (data) =>
              !listInputText ||
              data.variableName
                .toLowerCase()
                .includes(listInputText.toLowerCase()) ||
              data.variableCoding
                .toLowerCase()
                .includes(listInputText.toLowerCase())
          )
        "
        border
        stripe
        :header-cell-style="headClass"
        @selection-change="listSelectionChange"
      >
        <el-table-column
          type="index"
          label="序号"
          align="center"
          sortable
          width=""
        ></el-table-column>
        <el-table-column
          prop="deviceCode"
          label="设备编号"
          sortable
          width=""
        ></el-table-column>
        <el-table-column
          prop="variableName"
          label="变量名"
          sortable
          width=""
        ></el-table-column>
        <el-table-column
          prop="variableCoding"
          label="变量编码"
          sortable
          width=""
        ></el-table-column>
        <el-table-column
          prop="monitoringEquipment"
          label="监控设备"
          sortable
          width=""
        ></el-table-column>
        <el-table-column
          prop="communicationEquipment"
          label="通信设备"
          sortable
          width=""
        ></el-table-column>
        <el-table-column
          prop="dataAddress"
          label="数据地址"
          sortable
          width=""
        ></el-table-column>
        <el-table-column
          prop="dataType"
          label="数据类型"
          width=""
        ></el-table-column>
        <el-table-column
          prop="coefficient"
          label="系数"
          width=""
        ></el-table-column>
        <el-table-column
          prop="saveCycle"
          label="存盘周期"
          width=""
        ></el-table-column>
        <!-- <el-table-column label="操作" width="150">
          <template #default="scope">
            <el-button
              type="text"
              size="small"
              style="color: #409eff"
              @click.prevent="listUpdate(scope.row)"
            >
              修改
            </el-button>
            <el-popconfirm
              confirm-button-text="是"
              cancel-button-text="否"
              icon="el-icon-info"
              icon-color="red"
              title="确定删除?"
              @confirm="confirmEvent(scope.row)"
              @cancel="cancelEvent"
            >
              <template #reference>
                <el-button type="text" size="small" style="color: red">
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column> -->
      </el-table>

      <div class="listPagination">
        <el-pagination
          v-model:currentPage="currentPage"
          :page-sizes="[15, 20, 25, 30]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
        ></el-pagination>
      </div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="close">关闭</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { useStore } from 'vuex'
import { defineComponent, ref, watchEffect } from 'vue'
import * as api from '@/api/deviceManage/powerEquip/deviceAttribute'
import { ElMessage } from 'element-plus'

export default defineComponent({
  name: 'powerEquip',
  emits: ['closeNo'],
  components: {},
  props: {
    list_Dialog: Boolean,
    DialogArray: Object,
  },
  setup(props, context) {
    const store = useStore()

    const pageSize = ref(15)
    const currentPage = ref(1)
    const total = ref(0)

    const multipleSelection = ref([]) //变量列表弹窗复选框值存储
    const listDialog = ref(false)
    const listTitleDialog = ref()
    const listTabPosition = ref('model')
    const listNumberData = ref([]) //变量列表弹窗table值存储

    //变量列表弹窗table 复选框change事件
    const listSelectionChange = (val) => {
      multipleSelection.value = val
    }

    // open(): Dialog弹窗打开之前做的事
    const open = () => {
      listSelect()
    }

    // close(): Dialog弹窗关闭之后做的事
    const close = () => {
      context.emit('closeNo', false)
      listDialog.value = false
    }

    function listSelect() {
      const array = props.DialogArray
      api
        .variableListone({
          siteId: store.state.siteId,
          size: pageSize.value,
          current: currentPage.value,
          dataArea:
            listTabPosition.value == 'model'
              ? 1
              : listTabPosition.value == 'state'
              ? 2
              : listTabPosition.value == 'parameter'
              ? 3
              : 0,
          monitoringEquipment: array.id,
        })
        .then((requset) => {
          if (requset.status === 'SUCCESS') {
            listNumberData.value = requset.data.records
            total.value = requset.data.total
          } else {
            ElMessage.error(requset.msg)
          }
        })
    }

    //变量列表弹窗tabs切换change事件
    const listTabsChange = (value) => {
      listTabPosition.value = value
      listSelect()
    }
    //变量列表弹窗 条数切换change事件
    const handleSizeChange = (val) => {
      pageSize.value = val
      listSelect()
    }
    //变量列表弹窗 页数切换change事件
    const handleCurrentChange = (val) => {
      currentPage.value = val
      listSelect()
    }

    watchEffect((fn, options) => {
      fn, options
      listDialog.value = props.list_Dialog
    })

    // 表头样式设置
    const headClass = () => {
      return 'background:#FAFAFA !important;color: black;'
    }
    return {
      open,
      close,
      headClass,

      pageSize,
      currentPage,
      total,
      handleSizeChange,
      handleCurrentChange,

      listSelectionChange, //变量列表
      listTabsChange, //变量列表tabs切换
      listDialog,
      listTitleDialog,
      listTabPosition,

      listInputText: ref(''), //变量列表input搜索框
      multipleSelection, //变量列表弹窗复选框值存储
      listNumberData,
    }
  },
})
</script>

<style lang="scss" scoped>
//弹出框内容样式
.dialogOne {
  div:nth-child(1) {
    margin-bottom: 30px;
  }
  .content {
    margin-bottom: 20px;
    span:nth-child(1) {
      color: red;
    }
    .inputer {
      width: 150px;
    }
  }
}
.listPagination {
  margin-top: 15px;
  margin-bottom: -30px;
  float: right;
}
.listPagination1 {
  margin-top: 15px;
  float: right;
}
</style>