<template>
  <div>
    <!-- 物联数据-->
    <div class="basic-details" id="internet">
      <div class="basic-details-title">
        <span class="border-span">物联数据</span>
        <div
          ><el-button v-if="isIotEnable == 1" type="primary" @click="updateInfo"
            >更新</el-button
          >
          <el-button v-if="isIotEnable == 1" type="primary" @click="edit"
            >点位配置</el-button
          ></div
        >
      </div>
    </div>
    <div class="basic-details-name">{{ name }}</div>
    <!-- 挤压机 65 -->
    <!-- <InternetExtruder :info="info" v-if="parentClassId == '65'" /> -->
    <!-- 干燥箱 57 -->
    <!-- <InternetDryingBox :info="info" v-else-if="parentClassId == '57'" /> -->
    <!-- 其他设备 -->
    <!-- <InternetOther v-else :id="id"></InternetOther> -->
    <internetDetail
      ref="internetDetailRef"
      :info="info"
      :id="id"
      :iotDashboardPoint="iotDashboardPoint"
      @success="getInfo"
    ></internetDetail>
  </div>
</template>

<script>
  import InternetExtruder from './InternetExtruder/InternetExtruder';
  import InternetDryingBox from './InternetDryingBox/InternetDryingBox';
  import InternetOther from './InternetOther';
  import internetDetail from './components/internetDetail.vue';
  import { getDetail } from '@/api/ledgerAssets/equipment';
  import { getAssetInfo } from '@/api/ledgerAssets';
  export default {
    props: ['id', 'name'],
    components: {
      InternetExtruder,
      InternetDryingBox,
      InternetOther,
      internetDetail
    },

    data() {
      return {
        iotId: null,
        // 设备信息
        info: '',
        // 设备名称
        // name: '',
        // 父类id
        parentClassId: '65',
        isIotEnable: null,
        iotDashboardPoint:[]
      };
    },
    created() {
      this.getInfo();
    },
    methods: {
      async getInfo() {
        const data = await getAssetInfo(this.id);
        this.isIotEnable = data.isIotEnable;
        this.iotDashboardPoint=data.iotDashboardPoint
        console.log('data~~~~~', data);
        if (data.isIotEnable != 1) {
          return this.$message.error('该设备未启用物联。');
        }
        getDetail(this.id).then((res) => {
          this.info = res;
          console.log(this.info);
          // this.parentClassId = this.setParentClassId(
          //   this.info.information.classificationUrlId
          // );
        });
      },

      // 获取父类id
      setParentClassId(val) {
        let data = JSON.parse(val);
        return data[1];
      },
      edit() {
        this.$refs.internetDetailRef.edit();
      },
      // 更新信息
      updateInfo() {
        this.$refs.internetDetailRef.getRealData();
      }
    }
  };
</script>
<style lang="scss" scoped>
  .basic-details {
    background: #fff;
    padding: 20px;
  }
  .basic-details-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .basic-details-name {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 10px;
    margin-left: 5px;
  }
  .wrapper {
    background: #fff;
    padding: 20px;
  }

  .no-data {
    background: #fff;
    line-height: 100px;
    font-size: 26px;
    text-align: center;
  }
</style>
