<template>
  <div style="cursor: default">
    <div class="search-box">
      <el-input
        style="cursor: pointer"
        size="small"
        clearable
        @change="searchChange()"
        placeholder="请输入设备ID"
        v-model="queryInfo.f_id"
      >
        <i slot="suffix" class="el-input__icon el-icon-search"></i>
      </el-input>
    </div>
    <el-row :gutter="10" v-if="dataList.length > 0">
      <el-col
        :xs="24"
        :sm="24"
        :md="12"
        :lg="6"
        :xl="4"
        v-for="item in dataList"
        :key="item.id"
      >
        <el-card class="box-card pad0">
          <div class="img-box">
            <img src="@/assets/images/monitor/jkIconOn.png" />
            <p>苗情监测设备</p>
          </div>
          <div class="detail">
            <p>
              设备ID
              <span>{{ item.device_id }}</span>
            </p>
            <p>
              在线状态
              <span :class="item.status==0?'red':'green'">{{ item.status==1?'在线':'离线'  }}</span>
            </p>
             <p>
              通道
              <span>{{ item.jktype}}</span>
            </p>
            <p>
              设备名称
              <span>{{ item.device_name || "无" }}</span>
            </p>
          </div>
          <div class="bottom">
            <span @click="modifyName(item.device_id, item.device_name)">
              <i class="el-icon-edit-outline"></i> 修改名称
            </span>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 暂无数据 -->
    <div class="expertDiagnosis_referral_units_not" v-else>
      <img :src="zanwu" alt class="expertDiagnosis_referral_units_notImg" />
    </div>
    <el-pagination
      v-if="dataList.length > 0"
      background
      layout="prev, pager, next"
      :page-size="12"
      :total="totalNum"
      @current-change="changePage"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      zanwu: require("@/assets/images/monitor/zanwu.png"),
      queryInfo: {
        f_id: "",
        page: 1,
      },
      dataList: [],
      totalNum: 0,
      device_id: "",
    };
  },
  created() {
    this.getList();
  },
  beforeMount() {},
  methods: {
    //获取设备列表
    getList() {
      this.$axios({
        method: "POST",
        url: "/api/list_camera",
        data: this.qs.stringify({
          f_id: this.queryInfo.f_id,
          page: this.queryInfo.page,
          equip_type:1
        }),
      }).then((res) => {
        if (res.data.data) {
          this.dataList = res.data.data;
          this.totalNum = res.data.counts;
        }
      });
    },
    searchChange() {
      this.queryInfo.page = 1;
      this.getList();
    },
    // 修改设备名称
    modifyName(id, device_name) {
      let value = device_name;
      this.$prompt("", "修改名字", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPlaceholder: device_name,
      })
        .then(({ value }) => {
          if (value) {
            this.$axios({
              method: "POST",
              url: "/api/equiplist",
              data: this.qs.stringify({
                req: "rename",
                eid: id,
                ename: value,
              }),
            }).then((res) => {
              if (res.data == 0) {
                this.getList() ;
                this.$message({
                  type: "success",
                  message: "修改成功",
                });
              }
            });
          } else {
            this.$message({
              type: "info",
              message: "内容不能为空",
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入",
          });
        });
    },
    changePage(val) {
      this.queryInfo.page = val;
      this.getList();
    },
  },
};
</script>

<style lang='less' scoped>
.red{color:red}
.green{color:#5aae22}
.search-box {
  .el-input {
    width: 200px;
  }
}
.el-card {
  .img-box {
    text-align: center;
    border-bottom: 1px solid #e1e1e1;
    padding: 20px 0;
    img {
      height: 55px;
    }
    p {
      font-size: 14px;
      font-weight: 800;
      margin-top: 10px;
    }
  }
  .detail {
    border-bottom: 1px solid #e1e1e1;
    padding: 10px 0;
    padding: 0 20px;
    p {
      display: flex;
      justify-content: space-between;
      font-size: 13px;
      line-height: 34px;
      color: #666;
    }
  }
  .bottom {
    font-size: 13px;
    color: #666;
    line-height: 50px;
    text-align: center;
    span {
      cursor: pointer;
      i {
        font-size: 16px;
      }
    }
  }
}

// 暂无数据
.expertDiagnosis_referral_units_not {
  width: 272px;
  margin: 0 auto;
}

.el-row {
  /deep/.el-card__body {
    padding: 0 20px;
  }
}
.el-pagination {
  padding: 20px;
  text-align: center;
}
</style>