<!--suppress ALL -->
<template>
  <div>
    <el-menu class="navbar" mode="horizontal" style="background: #70B603!important;">
      <hamburger :toggle-click="toggleSideBar" :is-active="sidebar.opened" class="hamburger-container"/>
      <breadcrumb />
      <el-dropdown class="avatar-container" trigger="click">
        <div class="avatar-wrapper">
          <img :src="require('../../../assets/img/LOGO.jpg')" class="user-avatar">
          <i class="el-icon-caret-bottom"/>
        </div>
        <el-dropdown-menu slot="dropdown" class="user-dropdown">
          <router-link class="inlineBlock" to="/">
            <el-dropdown-item>
              主页
            </el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="logout">
            <span style="display:block;">退出</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-menu>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
/* import { searchTable1 } from '@/api/PurchasingCenter/PurchaseContractApproval'
import { getMaterial, getMaterial_NOTES, setChakan } from '@/api/PurchasingCenter/MaterialManagement'
import { initApproval, initApprovalOffline } from '@/api/PurchasingCenter/FundApproval'
import { searchUrgentItem } from '@/api/ManufacturingCenter/InitialProduction'
import { searchTable1 as searchTableInvoice } from '@/api/PurchasingCenter/InvoiceSettlementApprove'
import { RequestFund, setChakan2 } from '@/api/PurchasingCenter/PurchaseContractRequestFund'
import { initApproval1, initApprovalOutsourcing, initApprovalMaterials } from '@/api/WorkshopProcurement/FundApproval'
import { searchTable1 as InvoiceSettlementApprove1 } from '@/api/WorkshopProcurement/InvoiceSettlementApprove1'
import { searchTable1 as OutsourcingArrivalTicket } from '@/api/Outsourcing/ApprovalOfOutsourcingArrivalTicket'
import { searchInvoice as searchMaterialsInvoice } from '@/api/WorkshopProcurement/MaterialsInvoiceApproval'
import { searchTable1 as searchContractApproval } from '@/api/WorkshopProcurement/ProcurementContractApproval'*/
// import { getPickingList, setPickingList } from '@/api/Inventory/MaterialOut'
/* import { searchTable } from '@/api/PurchasingCenter/PurchaseMaterielModify'
import { search } from '@/api/Assembly/DeliveryConfirmation'
import { searchtable as searchtableSupplement } from '@/api/WorkshopProcurement/ScrappedSupplementaryInvestment1'*/ // 查询报废补投零件
import Cookies from 'js-cookie'
export default {
  components: {
    Breadcrumb,
    Hamburger
  },
  data() {
    return {
      timer: '',
      noticeFund: null,
      noticeInvoice: null,
      noticeContractKG: null, // 领料单
      selfMadeparts: null, // 自制件
      productionPicking: null, // 物料
      purchaseContract: null, // 采购合同
      purchaseOrder: null, // 采购订单
      productionOperation: null, // 生产投产
      orderOperation: null, // 订单投产
      deliveryNotice: null, // 发货通知
      partsScrapping: null, // 零件报废
      noticeDeliver: null,
      noticeApproval: null,
      noticeInvoiceManufacture: null,
      noticeInvoiceOutsourcing: null,
      noticeInvoiceMaterials: null,
      noticeContractApproval: null,
      PickingListSearch: null, // 领料单
      SelfMadePartsReceiptSearch: null, // 库存管理自制件
      PurchaseContract: null,
      OrderProduction: null,
      PurchaseContractSearch: null,
      DeliveryNotice: null,
      ScrapReplenishment: null,
      OrderConfirmationShipment: null
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id',
      'token',
      'token'
    ])
  },
  mounted() {
    console.log(Cookies.get('id'), 999)
    /* if (this.id === 3 || Cookies.get('id') === 3) { // id=3 沈大为 总经理
      this.checkApproval()
      this.timer = setInterval(this.checkApproval, 1000 * 60 * 5)
    } else if (this.token.toString() === '11') { // 11 技术部长
      // 存储过程 库存管理_物料主文件_基本_采购部_查询未审核数量
      this.comfirmMaterial() // 您有采购物料申请待审批，请及时处理，点击查看
      this.timer = setInterval(this.comfirmMaterial, 1000 * 60 * 5)
      // 存储过程 采购管理_采购物料修改确认_查询数据
      this.comfirmMaterial_Update() // 您有采购物料更改申请待审批，请及时处理，点击查看
      this.timer = setInterval(this.comfirmMaterial_Update, 1000 * 60 * 5)
    } else if (this.token.toString() === '2' || this.token.toString() === '3') { // 2 采购部长 3 采购员 18 财务(会计)
      this.comfirmMaterial_CG()
      this.timer = setInterval(this.comfirmMaterial_CG, 1000 * 60 * 5)
    } else if (this.token.toString() === '5') { // 5 计划员
      this.comfirmUrgentItem()
      this.timer = setInterval(this.comfirmUrgentItem, 1000 * 60 * 5)
      this.searchtableSupplement() // 报废补投(制造)
      this.timer = setInterval(this.searchtableSupplement, 1000 * 60 * 5)
    } else if (this.token.toString() === '21') { // 21 装配部长
      this.comfirmDeliver()
      this.timer = setInterval(this.comfirmDeliver, 1000 * 60 * 5)
    } else if (this.token.toString() === '26') { // 26 制造部总经理
      this.ManufacturingApprova()
      this.timer = setInterval(this.ManufacturingApprova, 1000 * 60 * 5)
    } else if (this.token.toString() === '18') { // 26 财务
      this.FinanceApprova()
      this.timer = setInterval(this.FinanceApprova, 1000 * 60 * 5)
    }*/
    /* if (this.token.toString() === '7') { // 仓库
      this.warehouseSearch()
      this.timer = setInterval(this.warehouseSearch, 1000 * 60 * 5)
    } else if (this.token.toString() === '11') { // 审核
      this.newPurchaseContract()
      this.timer = setInterval(this.newPurchaseContract, 1000 * 60 * 5)
    } else if (this.token.toString() === '8') { // 发货
      this.newDeliveryNotice()
      this.timer = setInterval(this.newDeliveryNotice, 1000 * 60 * 5)
    } else if (this.token.toString() === '16') { // 16 精工车间
      this.newScrapReplenishment()
      this.timer = setInterval(this.newScrapReplenishment, 1000 * 60 * 5)
    } else if (this.token.toString() === '4') { // 4 采购
      this.purchaseSearch()
      this.timer = setInterval(this.purchaseSearch, 1000 * 60 * 5)
    } else if (this.token.toString() === '3' || this.token.toString() === '11') { // 4 销售
      this.saleSearch()
      this.timer = setInterval(this.saleSearch, 1000 * 60 * 5)
    } else if (this.token.toString() === '15') { // 15 技术
      this.newOrderInformation()
      this.timer = setInterval(this.newOrderInformation, 1000 * 60 * 5)
    } else if (this.token.toString() === '15') { // 15 技术
      this.newOrderInformation()
      this.timer = setInterval(this.newOrderInformation, 1000 * 60 * 5)
    } else if (this.token.toString() === '2') { // 2 管理员
      this.newOrderProduction()
      this.timer = setInterval(this.newOrderProduction, 1000 * 60 * 5)
    }*/
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    warehouseSearch() {
      this.newPickingListSearch()
      this.newSelfMadePartsReceiptSearch()
    },
    purchaseSearch() {
      this.newPurchaseContractSearch()
      this.newPaymentOrder()
    },
    saleSearch() {
      this.newOrderConfirmationShipment()
    },
    newPickingListSearch() {
      // 新领料单通知查询
      var param = []
      var Data = this.CreateData('11', '装配管理_领料单明细_查询_新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.PickingListSearch = null
          this.PickingListSearch = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有新的领料单需要备料确认，请及时处理，<a style="color: #1e6abc">点击查看</a></div>',
            onClick: () => {
              this.$router.push({ path: '/WarehouseManagement/MaterialRequisition' })
              setTimeout(this.PickingListSearch.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '装配管理_领料单明细_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newSelfMadePartsReceiptSearch() {
      // 新自制件入库查询
      var param = []
      var Data = this.CreateData('11', '库存管理_自制件_查询_新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.SelfMadePartsReceiptSearch = null
          this.SelfMadePartsReceiptSearch = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有新的自制件入库，需要您确认<a style="color: #1e6abc">点击进入确认界面</a></div>',
            onClick: () => {
              this.$router.push({ path: '/WarehouseManagement/PurchasePartsStorage' })
              setTimeout(this.SelfMadePartsReceiptSearch.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '库存管理_自制件_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newPurchaseContract() {
    //  新采购合同查询
      var param = []
      var Data = this.CreateData('11', '采购管理_采购合同_查询_新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.PurchaseContract = null
          this.PurchaseContract = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有新的采购合同，需要您审批<a style="color: #1e6abc">点击进入确认界面</a></div>',
            onClick: () => {
              this.$router.push({ path: '/SeikoWorkshop/ProcurementContractAudit' })
              setTimeout(this.PurchaseContract.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '采购管理_采购合同_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newPurchaseContractSearch() {
      // 采购合同审核通过是否通知
      var param = []
      var Data = this.CreateData('11', '采购管理_采购合同_审核通过是否通知_查询新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.PurchaseContractSearch = null
          this.PurchaseContractSearch = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有新的合同审核通过<a style="color: #1e6abc">点击查看详情</a></div>',
            onClick: () => {
              this.$router.push({ path: '/PurchasingManagement/OrderInquiry' })
              setTimeout(this.PurchaseContractSearch.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '采购管理_采购合同_审核通过是否通知_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newOrderInformation() {
      // 新订单查询技术审核确认
      var param = []
      var Data = this.CreateData('11', '合同管理_订单信息_基础表_查询_新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.OrderInformation = null
          this.OrderInformation = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有新的订单，需要您技术审核确认<a style="color: #1e6abc">点击进入技术确认界面</a></div>',
            onClick: () => {
              this.$router.push({ path: '/TechnologyCenter/DrawingConfirmation' })
              setTimeout(this.OrderInformation.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '合同管理_订单信息_基础表_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newOrderProduction() {
      // 新订单查询订单投产
      var param = []
      var Data = this.CreateData('11', '合同管理_订单信息_基础表_查询_新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.OrderProduction = null
          this.OrderProduction = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有新的订单，需要投产<a style="color: #1e6abc">点击进入订单投产</a></div>',
            onClick: () => {
              this.$router.push({ path: '/SalesManagement/OrderRelease' })
              setTimeout(this.OrderProduction.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '合同管理_订单信息_基础表_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newPaymentOrder() {
      // 付款是否通知
      var param = []
      var Data = this.CreateData('11', '采购管理_采购合同_付款是否通知_新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.PaymentOrder = null
          this.PaymentOrder = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有合同付款通知<a style="color: #1e6abc">点击查看详情</a></div>',
            onClick: () => {
              this.$router.push({ path: '/PurchasingManagement/OrderInquiry' })
              setTimeout(this.PaymentOrder.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '采购管理_采购合同_付款通知_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newDeliveryNotice() {
    //  新发货通知是否查看
      var param = []
      var Data = this.CreateData('11', '合同管理_订单信息_基础表_通知发货是否查看_查询新通知', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.DeliveryNotice = null
          this.DeliveryNotice = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>您有新的发货通知，注意查看<a style="color: #1e6abc">点击查看详情</a></div>',
            onClick: () => {
              this.$router.push({ path: '/SalesManagement/ProductDelivery' })
              setTimeout(this.DeliveryNotice.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '合同管理_订单信息_基础表_通知发货是否查看_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newScrapReplenishment() {
      // 精工车间 报废补投新的查询
      var param = []
      var Data = this.CreateData('11', '车间生产管理工艺_零件工艺计划_报废零件记录_是否查看查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.ScrapReplenishment = null
          this.ScrapReplenishment = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>有零件报废，请及时补投<a style="color: #1e6abc">点击进入“报废补投”界面</a></div>',
            onClick: () => {
              this.$router.push({ path: '/SeikoWorkshop/ScrapProduction' })
              setTimeout(this.ScrapReplenishment.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '车间生产管理工艺_零件工艺计划_报废零件记录_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    newOrderConfirmationShipment() {
      //  订单确认发货
      var param = []
      var Data = this.CreateData('11', '合同管理_订单信息_基础表_已发货是否查看查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.OrderConfirmationShipment = null
          this.OrderConfirmationShipment = this.$notify.success({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: ' <div>有合同已发货<a style="color: #1e6abc">点击查看发货信息</a></div>',
            onClick: () => {
              this.$router.push({ path: '/SalesManagement/DeliveryRecord' })
              setTimeout(this.OrderConfirmationShipment.close(), 1000)
              var param = []
              var Data = this.CreateData('12', '合同管理_订单信息_基础表_已发货_确认查看', param)
              this.ExecDatabase(Data)
            },
            duration: 1000 * 60
          })
        }
      })
    },
    toggleSideBar() {
      this.$store.dispatch('ToggleSideBar')
    },
    logout() {
      this.$store.dispatch('FedLogOut').then(() => {
        location.reload() // 为了重新实例化vue-router对象 避免bug
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .navbar {
    height: 50px;
    line-height: 50px;
    border-radius: 0px !important;
    .hamburger-container {
      line-height: 58px;
      height: 50px;
      float: left;
      padding: 0 10px;
    }
    .screenfull {
      position: absolute;
      right: 90px;
      top: 16px;
      color: red;
    }
    .avatar-container {
      height: 50px;
      display: inline-block;
      position: absolute;
      right: 35px;
      .avatar-wrapper {
        cursor: pointer;
        margin-top: 5px;
        position: relative;
        width: 40px;
        height: 40px;
        background-color: rgb(35, 148, 242);
        .user-avatar {
          width: 35px;
          height: 35px;
          margin: 3px 0 0 3px;
        }
        .el-icon-caret-bottom {
          color: #fff;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
        /deep/ .el-notification.right{
          cursor:pointer!important;
        }
      }
    }
  }
</style>
