<template>
  <div class="app-container home">
    <!-- <el-row :gutter="20">
      <el-col :sm="24" :lg="24">
      </el-col>
    </el-row>
    <el-row style="margin-top: 4px; padding: 16px;" :gutter="20">
      <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8" style="margin-top: 20px;">
        <div style="height: 400px;box-shadow: 10px 10px 5px #888888;border:1px solid #97a8be;border-radius: 5% 2%;">
          <el-row style="margin-top: 4px; padding: 16px;" :gutter="20">
            <span style="font-size: 20px;font-weight:bold;color: #ff4949">货物过期通知：</span>
          </el-row>
          <el-row style="margin-top: 4px; padding: 16px;" :gutter="20">
            <span style="font-size: 15px;font-weight:bold;">{{ cargoMsg }}</span>
          </el-row>
        </div>
      </el-col>
      <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8" style="margin-top: 20px;">
        <div style="height: 400px;box-shadow: 10px 10px 5px #888888;border:1px solid #97a8be;border-radius: 5% 2%;">
          <el-row style="margin-top: 4px; padding: 16px;" :gutter="20">
            <span style="font-size: 20px;font-weight:bold;color: #ff4949">仓库过期通知：</span>
          </el-row>
          <el-row style="margin-top: 4px; padding: 16px;" :gutter="20">
            <span style="font-size: 15px;font-weight:bold;" >{{ stockMsg }}</span>
          </el-row>
        </div>
      </el-col>
    </el-row> -->
    <el-card class="box-card" :body-style="{ padding: '0px' }">
      <div slot="header" class="clearfix">
        <span>即将过期货物列表</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="goMoreCargo">查看所有货物</el-button>
      </div>
      <el-table v-if="cargoList.length" v-loading="cargoLoading" :data="cargoList" :show-header="true"
        :row-class-name="tableRowClassName" @row-dblclick="cargoClick" height="400">
        <el-table-column width="100" label="有效期至" prop="expiryDate" align="center"></el-table-column>
        <el-table-column width="100" label="货物" prop="cargoName" align="center"></el-table-column>
        <el-table-column width="100" label="项号" prop="bookNumber" align="center"></el-table-column>
<!--        <el-table-column width="100" label="库场" prop="stockName" align="center"></el-table-column>-->
        <el-table-column width="200" label="货主" show-overflow-tooltip prop="custName"></el-table-column>
        <el-table-column width="150" label="船舶" prop="vesselName"></el-table-column>
      </el-table>
      <el-empty v-else>
        <el-button type="none" plain @click="getCargoList">刷新</el-button>
      </el-empty>
      <el-pagination layout="prev, pager, next, jumper" :total="cargoTotal" small hide-on-single-page
        :current-page.sync="cargoParam.pageNum" :page-size.sync="cargoParam.pageSize" @current-change="getCargoList" />
    </el-card>
    <el-card class="box-card" :body-style="{ padding: '0px' }">
      <div slot="header" class="clearfix">
        <span>出库提离即将到期单据列表</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="goMoreBillCargo">查看所有出库单据</el-button>
      </div>
      <el-table v-if="outBillCargoList.length" v-loading="outBillCargoLoading" :data="outBillCargoList" :show-header="true"
                :row-class-name="tableRowClassName" @row-dblclick="outBillCargoClick" height="400">
        <el-table-column width="100" label="有效期至" prop="expiryDate" align="center"></el-table-column>
        <el-table-column width="100" label="报关单号" prop="customsNo" align="center"></el-table-column>
        <el-table-column width="100" label="货物" prop="cargoName" align="center"></el-table-column>
        <el-table-column width="100" label="项号" prop="bookNumber" align="center"></el-table-column>
        <el-table-column width="100" label="单据编号" prop="billNumber" align="center"></el-table-column>
        <el-table-column width="100" label="货物流向" prop="cargoFlow" align="center"></el-table-column>
        <el-table-column width="200" label="货主" show-overflow-tooltip prop="custName"></el-table-column>
        <el-table-column width="150" label="船舶" prop="vesselName"></el-table-column>
      </el-table>
      <el-empty v-else>
        <el-button type="none" plain @click="getOutBillCargo">刷新</el-button>
      </el-empty>
      <el-pagination layout="prev, pager, next, jumper" :total="outBillCargoTotal" small hide-on-single-page
                     :current-page.sync="outBillCargoParam.pageNum" :page-size.sync="outBillCargoParam.pageSize" @current-change="getOutBillCargo" />
    </el-card>
    <el-card class="box-card" :body-style="{ padding: '0px' }">
      <div slot="header" class="clearfix">
        <span>即将过期仓库列表</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="goMoreStock">查看所有仓库</el-button>
      </div>
      <el-table v-if="stockList.length" v-loading="stockLoading" :data="stockList" :row-class-name="tableRowClassName"
        @row-dblclick="stockClick" height="400">
        <el-table-column width="100" label="有效期至" prop="validityEnd" align="center"></el-table-column>
        <el-table-column width="150" label="仓库代码" prop="stockCode" align="center"></el-table-column>
        <el-table-column label="仓库" prop="stockName" align="center"></el-table-column>
        <el-empty slot="empty">
          <el-button type="none" plain @click="getStockList">刷新</el-button>
        </el-empty>
      </el-table>
      <el-empty v-else>
        <el-button type="none" plain @click="getCargoList">刷新</el-button>
      </el-empty>
      <el-pagination layout="prev, pager, next, jumper" :total="stockTotal" small hide-on-single-page
        :current-page.sync="stockParam.pageNum" :page-size.sync="stockParam.pageSize" @current-change="getStockList" />
    </el-card>
    <el-dialog title="查看即将过期货物详情" width="70%" :visible.sync="openCargo" append-to-body>
      <CargoDesc :cargo-stock-id="cargoStock.id"></CargoDesc>
    </el-dialog>
    <el-dialog title="查看即将过期仓库详情" :visible.sync="openStock" append-to-body>
      <StockDesc :stock-id="warehouse.id"></StockDesc>
    </el-dialog>
    <el-dialog title="查看出库提离即将到期单据详情" :visible.sync="openOutBillCargo" append-to-body>
      <OutBillCargoDesc :out-bill-cargo-id="outBillCargo.id"></OutBillCargoDesc>
    </el-dialog>
  </div>
</template>

<script>
import { getIndexMsg, stockNumList,pageListByExpire } from '@/api/jxc/ckstock';
import { listCkstock, pageListCkstock } from "@/api/jxc/ckstock";
import { pageListByBillCargoWithExpire } from "@/api/jxc/ckcargo";
import { pageListWarehouse,pageListByWarehouseWithExpire } from "@/api/jxc/warehouse";
import { getDaysBetweenDate } from '@/utils';
import CargoDesc from '@/views/components/CargoDesc';
import StockDesc from '@/views/components/StockDesc';
import OutBillCargoDesc from '@/views/components/OutBillCargoDesc';


export default {
  name: "Warehouse",
  components: {
    CargoDesc,
    StockDesc,
    OutBillCargoDesc
  },
  data() {
    return {
      billCargoMsg: '',
      cargoMsg: '',
      stockMsg: '',
      // 版本号
      version: "3.8.6",
      outBillCargoList: [],
      cargoList: [],
      stockList: [],
      outBillCargoLoading: false,
      cargoLoading: false,
      stockLoading: false,
      openOutBillCargo: false,
      openCargo: false,
      openStock: false,
      outBillCargo: {},
      cargoStock: {},
      warehouse: {},
      cargoTotal: 0,
      cargoParam: {
        pageNum: 1,
        pageSize: 8,
        // isExpire: '1',
      },
      stockTotal: 0,
      stockParam: {
        pageNum: 1,
        pageSize: 8,
        // isExpire: '1',
      },
      outBillCargoTotal: 0,
      outBillCargoParam: {
        pageNum: 1,
        pageSize: 8,
        inoutType: 2,
        // isExpire: '1',
      },
    };
  },
  created() {
    // this.getmsg();
    this.getStockList();
    this.getCargoList();
    this.getOutBillCargo();
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      const day = getDaysBetweenDate(row.expiryDate || row.validityEnd);
      if (day < 0) {
        return 'danger-row';
      }
      return 'warning-row';
    },
    getOutBillCargo() {
      this.outBillCargoLoading = true;
      pageListByBillCargoWithExpire(this.outBillCargoParam).then(res => {
        this.outBillCargoLoading = false;
        this.outBillCargoList = res.rows || [];
        this.outBillCargoTotal = res.total;
      }).catch(e => {
        this.outBillCargoLoading = false;
      });
    },
    getStockList() {
      this.stockLoading = true;
      pageListByWarehouseWithExpire(this.stockParam).then(res => {
        this.stockLoading = false;
        this.stockList = res.rows || [];
        this.stockTotal = res.total;
      }).catch(e => {
        this.stockLoading = false;
      });
    },
    getCargoList() {
      this.cargoLoading = true;
      pageListByExpire(this.cargoParam).then(res => {
        this.cargoLoading = false;
        this.cargoList = res.rows || [];
        this.cargoTotal = res.total;
      }).catch(e => {
        this.cargoLoading = false;
      });
    },
    goMoreCargo() {
      this.$router.push('manage/ckstock');
    },
    goMoreStock() {
      this.$router.push('base/warehouse');
    },
    goMoreBillCargo() {
      this.$router.push('search/outstock');
    },
    stockClick(row) {
      this.warehouse = row;
      this.openStock = true;
    },
    cargoClick(row) {
      this.cargoStock = row;
      this.openCargo = true;
    },
    outBillCargoClick(row) {
      this.outBillCargo = row;
      this.openOutBillCargo = true;
    },
    getmsg() {
      getIndexMsg().then(response => {
        this.cargoMsg = response.cargoMsg
        this.stockMsg = response.stockMsg
      }).catch(e => {
      })
    },
    goTarget(href) {
      window.open(href, "_blank");
    }
  }
};
</script>

<style scoped lang="scss">
.app-container {
  display: flex;
}

.box-card {
  width: 450px;
  min-height: 450px;
  margin-right: 20px;
}

.clearfix {
  font-size: 15px;
}

.remind {
  font-size: 13px;
  color: #E6A23C;
  max-height: 50px;
}

.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans",
  "Helvetica Neue",
  Helvetica,
  Arial,
  sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

