<template>
  <layout>
    <uv-sticky
      bgColor="#fff"
      customNavHeight="0"
    >
      <uv-navbar
        :fixed="false"
        title="全部订单"
        @leftClick="$onClickLeft"
      />
      <uv-tabs
        :list="navList"
        @click="click"
        lineColor="#f56c6c"
        :current="actionType"
      >
        ></uv-tabs>
    </uv-sticky>
    <view class="orderList">
      <order
        :data="item"
        v-for="(item, index) in orderListData"
        :key="actionType + '_' + index"
        @refresh="handleRefresh"
      />
    </view>
  </layout>
</template>

<script setup>
import { ref } from 'vue'
import { navigateTo, back } from '@/utils/router'
import { onLoad } from '@dcloudio/uni-app'
import { useMainStore } from '@/store/store'
import { orderList } from '@/api/order'

const orderListData = ref([])
const actionType = ref(0)


const navList = ref([
  { name: "全部", value: -1, },
  { name: "未支付", value: 0, },
  { name: "待发货", value: 1, },
  { name: "待收货", value: 2, },
  { name: "待评价", value: 3, },
  { name: "已完成", value: 4, },
  // { name: "退款中", value: 5, },
  // { name: "已退款", value: 6, },
  // { name: "退款", value: 7, },
])


const handleOrderList = async (option) => {
  orderListData.value = []
  let res = await orderList(option)
  orderListData.value = res
  console.log("gxs --> % data:\n", res)
}

const handleRefresh = () => {
  handleOrderList({
    type: navList.value[actionType.value].value + 1
  })
}


const click = (data) => {
  handleOrderList({
    type: data.value
  })
  console.log("--> % click % data:\n", data)

}

onLoad(({ type }) => {
  handleOrderList({
    type
  })
  if (type < 0 || !type) {
    actionType.value = 0
  } else {
    actionType.value = Number(type) + 1
  }
  console.log("--> % onLoad % actionType.value:\n", actionType.value)
  console.log("--> % onLoad % type:\n", type)

})



</script>

<style lang="less">
.orderList {
  padding: 20rpx 0;
}
</style>
