<template>
  <!-- #ifdef H5 -->
  <zj-page-layout
    :hasFooter="false"
    :isScroll="true"
    :refresherTriggered="refresherTriggered"
    @refresherrefresh="refresherrefresh"
  >
    <view class="all-container">
      <view class="card" v-if="type == 'M'">
        <view class="top">
          <text class="iconfont icon-kucun icon"></text>
          <view class="title">辅材库存</view>
          <view class="right" @tap="navToPage('/packageMaterial/pages/stock/index')"
            >我的库存<text class="iconfont icon-jinru"></text
          ></view>
        </view>
        <view class="center">
          <view class="text">无辅材/配件库存可以申请购买</view>
          <u-button
            type="primary"
            text="去购买"
            shape="circle"
            @click="navToPage(`/packageMaterial/pages/apply/index`)"
          ></u-button>
        </view>
        <!-- <view class="bottom">
          <view class="it" @tap="navToPage(`/packageMaterial/pages/stock/returnList?type=NEW`)">
            <view class="num">{{ count.newRefundCount || 0 }}</view>
            <view class="text">新件待返还</view>
          </view>
          <view class="it" @tap="navToPage(`/packageMaterial/pages/stock/returnList?type=OLD`)">
            <view class="num">{{ count.oldRefundCount || 0 }}</view>
            <view class="text">旧件待返还</view>
          </view>
        </view> -->
      </view>
      <view class="card" v-if="type == 'M'">
        <view class="top">
          <text class="iconfont icon-fucai icon"></text>
          <view class="title">辅材销售</view>
          <view class="right" @tap="navToPage(`/packageMaterial/pages/sale/orderList?type=M`)"
            >辅材订单<text class="iconfont icon-jinru"></text
          ></view>
        </view>
        <view class="center">
          <view class="text">用户需要使用辅材，销售收款</view>
          <u-button
            type="primary"
            text="辅材收款"
            shape="circle"
            @click="navToPage(`/packageMaterial/pages/sale/index?type=M`)"
          ></u-button>
        </view>
        <view class="bottom">
          <view class="it">
            <view class="num">{{ count.materialSalesCount || 0 }}</view>
            <view class="text">今日下单（单）</view>
          </view>
          <view class="it">
            <view class="num">{{ count.materialSalesAmount || 0 }}</view>
            <view class="text">今日销售金额</view>
          </view>
        </view>
      </view>
      <view class="card" v-if="type == 'P'">
        <view class="top">
          <text class="iconfont icon-kucun icon"></text>
          <view class="title">配件库存</view>
          <view class="right" @tap="navToPage('/packageAttachment/pages/sparePartsInventory/index')"
            >我的库存<text class="iconfont icon-jinru"></text
          ></view>
        </view>
        <view class="center">
          <view class="text">无辅材/配件库存可以申请购买</view>
          <u-button
            type="primary"
            text="去购买"
            shape="circle"
            @click="navToPage(`/packageAttachment/pages/applicationParts/index`)"
          ></u-button>
        </view>
        <!-- <view class="bottom">
          <view class="it" @tap="navToPage(`/packageAttachment/pages/returnOfNewParts/index`)">
            <view class="num">{{ count.newRefundCount || 0 }}</view>
            <view class="text">新件待返还</view>
          </view>
          <view class="it" @tap="navToPage(`/packageAttachment/pages/returnOfOldParts/index`)">
            <view class="num">{{ count.oldRefundCount || 0 }}</view>
            <view class="text">旧件待返还</view>
          </view>
        </view> -->
      </view>
      <view class="card" v-if="type == 'P'">
        <view class="top">
          <text class="iconfont icon-peijian icon"></text>
          <view class="title">配件销售</view>
          <view class="right" @tap="navToPage(`/packageMaterial/pages/newSale/orderList?type=P`)"
            >配件订单<text class="iconfont icon-jinru"></text
          ></view>
        </view>
        <view class="center">
          <view class="text">用户需要使用配件，销售收款</view>
          <u-button
            type="primary"
            text="配件收款"
            shape="circle"
            @click="navToPage(`/packageMaterial/pages/newSale/index?type=P`)"
          ></u-button>
        </view>
        <view class="bottom">
          <view class="it">
            <view class="num">{{ count.partsSalesCount || 0 }}</view>
            <view class="text">今日下单（单）</view>
          </view>
          <view class="it">
            <view class="num">{{ count.partsSalesAmount || 0 }}</view>
            <view class="text">今日销售金额</view>
          </view>
        </view>
      </view>
    </view>
  </zj-page-layout>
  <!-- #endif -->

  <!-- #ifndef H5 -->
  <web-view
    :src="webViewHref(`/packageMaterial/pages/index`, pam, crossPagePam)"
    @message="crossPage.$listener"
  ></web-view>
  <!-- #endif -->
</template>

<script>
// #ifdef H5
export default {
  data() {
    return {
      refresherTriggered: false,
      count: {},
    }
  },

  onLoad({ type }) {
    this.type = type
    this.getDetail();
  },

  methods: {
    getDetail() {
      this.$api.post('/material/worker/stock/my/data/count')
      .then(res => {
        this.count = res.data || {};
      }).finally(res => {
        this.refresherTriggered = false;
      })
    },

    // 下拉刷新
    refresherrefresh() {
      this.refresherTriggered = true;
      this.getDetail();
    },

    navToPage(url) {
      if(!url) return this.$toast('敬请期待～');

      this.$navToPage({
        url
      })
    }
  },
}

// #endif
// #ifndef H5
export default {
  data() {
    return {
      pam: {},
    }
  },
  onLoad(pam) {
    this.pam = pam;
  }
}
// #endif
</script>

<style lang="scss" scoped>
.all-container {
  padding: 20rpx;
  .card {
    @include zj-card;
    margin-bottom: 20rpx;
    padding: 40rpx 20rpx;
    &:nth-child(1),
    &:nth-child(3) {
      .top {
        .icon {
          background: $assist-color;
        }
      }
    }
    &:nth-child(2) {
      .top {
        .icon {
          background: $theme-color;
        }
      }
    }
    .top {
      display: flex;
      align-items: center;
      .icon {
        width: 40rpx;
        height: 40rpx;
        border-radius: 50%;
        font-size: 28rpx;
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .title {
        flex: 1;
        margin-left: 12rpx;
        font-size: 32rpx;
        font-weight: 500;
      }
      .right {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        color: $sec-font;
        .iconfont {
          font-size: 24rpx;
          margin-left: 8rpx;
        }
      }
    }
    .center {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 30rpx;
      .text {
        font-size: 28rpx;
        color: $sec-font;
      }
      ::v-deep .u-button {
        width: 160rpx;
        height: 60rpx;
        margin: 0;
      }
    }
    .bottom {
      display: flex;
      margin-top: 40rpx;
      .it {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        .num {
          font-size: 40rpx;
          font-weight: 600;
          color: $theme-color;
        }
        .text {
          font-size: 24rpx;
          font-weight: 500;
          margin-top: 12rpx;
        }
      }
    }
  }
}
</style>
