<template>
  <div class="app-container home">
    <ul class="block">
      <li @click="jump('/business/inStock')">
        <div>
          <i class="el-icon-download" style="font-size: 50px;text-align: center"></i>
          <p>入库</p>
        </div>
      </li>
      <li @click="jump('/business/outStock')">
        <div>
          <i class="el-icon-upload2" style="font-size: 50px;text-align: center"></i>
          <p>出库</p>
        </div>
      </li>
      <li @click="jump('/basicdata/corps')">
        <div>
          <i class="el-icon-s-custom" style="font-size: 50px;text-align: center"></i>
          <p>新增用户</p>
        </div>
      </li>
      <li @click="jump('/basicdata/goods')">
        <div>
          <i class="el-icon-s-cooperation" style="font-size: 50px;text-align: center"></i>
          <p>新增商品</p>
        </div>
      </li>
      <li @click="jump('/business/stockTransfer')">
        <div>
          <i class="el-icon-connection" style="font-size: 50px;text-align: center"></i>
          <p>调拨</p>
        </div>
      </li>
      <li @click="jump('/finance/charge')">
        <div>
          <i class="el-icon-wallet" style="font-size: 50px;text-align: center"></i>
          <p>收款</p>
        </div>
      </li>
      <li @click="jump('/finance/payment')">
        <div>
          <i class="el-icon-money" style="font-size: 50px;text-align: center"></i>
          <p>付款</p>
        </div>
      </li>
      <li @click="jump('/finance/contrast')">
        <div>
          <i class="el-icon-s-management" style="font-size: 50px;text-align: center"></i>
          <p>对账</p>
        </div>
      </li>
      <li @click="jump('/business/goodsTransfer')">
        <div>
          <i class="el-icon-takeaway-box" style="font-size: 50px;text-align: center"></i>
          <p>货转</p>
        </div>
      </li>
      <li @click="jump('/agreement/agreementStorage')">
        <div>
          <i class="el-icon-s-order" style="font-size: 50px;text-align: center"></i>
          <p>协议</p>
        </div>
      </li>
    </ul>
    <div style="width: 30%;float: right">
      <div style="display: flex;">
        <div id="box" style="width:100%;height:350px;"></div>

        <el-select v-model="select" slot="prepend" size="mini" :select="query()" placeholder="点击切换仓库"
                   style="position:absolute; width: 8%;right: 1%;"
        >
          <div v-for="(item, index) in warehouse" :key="index">
            <el-option :label="item.fName" :value="item.fWarehouseid"></el-option>
          </div>
        </el-select>
      </div>
    </div>
    <div style="width: 100%;margin-bottom: 50px;">
      <el-table :data="tableData" :header-cell-style="{borderBottom:'1px dashed #dfe6ec'}" :cell-style="cellStyle"
                style="width: 67.5%;float: left;"
      >
        <el-table-column prop="refno1" :show-overflow-tooltip="true" label="委托方"></el-table-column>
        <el-table-column prop="auditItem" :show-overflow-tooltip="true" label="日期">
          <template slot-scope="scope">
            <span v-if="!scope.row.auditItem">无时间</span>
            <span v-else>{{ scope.row.auditItem.slice(0, 10) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="refno3" :show-overflow-tooltip="true" label="提单号"></el-table-column>
        <el-table-column prop="refno2" :show-overflow-tooltip="true" label="业务类型">
          <template slot-scope="scope">
            <span v-if="scope.row.refno2 === 'SJRK'">入库</span>
            <span v-else-if="scope.row.refno2 === 'SJCK'">出库</span>
            <span v-else-if="scope.row.refno2 === 'HQZY'">货转</span>
            <span v-else-if="scope.row.refno2 === 'CKDB'">调拨</span>
            <span v-else-if="scope.row.refno2 === 'CCF'">仓储费</span>
            <span v-else-if="scope.row.refno2 === 'ZYF'">作业费</span>
            <span v-else-if="scope.row.refno2 === 'SF'">收费</span>
            <span v-else-if="scope.row.refno2 === 'DZ'">对账</span>
            <span v-else-if="scope.row.refno2 === 'FF'">付费</span>
            <span v-else-if="scope.row.refno2 === 'JSCCF'">计算仓储费</span>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="操作" width="80">
          <template slot-scope="scope">
            <span style="cursor:pointer" @click="approval(scope.row)">查看详情</span>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="tableDataTwo" :header-cell-style="{borderBottom:'1px dashed #dfe6ec'}" :cell-style="cellStyle"
                style="width: 30%;float: right;margin-left: 20px;"
      >
        <el-table-column prop="noticeTitle" :show-overflow-tooltip="true" label="消息中心"/>
        <el-table-column prop="address" label="操作" width="80">
          <template slot-scope="scope">
            <span @click="querytoDo(scope.row.noticeContent)" style="cursor:pointer">查看详情</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="width: 100%;float: left;margin-top:20px;">
      <div style="display: flex;">
        <div id="commoDity" style="width:68%;height:350px;margin-left: 40px"></div>
        <div id="cargoOwner" style="width:30%;height:350px;"></div>
      </div>
    </div>
    <el-dialog
      title="消息提示"
      :visible.sync="dialogVisible"
      width="80%"
      :before-close="handleClose"
      :close-on-click-modal="false"
    >
      <span v-html="text" class="text" style="max-width: 100%;height: auto;"></span>
      <span slot="footer" class="dialog-footer">
<!--    <el-button @click="dialogVisible = false">取 消</el-button>-->
    <el-button type="primary" @click="dialogVisible = false">关 闭</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import { listCorps, information, warehouse, inquiry } from '../../src/api/index'

export default {
  name: 'index',
  data() {
    return {
      editModel: {},
      // 版本号
      version: '3.2.1',
      select: '',
      text: '',
      dialogVisible: false,
      tableData: [],
      chart: [],
      warehouse: [],
      master: [],
      commodity: [],
      commoditytwo: [],
      name: [],
      tableDataTwo: []
    }
  },
  activated() {
    this.getList()
    this.warehouses()
    this.firstinventory()
    this.inquiry()
  },
  created() {
    this.getList()
    this.warehouses()
    this.firstinventory()
    this.inquiry()
  },
  methods: {
    //跳转审批页面
    approval(row) {
      switch (row.refno2) {
        case 'SJRK': {
          this.$router.push({ path: '/business/inStock', query: { data: JSON.stringify(row) } })
          break
        }
        case 'SJCK': {
          this.$router.push({ path: '/business/outStock', query: { data: JSON.stringify(row) } })
          break
        }
        case 'HQZY': {
          this.$router.push({ path: '/business/goodsTransfer', query: { data: JSON.stringify(row) } })
          break
        }
        case 'CKDB': {
          this.$router.push({ path: '/business/stockTransfer', query: { data: JSON.stringify(row) } })
          break
        }
        case 'JSCCF': {
          this.$router.push({ path: '/business/agreement', query: { data: JSON.stringify(row) } })
          break
        }
        case 'CCF': {
          this.$router.push({ path: '/agreement/agreementStorage', query: { data: JSON.stringify(row) } })
          break
        }
        case 'ZYF': {
          this.$router.push({ path: '/agreement/agreementTask', query: { data: JSON.stringify(row) } })
          break
        }
        case 'SF': {
          this.$router.push({ path: '/finance/charge', query: { data: JSON.stringify(row) } })
          break
        }
        case 'DZ': {
          this.$router.push({ path: '/finance/contrast', query: { data: JSON.stringify(row) } })
          break
        }
        case 'FF': {
          this.$router.push({ path: '/finance/payment', query: { data: JSON.stringify(row) } })
          break
        }
        default: {
          return this.$message.error('未知错误，无状态')
        }
      }
    },
    inquiry() {
      let data = {
        actId: ''
      }
      inquiry(data).then(res => {
        this.tableData = res.data
      })
    },
    querytoDo(res) {
      this.dialogVisible = true
      this.text = res
    },
    handleClose(done) {
      this.dialogVisible = false
    },
    firstinventory() {
      information(0).then(response => {
        this.chart = response.data
        if (this.chart.whouseList.length !== 0) {
          for (let index of this.chart.corpsListWhouse) {
            this.master.push({
              name: index.fName,
              value: index.fGrossweightD
            })
            this.name.push(index.fName)
          }
          for (let index of this.chart.goodslistWhouse) {
            this.commodity.push(index.fName)
            this.commoditytwo.push(index.fGrossweightD)
          }
          this.drawLine()
          this.drawLinetwo()
          this.commoDity()
        } else {
          this.chart = {
            corpsListWhouse: [{
              balance: 0,
              fCorpid: 58,
              fGrossweightD: 0,
              fName: '展示数据',
              fTotalgross: 10000,
              fWarehouseName: '展示数据'
            }],
            goodslistWhouse: [{
              balance: 0,
              fGoodsid: 13,
              fGrossweightD: 0,
              fName: '展示商品',
              fTotalgross: 10000,
              fWarehouseName: '展示数据'
            }],
            whouseList: [{
              fGrossweightD: 0,
              fName: '展示数据',
              fTotalgross: 10000,
              fWarehouseid: 36
            }]
          }
          for (let index of this.chart.corpsListWhouse) {
            this.master.push({
              name: index.fName,
              value: index.fGrossweightD
            })
            this.name.push(index.fName)
          }
          for (let index of this.chart.goodslistWhouse) {
            this.commodity.push(index.fName)
            this.commoditytwo.push(index.fGrossweightD)
          }

          this.drawLine()
          this.drawLinetwo()
          this.commoDity()
        }
      })
    },
    query() {
      this.master = []
      this.commodity = []
      this.commoditytwo = []
      this.name = []
      if (this.select === '') {
        return this.select
      } else {
        information(this.select).then(response => {
          this.chart = response.data
          for (let index of this.chart.corpsListWhouse) {
            this.master.push({
              name: index.fName,
              value: index.fGrossweightD
            })
            this.name.push(index.fName)
          }
          for (let index of this.chart.goodslistWhouse) {
            this.commodity.push(index.fName)
            this.commoditytwo.push(index.fGrossweightD)
          }
          this.drawLine()
          this.drawLinetwo()
          this.commoDity()
        })
      }
    },
    jump(res) {
      this.$router.push({ path: res })
    },
    //设置单元格边框
    cellStyle({ row, column, rowIndex, columnIndex }) {
      return 'border-bottom: 1px dashed rgb(223, 230, 236)'
    },
    //查询消息中心
    getList() {
      this.loading = true
      listCorps(this.queryParams).then(response => {
        this.tableDataTwo = response.rows
      })
    },
    //查询仓库
    warehouses() {
      warehouse().then(response => {
        this.warehouse = []
        for (let index of response.rows) {
          this.warehouse.push({
            fName: index.fName,
            fWarehouseid: index.fWarehouseid
          })
        }
      })
    },
    goTarget(href) {
      window.open(href, '_blank')
    },
    //仓库图表
    drawLine() {
      // 基于准备好的dom，初始化echarts实例，所以只能在mounted中调用
      let myChart = this.$echarts.init(document.getElementById('box'))
      // 绘制图表
      myChart.setOption({
        title: {
          text: this.chart.whouseList[0].fName + '统计',
          subtext: '实时数据',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          bottom: 10,
          left: 'center',
          data: ['空闲库容', '占用库容']
        },
        series: [
          {
            type: 'pie',
            name: '实时数据',
            radius: '65%',
            center: ['50%', '50%'],
            selectedMode: 'single',
            data: [
              {
                label: {
                  backgroundColor: '#eee',
                  borderColor: '#777',
                  borderWidth: 1,
                  borderRadius: 4,
                  rich: {
                    title: {
                      color: '#eee',
                      align: 'center'
                    },
                    abg: {
                      backgroundColor: '#333',
                      width: '100%',
                      align: 'right',
                      height: 25,
                      borderRadius: [4, 4, 0, 0]
                    },
                    Sunny: {
                      height: 30,
                      align: 'left'
                    },
                    Cloudy: {
                      height: 30,
                      align: 'left'
                    },
                    Showers: {
                      height: 30,
                      align: 'left'
                    },
                    weatherHead: {
                      color: '#333',
                      height: 24,
                      align: 'left'
                    },
                    hr: {
                      borderColor: '#777',
                      width: '100%',
                      borderWidth: 0.5,
                      height: 0
                    },
                    value: {
                      width: 20,
                      padding: [0, 20, 0, 30],
                      align: 'left'
                    },
                    valueHead: {
                      color: '#333',
                      width: 20,
                      padding: [0, 20, 0, 30],
                      align: 'center'
                    },
                    rate: {
                      width: 40,
                      align: 'right',
                      padding: [0, 10, 0, 0]
                    },
                    rateHead: {
                      color: '#333',
                      width: 40,
                      align: 'center',
                      padding: [0, 10, 0, 0]
                    }
                  }
                }
              },
              { value: this.chart.whouseList[0].fGrossweightD, name: '占用库容' },
              {
                value: parseFloat(this.chart.whouseList[0].fTotalgross - this.chart.whouseList[0].fGrossweightD).toFixed(1),
                name: '空闲库容'
              }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      })
    },
    drawLinetwo() {
      // 基于准备好的dom，初始化echarts实例，所以只能在mounted中调用
      let myChart = this.$echarts.init(document.getElementById('cargoOwner'))
      // 绘制图表
      myChart.setOption({
        title: {
          text: this.chart.whouseList[0].fName + '货权方统计',
          subtext: '实时数据',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          bottom: 10,
          left: 'center',
          data: this.name
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: ['40%', '60%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                // show: true,
                fontSize: '30',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data:
            this.master
          }
        ]
      })
    },
    commoDity() {
      // 基于准备好的dom，初始化echarts实例，所以只能在mounted中调用
      let myChart = this.$echarts.init(document.getElementById('commoDity'))
      // 绘制图表
      myChart.setOption({
        title: {
          text: this.chart.whouseList[0].fName + '商品统计',
          subtext: '实时数据',
          left: 'center'
        },
        color: ['#3398DB'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: this.commodity,
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '实时状态',
            type: 'bar',
            barWidth: '60%',
            data: this.commoditytwo
          }
        ]
      })
    }
  }
}
</script>

<style scoped lang="scss">
.block {
  width: 68%;
  float: left;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  height: 350px;

  li:hover {
    background-color: #025184;
  }

  li:nth-child(6), li:nth-child(7), li:nth-child(8), li:nth-child(9), li:nth-child(10) {
    background-color: #2f4554;
  }

  li:nth-child(6):hover, li:nth-child(7):hover, li:nth-child(8):hover, li:nth-child(9):hover, li:nth-child(10):hover {
    background-color: #2f4454d1;
  }

  li {
    width: 18%;
    height: 150px;
    background-color: #1c84c6;
    margin-left: 10px;
    text-align: center;
    color: #FFFFFF;
    border-radius: 10px;
    cursor: pointer;

    div {
      margin-top: 40px;

      p {
        font-size: 20px;
      }
    }
  }
}

.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>
<style>
.text img {
  max-width: 100%;
  height: auto;
}
</style>
