//删除仓库
<template>
  <div class="homepage">
    <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="connert">
      <el-table
        class="wenzi"
        :data="warehouseList"
        style="width: 100%; margin-top: 20px"
        height="780"
      >
        <el-table-column type="index" label="序号">
          <template scope="scope">
            <span v-if="scope.$index < 9">0{{ scope.$index + 1 }}</span>
            <span v-else>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="warehouseName" label="仓库名称">
        </el-table-column>
        <el-table-column prop="warehouseCity" label="仓库所在地">
        </el-table-column>
        <el-table-column prop="residual" label="应余库存（吨）">
        </el-table-column>
        <el-table-column prop="personCharge" label="负责人"> </el-table-column>

        <el-table-column prop="address" label="操作" width="200">
          <template slot-scope="scope">
            <div
              class="record"
              v-if="scope.row.showFlag == 0"
              @click="handleHide(scope.row)"
            >
              显示
            </div>
            <div
              class="record"
              v-if="scope.row.showFlag == 1"
              @click="handleHide(scope.row)"
            >
              隐藏
            </div>
            <div class="adjustment" @click="handleDelete(scope.row)">删除</div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import {
  delectlist,
  deletewarehouse,
  hide,
} 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 {
      isshow: false,
      //弹出框
      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,
      warehouseList: [],
      scope: [],
      show: '隐藏',
      // 提交类型
      submitType: true,
      size: 10,
      compId: sessionStorage.getItem('ws-pf_compId'),
      deptCircularPage: {},
      date: {
        year: dayjs().format('YYYY'),
        month: dayjs().format('MM'),
      },
      contractList: [],
      deptBudgetList: {},
      historyList: [],
      pickerBeginDateBefore: {
        disabledDate: (time) => {
          return time.getTime() > Date.now()
        },
      },
      accessoryTFs: false,
    }
  },
  activated() {
    this.getList()
    this.showType = this.isShow
  },
  methods: {
    returnWarehouse() {
      this.$router.push({ path: 'warehouseManagementList' })
    },

    //列表
    getList() {
      delectlist({
        compId: sessionStorage.getItem('ws-pf_compId'),
      })
        .toPromise()
        .then((response) => {
          this.warehouseList = response
        })
    },
    handleExamine(row) {
      this.$router.push({
        name: 'salesContractExamine',
        query: { id: row.id },
      })
    },
    // 关闭 dialog时 处理文件url 初始化upload组件
    handleCloe() {
      this.dialogViewSpareMoney = false
    },
    //删除
    handleDelete(row) {
      if(row.residual == 0){
    // console.log(row)
    this.$confirm(`此操作永久删除该仓库全部信息，是否确认删除`, {
      cancelButtonText: '取消',
      confirmButtonText: '确定',
      type: 'warning',
    })
      .then(() => {
        deletewarehouse({ id: row.id })
          .toPromise()
          .then((response) => {
            this.$notify.success({
              title: '成功',
              message: '删除成功',
            })
            this.getList()
          })
          .catch((response) => {
            // console.log(3333)
            // EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
          })
      })
      .catch(() => {
        return false
      })
      }else{
         this.$message({
            message: '还有应余库存，不能删除此仓库!',
            type: 'warning',
          })
          return
      }
  },
    //隐藏
    handleHide(row) {
      if (row.showFlag == 1) {
        this.$confirm(`隐藏后将对其他用户不可见，是否确认隐藏`, {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          type: 'warning',
        })
          .then(() => {
            hide({ id: row.id })
              .toPromise()
              .then((response) => {
                this.$notify.success({
                  title: '成功',
                  message: '隐藏成功',
                })
                this.getList()
              })
              .catch((response) => {
                // console.log(3333)
                // EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
              })
          })
          .catch(() => {
            return false
          })
      } else {
        hide({ id: row.id })
          .toPromise()
          .then((response) => {
            this.$notify.success({
              title: '成功',
              message: '显示成功',
            })
            this.getList()
          })
          .catch((response) => {
            // console.log(3333)
            // EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
          })
      }
    },
  },
  
  // deletecontract(){},
  //删除
  approve() {},
  listQuery() {},
  total() {},
  clearfiltQuery() {},
  selectCrtDuty() {},
  delectlist() {},
  deletewarehouse() {},
}
</script>
<style lang="scss" scoped>
/deep/.totalStorage .el-input__inner {
  color: #afb5cb;
  background: #f5f7fa;
}
.add,
.del {
  position: absolute;
  right: -38px;
  top: 9px;
  cursor: pointer;
}
.del {
  right: -70px;
}
.amap-page-container {
  width: 300px;
  height: 300px;
}
.el-form {
  padding: 0 15%;
}
.readonly {
  position: relative;
}
.readonly:after {
  content: '*';
  color: #ff2727;
  position: absolute;
  right: 8px;
  z-index: 10;
  top: 21%;
  font-size: 20px;
}
.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;
}
/deep/.el-table .el-table__header .cell,
/deep/.el-table .el-table__body .cell {
  text-align: center;
}
.button-container {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  width: 100%;
  height: 50px;
  padding: 0 10px;
  & > div {
    margin-left: 10px;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    & > span {
      line-height: 50px;
    }
  }

  /deep/.auditFlow-box {
    position: unset;
    margin-left: 10px;
    &/deep/.auditFlow-icon {
      width: auto;
      padding-right: 30px;
    }
    &/deep/.auditFlow-main {
      position: absolute;
    }
  }
}
.box-app {
  display: inline-block;
  float: left;
  margin-left: 30px;
  line-height: 50px;
}
/deep/.el-dialog {
  .el-form-item {
    margin-bottom: 0 !important;
    .el-input--medium {
      textarea {
        min-height: 100px !important;
      }
    }
  }
}
.collapse-bottom {
  margin-bottom: 20px;
}
.input-main .textarea .el-textarea__inner {
  width: 100%;
  z-index: 1;
}
.bg-left {
  padding-left: 30px;
}
.bg-right {
  padding-right: 10px;
  text-align: right;
}
.bg-bottom {
  margin: 15px 0px;
}
.wenzi {
  width: 900px;
  margin: 0 auto;
}
.wenzi h3 {
  display: inline-block;
  left: 10px;
}
.wenzi p {
  display: inline-block;
}
.center {
  width: 900px;
  margin: 0 auto;
}
.el-form-item {
  width: 50%;
}
.el-form-item__label {
  text-align: center;
}
.ce {
  width: 900px;
  margin: 0 auto;
}
/*.crt-main .textarea /deep/ .el-form-item__label {*/
/*  height: 82px;*/
/*}*/
// 控制select为只读的时候显示样式

.hide-sel {
  .el-input__inner {
    border: 0px;
  }
  .el-icon-arrow-up {
    display: none;
  }
  .el-textarea__inner {
    background-color: #fff !important;
    border: 0;
  }
  .el-date-editor {
    i {
      display: none;
    }
  }
  .is-disabled {
    .el-input__inner:hover {
      background-color: #fff !important;
      border: 0;
    }
    color: #606266;
    .el-input__inner {
      background-color: #fff !important;
      border: 0;
      color: #606266;
    }
    .el-textarea__inner {
      background-color: #fff !important;
      border: 0;
      color: #606266;
    }
  }
}

// 控制select为只读的时候显示样式
/deep/.ws-class-table-col {
  height: auto;
  padding: 0px 2px;
  /deep/.el-input__inner {
    padding: 0px 2px;
  }
}
/deep/.is-disabled {
  .el-input__prefix,
  .el-input__suffix {
    display: none;
  }
  .el-input__inner {
    background-color: #fff;
    border-color: #fff !important;
    color: #000 !important;
    font-size: 14px;
    cursor: text;
    padding: 0 !important;
  }
}
.winseaview-view {
  padding: 0 0 20px;
}
.container {
  overflow: scroll;
  height: 93vh;
}
.ws-info-table .el-form-item {
  width: 33.3333%;
}
.readonly:after {
  display: none;
}
.el-textarea__inner {
  display: none;
}
.el-form {
  margin-top: 50px;
}
.readonly {
  width: 16%;
}
.ws-info-table .el-form-item {
  width: 33.33%;
}
//去边框
/deep/.el-form-item {
  border-right: 0px;
  border-bottom: 0px;
}
/deep/.ws-info-table {
  border-left: 0px;
  border-top: 0px;
}

.connert {
  padding: 10px 40px;
}

//表格文字居中
/deep/.el-table th.is-leaf,
/deep/.el-table td {
  text-align: center;
}
//表格数据文字
/deep/.el-table .el-table__body .cell {
  font-size: 14px;
}
.record,
.adjustment {
  display: inline-block;
  color: #5878e8;
  padding: 0 4px !important;
  position: relative;
}
.record:after {
  position: absolute;
  content: '';
  display: block;
  top: 5px;
  right: -2px;
  width: 1px;
  height: 12px;
  background: #e9ecf7;
}
</style>
