<template>
  <div style="cursor: default">
    <el-breadcrumb
			separator-class="el-icon-arrow-right"
			v-show="flag.flag"
		>
		<el-breadcrumb-item>{{flag.siteNameTitle}}  设备列表 </el-breadcrumb-item>
	</el-breadcrumb>
    <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">
          <!-- <div class="img-box">
            <img src="@/assets/images/monitor/jkIconOn.png" />
            <p :title="item.device_name">{{ (item.device_name || "苗情监测设备") | ellipsis }}</p>
          </div> -->
          <div class="detail">
            <p>
              <span style="display: inline-block;
                width: 10px;
                height: 10px;
                background: #52459F;
                border-radius: 50%;
                margin-right: 15px;">
              </span>
              {{ (item.device_name || "苗情监测设备") | ellipsis }}
            </p>
            <p>
				      <img src="../assets/images/cardicon/sbid.png" />
              设备ID:
              <span>{{ item.device_id }}</span>
            </p>
            <p>
				      <img src="../assets/images/cardicon/zxzt.png" />
              	在线状态:
                <span :class="item.status==0?'red':'green'">{{ item.status==1?'在线':'离线'  }}</span>
            </p>
            <p>
				      <img src="../assets/images/cardicon/yxgh.png" />
              通道:
              <span>{{ item.jktype }}</span>
            </p>
          </div>
          <div class="btns" style="padding-top:10px;">
            <el-button
              size="mini"
              type="info"
              @click="modifyName(item.device_id, item.device_name)"
              >修改名称</el-button
            >
          
        </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 {
  props: {
    siteId: {
      type: Number
    },
    flag: {
      type: Object,
      default: () => {},
    },
  },
  filters: {
    ellipsis(value) {
			if (!value) return ''
			if (value.length > 10) {
				return value.slice(0, 10) + '...'
			}
			return value
		},
  },
  data() {
    return {
      zanwu: require("@/assets/images/monitor/zanwu.png"),
      queryInfo: {
        f_id: "",
        page: 1,
      },
      dataList: [],
      totalNum: 0,
      device_id: "",
      objData: {},
    };
  },
  created() {
    this.getList();
  },
  beforeMount() {},
  methods: {
    //获取设备列表
    getList(obj, page) {
      if (obj) {
        console.log(obj)
				this.queryInfo.page = page
				this.objData = obj
      }
      var id = ''
			if (this.objData !== undefined) {
				id = this.objData.id
			} else if (obj !== undefined) {
				id = obj.id
			}
      this.$axios({
        method: "POST",
        url: "list_camera",
        data: this.qs.stringify({
          f_id: this.queryInfo.f_id,
          page: this.queryInfo.page,
          equip_type:1,
          site_id: id
        }),
      }).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: "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 {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
  .el-input {
    width: 200px;
  }
  /deep/.el-input__inner{
    background-color: #E5E7FF;
    border: none;
    color: #5361FF;
  }
  /deep/.el-input__inner::placeholder{
    color: #5361FF;
  }
  /deep/.el-input__inner::-moz-placeholder{
    color: #5361FF;
  }
  /deep/.el-input__inner::-webkit-input-placeholder{
    color: #5361FF;
  }
  /deep/.el-input__inner::-ms-input-placeholder{
    color: #5361FF;
  }
  /deep/.el-input__icon{
    color: #5361FF;
  }
}
.box-card{
	box-shadow: 0px 0px 36px 0px rgba(72,68,219,0.19);
	border-radius: 14px;
	background: url(../assets/images/cardBG.png) no-repeat right bottom;
	background-size: 150px;
}
.el-card {
  /deep/.el-card__body{
		padding: 15px 15px;
		box-sizing: border-box;
	}
  .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 {
    p {
      display: flex;
      justify-content: flex-start;
	    align-items: center;
      font-size: 14px;
      line-height: 34px;
      color: #464B5A;
      img{
        width: 14px;
        height: 14px;
        position: relative;
        top: 2px;
        margin-right: 10px;
	    }
    }
  }
  .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>