<template>
  <view class="main">
    <div class="fliter">
      <!-- <div class="select_box">
        <div class="search_box">
          <img
            src="/static/images/home/search_icon.svg"
            alt=""
            class="search_icon"
          />
          <input
            v-model="searchText"
            confirm-type="search"
            @confirm="getorderList"
            placeholder="请输入关键字"
            class="select_input"
          />
        </div>
        <div class="select_btn" @click="handleSelect">
          <img
            src="/static/images/home/select_icon.svg"
            alt=""
            class="select_icon"
          />
          筛选
        </div>
      </div> -->

      <div class="tabs" v-if="searchType !== '4'">
        <div
          class="tabs_item"
          :class="currentTab === item.value ? 'tab_active' : ''"
          v-for="(item, idx) in tabList"
          :key="idx"
          @click="handleTab(item.value)"
        >
          {{ item.label }}
        </div>
      </div>

      <div class="sum_count" v-if="TotalCount > 0">
        共<span>{{ TotalCount }}</span
        >笔订单, 合计<span>{{ TotalAmount }}</span
        >元
      </div>
    </div>

    <template v-if="orderList && orderList.length > 0">
      <div
        @click="goEvaluate(item)"
        v-for="(item, idx) in orderList"
        :key="idx"
      >
        <OrderItem :obj="item" @handleGetOrderList="handleGetOrderList" />
      </div>
    </template>
    <no-data text="暂无订单数据" v-else />
  </view>
</template>

</view>
</template>
<script>
import NoData from "../../../components/noData.vue";
import OrderItem from "./components/orderItem.vue";
export default {
  data() {
    return {
      tabList: [
        {
          label: "全部订单",
          value: 1,
        },
        {
          label: "待付款",
          value: 2,
        },
        {
          label: "待发货",
          value: 3,
        },
        {
          label: "待收货",
          value: 4,
        },
        {
          label: "已完成",
          value: 5,
        },
      ],
      currentTab: 1,
      orderList: [],
      pageMsg: {
        pageIndex: 1,
        pageSize: 10,
      },
      searchType: "",
    };
  },
  components: {
    OrderItem,
    NoData,
  },
  onLoad(query) {
    if (query.type) {
      this.searchType = query.type;
    }
    // 获取订单数据
    this.handleGetOrderList();
  },
  methods: {
    handleTab(val) {
      this.currentTab = val;
      this.orderList = [];
      let type =
        val === 1
          ? ""
          : val === 2
          ? "1005"
          : val === 3
          ? "1010,2000"
          : val === 4
          ? "2010"
          : val === 5
          ? "3000"
          : "";
      this.handleGetOrderList(type);
    },
    // 获取订单数据
    async handleGetOrderList(status) {
      uni.showLoading({
        title: "正在加载...",
        mask: true,
      });
      const req = {
        action_type: "GetMallOrderList",
        salebillType: 3000,
        salebillState: status || "",
        PageIndex: this.pageMsg.pageIndex,
        pageSize: this.pageMsg.pageSize,
        ownerUnitId: 911,
        requestType: "application/x-www-form-urlencoded",
      };
      const data = await this.$api.postCoop(req);
      console.log("data", data);
      // 手动添加待付款、待发货、待收货
      let list = data.Data ? data.Data.List : [];
      let resList = [];
      if (list && list.length > 0) {
        if (this.searchType === "4") {
          list.forEach((item) => {
            if (
              item.SALEBILL_STATE >= 3000 &&
              item.SALEBILL_STATE !== 8999 &&
              item.SALEBILL_STATE !== 9000 &&
              item.SALEBILL_STATE !== 9999
            ) {
              resList.push(item);
            }
          });
        } else {
          list.forEach((item) => {
            if (
              item.SALEBILL_STATE === 1005 ||
              item.SALEBILL_STATE === 1010 ||
              item.SALEBILL_STATE === 2000 ||
              item.SALEBILL_STATE === 2010 ||
              item.SALEBILL_STATE === 3000
            ) {
              resList.push(item);
            }
          });
        }
      }
      console.log("获取订单数据", list);
      this.orderList = resList;
      uni.hideLoading();
    },
    goEvaluate(item) {
      console.log("item", item);
      uni.navigateTo({
        url:
          "/pages/order/orderdetail/index?sellchildid=" +
          item.SALEBILL_CHILD_ID +
          "&orderInternal=" +
          item.SALEBILL_ID +
          "&orderStatus=" +
          item.SALEBILL_STATE +
          "&SUPPLIER_NAME=" +
          item.SUPPLIER_NAME,
      });
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  width: 100vw;
  height: 100vh;

  .fliter {
    background: #fff;
    margin-bottom: 24rpx;

    .select_box {
      display: flex;
      flex-direction: row;
      padding: 16rpx 32rpx 8rpx;
      align-items: center;
      justify-content: space-between;

      .search_box {
        width: 558rpx;
        height: 72rpx;
        background: #f2f4f5;
        display: flex;
        flex-direction: row;
        align-items: center;
        border-radius: 36rpx;

        img {
          width: 35rpx;
          height: 35rpx;
          margin: auto 16rpx auto 24rpx;
        }

        .select_input {
          width: 476rpx;
          border: none;
          height: 40rpx;
          font-size: 28rpx;
        }
      }

      .select_btn {
        display: flex;
        flex-direction: row;
        align-items: center;
        font-size: 28rpx;
        color: #6c737a;

        img {
          width: 35rpx;
          height: 35rpx;
          margin-right: 12rpx;
        }
      }
    }

    .tabs {
      width: 100%;
      height: 88rpx;
      display: flex;

      .tabs_item {
        text-align: center;
        color: #6c737a;
        font-size: 28rpx;
        line-height: 88rpx;
        flex: 1;
      }

      .tab_active {
        color: #1890ff;
        font-weight: 600;
        position: relative;
      }

      .tab_active:after {
        content: "";
        display: block;
        position: absolute;
        bottom: 2rpx;
        left: 50%;
        margin-left: -24rpx;
        width: 48rpx;
        height: 6rpx;
        background: #1890ff;
        border-radius: 2rpx;
      }
    }

    .sum_count {
      height: 72rpx;
      background: #fff;
      border-radius: 2rpx;
      padding-left: 32rpx;
      line-height: 72rpx;
      font-size: 28rpx;
      color: #6c737a;
      border-top: 2rpx solid #f2f4f5;

      span {
        color: #020e1a;
      }
    }
  }
}
</style>