<template>
  <view class="warpper">
    <view class="sum-box">
      <view class="">
        <view class="title">交易金额</view>
        <view class="value">{{ topInfo.tradingVolume }}</view>
      </view>
      <view class="">
        <view class="title">总交易量(吨)</view>
        <view class="value">{{ topInfo.volumeOfBusiness }}</view>
      </view>
    </view>
    <uGap></uGap>
    <scroll-list ref="list" :option="option" @load="upCallback" @refresh="downCallback" style="background-color: #ffffff">
      <view class="card-box" v-for="(item, index) in list" :key="index">
        <view class="header">
          <view class="left-title">{{ item.orderId }}</view>
          <view class="right-title">¥ {{ item.totalOfferPrice }}</view>
        </view>
        <view class="content" v-for="(subItem, subIndex) in item.supplierOrderList[0].orderItems" :key="subIndex">
          <!-- <image class="image" :src="/static/imgs/client/client-default.png" mode=""></image> -->
          <image class="image" :src="subItem.productImg || 'https://qncloud.oss-cn-shenzhen.aliyuncs.com/paper_shopkeeper/paper-default-small.png'" mode=""></image>
          <view class="">
            <view class="title">{{ subItem.productName }}</view>
            <view class="desc">
              {{ subItem.brandName }}/{{ subItem.categoryName }}/{{ subItem.gramWeight }}g/{{ subItem.length }}*{{ subItem.width }}/{{
                subItem.pieceQuantity
              }}张
            </view>
          </view>
        </view>
        <!-- <view class="content">
					<image class="image" src="/static/imgs/client/client-default.png" mode=""></image>
					<view class="">
						<view class="title">丽盈白卡</view>
						<view class="desc">白卡纸/丽盈/350g/787*1092/2200张</view>
					</view>
				</view> -->
        <view class="other">
          <view class="time">{{ item.createTime }}</view>
          <view class="btn">
            更多详情
            <image class="icon" src="/static/imgs/client-detail/arrow-right-icon.png"></image>
          </view>
        </view>
        <uGap></uGap>
      </view>
    </scroll-list>
  </view>
</template>

<script>
import uGap from '@/components/u-gap/u-gap.vue'
import { getBasePaperDeals, getOrderVolumeStatistics } from '@/apis/clientDetailApi.js'

export default {
  components: { uGap },
  props: {
    // 当前企业id
    id: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      option: {
        size: 10,
        auto: true,
        emptyText: '暂无原纸交易~',
        background: '#F7F8FA',
        disabled: false,
        emptyImage: '/static/imgs/order/order-empty.png'
      },
      params: {
        asc: '',
        desc: '',
        customerEnterpriseId: this.id, 
        mallSupplierId: this.$store.state.supplierInfo.supplierId || null, // 供应商id
        // customerEnterpriseId: '651107734133018624', // 客户企业ID
        // mallSupplierId: '670334117090562048', // 供应商id
        status: '0' // 状态 0 全部 待发货/30106,待收货/30107,待借款/30207,已完成/30104
      },
      pagination: {
        pageNum: 0, // 初始会执行一次下拉加载
        pageSize: 10
      },
      orderParams: {
        beginDate: '',
        // currentSupplier: '670334117090562048',
        currentSupplier: this.$store.state.supplierInfo.supplierId || null,
        endDate: ''
      },
      list: [],
      topInfo: {}
    }
  },

  created() {
    if (this.id) {
      this.getOrderVolumeStatistics()
    }
  },
  methods: {
    // 顶部统计数据
    getOrderVolumeStatistics() {
      getOrderVolumeStatistics({ ...this.orderParams, customerEnterpriseId: this.id }).then((res) => {
        // console.log('原纸交易顶部统计数据', res)
        this.topInfo = res
      })
    },
    getList() {
      return new Promise((resolve, reject) => {
        getBasePaperDeals({ ...this.params, ...this.pagination })
          .then((res) => {
            // console.log('原纸交易', res)
            if (res) {
              if (this.pagination.pageNum == 1) {
                this.list = res.records
              } else {
                this.list = this.list.concat(res.records)
              }
              // this.list = []
              // this.list = [...this.list, ...[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]
              resolve({ list: this.list, total: res.total })
            } else {
              reject()
            }
          })
          .catch((err) => {
            reject(err)
          })
      })
    },
    downCallback() {
      this.pagination.pageNum = 1
      this.getList()
        .then(({ list, total }) => {
          this.$refs.list.refreshSuccess({ list, total })
        })
        .catch(() => {
          this.$refs.list.refreshFail()
        })
    },
    upCallback() {
      this.pagination.pageNum++
      this.getList()
        .then(({ list, total }) => {
          this.$refs.list.loadSuccess({ list, total })
        })
        .catch(() => {
          this.$refs.list.loadFail()
        })
    }
  }
}
</script>

<style lang="scss">
.warpper {
  width: 750rpx;
  .sum-box {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    // text-align: center;
    height: 184rpx;
    background: url('/static/imgs/client-detail/yzjy-icon.png') no-repeat;
    background-size: 100%;
    .title {
      font-size: 26rpx;
      color: #ffffff;
      letter-spacing: 0;
      font-weight: 500;
    }
    .value {
      font-size: 56rpx;
      color: #ffffff;
      letter-spacing: 0;
      text-align: left;
      font-weight: 500;
      margin-top: 16rpx;
    }
  }
  .card-box {
    .header {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      height: 88rpx;
      background: #ffffff;
      border-bottom: 2rpx solid rgba(221, 221, 221, 0.5);
      padding: 0rpx 32rpx;
      .left-title {
        font-size: 30rpx;
        color: #000000;
        letter-spacing: 0;
        font-weight: 600;
      }
      .right-title {
        font-size: 30rpx;
        color: #ff5368;
        letter-spacing: 0;
        text-align: right;
        font-weight: 500;
      }
    }
    .content {
      display: flex;
      flex-direction: row;
      align-items: center;
      height: 148rpx;
      background: #ffffff;
      border-bottom: 2rpx solid rgba(221, 221, 221, 0.5);
      padding: 0rpx 32rpx;
      .image {
        width: 100rpx;
        height: 100rpx;
        flex: 0 0 100rpx;
        margin-right: 20rpx;
      }
      .title {
        font-size: 30rpx;
        color: #333333;
        letter-spacing: 0;
        text-align: left;
        font-weight: 400;
      }
      .desc {
        padding-top: 26rpx;
        font-size: 26rpx;
        color: #888888;
        letter-spacing: 0;
        text-align: left;
        font-weight: 400;
      }
    }
    .other {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      height: 80rpx;
      background: #ffffff;
      padding: 0rpx 32rpx;
      .time {
        font-size: 26rpx;
        color: #888888;
        letter-spacing: 0;
        text-align: left;
        font-weight: 400;
      }
      .btn {
        font-size: 28rpx;
        color: #007aff;
        letter-spacing: 0;
        text-align: center;
        font-weight: 500;
        display: flex;
        align-items: center;
      }
      .icon {
        width: 24rpx;
        height: 24rpx;
        margin-left: 6rpx;
      }
    }
  }
}
</style>
