<template>
  <div class="app-container">
    <div class="header boxShadow">
      <div class="tab-content">
        <div class="tab-btns">
          <el-button type="default" icon="el-icon-document-add">导入</el-button>
          <el-button type="default" icon="el-icon-plus" @click="add('routeName')">新增</el-button>
        </div>
        <div class="tab-form">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item>
              <el-input v-model="formInline.cnameOrNumber" placeholder="输入分类名称或编号" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="search">搜 索</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
    <van-list>
      <div class="list boxShadow" v-for="(item,index) in list" :key="index">
        <div class="list-main">
          <div class="list-content">
            <van-row class="content-1">
              <van-col span="6">仓房名称: <span class="text-colorc">{{item.houseCode }}</span></van-col>
              <van-col span="6">设备名称: <span class="text-colorc">{{item.deviceName}}</span></van-col>
              <van-col span="6">通道号: <span class="text-colorc">{{item.channelNumber}} </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.deviceStatus}} </span></van-col>
              <van-col span="6">设备类型: <span class="text-colorc">{{item.deviceType}} </span></van-col>
               <van-col span="6">更新时间: <span>{{item.lastSeenTime}} </span></van-col>
            </van-row>
          </div>
          <div class="list-btns">
            <el-button type="primary" @click="handleDetail(item)">详情</el-button>
            <el-button type="primary" @click="handleEdit(item)">修改</el-button>
            <el-button type="danger" @click="handleDelete(item)">删除</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, deleteLightingItem } from '@/api/equipConfig/equipConfiguration/index'

export default {
  filters: {

  },
  data () {
    return {
      formInline: {
        cnameOrNumber: ''
      },
      list: [
        {
           houseCode: 'P001', deviceName: '1号仓粮情设备', channelNumber: '0', lastSeenTime: '4',deviceType: '5', deviceStatus: '9'
        },
      ],
      loading: 'false',
      finished: 'false',
      listQuery: {
        condition: "",
        page: 1,
        limit: 10,
        total: 10,
      },
    }
  },
  created () {

  },
  mounted() {
    this.getList()
  },
  methods: {
    getList () {
      let re = /[\u4e00-\u9fa5]/
      let flag = re.test(this.formInline.cnameOrNumber.trim())
      let condition = {
        deviceName: flag ? this.formInline.cnameOrNumber.trim() : '',
        deviceNumber: flag ? '' : this.formInline.cnameOrNumber.trim(),
      }
      let data = {
        pageIndex: this.listQuery.page,
        pageSize: this.listQuery.limit,
        condition: JSON.stringify(condition)
      }
      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(err)
      })
    },
    handleDelete (data) {
      this.$confirm('此操作将删除该条数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteLightingItem(data.id).then(res => {
          // console.log(res, 'delete')
          if (res.code == 200) {
            // this.loading = false
            this.getList()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          } else {
            // this.loading = false
          }
        })
      }).catch(() => {
        // this.loading = false
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleDetail(data) {
      this.$router.push({ name: 'LightingEquipDetail', params: { data: data }})
    },
    handleEdit(data) {
      this.$router.push({ name: 'LightingEquipEdit', params: { data: data } })
    },
    add () {
      this.$router.push({
        name: 'LightingEquipAdd'
      })
    },
    search () {
      this.getList()
    },
    sizeChange (v) {
      this.listQuery.limit = v
      console.log(`每页 ${v} 条`);
      this.list.splice(v, this.list.length - 1)
      this.getList()
    },
    pageChange (v) {
      this.listQuery.page = v
      console.log(`当前页: ${v}`);
      this.getList()
    },
  }
}
</script>
<style lang='scss' scoped>
// .boxShadow {
//   box-shadow: 5px -5px 10px -4px #efe3e3, -5px 5px 10px -4px #efe3e3;
// }
.app-container {
  padding: 0;
}
.header {
  background-color: #fff;
  border-radius: 15px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-top: 10px;
  .header-title {
    font-size: 14px;
    font-weight: 600;
    padding-left: 10px;
    border-left: 4px solid #5283e7;
  }
  .tab-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .tab-form {
      height: 40px;
    }
  }
}
.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;
      height:100px;
      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;
          font-family:' MicrosoftYaHei', '微软雅黑', sans-serif;
        }
      }
      .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>
