<template>
  <div class="app-container">
    <router-view />
    <div class="header boxShadow">
      <div class="header-title">照明设备</div>
      <van-notice-bar color="#f12b07" background="#fff" left-icon="info-o" v-if="notice">
        今日检测共有10个仓房能耗异常！
      </van-notice-bar>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="标签类型">
          <el-input v-model="formInline.equipmentType" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="所在位置">
          <el-input v-model="formInline.equipmentLocation" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="设备标签">
          <el-input v-model="formInline.equipmentTagid" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
          <!-- <el-button type="primary" @click="onSubmit">能耗检测</el-button> -->
        </el-form-item>
      </el-form>
    </div>
    <van-list>
      <!-- <van-cell v-for="item in list" :key="item" :title="item" /> -->
      <div class="list boxShadow" v-for="(item,index) in list" :key="index">
        <div class="list-main">

          <div class="list-content">
            <div class="list-title">{{ item.equipmentName}}</div>
            <van-row class="content-1">
              <van-col span="6">标签编号: <span>{{item.equipmentTagid}}</span></van-col>
              <van-col span="6">设备类型: <span>{{item.equipmentType}}</span></van-col>
              <van-col span="6">所在位置: <span>{{item.equipmentLocation}} </span></van-col>
              <!-- <van-col span="6">是否存在异常:<span><strong>{{item.isAbnormal}}</strong> </span></van-col> -->
            </van-row>
            <van-row class="content-1">
              <van-col span="6">设备状态:
                <!-- <span>{{item.equipmentDeviceState}} </span> -->
                <span v-if="item.equipmentStatus == '0'">关闭中</span>
                <span v-if="item.equipmentStatus == '1'">运行中</span>
              </van-col>
              <van-col span="6">操作员: <span >{{item.equipmentOperator}} </span></van-col>
              <van-col span="6">运行时间: <span>{{item.equipmentOpeningTime}} </span></van-col>
            </van-row>
          </div>
          <div class="list-btns">
            <el-button type="primary" @click="handleRecord(item)">运行记录</el-button>
            <el-button type="primary" @click="close(item)">关闭</el-button>
            <!-- <el-button type="primary" @click="handleHistory">历史记录</el-button> -->
          </div>
        </div>

      </div>
    </van-list>
    <div class="pagination-container">
      <el-pagination class="right" background :current-page.sync="listQuery.page" :page-size="listQuery.limit" :page-sizes="[5, 10, 20, 30]" :total="listQuery.total" @size-change="sizeChange" @current-change="pageChange" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    </div>
  </div>
</template>

<script>
import { getLightingList, updateLightingItem } from '@/api/equipControl/index'

export default {
  data () {
    return {
      notice: false,
      formInline: {
        equipmentType: '',
        equipmentLocation: '',
        equipmentTagid: ''
      },
      list: [
        {
          equipmentName: '1号环流风机', equipmentTagid: '1001', equipmentType: '环流风机', equipmentLocation: '1号仓房', state: '运行中', equipmentOperator: '王全德', equipmentOpeningTime: '6h'
        },
      ],
      loading: 'false',
      finished: 'false',

      listQuery: {
        condition: "",
        page: 1,
        limit: 10,
        total: 10,
      },
    }
  },
  created () {

  },
  mounted () {
    this.getList()
  },
  methods: {
    search () {
      this.getList()
    },
    getList () {
      let data = {
        currentPage: this.listQuery.page,
        pageSize: this.listQuery.limit,
        equipmentType: this.formInline.equipmentType,
        equipmentTagid: this.formInline.equipmentTagid,
        equipmentLocation: this.formInline.equipmentLocation,
      }
      getLightingList(data).then(res => {
        console.log(res, 'getLightingList')
        if (res.code == 200) {
          this.list = res.data.records
          this.listQuery.limit = res.data.size
          this.listQuery.total = res.data.total
        }
      }).catch(err => {
        console.log(res)
      })
    },
    close (data) {
      if (data.equipmentStatus == 1) {
        data.equipmentStatus = 0
        updateLightingItem(data).then(res => {
          console.log(res, 'updateLightingItem')
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '关闭成功!'
            });
          }
        }).catch(err => {
          console.log(err)
        })
      } else {
        this.$message({
          type: 'warning',
          message: '该设备已处于关闭状态！!'
        });
      }

    },
    handleHistory () {
      this.$router.push({ name: 'EnergyConsumptionAbnormalList' })
    },
    handleRecord (data) {
      this.$router.push({ name: 'LightingLog', params: { data: data ,type:'tf'} })
    },
    sizeChange (v) {
      this.listQuery.limit = v
      console.log(`每页 ${v} 条`);
      this.list.splice(v, this.list.length - 1)
    },
    pageChange (v) {
      this.listQuery.page = v
      console.log(`当前页: ${v}`);
    },
  }
}
</script>
<style lang='scss' scoped>
.boxShadow {
  box-shadow: 5px -5px 10px -4px #efe3e3, -5px 5px 10px -4px #efe3e3;
}
::v-deep .van-notice-bar {
  font-weight: 600;
  padding: 0;
  cursor: pointer;
}
.header {
  background-color: #fff;
  border-radius: 15px;
  padding: 15px;
  // height: 160px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .header-title {
    font-size: 14px;
    font-weight: 600;
    padding-left: 10px;
    border-left: 4px solid #5283e7;
  }
  .van-notice-bar {
    padding: 10px 0 10px 0;
  }
  .el-form {
    .el-form-item {
      margin-bottom: 0;
    }
  }
}
.list {
  background-color: #fff;
  border-radius: 15px;
  margin-top: 10px;
  .list-main {
    padding-left: 15px;
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
    .list-title {
      font-size: 15px;
      font-weight: 700;
      padding: 10px 0;
    }
    .list-content {
      width: 78%;
      padding: 10px 10px 10px 5px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .content-1 {
        font-size: 13px;
        display: flex;
        justify-content: space-between;
        margin-top: 10px;
        // padding: 5px 0;
        strong {
          color: #d24848;
        }
        .text-colorc {
          color: #b8b8b8;
        }
      }
      .content-1:nth-last-child(1) {
        padding-bottom: 10px;
      }
    }
    .list-btns {
      width: 22%;
      background-color: #edf2fd;
      display: flex;
      justify-content: space-evenly;
      align-items: center;
    }
  }
}
</style>
