<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-05-11 10:05:31
 * @Description: file content
 * @FilePath: \oms\pages\home\index.vue
-->
<template>
  <view class="home">
    <!-- <WaterMark></WaterMark> -->
    <view class="nav">
      <view :style="{ paddingTop }">
        <view class="title" :style="[{ height }, { lineHeight: height }]">首页</view>
      </view>
    </view>
    <view class="main">
      <view class="header">
        <u-swiper :list="bannerList" radius="0" interval="5000" circular></u-swiper>
        <!-- <view class="h-left">
        <text class="name">大数华创</text>
        <text class="txt">提升工作效率，降低管理难度</text>
        <view class="line"></view>
      </view>
      <view class="h-right"></view> -->
      </view>
      <view class="content">
        <view class="msg-box">
          <view class="tab-date-wrap">
            <text class="tab-date-item" @click="getReport('week')" :class="{ dateActive: tabDate == 'week' }">
              本周
            </text>
            <text class="tab-date-item" @click="getReport('month')" :class="{ dateActive: tabDate == 'month' }">
              本月
            </text>
          </view>
          <view class="date-msg">
            <u-row justify="space-between">
              <u-col span="4">
                <view class="center flex-column" @click="handleHomeLink('/pages/openSeaCustomer/index')">
                  <view class="num">{{ newCustomer }}</view>
                  <view class="txt">新增客户</view>
                </view>
              </u-col>
              <u-col span="4">
                <view class="center flex-column" @click="handleHomeLink('/pages/project/index')">
                  <view class="num">{{ newBusiness }}</view>
                  <view class="txt">新增项目</view>
                </view>
              </u-col>
              <u-col span="4">
                <view class="center flex-column" @click="handleHomeLink('/pages/schedule/index?type=1', 2)">
                  <view class="num">{{ newTask }}</view>
                  <view class="txt">督办事项</view>
                </view>
              </u-col>
            </u-row>
          </view>
        </view>
        <view class="menu-wrap">
          <u-row justify="space-between" gutter="14">
            <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/openSeaCustomer/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu5.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">公海客户</view>
                  <view class="tit2">公海客户管理</view>
                </view>
              </view>
            </u-col>
            <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/customer/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu1.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">客户管理</view>
                  <view class="tit2">客户信息管理</view>
                </view>
              </view>
            </u-col>
          </u-row>
          <u-row justify="space-between" gutter="14">
            <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/project/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu2.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">项目管理</view>
                  <view class="tit2">项目进展查询</view>
                </view>
              </view>
            </u-col>
            <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/contract/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu3.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">合同管理</view>
                  <view class="tit2">合同信息查阅</view>
                </view>
              </view>
            </u-col>
          </u-row>
          <u-row justify="space-between" gutter="14">
            <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/distributor/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu4.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">经销商代理商</view>
                  <view class="tit2">经销商代理商展示</view>
                </view>
              </view>
            </u-col>
            <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/inviteTenders/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu6.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">招标信息</view>
                  <view class="tit2">招标信息查询</view>
                </view>
              </view>
            </u-col>
          </u-row>
          <u-row justify="space-between" gutter="14">
            <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/partners/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu7.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">合作伙伴</view>
                  <view class="tit2">合作伙伴展示</view>
                </view>
              </view>
            </u-col>
            <!-- <u-col span="6">
              <view class="menu-item flex_l flex-colunm" @click="handleHomeLink('/pages/inviteTenders/index')">
                <view class="menu-img-box">
                  <image class="menu-img" src="../../static/images/menu6.png" mode="scaleToFill" />
                </view>
                <view class="menu-info flex flex-column">
                  <view class="tit1">招标信息</view>
                  <view class="tit2">招标信息查询</view>
                </view>
              </view>
            </u-col> -->
          </u-row>
        </view>

        <view class="data-container">
          <h4>个人看板</h4>
          <view class="flex flex-wrap flex-around">
            <view class="board-data" v-for="(v, i) in privateBoard" :key="i">
              <view>
                <u-text :bold="true" :text="v.report_data"></u-text>
              </view>
              <view>
                <u-text lines="1" :text="v.report_name"></u-text>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view class="check" @click="toCheckIn">卡</view>
  </view>
</template>

<script>
  import indexApi from '@/api/system/index.js'
  import homeApi from '@/api/home'
  import to from 'await-to-js'
  export default {
    name: 'omsIndex',
    data() {
      return {
        showSaleType: false,
        showCollectionType: false,
        saleVal: '全年',
        collectionVal: '全年',
        saleType: 0,
        collectionType: 0,
        quarter: [
          {
            name: '一季度',
            type: 1,
          },
          {
            name: '二季度',
            type: 2,
          },
          {
            name: '三季度',
            type: 3,
          },
          {
            name: '四季度',
            type: 4,
          },
          {
            name: '全年',
            type: 0,
          },
        ],
        bannerList: [
          require('@/static/images/swiper/banner1.png'),
          require('@/static/images/swiper/banner2.png'),
          require('@/static/images/swiper/banner3.png'),
        ],
        privateBoard: [], //个人看板数据
        height: '',
        paddingTop: '',
        tabDate: 'week',
        newCustomer: 0,
        newBusiness: 0,
        newTask: 0,
      }
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    mounted() {
      this.getHomeConfig()
    },
    onShow() {
      this.getReport('week')
    },

    methods: {
      // 获取首页新增数据
      async getReport(type) {
        this.tabDate = type
        let params = { viewInterval: this.tabDate }
        const [err, res] = await to(homeApi.getReportData(params))
        if (err) return
        if (res.code == 200) {
          this.newCustomer = res.data.newCustomer
          this.newBusiness = res.data.newBusiness
          this.newTask = res.data.newTask
        }
      },
      handleHomeLink(url, linkType) {
        if (!url) {
          uni.showToast({
            title: '功能开发中~',
            icon: 'none',
          })
          return
        }
        if (linkType && linkType == '2') {
          uni.reLaunch({
            url,
          })
        } else {
          uni.navigateTo({
            //保留当前页面，跳转到应用内的某个页面
            url,
          })
        }
      },
      // 获取首页配置
      async getHomeConfig() {
        const [err, res] = await to(
          indexApi.getHomeReport({
            module_code: 'HomePage',
          })
        )
        if (err) return
        if (res && res.data) {
          const obj = JSON.parse(res.data.configInfo)
          this.privateBoard = obj.num_report_config || []
          this.getHomeNumReportData()
        }
      },
      // 获取首页个人看板数据
      async getHomeNumReportData() {
        let ids = this.privateBoard.map((item) => {
          return item.id
        })
        const {
          data: { num_report_response },
        } = await indexApi.getHomeNumReportData({ ids: ids })
        let privateBoardData = []
        this.privateBoard.forEach((item, index) => {
          num_report_response.forEach((val) => {
            if (item.id === val.id) {
              this.privateBoard[index].report_data = val.data
              privateBoardData.push(this.privateBoard[index])
            }
          })
        })
        this.privateBoard = privateBoardData.splice(0, 6)
      },
      toCheckIn() {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/home/checkIn',
        })
      },
    },
  }
</script>
<style>
  page {
    background: #f2f3f5;
  }
</style>
<style lang="scss" scoped>
  .home {
    padding-top: 200rpx;
    // position: relative;
    .check {
      position: fixed;
      right: 20rpx;
      bottom: 20rpx;
      width: 90rpx;
      height: 90rpx;
      line-height: 90rpx;
      text-align: center;
      border-radius: 45rpx;
      background-color: #3e7ef8;
      color: #fff;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    }
    .nav {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 556rpx;
      background: #3e7ef8;
      border-radius: 0 0 92rpx 92rpx;
      z-index: -1;

      .title {
        text-align: center;
        font-size: 32rpx;
        font-weight: bold;
        color: #ffffff;
      }
    }

    .main {
      box-sizing: border-box;
      padding: 0 0 46rpx;
      position: absolute;
      width: 100%;
      height: calc(100vh - 200rpx);
      .content {
        padding: 0 32rpx;
      }
      // overflow: hidden;
      .msg-box {
        width: 100%;
        height: 185rpx;
        background: #ffffff;
        box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
        border-radius: 31rpx 31rpx 31rpx 31rpx;
        margin: 0 auto;

        .tab-date-wrap {
          padding: 8rpx 0 24rpx 38rpx;

          .tab-date-item {
            font-size: 24rpx;
            font-weight: bold;
            color: #d8e5fe;
            margin-right: 16rpx;
          }

          .dateActive {
            font-size: 28rpx;
            color: #3e7ef8;
          }
        }

        .date-msg {
          .num {
            font-size: 38rpx;
            font-weight: bold;
            color: #fe6936;
            margin-bottom: 4rpx;
          }

          .txt {
            font-size: 24rpx;
            color: #646464;
          }
        }
      }

      .menu-wrap {
        .menu-item {
          margin-top: 32rpx;
          background: #ffffff;
          box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
          border-radius: 31rpx;
          padding: 40rpx 0 40rpx 52rpx;

          .menu-img-box {
            margin-right: 14rpx;
            display: flex;
            align-items: center;
            justify-content: center;
          }

          .menu-img {
            width: 36px;
            height: 36px;
          }

          .menu-info {
            display: flex;

            .tit1 {
              font-size: 28rpx;
              font-weight: bold;
              color: #323232;
              margin-bottom: 12rpx;
            }

            .tit2 {
              font-size: 24rpx;
              color: #646464;
            }
          }
        }
      }

      .rank-wrap {
        margin-top: 34rpx;

        .rank-tit {
          margin-bottom: 18rpx;

          .rank-tit-img {
            margin: 0 10rpx 0 28rpx;
            width: 31rpx;
            height: 31rpx;
          }

          text {
            font-size: 28rpx;
            font-weight: bold;
            color: #323232;
          }
        }

        .rank-list-wrap {
          width: 100%;
          background: #ffffff;
          border-radius: 31rpx;

          .rank-th {
            padding: 34rpx 0 20rpx 72rpx;
          }

          .rank-list {
            margin-bottom: 24rpx;

            .rank-item {
              .rank-box {
                .rank-img {
                  width: 41px;
                  height: 42px;
                }

                .rank {
                  width: 41px;
                  height: 42px;
                  line-height: 42px;
                  font-size: 28rpx;
                  font-weight: bold;
                  color: #969696;
                }
              }

              padding: 19rpx 0 19rpx 72rpx;

              &:not(:last-child) {
                border-bottom: 2rpx solid #f2f3f5;
              }
            }
          }
        }

        .view-all {
          font-size: 24rpx;
          color: #3e7ef8;
          text-align: center;
          height: 60rpx;
        }
      }

      .data-container {
        background-color: #fff;
        box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
        border-radius: 31rpx 31rpx 31rpx 31rpx;
        margin: 0 auto;
        margin-top: 32rpx;
        padding: 0 20rpx 20rpx;

        h4 {
          font-size: 28rpx;
          line-height: 80rpx;
          font-weight: bold;
          color: #323232;
          padding-left: 40rpx;
        }
        .board-data {
          width: 46%;
          border-radius: 10rpx;
          padding: 0 20rpx;
          border: 1px solid #eee;
          line-height: 50rpx;
          margin-bottom: 20rpx;
        }
        .echarts {
          height: 500rpx;
          box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
          border-radius: 31rpx 31rpx 31rpx 31rpx;

          + .echarts {
            margin-top: 32rpx;
          }

          .chart {
            height: 420rpx;
          }
        }
      }
    }
  }
</style>
