<template>
  <div class="container">
    <el-row>
      <el-col :span="20">
        <h2 class="bg-left title">查看仓库详情</h2>
      </el-col>
      <el-col :span="4" class="bg-right">
        <el-button
          class="bg-bottom"
          type="primary"
          size="small"
          @click="returnWarehouse()"
          ><img
            width="6"
            height="10"
            style="vertical-align: bottom; margin-right: 3px"
            src="../../../public/img/lujing.png"
            alt=""
          />返回</el-button
        >
      </el-col>
    </el-row>
    <div class="center">
      <el-radio-group v-model="warehouseType" @change="warehouseTypechange">
        <el-radio label="1">自有库</el-radio>
        <el-radio label="2">临时库</el-radio>
      </el-radio-group>
      <ws-form ref="deptBudgetList" :model="deptBudgetList">
        <div class="small-title">基本信息</div>
        <!--基本信息-->
        <ws-info-table>
          <!--仓库名称-->
          <ws-form-item
            class="warehouseName"
            label="仓库名称"
            span="1"
            prop="warehouseName"
          >
            <ws-select
              v-model="deptBudgetList.warehouseName"
              placeholder="请输入仓库名称"
              class="typeselect"
              @change="selectpackingMethod"
            >
              <ws-option
                v-for="item in packtypeList"
                :key="item.constKey"
                :label="item.warehouseName"
                :value="item.warehouseName"
              />
            </ws-select>
          </ws-form-item>
          <!--负责人-->
          <ws-form-item label="负责人" span="1" prop="personCharge">
            {{ deptBudgetList.personCharge }}
          </ws-form-item>
          <!--负责人电话-->
          <ws-form-item
            label="负责人电话"
            span="1"
            prop="personPhone"
            class="readonly"
          >
            {{ deptBudgetList.personPhone }}
          </ws-form-item>
          <!--仓库所在地-->
          <ws-form-item label="仓库所在地" span="1" prop="warehouseLocation">
            {{ deptBudgetList.warehousePrivate
            }}{{ deptBudgetList.warehouseCity
            }}{{ deptBudgetList.warehouseArea }}
          </ws-form-item>
          <!--详细地址-->
          <ws-form-item
            label="详细地址"
            span="1"
            prop="detailedAddress"
            class="readonly"
          >
            {{ deptBudgetList.detailedAddress }}
          </ws-form-item>
          <!--总储量（吨)-->
          <ws-form-item
            v-show="warehouseType == 1"
            label="总储量（吨)"
            span="1"
            prop="totalStorage"
          >
            {{ totalStorage }}
          </ws-form-item>
        </ws-info-table>

        <div v-for="item in deptBudgetList.warehousePositionInfoList">
          <ws-info-table>
            <!--仓位编号-->
            <ws-form-item
              label="仓位编号"
              span="1"
              prop="binNumber"
              class="forlist"
            >
              {{ item.binNumber }}
            </ws-form-item>
            <!--最大储量（吨）-->
            <ws-form-item
              label="最大储量（吨）"
              span="1"
              prop="maxStorage"
              class="forlist"
            >
              {{ item.maxStorage }}
            </ws-form-item>
            <!--现有储量-->
            <ws-form-item
              :label="'现有储量(' + item.nowStorage + '吨)'"
              span="1"
              prop="detailStorage"
            >
              {{ item.detailStorage }}
            </ws-form-item>
            <!--备注（选填）-->
            <ws-form-item label="备注（选填）" span="1" prop="remark">
              {{ item.remark }}
            </ws-form-item>
          </ws-info-table>
        </div>
        <div class="small-title">仓库照片</div>
      </ws-form>
    </div>
    <div style="text-align: right; padding: 10px">
      <el-button
        class="bg-bottom-up"
        type="primary"
        size="small"
        @click="returnWarehouse()"
        >关闭</el-button
      >
    </div>
  </div>
</template>
<script>
import { xiala, billoperatehis, getLook } from '@/model/warehouse/index'
import { downloadFile } from '@/utils/batchDown'
import Pagination from '@/components/Pagination'
import WsUpload from '@/components/WsUpload'
import { dayjs, fmoney, EventBus } from 'base-core-lib'
export default {
  name: 'viewSpareMoney',
  components: {
    WsUpload,
    Pagination,
  },
  watch: {
    vesselId(val) {
      this.getList()
    },
    isShow(val) {
      this.showType = val
    },
  },
  data() {
    return {
      //弹出框
      dialogViewSpareMoney: false,
      dialogApproveFormVisible: false,
      // 船舶类型
      monetaryKey: null,
      // 表格显示数据
      tableDate: [],
      // 是否显示
      showType: true,
      // 年
      year: '',
      deptBudgetTotal: 0,
      currentPage: 1,
      pageSize: 10,
      searchType: 1,
      searchKeyWord: '',
      contractType: 2,
      startDate: null,
      endDate: null,
      unitList: [],
      warehouseType: '1',
      // 提交类型
      submitType: true,
      size: 10,
      compId: sessionStorage.getItem('ws-pf_compId'),
      deptCircularPage: {},
      packtypeList: [],
      date: {
        year: dayjs().format('YYYY'),
        month: dayjs().format('MM'),
      },
      contractList: [],
      deptBudgetList: {},
      historyList: [],

      pickerBeginDateBefore: {
        disabledDate: (time) => {
          return time.getTime() > Date.now()
        },
      },
      accessoryTFs: false,
    }
  },
  activated() {
    this.selectpackingMethod()
    this.showType = this.isShow
    this.loaddata()
  },
  computed: {
    totalStorage: function () {
      var sum = 0
      if (this.deptBudgetList.warehousePositionInfoList) {
        for (
          var i = 0;
          i < this.deptBudgetList.warehousePositionInfoList.length;
          i++
        ) {
          sum += Number(
            this.deptBudgetList.warehousePositionInfoList[i].maxStorage
          )
        }
      }
      return sum
    },
  },
  methods: {
    //返回按钮
    returnWarehouse() {
      this.$router.push({ path: 'warehouseManagementList' })
      this.deptBudgetList = {}
    },
    warehouseTypechange() {
      this.loaddata()
    },
    dateFormat(fmt, date) {
      let ret
      const opt = {
        'Y+': date.getFullYear().toString(), // 年
        'm+': (date.getMonth() + 1).toString(), // 月
        'd+': date.getDate().toString(), // 日
        'H+': date.getHours().toString(), // 时
        // "M+": date.getMinutes().toString(),         // 分
        // "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
      }
      for (let k in opt) {
        ret = new RegExp('(' + k + ')').exec(fmt)
        if (ret) {
          fmt = fmt.replace(
            ret[1],
            ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
          )
        }
      }
      return fmt
    },
    handleClose() {
      this.accessoryTFs = false
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      console.log(`当前页: ${val}`)
      this.getList()
    },
    selectpackingMethod(e) {
      console.log(e)
      for (var i = 0; i < this.packtypeList.length; i++) {
        if (this.packtypeList[i].warehouseName == e) {
          this.getLook(this.packtypeList[i].id)
        }
      }
    },
    loaddata() {
      // 仓库名称
      xiala({
        compId: sessionStorage.getItem('ws-pf_compId'),
        warehouseType: this.warehouseType,
      })
        .toPromise()
        .then((response) => {
          this.packtypeList = response
        })
    },
    getLook(compId1) {
      getLook({
        id: compId1,
      })
        .toPromise()
        .then((response) => {
          this.deptBudgetList = response
          //  console.log(this.deptBudgetList)
        })
    },
    // 关闭 dialog时 处理文件url 初始化upload组件
    handleCloe() {
      this.dialogViewSpareMoney = false
    },
    history(row) {
      console.log(row)
      billoperatehis({ id: row.id })
        .toPromise()
        .then((response) => {
          this.historyList = response
        })
    },
    //删除

    approve() {},
    listQuery() {},
    total() {},
    clearfiltQuery() {},
    selectCrtDuty() {},
  },
}
</script>
<style lang="scss" scoped>
.center {
  position: relative;
  margin-top: 100px;
  top: 30px;
  width: 90%;
  height: 500px;
  margin: 0 auto;
}
.container .bg-left {
  padding-left: 40px;
}
.bg-right {
  padding: 16px;
  text-align: right;
}
.vertical-text-left {
  width: 62px;
  text-align: right;
}
/deep/.el-form-item {
  width: 33.33%;
}
.forlist {
  width: 16.67%;
}
//文字基本信息
.center h3 {
  margin-left: 42px;
}
//去边框
/deep/.el-form-item {
  border-right: 0px;
  border-bottom: 0px;
}
/deep/.ws-info-table {
  border-left: 0px;
  border-top: 0px;
}
.ws-info-table .el-form-item .el-form-item__content {
  border-right: 0px;
  border-bottom: 0px;
  border-left: 0px;
  border-top: 0px;
}
/deep/.ws-info-table .el-form-item {
  border-right: 0px;
  border-bottom: 0px;
  border-left: 0px;
  border-top: 0px;
}
//背景
/deep/.ws-info-table .el-form-item .el-form-item__content {
  background: #f5f7fa;
  border-radius: 4px;
  border: 1px solid #d8dce6;
  font-family: PingFangSC-Regular, PingFang SC;
  margin-bottom: 5px;
  font-size: 14px;
  font-weight: 400;
  color: #8890b1;
  line-height: 16px;
}
/deep/.ws-info-table .el-form-item .el-form-item__label {
  background-color: #fff;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #8890b1;
  line-height: 16px;
}
//多选框
/deep/.el-input__inner {
  display: inline-block;
  background-color: #fff;
}
/deep/.ws-info-table .warehouseName.el-form-item .el-form-item__content {
  background: #fff;
  border: none;
}
.title {
  position: relative;
}
.title::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 30px;
  background: #5473e8;
  position: absolute;
  left: 0;
}
.ws-info-table {
  border-left: 1px solid transparent;
  border-top: 1px solid transparent;
}
.el-button--primary {
  background-color: #5878e8;
  border-color: #5878e8;
}
.el-col {
  background: #f6f7fc;
}
.small-title {
  position: relative;
  padding: 10px;
  font-weight: 600;
}
.small-title::before {
  position: absolute;
  content: '';
  display: block;
  background: #5473e8;
  width: 4px;
  height: 14px;
  left: 0px;
  top: 13px;
}
</style>
