<template>
  <view class="order-data-root" @tap="getOrderRealTime">
    <view class="title-root">
      <view>
        <text class="text">今日完成实时数据</text>
        <jx-icon icon="wenhaoxiao" color="#cfcccc" @tap.stop="explain" />
      </view>

      <view class="see-more" v-if="showMore">
        <text>更多</text>
        <jx-icon icon="gengduo" color="#cfcccc" />
      </view>
    </view>

    <view class="order-money">
      <view class="money">
        <text class="number">{{ price }}</text>
        <text>{{ vendorTitle }}</text>
      </view>
      <view class="order">
        <text class="number">{{ count }}</text>
        <text>有效订单量</text>
      </view>
      <view class="order1">
        <text class="number" :class="{'afterNumber': +actualFee > 0}">{{ actualFee }}</text>
        <text>运费</text>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import jxIcon from '@/components/jx-icon/jx-icon.vue'
import { computed, Ref } from 'vue'
import useGlobalFunc from '@/composables/useGlobalFunc'
import { store } from '@/store'
const { wholeCalcPrice, singleCalcPrice } = useGlobalFunc()

interface propsType {
  saleInfo: AnyObject
  showMore?: boolean
  _vendorPayPercentage: number | string
  isNotQuote: boolean
  isShowShop?: boolean
  isZero: boolean
  isUpperfif: boolean
  isOut?: boolean
  isAllplatfrom?: boolean
}
const props = defineProps<propsType>()

/*************************************************
 * 判断门店是否为折扣
 */
const isPointStore = computed(() => {
  return store.getters['storeInfo/isPointStore']
})

/*************************************************
 * 收入说明
 */
const vendorTitle = computed(() => {
  if (isPointStore.value) {
    return '实际支付'
  } else {
    if (props._vendorPayPercentage != 0 && +props._vendorPayPercentage < 50) {
      //扣点
      return '实际支付'
    } else {
      //报价
      return '实际收入'
    }
  }
})

/*************************************************
 * 订单数量
 */
const count: Ref<number | string> = computed(() => {
  return props.saleInfo.count || '0'
})

/*************************************************
 * 扣除运费
 */
const actualFee: Ref<number | string> = computed(() => {
  return props.saleInfo.actualFee || '0'
})

/*************************************************
 * 门店收益
 */
const price = computed(() => {
  if (count.value) {
    if (props.isAllplatfrom || props.isOut) {
      //全平台
      let calcData = {
        vendorPayPercentage: props._vendorPayPercentage,
        actualPayPrice: props.saleInfo.actualPayPrice,
        shopPrice: props.saleInfo.shopPrice,
        isPointStore: isPointStore.value,
        isUpperfif: props.isUpperfif,
        isZero: props.isZero,
        isNotQuote: props.isNotQuote,
        earningPrice: props.saleInfo.earningPrice,
      }
      return wholeCalcPrice(calcData)
    } else {
      //单平台
      let calcData = {
        vendorPayPercentage: props._vendorPayPercentage,
        actualPayPrice: props.saleInfo.actualPayPrice,
        shopPrice: props.saleInfo.shopPrice,
        isPointStore: isPointStore.value,
        earningPrice: props.saleInfo.earningPrice,
      }
      return singleCalcPrice(calcData)
    }
  } else {
    return 0
  }
})

/**
 * 打开说明窗口
 */
function explain() {
  uni.jxAlert({
    title: '说明',
    content: `实际收入: 从当日0时到当前时间的实际获得，不再扣点，已扣除售后退款\r\n有效订单: 统计时间内，已支付订单中未被取消的订单数量`,
  })
}

/**
 * 跳转到营业数据
 */
function getOrderRealTime() {
  if (props.showMore != true) return
  uni.navigateTo({
    url: `/subPages/merchantChild/orderRealTime/orderRealTime?_vendorPayPercentage=${props._vendorPayPercentage}&isShowShop=${props.isShowShop}&isNotQuote=${props.isNotQuote}&isZero=${props.isZero}&isUpperfif=${props.isUpperfif}`,
  })
}
</script>

<style lang="scss" scoped>
@import './orderData.scss';
</style>