<template>
  <div class="home-container">
    <el-card class="home-container__card">
      <div class="title">
        <span>
          审核数据
        </span>
        <span>
          <i
            class="el-icon-refresh-right"
            style="cursor: pointer;font-size:20px"
            @click="refresh"
          ></i>
        </span>
      </div>
      <div class="content" v-loading="loading" v-if="sysType != 2">
        <div class="content-item" v-for="(item, index) in list" :key="index">
          <div class="card">
            <i :class="item.icon" style="font-size:30px;color:#409EFF"></i>
            <div class="card-content">
              <span class="card-content-num">{{ item.qty }}</span>
              <span class="card-content-text">{{ item.text }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="content" v-loading="loading" v-if="sysType == 2">
        <div class="content-item" v-for="(item, index) in domList" :key="index">
          <div class="card">
            <i :class="item.icon" style="font-size:30px;color:#409EFF"></i>
            <div class="card-content">
              <span class="card-content-num">{{ item.qty }}</span>
              <span class="card-content-text">{{ item.text }}</span>
            </div>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import {
  checkDate,
  shipCheckDate,
  financeCheck
} from "@/api/wel";
export default {
  name: "basicContainer",
  props: {
    sysType: Number
  },
  data() {
    return {
      loading: false,
      list: [
        { icon: "el-icon-s-order", qty: "0", text: "报价订单/待审核" },
        { icon: "el-icon-s-order", qty: "0", text: "销售订单/待审核" },
        { icon: "el-icon-s-goods", qty: "0", text: "采购订单/待审核" },
        { icon: "el-icon-s-home", qty: "0", text: "发货/待审核" },
        { icon: "el-icon-s-home", qty: "0", text: "收货/待审核" },
        { icon: "el-icon-s-finance", qty: "0", text: "申请付款/待审核" }
      ],
      domList: [
        { icon: "el-icon-s-order", qty: "0", text: "销售订单/待审核" },
        { icon: "el-icon-s-goods", qty: "0", text: "采购订单/待审核" },
        { icon: "el-icon-s-home", qty: "0", text: "发货/待审核" },
        { icon: "el-icon-s-home", qty: "0", text: "收货/待审核" },
        { icon: "el-icon-s-finance", qty: "0", text: "申请付款/待审核" }
      ],
      tradeType: null
    };
  },
  created() {
    this.getSysType();
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      // if(this.sysType === 3){

      // }
      if (this.sysType === 5) {
        this.list = [
          { icon: "el-icon-s-order", qty: "0", text: "主营业务/待审核" }
        ];
      }
      this.getCheckDate();
      this.getshipCheckDate();
      this.getfinanceCheck()
    },
    getSysType() {
      const sysType = localStorage.getItem("sysitemType");
      if (sysType == 6) {
        this.tradeType = "JXS";
      } else if (sysType == 5) {
        this.tradeType = "SW";
      } else if (sysType == 4) {
        this.tradeType = "CK";
      } else if (sysType == 3) {
        this.tradeType = "JK";
      } else if (sysType == 2) {
        this.tradeType = "GN";
      } else if (sysType == 1) {
        this.tradeType = "XX";
      }else if(sysType == 999){
        this.tradeType = "ADMIN";
      }
    },
    getCheckDate() {
      this.loading = true;
      checkDate({ tradeType: this.tradeType })
        .then(res => {
          if (this.sysType == 2){
            this.domList.forEach(e => {
              if (e.text == "报价订单/待审核") {
                e.qty = res.data.data.offerNumber;
              }
              if (e.text == "销售订单/待审核") {
                e.qty = res.data.data.sellNumber;
              }
              if (e.text == "采购订单/待审核") {
                e.qty = res.data.data.purchaseNumber;
              }
            });
          }else {
            this.list.forEach(e => {
              if (e.text == "报价订单/待审核") {
                e.qty = res.data.data.offerNumber;
              }
              if (e.text == "销售订单/待审核") {
                e.qty = res.data.data.sellNumber;
              }
              if (e.text == "采购订单/待审核") {
                e.qty = res.data.data.purchaseNumber;
              }
            });
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    getshipCheckDate() {
      this.loading = true;
      shipCheckDate({ tradeType: this.tradeType })
        .then(res => {
          if (this.sysType == 2){
            this.domList.forEach(e => {
              if (e.text == "发货/待审核") {
                e.qty = res.data.data.sellNumber;
              }
              if (e.text == "收货/待审核") {
                e.qty = res.data.data.purchaseNumber;
              }
            });
          }else {
            this.list.forEach(e => {
              if (e.text == "发货/待审核") {
                e.qty = res.data.data.sellNumber;
              }
              if (e.text == "收货/待审核") {
                e.qty = res.data.data.purchaseNumber;
              }
            });
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    getfinanceCheck(){
      this.loading = true;
      financeCheck({ tradeType: this.tradeType })
        .then(res => {
          if (this.sysType == 2){
            this.domList.forEach(e => {
              if (e.text == "申请付款/待审核") {
                e.qty = res.data.data;
              }
            });
          }else {
            this.list.forEach(e => {
              if (e.text == "申请付款/待审核") {
                e.qty = res.data.data;
              }
            });
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    refresh() {
      this.getCheckDate();
      this.getshipCheckDate();
      this.getfinanceCheck()
    }
  }
};
</script>

<style lang="scss" scoped>
.home-container {
  padding: 0px 5px 5px 5px;
  box-sizing: border-box;
  height: 100%;
  ::v-deep .el-card__body {
    padding: 10px 15px;
    font-size: 14px;
  }
  &__card {
    width: 100%;
    height: 100%;
  }
  .title {
    display: flex;
    justify-content: space-between;
  }
}
.content {
  display: flex;
  &-item {
    background-color: #f4f8ff;
    margin-top: 0.5vh;
    margin-right: 0.5vw;
    height: 13vh;
    width: 15vw;
    display: flex;
    align-items: center;
    padding-left: 1.5vw;
    .card {
      display: flex;
      align-items: center;
      &-content {
        padding-left: 1vw;
        display: flex;
        flex-direction: column;
        &-num {
          font-size: 20px;
          font-weight: 600;
        }
        &-text {
          color: #909399;
        }
      }
    }
  }
}
</style>
