<template>
  <div>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">

      <el-form-item>
        <el-button type="success" @click="addNewSpec()">新增一次盘点</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="dataListLoading" :data="data" style="width: 100%" @row-click="rowClick">
      <el-table-column prop="id" header-align="center" align="center" label="ID"></el-table-column>
      <el-table-column prop="num" header-align="center" align="center" label="第几次盘点"></el-table-column>
      <el-table-column prop="gmtCreate" header-align="center" align="center" label="创建时间"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="100" label="操作">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="specReq.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="specReq.rows"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <device-type-detail v-if="isShowDetail" ref="deviceTypeDetail" @refreshDataList="getData"></device-type-detail>
  </div>
</template>
<script>
import { apiGetTCounts, apiAddTCounts, apiDelTCounts } from "@/api/api_equipment";
import DeviceTypeDetail from './device-type-detail.vue'
export default {
  components: {
      DeviceTypeDetail
    },
  data() {
    
    return {
      isShowSearch: true,
      data: [],
      name: "",
      categorys: "",
      input: "",
      dataListLoading: false,
      typeIndex: 0, //0现在是1级 1二级2三级
      showHeader: false,
      totalPage: 1,
      departmentReaderOnly: false,
      specReq: {
        page: 1,
        rows: 10,
        sort: null,
        order: null,
        id: null,
        isDelete: 0,
        gmtCreate: null,
        gmtModified: null,
        count: null
      },
      isShowDetail: false
    };
  },
  created() {
    // this.handleGetImgCaptcha()
  },
  
  mounted() {
    this.getData();
  },
  methods: {
    
    addNewSpec(){
      apiAddTCounts().then((data) =>{
        if(data.code == 0){
          this.$message(data.msg)
          this.specReq.page = 1
          this.getData()
        }else{
          this.$message.error(data.msg)
        }
      });
      
    },
    changeDepartment(type) {
      if(type == 1){
        //获取品牌
        this.getBrands()
        this.specReq.brandId = null
      }else{
        this.specReq.page = 1
        this.getData()
      }
    },
    sizeChangeHandle(val) {
      this.specReq.page = 1
      this.specReq.rows = val
      this.getData();
    },
    currentChangeHandle(val) {
      this.specReq.page = val
      this.getData();
    },
    
    // 删除
      handleDelete (val) {
        
        this.$confirm('确定删除第“' + val.num + '”次盘点吗？删除后该类型将无法使用。如果该次盘点有盘点记录,将无法删除成功', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.delTCount(val.id)
        }).catch(() => {
        })
      },
      delTCount(id){
        apiDelTCounts({page: 1,
        rows: 10,
        sort: null,
        order: null,
        id: id,
        isDelete: 0,
        gmtCreate: null,
        gmtModified: null,
        count:null
        }).then((data) => {
        console.log(data);
        if (data && data.code === 0) {
          this.$message('删除成功')
          this.getData()
        } else {
          this.$message.error('删除失败' + data.msg)
        }
        this.dataListLoading = false;
      });
      },
    getData() {
      console.log("获取数据")
      console.log(this.name)
      console.log(this.categorys)
      this.dataListLoading = true
      apiGetTCounts(this.specReq).then((data) => {
        console.log(data);
        if (data && data.code === 0) {
          this.data = data.rows.list;
          this.totalPage = data.rows.totalCount
        } else {
          this.data = [];
        }
        this.dataListLoading = false;
      });
    },
    
    btnSearch() {
      this.specReq.page = 1
      this.getData();
    },

    rowClick(row, event, column) {},
  },
};
</script>

<style>
.el-row {
  margin-bottom: 20px;
}
.el-col {
  border-radius: 10px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5f2f1;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.div_height {
  height: 38px;
}
.div_width {
  width: 100%;
}
.width_100 {
  width: 100px;
}
.center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  padding: 1em;
}
.flex {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border: 1px solid;
}
.flex_son {
  width: 100%;
  height: 100%;
  border: 0x solid;
}
</style>