<template>
  <div>
    <d2-container>
      <!-- <template slot="header"
        ><div class="nav">当前所在位置:首页>仓房信息</div></template
      > -->
      <div class="main">
        <div class="right_main">
          <!-- <div class="right_title">
            <i
              class="fa fa-university"
              aria-hidden="true"
              style="padding-right: 5px"
            ></i
            >仓房信息
          </div> -->
          <div class="right_table">
            <div class="head">
              <div class="backImg"></div>
              <div>保管员信息</div>
            </div>
            <el-form :inline="true" :model="form" class="demo-form-inline">
              <div class="middle">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="姓名:">
                      <el-select
                        v-model="form.keeper"
                        placeholder="请选择"
                        :disabled="disabled"
                      >
                        <el-option
                          v-for="item in keeperLists"
                          :key="item.id"
                          :label="item.userName"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="联系方式:">
                      <el-input
                        v-model="form.lxfs"
                        :disabled="disabled"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
              <div class="head">
                <div class="backImg"></div>
                <div>仓房信息</div>
              </div>
              <div class="middle">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="所属机构:">
                      <!-- <el-select v-model="form.ssfk" placeholder="请选择" :disabled='true'>
                        <el-option
                          v-for="item in ckLists"
                          :key="item.id"
                          :label="item.orgName"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select> -->
                      <el-input v-model="form.ssfk" :disabled='true'></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="仓房名称:">
                      <el-input
                        v-model="form.orgName"
                        :disabled="disabled"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="仓房类型:">
                      <el-select
                        v-model="form.houseType"
                        placeholder="请选择"
                        :disabled="disabled"
                      >
                        <el-option
                          v-for="item in cftypeLists"
                          :key="item.id"
                          :label="item.enumName"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="装粮线高度:">
                      <el-input v-model="form.zlxgd" :disabled="disabled">
                        <template slot="append">米</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="长:">
                      <el-input v-model="form.chang" :disabled="disabled">
                        <template slot="append">米</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="宽:">
                      <el-input v-model="form.kuan" :disabled="disabled">
                        <template slot="append">米</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="高:">
                      <el-input v-model="form.high" :disabled="disabled">
                        <template slot="append">米</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="半径:">
                      <el-input v-model="form.radius" :disabled="disabled">
                        <template slot="append">米</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row>
                  <el-col :span="12">
                    <el-form-item label="仓容:">
                      <el-input v-model="form.sjcr" :disabled="disabled">
                        <template slot="append">吨</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="仓内体积:">
                      <el-input v-model="form.cntj" :disabled="disabled">
                        <template slot="append">立方米</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="仓房状态">
                      <el-radio-group
                        v-model="form.cfStatus"
                        :disabled="disabled"
                      >
                        <el-radio :label="2">入库</el-radio>
                        <el-radio :label="4">出库</el-radio>
                        <el-radio :label="3">库存</el-radio>
                        <el-radio :label="1">空仓</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="创建时间:">
                      <el-date-picker
                        v-model="form.buildTime"
                        type="datetime"
                        placeholder="请选择"
                        value-format="yyyy-MM-dd hh:mm:ss"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
              <div class="head">
                <div class="backImg"></div>
                <div>储粮信息</div>
              </div>

              <div class="middle">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="品种:">
                      <el-select
                        v-model="form.pz"
                        placeholder="请选择"
                        class="tableInput"
                        :disabled="disabled"
                      >
                        <el-option
                          v-for="item in pzLists"
                          :key="item.id"
                          :label="item.enumName"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="等级:">
                      <el-select
                        v-model="form.dj"
                        placeholder="请选择"
                        class="tableInput"
                        :disabled="disabled"
                      >
                        <el-option
                          v-for="item in djLists"
                          :key="item.id"
                          :label="item.enumName"
                          :value="item.id"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row>
                  <el-col :span="12">
                    <el-form-item label="仓内粮食容重:">
                      <el-input
                        v-model="form.cnlsrz"
                        placeholder="请输入"
                        class="tableInput"
                        :disabled="disabled"
                      >
                        <template slot="append">公斤/立方米</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-form>
        
     

             
      
            <div class="footBtn">
              <el-button
              v-if="this.btnType===2 "
                type="primary"
                icon="el-icon-s-claim"
                class="saveBtn"
                @click="save()"
                :disabled="disabled"
                >保存</el-button
              >
              <el-button
                icon="el-icon-circle-close"
                class="closeBtn"
                @click="close()"
                >取消</el-button
              >
            </div>
          </div>
        </div>
      </div>
    </d2-container>
  </div>
</template>
<script>
import api from "@/api";

export default {
  name: "warehouseInfo-check",
  data() {
    return {
      //仓房类型下拉选
      cftypeLists: [],
      //品种下拉选
      pzLists: [],
      // 等级下拉选
      djLists: [],
      //仓库列表
      ckLists: [],
      //保管员列表
      keeperLists: [],
      //按钮类型  1---查看      2----编辑
      btnType: null,
      //路由携带过来的参数
      routeParame: {},
      disabled: false,
      //姓名下拉列表
      nameList: [],
      form: {
    
        keeper:"",
        // orgId: null,
        // 联系方式：
        lxfs: null,
       
    // 所属机构
        ssfk: "泉州福海粮油工业有限公司",
        //仓房名称
        orgName: null,
            // 仓房类型
        houseType: null,


         // 装粮线高度
        zlxgd: null,
       
        // 长
        chang: null,
        //高
        high:null,
        //半径
        radius:null,
        // 宽
        kuan: null,
        // 设计仓容
        sjcr: null,
        //仓内体积
        cntj:null,

        // 仓房状态(1:空仓,2:入库,3:封仓,4:出库)
        cfStatus:null,
    
        
        // 创建时间
        buildTime: null,
       
      

        // 品种：
        pz: null,
        // 等级：
        dj: null,
        cnlsrz: null,
      },
     
    };
  },
  methods: {
    //打开弹框时的列表
    diaList() {
      console.log(this.$route.query.row, "this.$route.query.row");
      let params = {
        id: this.$route.query.row.id,
      };
      console.log(params.id, "Id...");
      api.cfDialogList(params).then((res) => {
        console.log(res, "res.....");
        this.form = res.data.storehouse;
        if(this.form.pz===null){
          this.form.pz="";
        }else{
          this.form.pz=parseInt(this.form.pz);
        }
        if(this.form.dj===null){
           this.form.dj="";
        }else{
           this.form.dj=parseInt(this.form.dj);
        }
        
       
         this.form.houseType=parseInt(this.form.houseType);
          //  this.form.cnlsrz=parseInt(this.form.cnlsrz);
           this.form.ssfk="泉州福海粮油工业有限公司",
           

         console.log(this.form,"this.form....")
        
        
        // this.form.buildTime=this.form.buildTime.replace("T"," ");
        // console.log(this.form, "form.");
      });
    },
    //仓房类型
    cftypeList() {
      var condition = {
        enumName: "",
        enumCode: 400000,
      };
      condition = JSON.stringify(condition);
      var data = {
        condition: condition,
      };
      api
        .dataDic(data)
        .then((res) => {
          if (res.code == 200) {
            res.data.forEach((ele) => {
              if (ele.enumCode === "400000") {
                console.log(ele, "ele.enumCode");
                this.cftypeLists = ele.children;
                console.log(this.cftypeLists, "this.roleLists");
              }
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //品种下拉选
    pzList() {
      var condition = {
        enumName: "",
        enumCode: 200000,
      };
      condition = JSON.stringify(condition);
      var data = {
        condition: condition,
      };
      api
        .dataDic(data)
        .then((res) => {
          if (res.code == 200) {
            res.data.forEach((ele) => {
              if (ele.enumCode === "200000") {
                console.log(ele, "ele.enumCode");
                this.pzLists = ele.children;
              
                
              }
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //等级下拉选
    djList() {
      var condition = {
        enumName: "",
        enumCode: 200100,
      };
      condition = JSON.stringify(condition);
      var data = {
        condition: condition,
      };
      api
        .dataDic(data)
        .then((res) => {
          if (res.code == 200) {
            res.data.forEach((ele) => {
              if (ele.enumCode === "200100") {
                console.log(ele, "ele.enumCode");
                this.djLists = ele.children;
                console.log(this.cftypeLists, "this.roleLists");
              }
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //仓库下拉选
    ckList() {
      var data = {
        storeTypeCode: 300002,
      };
      api
        .ckList(data)
        .then((res) => {
          if (res.code == 200) {
            this.ckLists = res.data;
            this.ckLists.forEach((item) => {
              if (item.orgName === this.$route.query.row.ssfk) {
                this.form.orgId = item.id;
              }
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //获取保管员
    keeperList() {
      var params = {
        orgId: null,
      };
      api
        .keeper(params)
        .then((res) => {
          console.log(res, "保管员");
          this.keeperLists = res.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //返回按钮
    close() {
      // window.history.go(-1);
       this.$router.push(
         {
           path:"/warehouseInfo"
         }
       )
    },
    
    //编辑仓房信息
    editList() {
     var storehouse={
       id:this.$route.query.row.id,
        keeper:this.form.keeper,
        // orgId: null,
        // 联系方式：
        lxfs: this.form.lxfs,
       
    // 所属机构
        ssfk: this.form.ssfk,
        //仓房名称
        orgName:this.form.orgName,
            // 仓房类型：
        houseType:this.form.houseType,


         // 装粮线高度
        zlxgd: this.form.zlxgd,
       
        // 长
        chang: this.form.chang,
        //高
        high:this.form.high,
        //半径
        radius:this.form.radius,
        // 宽
        kuan:this.form.kuan,
        // 设计仓容
        sjcr: this.form.sjcr,
        //仓内体积
        cntj:this.form.cntj,

        // 仓房状态(1:空仓,2:入库,3:封仓,4:出库)
        cfStatus: this.form.cfStatus,
    
        
        // 创建时间
        buildTime: this.form.buildTime,
       
      

        // 品种：
        pz: this.form.pz,
        // 等级：
        dj:this.form.dj,
        cnlsrz: this.form.cnlsrz,
      };
console.log(storehouse,"formData")
      var formData = new FormData();
      formData.append("storehouse", JSON.stringify(storehouse));
      console.log(formData,"formData")

      api
        .editWareInfo(formData)
        .then((res) => {
          if (res.code == 200) {
        
                this.$message.success("修改成功");
             this.$router.push(
         {
           path:"/warehouseInfo"
         }
       )
          
            // this.getList();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    save() {
      this.editList();
      // window.history.go(-1);
    },

   
  },
  mounted() {
    this.keeperList();
    this.ckList();
    this.cftypeList();
    this.pzList();
    this.djList();
    this.diaList();

    this.btnType = this.$route.query.type;

    if (this.btnType == 1) {
      this.disabled = true;
    } else {
      this.disabled = false;
    }
  },
};
</script>
<style lang="scss" scoped>
.title {
  display: flex;
  justify-content: space-between;
  .titleLeft {
    line-height: 40px;
  }
}
.main {
  color: #9fd0d8;
  .head,
  .bottomHead {
    height: 25px;

    align-items: center;
    display: flex;

    .backImg {
      width: 5px;
      height: 15px;
      background: rgb(59, 103, 213);
      border-radius: 3px;
      margin-right: 10px;
    }
  }
  .middle {
    margin: 20px 0 20px 20px;
    .el-radio {
      color: none;
    }
  }
  .bottom {
    display: flex;
    justify-content: space-between;
  }
  ::v-deep .el-form--inline .el-form-item__label {
    width: 130px;
    color: #9fd0d8;
  }
  .el-select,
  .el-input {
    width: 300px;
  }
  ::v-deep .el-input__inner {
    background: #1d3b6b;
    border: 1px solid #345684;
    opacity: 12.5;
  }
  ::v-deep .el-input-group__append {
    background: #1d3b6b;
    border: 1px solid #345684;
    opacity: 12.5;
  }
  #table .tableInput {
    width: 100%;
  }
  .footBtn {
    margin-top: 10px;
    text-align: center;
  }

  .closeBtn {
    margin-left: 15px;
  }
  .saveBtn {
    margin-right: 15px;
  }
}
</style>