<style>
  .Materialwarehouse .template_comheader {
    padding: 13px 20px;
    border-bottom: 1px solid #EBEEF5;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background: #fff;
  }

  .Materialwarehouse .template_comheader>div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
  }

  .Materialwarehouse .temp_content {
    margin-top: 10px;
    background: #fff;
    padding: 20px;
  }

  .Materialwarehouse .temp_imgStyle {
    display: inline-block;
    margin-right: 10px;
  }
 .Materialwarehouse .app-add-cat .el-checkbox-group{
    font-size: 14px!important;
}
 .Materialwarehouse .app-add-cat .el-checkbox {
    margin-right: 0;
}
 .Materialwarehouse .app-add-cat .el-dialog__body{
    padding:10px 20px!important;
}
   .Materialwarehouse .app-add-cat .tag-box .tag-item {
    margin-right: 5px;
}
 .Materialwarehouse .app-add-cat .tag-box {
    margin: 20px 0;
}
 .Materialwarehouse .app-add-cat .app-goods-cat-list .active {
    background: #FAFAFA;
}
 .Materialwarehouse .app-add-cat .app-goods-cat-list .cat-item {
    cursor: pointer;
    padding: 5px 10px;
}
 .Materialwarehouse .app-add-cat .app-goods-cat-list {
    border: 1px solid #E8EAEE;
    border-radius: 5px;
    margin-top: -5px;
    padding: 10px 0;
    overflow: scroll;
    height: 400px;
}
.Materialwarehouse .el-table td, .el-table th{
  padding: 5px 0;
  font-size: 14px;
}
</style>
<template>
  <div class="Materialwarehouse">
    <div class="template_comheader">
      <div>
        <span>物料仓库</span>
        <el-button type="primary" size="small" @click="flDig=true,addMsg.Id = 0,addMsg.Name=''">新增仓库</el-button>
      </div>
    </div>
    <div class="temp_content">
        <div>
            <div class="searchInput" style="width:250px;margin-right: 10px;">
                <el-input @keyup.enter.native="msg.pageIndex=1,getList()" style="display:inline-block;width:225px;height:30px"
                placeholder="请输入商品名称"
                v-model="msg.Name"
                @clear="msg.pageIndex=1,getList()"
                size="small"
                clearable>
                </el-input>
                <span @click="msg.pageIndex=1,getList()" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
            </div>
        </div>
        <el-table :data="dataList" border style="width: 100%;margin-Top:10px">
            <el-table-column prop="Name" label="仓库名称" ></el-table-column>
            <el-table-column prop="UpdateDate" label="操作时间" ></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                    <img src="../../assets/img/setup/edit.png" alt="" class="temp_imgStyle" @click="EditeTemplate(scope.row)">
                    </el-tooltip>
                    <el-tooltip class="item" effect="dark" content="删除" placement="top">
                    <img src="../../assets/img/setup/del.png" alt="" class="temp_imgStyle" @click="DeleteTemplate(scope.row)">
                    </el-tooltip>
                </template>
            </el-table-column>
                 
        </el-table>
        <el-pagination style="text-align:right" background @current-change="handleCurrentChange"  :current-page.sync="msg.pageIndex"
            :page-size="msg.pageSize" layout="prev, pager, next" :total="total">
        </el-pagination>
    </div>
      <!-- 选择分类 -->
    <el-dialog custom-class="app-add-cat" :title="addMsg.Id == 0 ?'新增仓库':'编辑仓库' " :visible.sync="flDig" width="700px">
         <el-form
          :model="addMsg"
          :rules="rules"
          ref="addMsg"
          label-width="100px"
        >
          <el-form-item label="仓库名称"  size="small" prop="Name">
            <el-input
              type="text"
              size="small"
              maxlength="200"
              v-model="addMsg.Name"
            >
            </el-input>
          </el-form-item>
         
         
        </el-form>
           
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="flDig = false">取 消</el-button>
            <el-button @click="submitForm('addMsg')" size="small" type="primary">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        dataList: [],
        msg: {
          pageIndex: 1,
          pageSize: 15,
          Name:'',
        },
        addMsg:{
            Id:0,
            Name:'',
            Contact:'',
            Mobile:'',
        },
        flDig:false,
        total: 0,
        rules:{
            Name: [
                { required: true, message: '请输入仓库名称', trigger: 'blur' }
            ]
        },
      };
    },
    created() {

    },
    methods: {
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      getList() {
        this.apiJavaPost("/api/Supplies/GetWareHousePageList", this.msg, res => {
          if (res.data.resultCode == 1) {
            this.dataList = res.data.data.pageData;
            this.total = res.data.data.count;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      
        submitForm(msg){
             this.$refs[msg].validate(valid => {
          if (valid) {
            this.apiJavaPost(
              "/api/Supplies/SetWareHouseInfo",
              this.addMsg,
              res => {
                if (res.data.resultCode == 1) {
                    this.Success(res.data.message);
                    this.flDig=false;
                    this.getList();
                   
                } else {
                  this.Info(res.data.message);
                }
              }
            );
          } else {
            return false;
          }
        });
        },
        EditeTemplate(row){
            this.addMsg.Id = row.Id;
            this.addMsg.Name = row.Name;
            this.flDig=true
        },
        DeleteTemplate(row){
            let Id=row.Id;
        this.$confirm("确认删除该仓库？","提示", {
            confirmButtonText:"确定",
            cancelButtonText: "取消",
            type: 'warning'
            }).then(() => {
                this.apiJavaPost("/api/Supplies/DelWareHouseInfo",{WareHouseId:Id},
                    res => {
                    if (res.data.resultCode === 1) {
                        this.getList();
                        this.Success(res.data.message)
                    } else {
                        this.Error(res.data.message);
                    }
                    },
                    null
                );

            }).catch(() => {
            this.$message.info('已取消删除！')
        });
        }
       
    },
    mounted() {
      this.getList();
    }
  };

</script>
