<template>
  <div>

    <div class="tab-header webtop">
      <!-- 标题 -->
      <div>仓库信息</div>
      <!-- start 添加修改按钮 -->
      <div>
        <el-button type="primary" size="small" :disabled="submitdisabled" @click="saveOrUpdate">保存</el-button>
        <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
      </div>
      <!-- end 添加修改按钮 -->
      <!-- end 详情按钮 -->
    </div>

    <div class="listconadd">

      <el-card class="box-card">
        <div class="item">
          <span class="item_text">仓库名称：</span>
          <el-input v-model="formobj.warehouseName" placeholder="仓库名称" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">仓库编码：</span>
          <el-input v-model="formobj.warehouseCode" placeholder="仓库编码" class="item_input" clearable
            oninput="value=value.replace(/[^A-Za-z0-9]/g, '')" />
        </div>
        <div class="item">
          <span class="item_text">仓库联系人：</span>
          <el-input v-model="formobj.contacts" placeholder="仓库联系人" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">手机号码：</span>
          <el-input v-model="formobj.mob" placeholder="手机号码" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">仓库主管：</span>
          <el-input v-model="formobj.manager" placeholder="仓库主管" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">联系电话：</span>
          <el-input v-model="formobj.telephone" placeholder="联系电话" class="item_input" clearable />
        </div>

        <div class="item">
          <span class="item_text">占地面积：</span>
          <el-input v-model="formobj.squareMeter" placeholder="占地面积" class="item_input" clearable
            oninput="value=value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')" />
        </div>
        <div class="item">
          <span class="item_text">仓库经度：</span>
          <el-input v-model="formobj.longitude" placeholder="仓库经度" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">仓库纬度：</span>
          <el-input v-model="formobj.latitude" placeholder="仓库纬度" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">具体地址：</span>
          <el-input v-model="formobj.address" placeholder="具体地址" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">使用状态：</span>
          <el-radio-group v-model="formobj.usageStatus" size="small" @change="changeTheme" class="item_input">
            <el-radio :label="1">正常</el-radio>
            <el-radio :label="0">停用</el-radio>
          </el-radio-group>
          <!-- <el-input v-model="formobj.usageStatus" placeholder="仓库排序" class="item_input" clearable /> -->
        </div>
        <div class="item">
          <span class="item_text">仓库排序：</span>
          <el-input v-model="formobj.sortNo" placeholder="仓库排序" class="item_input" clearable />
        </div>
        <div class="item">
          <span class="item_text">仓库备注：</span>
          <el-input v-model="formobj.remarks" placeholder="备注" class="item_input" clearable />
        </div>
      </el-card>

    </div>

  </div>
</template>

<script>
  import req from '@/api/baseinfo/warehouse/warehouse.js'
  export default {
    components: {},
    data() {
      return {
        submitdisabled: false,
        formobj: {
          sid: '',
          warehouseName: '',
          warehouseCode: '',
          contacts: "",
          mob: "",
          telephone: "",
          manager: '',
          longitude: '',
          latitude: '',
          usageStatus: "",
          address: '',
          squareMeter: '',
          sortNo: '',
          remarks: '',
          warehouseType: "0",
          orgPath: window.sessionStorage.getItem('orgSidPath'),
          useOrgSid: window.sessionStorage.getItem('defaultDeptSid'),
          userSid: window.sessionStorage.getItem('userSid'),
          createOrgSid: window.sessionStorage.getItem('orgSid'),
        },
      }
    },
    created() {},
    methods: {
      changeTheme(val) {

      },
      saveOrUpdate() {
        console.log('>>>>>>>>>saveOrUpdate', this.formobj)

        if (this.formobj.warehouseName == '') {
          this.$message({
            showClose: true,
            type: 'error',
            message: '仓库名称不能为空'
          })
          return
        }

        if (this.formobj.warehouseCode == '') {
          this.$message({
            showClose: true,
            type: 'error',
            message: '仓库编码不能为空'
          })
          return
        }


        req.saveWarehouse(this.formobj)
          .then(resp => {
            if (resp.success) {
              this.$message({
                showClose: true,
                type: 'success',
                message: resp.msg
              })
              this.handleReturn('true')
            } else {
              // 根据resp.code进行异常情况处理
            }
          })
          .catch(() => {})
      },
      handleReturn(isreload) {
        if (isreload === 'true') this.$emit('reloadlist')
        this.formobj = {
          sid: '',
          warehouseName: '',
          warehouseCode: '',
          contacts: "",
          mob: "",
          telephone: "",
          manager: '',
          longitude: '',
          latitude: '',
          usageStatus: "",
          address: '',
          squareMeter: '',
          sortNo: '',
          remarks: '',
          warehouseType: "0",
          orgPath: window.sessionStorage.getItem('orgSidPath'),
          useOrgSid: window.sessionStorage.getItem('defaultDeptSid'),
          userSid: window.sessionStorage.getItem('userSid'),
          createOrgSid: window.sessionStorage.getItem('orgSid'),
        }
        this.$emit('doback')
      },
      showAdd() {},
      showEdit(row) {
        req.initWarehouse(row.sid)
          .then(resp => {
            if (resp.success) {
              this.formobj = resp.data
            }
          })
          .catch(e => {
            this.formobj = row
          })
      },

    }
  }
</script>
<style lang="scss" scoped>
  // 隐藏上传组件

  ::v-deep .hide {
    .el-upload--picture-card {
      display: none !important;
    }
  }

  .box-card {
    margin-left: 60px;
    margin-right: 60px;
    min-width: 70%;
    margin-top: 20px;

    .item {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-top: 15px;
      height: 40px;
      line-height: 40px;

      .item_text {
        flex: 0.8;
        font-size: 18px;
        text-align: right;
      }

      .item_input {
        flex: 4;
        font-size: 16px;
        margin-left: 10px;
        margin-right: 80px;
      }

      .item_left_input {
        width: 20%;
      }

      .item_left_text {
        height: 30px;
        margin-left: 20px;
        line-height: 30px;
        color: #018AD2;
        padding: 0px 15px;
        border: 1.5px solid #018AD2;
        border-radius: 5px;

      }

      .item_right {
        flex: 1;
        justify-items: center;

        .item_right_list_text {
          font-size: 16px;
        }

        .item_right_list_delect {
          color: #5E94FF;
          margin-left: 20px;
          font-size: 16px;
          text-decoration: underline;
        }
      }

    }

  }
</style>
