<template>

  <div class="box-center">
    <!-- 头 -->
    <div class="app-top">
      <div class="app-titel" style="margin-top: 5px">
        <div class="label">批次号：</div>
        <div>
             <el-input v-model="batchId"></el-input>
        </div>
        <div style="margin-left: 20px">
          <el-button style="background: #2671e2; color: #ffffff" @click="Screening()">筛选</el-button
          >
        </div>
        <div style="margin-left: 20px">
          <el-button @click="Screeningofempty()">清空筛选条件</el-button>
        </div>
         <div style="margin-left: 20px">
          <el-button @click="editorinfo()" style="background: #2671e2; color: #ffffff"
            >添加批次</el-button
          >
        </div>
      </div>
    </div>

    <!-- 表格 -->
    <div class="cen-tab">
        <el-table
          :data="tableData"
          stripe
          height="500"
          style="width: 100%">
          <el-table-column
            prop="batchId"
            label="批次号"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="name"
            label="设备号"
             align="center"
           >
            <template slot-scope="scope">
                <p>{{scope.row.deviceNoStart}}:{{scope.row.deviceNoEnd}}</p>
              </template>
          </el-table-column>
          <el-table-column
            prop="realityEquipmentCount"
            label="应收设备数量"
             align="center">
          </el-table-column>

          <el-table-column
            prop="receivableEquipmentCount"
            label="实收设备数量"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="acceptanceNum"
            label="已验收设备数量"
             align="center"
           >
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
             align="center">
          </el-table-column>

          <el-table-column
            prop="remark"
            label="备注"
            align="center"
          >
          </el-table-column>
         <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <div style="color: #2671E2;" @click="clickbianji(scope.row)">修改</div>
            </template>
          </el-table-column>
        </el-table>
        <div style="display: flex;justify-content:flex-end;margin-top: 10px;">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage4"
              :page-sizes="[8, 16, 24, 32]"
              :page-size="4"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
        </div>
    </div>



       <el-dialog :title='isshow' :visible.sync="dialogVisible" >
      <el-form :model="addagentobj" label-position="labelPosition" :rules="rules"  ref="addagentobj" label-width="140px" style="width:60%; margin: 0 auto;">
           <el-form-item label="批次号" prop="batchId">
                <el-input v-model="addagentobj.batchId"></el-input>
          </el-form-item>
          <el-form-item label="应收设备数量" prop="realityEquipmentCount">
                <el-input v-model="addagentobj.realityEquipmentCount"></el-input>
          </el-form-item>
           <el-form-item label="实收设备数量" prop="receivableEquipmentCount">
              <el-input v-model="addagentobj.receivableEquipmentCount"></el-input>
          </el-form-item>
          <el-form-item label="设备号开头" prop="deviceNoStart">
              <el-input v-model="addagentobj.deviceNoStart"></el-input>
          </el-form-item>
          <el-form-item label="设备号结尾" prop="deviceNoEnd">
              <el-input v-model="addagentobj.deviceNoEnd"></el-input>
          </el-form-item>
            <el-form-item label="备注：">
              <el-input type="textarea" v-model="addagentobj.remark"></el-input>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editor()">保存</el-button>
      </div>
  </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible:false,
      batchId:'',
      tableData: [],
      currentPage4:1,
      addagentobj:{
        id:'',
        batchId:'',// 批次号
        realityEquipmentCount:'',// 应收数
        receivableEquipmentCount:'',// 实收数
        deviceNoStart:'',// 开头
        deviceNoEnd:'',// 结尾
        remark:''//备注
      },
      rules:{
        batchId: [
            { required: true, message: '请输入批次号', trigger: 'blur' },
          ],
          realityEquipmentCount: [
            { required: true, message: '请输入应收设备数量', trigger: 'blur' },
          ],
          receivableEquipmentCount: [
            { required: true, message: '请输入实收设备数量', trigger: 'blur' },
          ],
          deviceNoStart: [
            { required: true, message: '请输入设备号开头', trigger: 'blur' },
          ],
          deviceNoEnd: [
            { required: true, message: '请输入设备号结尾', trigger: 'blur' },
          ],
      },
      total:0,//总条数
      pageNum:1,
      pageSize:8,
      isshow:'绑定'

    };
  },
  mounted() {
    this.getcompanyList()
  },
  methods: {
    //編輯
    clickbianji(row){
      this.addagentobj.id=row.id;
      this.addagentobj.batchId=row.batchId;
      this.addagentobj.realityEquipmentCount=row.realityEquipmentCount;
      this.addagentobj.receivableEquipmentCount=row.receivableEquipmentCount;
      this.addagentobj.deviceNoStart=row.deviceNoStart;
      this.addagentobj.deviceNoEnd=row.deviceNoEnd;
      this.addagentobj.remark=row.remark;
      this.isshow='编辑';
      this.dialogVisible=true;
    },

    //添加
    editorinfo(){
      this.isshow='绑定';
      this.addagentobj.id='';
      this.addagentobj.batchId='';
      this.addagentobj.realityEquipmentCount='';
      this.addagentobj.receivableEquipmentCount='';
      this.addagentobj.deviceNoStart='';
      this.addagentobj.deviceNoEnd='';
      this.addagentobj.remark='';
      this.dialogVisible=true;
    },
    //确认添加
     editor(){
         this.$refs.addagentobj.validate((valid) => {
          if (valid) {
            if(this.isshow=='绑定'){
                this.$api.http.insert(this.addagentobj).then((res) => {
               if(res.code==0){
                    this.dialogVisible=false;
                    this.$refs.addagentobj.resetFields();
                    this.Screeningofempty()
                }else{
                  this.$message.error(res.message);
               }
             });
            }else{
              this.$api.http.insertupdate(this.addagentobj).then((res) => {
               if(res.code==0){
                    this.dialogVisible=false;
                    this.$refs.addagentobj.resetFields();
                    this.Screeningofempty()
                }else{
                  this.$message.error(res.message);
               }
             });
            }
          } else {
            return false;
          }
        });
    },
      //清空筛选
    Screeningofempty(){
        this.batchId='';
        this.getcompanyList()
    },
    //筛选
    Screening(){
      this.getcompanyList()
    },
       // 获取列表
    getcompanyList() {
      this.tableData=[];
      let parmest={
          current: this.pageNum,
          size: this.pageSize,
          batchId:this.batchId
      }
      this.$api.http.getequipmentbatch(parmest).then((res) => {
          console.log(res.data);
          this.tableData=res.data.records;
          this.total=res.data.total
        });
    },
      handleSizeChange(val) {
       this.pageSize=val;
        this.getcompanyList()
      },
      handleCurrentChange(val) {
        this.pageNum=val;
        this.getcompanyList()
      },
  },
};
</script>

<style scoped="scoped" lang="scss" >
.box-center {
  width: 100%;
  padding: 15px;
  min-width: 1200px;
  padding-bottom: 40px;
}
.cen-tab{
  width: 100%;
  padding: 15px;
  background: #FFFFFF;
  margin-top: 15px;
}
.tophove {
  color: #ffffff;
  background: #2671e2;
}
.app-top {
  width: 100%;
  background: #ffffff;
  box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  padding-top: 15px;
  padding-bottom: 15px;
  .app-titel {
    width: 100%;
    display: flex;
    align-items: center;
    .label {
      font-size: 14px;
      font-weight: 400;
      color: #32363d;
      line-height: 14px;
      margin-left: 15px;
    }
    .toptimeqhuan {
      height: 30px;
      background: #ffffff;
      display: flex;
      align-items: center;
    }
    .toptimeqhuan div {
      padding-left: 20px;
      padding-right: 20px;
      text-align: center;
      line-height: 30px;
      font-size: 14px;
      margin-right: 15px;
      border-radius: 4px;
      border: 1px solid #e0e0e0;
    }
  }
}
</style>
