<template>
  <div class="app-container">
    <router-view />
    <div class="header boxShadow">
      <div class="header-title">仓房基本信息</div>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="仓房名称" prop="houseName">
          <el-input v-model="formInline.houseName" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="仓房编号" prop="houseCode">
          <el-input v-model="formInline.houseCode" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item class="fr">
          <el-button @click="onSubmit">查 询</el-button>
          <el-button @click="onSubmit" icon="el-icon-document-add">导 入</el-button>
          <el-button type="default" @click="handleAdd" icon="el-icon-plus">新 增</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.houseName}} <span class="dc" v-if="item.isDc">代储</span></div>
            <van-row class="content-1">
              <van-col span="6">仓房编号: <span>{{item.houseCode}}</span></van-col>
              <van-col span="6">仓房类型: <span>{{item.houseType}}</span></van-col>
              <van-col span="6">实际仓容: <span>{{item.actualCapacity}} </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.state}} </span></van-col>
              <van-col span="6">设备数量: <span>{{item.operator}} </span></van-col>
              <van-col span="6">保管员: <span>{{item.keeperName}} </span></van-col>
            </van-row>
            <div class='ribbon tf' v-if="item.isTongFeng">
              <span class="tfz">通风中</span>
            </div>
            <div class='ribbon kw' v-if="item.isKongWen">
              <span class="tfz">控温中</span>
            </div>
          </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="primary" @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 { getHouseInfoList ,deleteHouseInfoItem} from '@/api/equipConfig/barnBasicInfo/index'

export default {
  filters: {

  },
  data () {
    return {
      notice: false,
      formInline: {
        type: '',
        houseName: '',
        houseCode: ''
      },
      list: [
        {
          houseName: '1号仓', houseCode: '1001', houseType: '45', actualCapacity: '2021-01-12', state: '蓝牙', keeperName: '王全德', runTime: '6h',
          isTongFeng: false, isKongWen: true, isDc:true
        },
        {
          houseName: '2号仓', houseCode: '1001', houseType: '45', actualCapacity: '2021-01-12', state: '蓝牙', keeperName: '王全德', runTime: '6h',
          isTongFeng: false, isKongWen: false,isDc:false
        },
        {
          houseName: '3号仓', houseCode: '1001', houseType: '45', actualCapacity: '2021-01-12', state: '蓝牙', keeperName: '王全德', runTime: '6h',
          isTongFeng: true, isKongWen: false,isDc:true
        },
        {
          houseName: '4号仓', houseCode: '1001', houseType: '45', actualCapacity: '2021-01-12', state: '蓝牙', keeperName: '王全德', runTime: '6h',
          isTongFeng: false, isKongWen: false, isDc:false
        },
        {
          houseName: '5号仓', houseCode: '1001', houseType: '45', actualCapacity: '2021-01-12', state: '蓝牙', keeperName: '王全德', runTime: '6h',
          isTongFeng: false, isKongWen: false, isDc:false
        },
        {
          houseName: '6号仓', houseCode: '1001', houseType: '45', actualCapacity: '2021-01-12', state: '蓝牙', keeperName: '王全德', runTime: '6h',
          isTongFeng: false, isKongWen: true, isDc:false
        },
      ],
      loading: 'false',
      finished: 'false',

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

  },
  mounted() {
    this.getList()
  },
  methods: {
    onSubmit () {
      console.log('submit!');
    },
    getList () {
      let condition = {
        houseName: this.formInline.houseName.trim(),
        houseCode: this.formInline.houseCode,
      }
      let data = {
        pageIndex: this.listQuery.page,
        pageSize: this.listQuery.limit,
        condition: JSON.stringify(condition)
      }
      getHouseInfoList(data).then(res => {
        console.log(res, 'getHouseInfoList')
        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) {
      console.log(data, 'data')
      this.$confirm('此操作将删除该条数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteHouseInfoItem(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: '已取消删除'
        });
      });
    },
    handleAdd () {
      this.$router.push({ name: 'BarnBasicInfoAdd' })
    },
    handleDetail (data) {
      this.$router.push({ name: 'BarnBasicInfoDetail',params:{data:data} })
    },
    handleEdit (data) {
      this.$router.push({ name: 'BarnBasicInfoEdit',params:{data:data} })
    },
    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;
    }
    .fr {
      float: right;
    }
  }
}
.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;
      display: flex;
      .dc {
        display: block;
        width: 60px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        font-size: 12px;
        color: #fff;
        background-color: #b2b2b2;
        border-radius: 5px;
        margin-left: 15px;
      }
    }
    .list-content {
      width: 78%;

      padding: 10px 10px 10px 5px;
      position: relative;
      overflow: hidden;
      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;
      }
    }
    .ribbon {
      /* 右上角飘带 */
      // background-color: #b7c2f9; /* 左上角飘带的背景颜色 */
      overflow: hidden;
      white-space: nowrap; /* 文字不换行*/
      position: absolute; /* 绝对定位 */
      right: -40px;
      top: 10px;
      transform: rotate(45deg); /* 旋转45°*/
      // box-shadow: 0 0 10px #888; /* 飘带的阴影*/
      span {
        // border: 1px solid #54cbff;
        // color: #b7c2f9;
        display: block;
        font: bold 100% "Helvetica Neue", Helvetica, Arial, sans-serif;
        margin: 1px 0;
        padding: 5px 42px;
        text-align: center;
        // text-shadow: 0 0 5px #444;
      }
      .tf {
        color: #a9bef7;
      }
    }

    .list-btns {
      width: 22%;
      background-color: #edf2fd;
      display: flex;
      justify-content: space-evenly;
      align-items: center;
    }
  }
}
.tf {
  background-color: #9de7c2; /* 左上角飘带的背景颜色 */
  span {
    color: #21ae68;
  }
}
.kw {
  background-color: #b7c2f9; /* 左上角飘带的背景颜色 */

  span {
    color: #6d8ce1;
  }
}
</style>
